/work/obj-fuzz/dist/include/nsSimpleURI.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #ifndef nsSimpleURI_h__ |
7 | | #define nsSimpleURI_h__ |
8 | | |
9 | | #include "mozilla/MemoryReporting.h" |
10 | | #include "nsIURI.h" |
11 | | #include "nsISerializable.h" |
12 | | #include "nsString.h" |
13 | | #include "nsIClassInfo.h" |
14 | | #include "nsISizeOf.h" |
15 | | #include "nsIIPCSerializableURI.h" |
16 | | #include "nsIURIMutator.h" |
17 | | |
18 | | namespace mozilla { |
19 | | namespace net { |
20 | | |
21 | | #define NS_THIS_SIMPLEURI_IMPLEMENTATION_CID \ |
22 | | { /* 0b9bb0c2-fee6-470b-b9b9-9fd9462b5e19 */ \ |
23 | | 0x0b9bb0c2, \ |
24 | | 0xfee6, \ |
25 | | 0x470b, \ |
26 | | {0xb9, 0xb9, 0x9f, 0xd9, 0x46, 0x2b, 0x5e, 0x19} \ |
27 | | } |
28 | | |
29 | | class nsSimpleURI |
30 | | : public nsIURI |
31 | | , public nsISerializable |
32 | | , public nsIClassInfo |
33 | | , public nsISizeOf |
34 | | , public nsIIPCSerializableURI |
35 | | { |
36 | | protected: |
37 | | nsSimpleURI(); |
38 | | virtual ~nsSimpleURI() = default; |
39 | | |
40 | | public: |
41 | | NS_DECL_THREADSAFE_ISUPPORTS |
42 | | NS_DECL_NSIURI |
43 | | NS_DECL_NSISERIALIZABLE |
44 | | NS_DECL_NSICLASSINFO |
45 | | NS_DECL_NSIIPCSERIALIZABLEURI |
46 | | |
47 | | static already_AddRefed<nsSimpleURI> From(nsIURI* aURI); |
48 | | |
49 | | // nsSimpleURI methods: |
50 | | |
51 | | bool Equals(nsSimpleURI* aOther) |
52 | 0 | { |
53 | 0 | return EqualsInternal(aOther, eHonorRef); |
54 | 0 | } |
55 | | |
56 | | // nsISizeOf |
57 | | // Among the sub-classes that inherit (directly or indirectly) from |
58 | | // nsSimpleURI, measurement of the following members may be added later if |
59 | | // DMD finds it is worthwhile: |
60 | | // - nsJSURI: mBaseURI |
61 | | // - nsSimpleNestedURI: mInnerURI |
62 | | // - nsBlobURI: mPrincipal |
63 | | virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override; |
64 | | virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; |
65 | | |
66 | | protected: |
67 | | // enum used in a few places to specify how .ref attribute should be handled |
68 | | enum RefHandlingEnum { |
69 | | eIgnoreRef, |
70 | | eHonorRef, |
71 | | eReplaceRef |
72 | | }; |
73 | | |
74 | | virtual nsresult Clone(nsIURI** aURI); |
75 | | virtual nsresult SetSpecInternal(const nsACString &input); |
76 | | virtual nsresult SetScheme(const nsACString &input); |
77 | | virtual nsresult SetUserPass(const nsACString &input); |
78 | | nsresult SetUsername(const nsACString &input); |
79 | | virtual nsresult SetPassword(const nsACString &input); |
80 | | virtual nsresult SetHostPort(const nsACString &aValue); |
81 | | virtual nsresult SetHost(const nsACString &input); |
82 | | virtual nsresult SetPort(int32_t port); |
83 | | virtual nsresult SetPathQueryRef(const nsACString &input); |
84 | | virtual nsresult SetRef(const nsACString &input); |
85 | | virtual nsresult SetFilePath(const nsACString &input); |
86 | | virtual nsresult SetQuery(const nsACString &input); |
87 | | virtual nsresult SetQueryWithEncoding(const nsACString &input, const Encoding* encoding); |
88 | | nsresult ReadPrivate(nsIObjectInputStream *stream); |
89 | | |
90 | | // Helper to share code between Equals methods. |
91 | | virtual nsresult EqualsInternal(nsIURI* other, |
92 | | RefHandlingEnum refHandlingMode, |
93 | | bool* result); |
94 | | |
95 | | // Helper to be used by inherited classes who want to test |
96 | | // equality given an assumed nsSimpleURI. This must NOT check |
97 | | // the passed-in other for QI to our CID. |
98 | | bool EqualsInternal(nsSimpleURI* otherUri, RefHandlingEnum refHandlingMode); |
99 | | |
100 | | // Used by StartClone (and versions of StartClone in subclasses) to |
101 | | // handle the ref in the right way for clones. |
102 | | void SetRefOnClone(nsSimpleURI* url, RefHandlingEnum refHandlingMode, |
103 | | const nsACString& newRef); |
104 | | |
105 | | // NOTE: This takes the refHandlingMode as an argument because |
106 | | // nsSimpleNestedURI's specialized version needs to know how to clone |
107 | | // its inner URI. |
108 | | virtual nsSimpleURI* StartClone(RefHandlingEnum refHandlingMode, |
109 | | const nsACString& newRef); |
110 | | |
111 | | // Helper to share code between Clone methods. |
112 | | virtual nsresult CloneInternal(RefHandlingEnum refHandlingMode, |
113 | | const nsACString &newRef, |
114 | | nsIURI** clone); |
115 | | |
116 | | nsresult SetPathQueryRefEscaped(const nsACString &aPath, bool aNeedsEscape); |
117 | | |
118 | | bool Deserialize(const mozilla::ipc::URIParams&); |
119 | | |
120 | | nsCString mScheme; |
121 | | nsCString mPath; // NOTE: mPath does not include ref, as an optimization |
122 | | nsCString mRef; // so that URIs with different refs can share string data. |
123 | | nsCString mQuery; // so that URLs with different querys can share string data. |
124 | | bool mMutable; |
125 | | bool mIsRefValid; // To distinguish between empty-ref and no-ref. |
126 | | bool mIsQueryValid; // To distinguish between empty-query and no-query. |
127 | | |
128 | | |
129 | | public: |
130 | | class Mutator final |
131 | | : public nsIURIMutator |
132 | | , public BaseURIMutator<nsSimpleURI> |
133 | | , public nsISerializable |
134 | | { |
135 | | NS_DECL_ISUPPORTS |
136 | | NS_FORWARD_SAFE_NSIURISETTERS_RET(mURI) |
137 | | NS_DEFINE_NSIMUTATOR_COMMON |
138 | | |
139 | | NS_IMETHOD |
140 | | Write(nsIObjectOutputStream *aOutputStream) override |
141 | | { |
142 | | return NS_ERROR_NOT_IMPLEMENTED; |
143 | | } |
144 | | |
145 | | MOZ_MUST_USE NS_IMETHOD |
146 | | Read(nsIObjectInputStream* aStream) override |
147 | | { |
148 | | return InitFromInputStream(aStream); |
149 | | } |
150 | | |
151 | | explicit Mutator() = default; |
152 | | private: |
153 | | virtual ~Mutator() = default; |
154 | | |
155 | | friend class nsSimpleURI; |
156 | | }; |
157 | | |
158 | | friend BaseURIMutator<nsSimpleURI>; |
159 | | }; |
160 | | |
161 | | } // namespace net |
162 | | } // namespace mozilla |
163 | | |
164 | | #endif // nsSimpleURI_h__ |