/src/mozilla-central/netwerk/base/nsStandardURL.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 4; 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 nsStandardURL_h__ |
7 | | #define nsStandardURL_h__ |
8 | | |
9 | | #include "nsString.h" |
10 | | #include "nsISerializable.h" |
11 | | #include "nsIFileURL.h" |
12 | | #include "nsIStandardURL.h" |
13 | | #include "mozilla/Encoding.h" |
14 | | #include "nsIObserver.h" |
15 | | #include "nsCOMPtr.h" |
16 | | #include "nsURLHelper.h" |
17 | | #include "nsIClassInfo.h" |
18 | | #include "nsISizeOf.h" |
19 | | #include "mozilla/Attributes.h" |
20 | | #include "mozilla/LinkedList.h" |
21 | | #include "mozilla/MemoryReporting.h" |
22 | | #include "nsIIPCSerializableURI.h" |
23 | | #include "nsISensitiveInfoHiddenURI.h" |
24 | | #include "nsIURIMutator.h" |
25 | | |
26 | | #ifdef NS_BUILD_REFCNT_LOGGING |
27 | | #define DEBUG_DUMP_URLS_AT_SHUTDOWN |
28 | | #endif |
29 | | |
30 | | class nsIBinaryInputStream; |
31 | | class nsIBinaryOutputStream; |
32 | | class nsIIDNService; |
33 | | class nsIPrefBranch; |
34 | | class nsIFile; |
35 | | class nsIURLParser; |
36 | | |
37 | | namespace mozilla { |
38 | | class Encoding; |
39 | | namespace net { |
40 | | |
41 | | //----------------------------------------------------------------------------- |
42 | | // standard URL implementation |
43 | | //----------------------------------------------------------------------------- |
44 | | |
45 | | class nsStandardURL : public nsIFileURL |
46 | | , public nsIStandardURL |
47 | | , public nsISerializable |
48 | | , public nsIClassInfo |
49 | | , public nsISizeOf |
50 | | , public nsIIPCSerializableURI |
51 | | , public nsISensitiveInfoHiddenURI |
52 | | #ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN |
53 | | , public LinkedListElement<nsStandardURL> |
54 | | #endif |
55 | | { |
56 | | protected: |
57 | | virtual ~nsStandardURL(); |
58 | | explicit nsStandardURL(bool aSupportsFileURL = false, bool aTrackURL = true); |
59 | | |
60 | | public: |
61 | | NS_DECL_THREADSAFE_ISUPPORTS |
62 | | NS_DECL_NSIURI |
63 | | NS_DECL_NSIURL |
64 | | NS_DECL_NSIFILEURL |
65 | | NS_DECL_NSISTANDARDURL |
66 | | NS_DECL_NSISERIALIZABLE |
67 | | NS_DECL_NSICLASSINFO |
68 | | NS_DECL_NSIIPCSERIALIZABLEURI |
69 | | NS_DECL_NSISENSITIVEINFOHIDDENURI |
70 | | |
71 | | // nsISizeOf |
72 | | virtual size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const override; |
73 | | virtual size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override; |
74 | | |
75 | | static void InitGlobalObjects(); |
76 | | static void ShutdownGlobalObjects(); |
77 | | |
78 | | public: /* internal -- HPUX compiler can't handle this being private */ |
79 | | // |
80 | | // location and length of an url segment relative to mSpec |
81 | | // |
82 | | struct URLSegment |
83 | | { |
84 | | uint32_t mPos; |
85 | | int32_t mLen; |
86 | | |
87 | 29.8M | URLSegment() : mPos(0), mLen(-1) {} |
88 | 2.32k | URLSegment(uint32_t pos, int32_t len) : mPos(pos), mLen(len) {} |
89 | | URLSegment(const URLSegment& aCopy) = default; |
90 | 13.8M | void Reset() { mPos = 0; mLen = -1; } |
91 | | // Merge another segment following this one to it if they're contiguous |
92 | | // Assumes we have something like "foo;bar" where this object is 'foo' and right |
93 | | // is 'bar'. |
94 | 0 | void Merge(const nsCString &spec, const char separator, const URLSegment &right) { |
95 | 0 | if (mLen >= 0 && |
96 | 0 | *(spec.get() + mPos + mLen) == separator && |
97 | 0 | mPos + mLen + 1 == right.mPos) { |
98 | 0 | mLen += 1 + right.mLen; |
99 | 0 | } |
100 | 0 | } |
101 | | }; |
102 | | |
103 | | // |
104 | | // URL segment encoder : performs charset conversion and URL escaping. |
105 | | // |
106 | | class nsSegmentEncoder |
107 | | { |
108 | | public: |
109 | | explicit nsSegmentEncoder(const Encoding* encoding = nullptr); |
110 | | |
111 | | // Encode the given segment if necessary, and return the length of |
112 | | // the encoded segment. The encoded segment is appended to |buf| |
113 | | // if and only if encoding is required. |
114 | | int32_t EncodeSegmentCount(const char *str, |
115 | | const URLSegment &segment, |
116 | | int16_t mask, |
117 | | nsCString& buf, |
118 | | bool& appended, |
119 | | uint32_t extraLen = 0); |
120 | | |
121 | | // Encode the given string if necessary, and return a reference to |
122 | | // the encoded string. Returns a reference to |buf| if encoding |
123 | | // is required. Otherwise, a reference to |str| is returned. |
124 | | const nsACString& EncodeSegment(const nsACString& str, |
125 | | int16_t mask, |
126 | | nsCString& buf); |
127 | | private: |
128 | | const Encoding* mEncoding; |
129 | | }; |
130 | | friend class nsSegmentEncoder; |
131 | | |
132 | | static nsresult NormalizeIPv4(const nsACString& host, nsCString& result); |
133 | | |
134 | | protected: |
135 | | // enum used in a few places to specify how .ref attribute should be handled |
136 | | enum RefHandlingEnum { |
137 | | eIgnoreRef, |
138 | | eHonorRef, |
139 | | eReplaceRef |
140 | | }; |
141 | | |
142 | | // Helper to share code between Equals and EqualsExceptRef |
143 | | // NOTE: *not* virtual, because no one needs to override this so far... |
144 | | nsresult EqualsInternal(nsIURI* unknownOther, |
145 | | RefHandlingEnum refHandlingMode, |
146 | | bool* result); |
147 | | |
148 | | virtual nsStandardURL* StartClone(); |
149 | | |
150 | | // Helper to share code between Clone methods. |
151 | | nsresult CloneInternal(RefHandlingEnum aRefHandlingMode, |
152 | | const nsACString& newRef, |
153 | | nsIURI** aClone); |
154 | | // Helper method that copies member variables from the source StandardURL |
155 | | // if copyCached = true, it will also copy mFile and mDisplayHost |
156 | | nsresult CopyMembers(nsStandardURL * source, RefHandlingEnum mode, |
157 | | const nsACString& newRef, |
158 | | bool copyCached = false); |
159 | | |
160 | | // Helper for subclass implementation of GetFile(). Subclasses that map |
161 | | // URIs to files in a special way should implement this method. It should |
162 | | // ensure that our mFile is initialized, if it's possible. |
163 | | // returns NS_ERROR_NO_INTERFACE if the url does not map to a file |
164 | | virtual nsresult EnsureFile(); |
165 | | |
166 | | virtual nsresult Clone(nsIURI** aURI); |
167 | | virtual nsresult SetSpecInternal(const nsACString &input); |
168 | | virtual nsresult SetScheme(const nsACString &input); |
169 | | virtual nsresult SetUserPass(const nsACString &input); |
170 | | virtual nsresult SetUsername(const nsACString &input); |
171 | | virtual nsresult SetPassword(const nsACString &input); |
172 | | virtual nsresult SetHostPort(const nsACString &aValue); |
173 | | virtual nsresult SetHost(const nsACString &input); |
174 | | virtual nsresult SetPort(int32_t port); |
175 | | virtual nsresult SetPathQueryRef(const nsACString &input); |
176 | | virtual nsresult SetRef(const nsACString &input); |
177 | | virtual nsresult SetFilePath(const nsACString &input); |
178 | | virtual nsresult SetQuery(const nsACString &input); |
179 | | virtual nsresult SetQueryWithEncoding(const nsACString &input, const Encoding* encoding); |
180 | | bool Deserialize(const mozilla::ipc::URIParams&); |
181 | | nsresult ReadPrivate(nsIObjectInputStream *stream); |
182 | | |
183 | | private: |
184 | | nsresult Init(uint32_t urlType, int32_t defaultPort, const nsACString &spec, |
185 | | const char *charset, nsIURI *baseURI); |
186 | | nsresult SetDefaultPort(int32_t aNewDefaultPort); |
187 | | nsresult SetFile(nsIFile *file); |
188 | | |
189 | | nsresult SetFileNameInternal(const nsACString &input); |
190 | | nsresult SetFileBaseNameInternal(const nsACString &input); |
191 | | nsresult SetFileExtensionInternal(const nsACString &input); |
192 | | |
193 | 0 | int32_t Port() { return mPort == -1 ? mDefaultPort : mPort; } |
194 | | |
195 | | void ReplacePortInSpec(int32_t aNewPort); |
196 | | void Clear(); |
197 | | void InvalidateCache(bool invalidateCachedFile = true); |
198 | | |
199 | | bool ValidIPv6orHostname(const char *host, uint32_t aLen); |
200 | | static bool IsValidOfBase(unsigned char c, const uint32_t base); |
201 | | nsresult NormalizeIDN(const nsACString& host, nsCString& result); |
202 | | nsresult CheckIfHostIsAscii(); |
203 | | void CoalescePath(netCoalesceFlags coalesceFlag, char *path); |
204 | | |
205 | | uint32_t AppendSegmentToBuf(char *, uint32_t, const char *, |
206 | | const URLSegment &input, URLSegment &output, |
207 | | const nsCString *esc=nullptr, |
208 | | bool useEsc = false, int32_t* diff = nullptr); |
209 | | uint32_t AppendToBuf(char *, uint32_t, const char *, uint32_t); |
210 | | |
211 | | nsresult BuildNormalizedSpec(const char* spec, const Encoding* encoding); |
212 | | nsresult SetSpecWithEncoding(const nsACString &input, const Encoding* encoding); |
213 | | |
214 | | bool SegmentIs(const URLSegment &s1, const char *val, bool ignoreCase = false); |
215 | | bool SegmentIs(const char* spec, const URLSegment &s1, const char *val, bool ignoreCase = false); |
216 | | bool SegmentIs(const URLSegment &s1, const char *val, const URLSegment &s2, bool ignoreCase = false); |
217 | | |
218 | | int32_t ReplaceSegment(uint32_t pos, uint32_t len, const char *val, uint32_t valLen); |
219 | | int32_t ReplaceSegment(uint32_t pos, uint32_t len, const nsACString &val); |
220 | | |
221 | | nsresult ParseURL(const char *spec, int32_t specLen); |
222 | | nsresult ParsePath(const char *spec, uint32_t pathPos, int32_t pathLen = -1); |
223 | | |
224 | | char *AppendToSubstring(uint32_t pos, int32_t len, const char *tail); |
225 | | |
226 | | // dependent substring helpers |
227 | | const nsDependentCSubstring Segment(uint32_t pos, int32_t len); // see below |
228 | 6.77M | const nsDependentCSubstring Segment(const URLSegment &s) { return Segment(s.mPos, s.mLen); } |
229 | | |
230 | | // dependent substring getters |
231 | | const nsDependentCSubstring Prepath(); // see below |
232 | 4.00M | const nsDependentCSubstring Scheme() { return Segment(mScheme); } |
233 | | const nsDependentCSubstring Userpass(bool includeDelim = false); // see below |
234 | 0 | const nsDependentCSubstring Username() { return Segment(mUsername); } |
235 | 0 | const nsDependentCSubstring Password() { return Segment(mPassword); } |
236 | | const nsDependentCSubstring Hostport(); // see below |
237 | | const nsDependentCSubstring Host(); // see below |
238 | 26.2k | const nsDependentCSubstring Path() { return Segment(mPath); } |
239 | 32 | const nsDependentCSubstring Filepath() { return Segment(mFilepath); } |
240 | 0 | const nsDependentCSubstring Directory() { return Segment(mDirectory); } |
241 | | const nsDependentCSubstring Filename(); // see below |
242 | 0 | const nsDependentCSubstring Basename() { return Segment(mBasename); } |
243 | 0 | const nsDependentCSubstring Extension() { return Segment(mExtension); } |
244 | 0 | const nsDependentCSubstring Query() { return Segment(mQuery); } |
245 | 4.64k | const nsDependentCSubstring Ref() { return Segment(mRef); } |
246 | | |
247 | | // shift the URLSegments to the right by diff |
248 | | void ShiftFromAuthority(int32_t diff); |
249 | | void ShiftFromUsername(int32_t diff); |
250 | | void ShiftFromPassword(int32_t diff); |
251 | | void ShiftFromHost(int32_t diff); |
252 | | void ShiftFromPath(int32_t diff); |
253 | | void ShiftFromFilepath(int32_t diff); |
254 | | void ShiftFromDirectory(int32_t diff); |
255 | | void ShiftFromBasename(int32_t diff); |
256 | | void ShiftFromExtension(int32_t diff); |
257 | | void ShiftFromQuery(int32_t diff); |
258 | | void ShiftFromRef(int32_t diff); |
259 | | |
260 | | // fastload helper functions |
261 | | nsresult ReadSegment(nsIBinaryInputStream *, URLSegment &); |
262 | | nsresult WriteSegment(nsIBinaryOutputStream *, const URLSegment &); |
263 | | |
264 | | void FindHostLimit(nsACString::const_iterator& aStart, |
265 | | nsACString::const_iterator& aEnd); |
266 | | |
267 | | // mSpec contains the normalized version of the URL spec (UTF-8 encoded). |
268 | | nsCString mSpec; |
269 | | int32_t mDefaultPort; |
270 | | int32_t mPort; |
271 | | |
272 | | // url parts (relative to mSpec) |
273 | | URLSegment mScheme; |
274 | | URLSegment mAuthority; |
275 | | URLSegment mUsername; |
276 | | URLSegment mPassword; |
277 | | URLSegment mHost; |
278 | | URLSegment mPath; |
279 | | URLSegment mFilepath; |
280 | | URLSegment mDirectory; |
281 | | URLSegment mBasename; |
282 | | URLSegment mExtension; |
283 | | URLSegment mQuery; |
284 | | URLSegment mRef; |
285 | | |
286 | | nsCOMPtr<nsIURLParser> mParser; |
287 | | |
288 | | // mFile is protected so subclasses can access it directly |
289 | | protected: |
290 | | nsCOMPtr<nsIFile> mFile; // cached result for nsIFileURL::GetFile |
291 | | |
292 | | private: |
293 | | // cached result for nsIURI::GetDisplayHost |
294 | | nsCString mDisplayHost; |
295 | | |
296 | | enum { |
297 | | eEncoding_Unknown, |
298 | | eEncoding_ASCII, |
299 | | eEncoding_UTF8 |
300 | | }; |
301 | | |
302 | | uint32_t mURLType : 2; // nsIStandardURL::URLTYPE_xxx |
303 | | uint32_t mSupportsFileURL : 1; // QI to nsIFileURL? |
304 | | uint32_t mCheckedIfHostA : 1; // If set to true, it means either that |
305 | | // mDisplayHost has a been initialized, or |
306 | | // that the hostname is not punycode |
307 | | |
308 | | // global objects. don't use COMPtr as its destructor will cause a |
309 | | // coredump if we leak it. |
310 | | static nsIIDNService *gIDN; |
311 | | static const char gHostLimitDigits[]; |
312 | | static bool gInitialized; |
313 | | static bool gPunycodeHost; |
314 | | |
315 | | public: |
316 | | #ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN |
317 | | void PrintSpec() const { printf(" %s\n", mSpec.get()); } |
318 | | #endif |
319 | | |
320 | | public: |
321 | | |
322 | | // We make this implementation a template so that we can avoid writing |
323 | | // the same code for SubstitutingURL (which extends nsStandardURL) |
324 | | template<class T> |
325 | | class TemplatedMutator |
326 | | : public nsIURIMutator |
327 | | , public BaseURIMutator<T> |
328 | | , public nsIStandardURLMutator |
329 | | , public nsIURLMutator |
330 | | , public nsIFileURLMutator |
331 | | , public nsISerializable |
332 | | { |
333 | | NS_FORWARD_SAFE_NSIURISETTERS_RET(BaseURIMutator<T>::mURI) |
334 | | |
335 | | MOZ_MUST_USE NS_IMETHOD |
336 | | Deserialize(const mozilla::ipc::URIParams& aParams) override |
337 | 0 | { |
338 | 0 | return BaseURIMutator<T>::InitFromIPCParams(aParams); |
339 | 0 | } Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::Deserialize(mozilla::ipc::URIParams const&) Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::Deserialize(mozilla::ipc::URIParams const&) |
340 | | |
341 | | NS_IMETHOD |
342 | | Write(nsIObjectOutputStream *aOutputStream) override |
343 | 0 | { |
344 | 0 | MOZ_ASSERT_UNREACHABLE("Use nsIURIMutator.read() instead"); |
345 | 0 | return NS_ERROR_NOT_IMPLEMENTED; |
346 | 0 | } Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::Write(nsIObjectOutputStream*) Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::Write(nsIObjectOutputStream*) |
347 | | |
348 | | MOZ_MUST_USE NS_IMETHOD |
349 | | Read(nsIObjectInputStream* aStream) override |
350 | 0 | { |
351 | 0 | return BaseURIMutator<T>::InitFromInputStream(aStream); |
352 | 0 | } Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::Read(nsIObjectInputStream*) Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::Read(nsIObjectInputStream*) |
353 | | |
354 | | MOZ_MUST_USE NS_IMETHOD |
355 | | Finalize(nsIURI** aURI) override |
356 | 1.10M | { |
357 | 1.10M | BaseURIMutator<T>::mURI.forget(aURI); |
358 | 1.10M | return NS_OK; |
359 | 1.10M | } mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::Finalize(nsIURI**) Line | Count | Source | 356 | 1.10M | { | 357 | 1.10M | BaseURIMutator<T>::mURI.forget(aURI); | 358 | 1.10M | return NS_OK; | 359 | 1.10M | } |
mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::Finalize(nsIURI**) Line | Count | Source | 356 | 689 | { | 357 | 689 | BaseURIMutator<T>::mURI.forget(aURI); | 358 | 689 | return NS_OK; | 359 | 689 | } |
|
360 | | |
361 | | MOZ_MUST_USE NS_IMETHOD |
362 | | SetSpec(const nsACString& aSpec, nsIURIMutator** aMutator) override |
363 | 0 | { |
364 | 0 | if (aMutator) { |
365 | 0 | nsCOMPtr<nsIURIMutator> mutator = this; |
366 | 0 | mutator.forget(aMutator); |
367 | 0 | } |
368 | 0 | return BaseURIMutator<T>::InitFromSpec(aSpec); |
369 | 0 | } Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::SetSpec(nsTSubstring<char> const&, nsIURIMutator**) Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::SetSpec(nsTSubstring<char> const&, nsIURIMutator**) |
370 | | |
371 | | MOZ_MUST_USE NS_IMETHOD |
372 | | Init(uint32_t aURLType, int32_t aDefaultPort, |
373 | | const nsACString& aSpec, const char* aCharset, nsIURI* aBaseURI, |
374 | | nsIURIMutator** aMutator) override |
375 | 1.12M | { |
376 | 1.12M | if (aMutator) { |
377 | 0 | nsCOMPtr<nsIURIMutator> mutator = this; |
378 | 0 | mutator.forget(aMutator); |
379 | 0 | } |
380 | 1.12M | RefPtr<T> uri; |
381 | 1.12M | if (BaseURIMutator<T>::mURI) { |
382 | 0 | // We don't need a new URI object if we already have one |
383 | 0 | BaseURIMutator<T>::mURI.swap(uri); |
384 | 1.12M | } else { |
385 | 1.12M | uri = Create(); |
386 | 1.12M | } |
387 | 1.12M | nsresult rv = uri->Init(aURLType, aDefaultPort, aSpec, aCharset, aBaseURI); |
388 | 1.12M | if (NS_FAILED(rv)) { |
389 | 28.1k | return rv; |
390 | 28.1k | } |
391 | 1.09M | BaseURIMutator<T>::mURI = uri.forget(); |
392 | 1.09M | return NS_OK; |
393 | 1.09M | } mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::Init(unsigned int, int, nsTSubstring<char> const&, char const*, nsIURI*, nsIURIMutator**) Line | Count | Source | 375 | 1.12M | { | 376 | 1.12M | if (aMutator) { | 377 | 0 | nsCOMPtr<nsIURIMutator> mutator = this; | 378 | 0 | mutator.forget(aMutator); | 379 | 0 | } | 380 | 1.12M | RefPtr<T> uri; | 381 | 1.12M | if (BaseURIMutator<T>::mURI) { | 382 | 0 | // We don't need a new URI object if we already have one | 383 | 0 | BaseURIMutator<T>::mURI.swap(uri); | 384 | 1.12M | } else { | 385 | 1.12M | uri = Create(); | 386 | 1.12M | } | 387 | 1.12M | nsresult rv = uri->Init(aURLType, aDefaultPort, aSpec, aCharset, aBaseURI); | 388 | 1.12M | if (NS_FAILED(rv)) { | 389 | 26.2k | return rv; | 390 | 26.2k | } | 391 | 1.09M | BaseURIMutator<T>::mURI = uri.forget(); | 392 | 1.09M | return NS_OK; | 393 | 1.09M | } |
mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::Init(unsigned int, int, nsTSubstring<char> const&, char const*, nsIURI*, nsIURIMutator**) Line | Count | Source | 375 | 2.57k | { | 376 | 2.57k | if (aMutator) { | 377 | 0 | nsCOMPtr<nsIURIMutator> mutator = this; | 378 | 0 | mutator.forget(aMutator); | 379 | 0 | } | 380 | 2.57k | RefPtr<T> uri; | 381 | 2.57k | if (BaseURIMutator<T>::mURI) { | 382 | 0 | // We don't need a new URI object if we already have one | 383 | 0 | BaseURIMutator<T>::mURI.swap(uri); | 384 | 2.57k | } else { | 385 | 2.57k | uri = Create(); | 386 | 2.57k | } | 387 | 2.57k | nsresult rv = uri->Init(aURLType, aDefaultPort, aSpec, aCharset, aBaseURI); | 388 | 2.57k | if (NS_FAILED(rv)) { | 389 | 1.88k | return rv; | 390 | 1.88k | } | 391 | 689 | BaseURIMutator<T>::mURI = uri.forget(); | 392 | 689 | return NS_OK; | 393 | 689 | } |
|
394 | | |
395 | | MOZ_MUST_USE NS_IMETHODIMP |
396 | | SetDefaultPort(int32_t aNewDefaultPort, nsIURIMutator** aMutator) override |
397 | 0 | { |
398 | 0 | if (!BaseURIMutator<T>::mURI) { |
399 | 0 | return NS_ERROR_NULL_POINTER; |
400 | 0 | } |
401 | 0 | if (aMutator) { |
402 | 0 | nsCOMPtr<nsIURIMutator> mutator = this; |
403 | 0 | mutator.forget(aMutator); |
404 | 0 | } |
405 | 0 | return BaseURIMutator<T>::mURI->SetDefaultPort(aNewDefaultPort); |
406 | 0 | } Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::SetDefaultPort(int, nsIURIMutator**) Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::SetDefaultPort(int, nsIURIMutator**) |
407 | | |
408 | | MOZ_MUST_USE NS_IMETHOD |
409 | | SetFileName(const nsACString& aFileName, nsIURIMutator** aMutator) override |
410 | 0 | { |
411 | 0 | if (!BaseURIMutator<T>::mURI) { |
412 | 0 | return NS_ERROR_NULL_POINTER; |
413 | 0 | } |
414 | 0 | if (aMutator) { |
415 | 0 | nsCOMPtr<nsIURIMutator> mutator = this; |
416 | 0 | mutator.forget(aMutator); |
417 | 0 | } |
418 | 0 | return BaseURIMutator<T>::mURI->SetFileNameInternal(aFileName); |
419 | 0 | } Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::SetFileName(nsTSubstring<char> const&, nsIURIMutator**) Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::SetFileName(nsTSubstring<char> const&, nsIURIMutator**) |
420 | | |
421 | | MOZ_MUST_USE NS_IMETHOD |
422 | | SetFileBaseName(const nsACString& aFileBaseName, nsIURIMutator** aMutator) override |
423 | 0 | { |
424 | 0 | if (!BaseURIMutator<T>::mURI) { |
425 | 0 | return NS_ERROR_NULL_POINTER; |
426 | 0 | } |
427 | 0 | if (aMutator) { |
428 | 0 | nsCOMPtr<nsIURIMutator> mutator = this; |
429 | 0 | mutator.forget(aMutator); |
430 | 0 | } |
431 | 0 | return BaseURIMutator<T>::mURI->SetFileBaseNameInternal(aFileBaseName); |
432 | 0 | } Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::SetFileBaseName(nsTSubstring<char> const&, nsIURIMutator**) Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::SetFileBaseName(nsTSubstring<char> const&, nsIURIMutator**) |
433 | | |
434 | | MOZ_MUST_USE NS_IMETHOD |
435 | | SetFileExtension(const nsACString& aFileExtension, nsIURIMutator** aMutator) override |
436 | 0 | { |
437 | 0 | if (!BaseURIMutator<T>::mURI) { |
438 | 0 | return NS_ERROR_NULL_POINTER; |
439 | 0 | } |
440 | 0 | if (aMutator) { |
441 | 0 | nsCOMPtr<nsIURIMutator> mutator = this; |
442 | 0 | mutator.forget(aMutator); |
443 | 0 | } |
444 | 0 | return BaseURIMutator<T>::mURI->SetFileExtensionInternal(aFileExtension); |
445 | 0 | } Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::SetFileExtension(nsTSubstring<char> const&, nsIURIMutator**) Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::SetFileExtension(nsTSubstring<char> const&, nsIURIMutator**) |
446 | | |
447 | | T* Create() override |
448 | 1.12M | { |
449 | 1.12M | return new T(mMarkedFileURL); |
450 | 1.12M | } mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::Create() Line | Count | Source | 448 | 1.12M | { | 449 | 1.12M | return new T(mMarkedFileURL); | 450 | 1.12M | } |
Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::Create() |
451 | | |
452 | | MOZ_MUST_USE NS_IMETHOD |
453 | | MarkFileURL() override |
454 | 4.68k | { |
455 | 4.68k | mMarkedFileURL = true; |
456 | 4.68k | return NS_OK; |
457 | 4.68k | } mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::MarkFileURL() Line | Count | Source | 454 | 4.68k | { | 455 | 4.68k | mMarkedFileURL = true; | 456 | 4.68k | return NS_OK; | 457 | 4.68k | } |
Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::MarkFileURL() |
458 | | |
459 | | MOZ_MUST_USE NS_IMETHOD |
460 | | SetFile(nsIFile* aFile) override |
461 | 0 | { |
462 | 0 | RefPtr<T> uri; |
463 | 0 | if (BaseURIMutator<T>::mURI) { |
464 | 0 | // We don't need a new URI object if we already have one |
465 | 0 | BaseURIMutator<T>::mURI.swap(uri); |
466 | 0 | } else { |
467 | 0 | uri = new T(/* aSupportsFileURL = */ true); |
468 | 0 | } |
469 | 0 |
|
470 | 0 | nsresult rv = uri->SetFile(aFile); |
471 | 0 | if (NS_FAILED(rv)) { |
472 | 0 | return rv; |
473 | 0 | } |
474 | 0 | BaseURIMutator<T>::mURI.swap(uri); |
475 | 0 | return NS_OK; |
476 | 0 | } Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::SetFile(nsIFile*) Unexecuted instantiation: mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::SetFile(nsIFile*) |
477 | | |
478 | | explicit TemplatedMutator() : mMarkedFileURL(false) |
479 | 1.12M | { |
480 | 1.12M | } mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::TemplatedMutator() Line | Count | Source | 479 | 1.12M | { | 480 | 1.12M | } |
mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::TemplatedMutator() Line | Count | Source | 479 | 2.57k | { | 480 | 2.57k | } |
|
481 | | private: |
482 | 1.12M | virtual ~TemplatedMutator() = default; mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::nsStandardURL>::~TemplatedMutator() Line | Count | Source | 482 | 1.12M | virtual ~TemplatedMutator() = default; |
mozilla::net::nsStandardURL::TemplatedMutator<mozilla::net::SubstitutingURL>::~TemplatedMutator() Line | Count | Source | 482 | 2.57k | virtual ~TemplatedMutator() = default; |
|
483 | | |
484 | | bool mMarkedFileURL = false; |
485 | | |
486 | | friend T; |
487 | | }; |
488 | | |
489 | | class Mutator final |
490 | | : public TemplatedMutator<nsStandardURL> |
491 | | { |
492 | | NS_DECL_ISUPPORTS |
493 | | public: |
494 | 1.12M | explicit Mutator() = default; |
495 | | private: |
496 | | virtual ~Mutator() = default; |
497 | | }; |
498 | | |
499 | | friend BaseURIMutator<nsStandardURL>; |
500 | | }; |
501 | | |
502 | | #define NS_THIS_STANDARDURL_IMPL_CID \ |
503 | | { /* b8e3e97b-1ccd-4b45-af5a-79596770f5d7 */ \ |
504 | | 0xb8e3e97b, \ |
505 | | 0x1ccd, \ |
506 | | 0x4b45, \ |
507 | | {0xaf, 0x5a, 0x79, 0x59, 0x67, 0x70, 0xf5, 0xd7} \ |
508 | | } |
509 | | |
510 | | //----------------------------------------------------------------------------- |
511 | | // Dependent substring getters |
512 | | //----------------------------------------------------------------------------- |
513 | | |
514 | | inline const nsDependentCSubstring |
515 | | nsStandardURL::Segment(uint32_t pos, int32_t len) |
516 | 6.77M | { |
517 | 6.77M | if (len < 0) { |
518 | 1.06M | pos = 0; |
519 | 1.06M | len = 0; |
520 | 1.06M | } |
521 | 6.77M | return Substring(mSpec, pos, uint32_t(len)); |
522 | 6.77M | } |
523 | | |
524 | | inline const nsDependentCSubstring |
525 | | nsStandardURL::Prepath() |
526 | 0 | { |
527 | 0 | uint32_t len = 0; |
528 | 0 | if (mAuthority.mLen >= 0) |
529 | 0 | len = mAuthority.mPos + mAuthority.mLen; |
530 | 0 | return Substring(mSpec, 0, len); |
531 | 0 | } |
532 | | |
533 | | inline const nsDependentCSubstring |
534 | | nsStandardURL::Userpass(bool includeDelim) |
535 | 0 | { |
536 | 0 | uint32_t pos=0, len=0; |
537 | 0 | // if there is no username, then there can be no password |
538 | 0 | if (mUsername.mLen > 0) { |
539 | 0 | pos = mUsername.mPos; |
540 | 0 | len = mUsername.mLen; |
541 | 0 | if (mPassword.mLen >= 0) |
542 | 0 | len += (mPassword.mLen + 1); |
543 | 0 | if (includeDelim) |
544 | 0 | len++; |
545 | 0 | } |
546 | 0 | return Substring(mSpec, pos, len); |
547 | 0 | } |
548 | | |
549 | | inline const nsDependentCSubstring |
550 | | nsStandardURL::Hostport() |
551 | 5.77k | { |
552 | 5.77k | uint32_t pos=0, len=0; |
553 | 5.77k | if (mAuthority.mLen > 0) { |
554 | 5.77k | pos = mHost.mPos; |
555 | 5.77k | len = mAuthority.mPos + mAuthority.mLen - pos; |
556 | 5.77k | } |
557 | 5.77k | return Substring(mSpec, pos, len); |
558 | 5.77k | } |
559 | | |
560 | | inline const nsDependentCSubstring |
561 | | nsStandardURL::Host() |
562 | 3.04k | { |
563 | 3.04k | uint32_t pos=0, len=0; |
564 | 3.04k | if (mHost.mLen > 0) { |
565 | 2.55k | pos = mHost.mPos; |
566 | 2.55k | len = mHost.mLen; |
567 | 2.55k | if (mSpec.CharAt(pos) == '[' && mSpec.CharAt(pos + len - 1) == ']') { |
568 | 23 | pos++; |
569 | 23 | len -= 2; |
570 | 23 | } |
571 | 2.55k | } |
572 | 3.04k | return Substring(mSpec, pos, len); |
573 | 3.04k | } |
574 | | |
575 | | inline const nsDependentCSubstring |
576 | | nsStandardURL::Filename() |
577 | 0 | { |
578 | 0 | uint32_t pos=0, len=0; |
579 | 0 | // if there is no basename, then there can be no extension |
580 | 0 | if (mBasename.mLen > 0) { |
581 | 0 | pos = mBasename.mPos; |
582 | 0 | len = mBasename.mLen; |
583 | 0 | if (mExtension.mLen >= 0) |
584 | 0 | len += (mExtension.mLen + 1); |
585 | 0 | } |
586 | 0 | return Substring(mSpec, pos, len); |
587 | 0 | } |
588 | | |
589 | | } // namespace net |
590 | | } // namespace mozilla |
591 | | |
592 | | #endif // nsStandardURL_h__ |