/src/mozilla-central/netwerk/base/nsNetUtil.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* vim:set ts=4 sw=4 sts=4 et cin: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef nsNetUtil_h__ |
8 | | #define nsNetUtil_h__ |
9 | | |
10 | | #include "mozilla/Maybe.h" |
11 | | #include "nsCOMPtr.h" |
12 | | #include "nsIInterfaceRequestor.h" |
13 | | #include "nsIInterfaceRequestorUtils.h" |
14 | | #include "nsILoadGroup.h" |
15 | | #include "nsINetUtil.h" |
16 | | #include "nsIRequest.h" |
17 | | #include "nsILoadInfo.h" |
18 | | #include "nsIIOService.h" |
19 | | #include "mozilla/NotNull.h" |
20 | | #include "mozilla/Services.h" |
21 | | #include "mozilla/Unused.h" |
22 | | #include "nsNetCID.h" |
23 | | #include "nsReadableUtils.h" |
24 | | #include "nsServiceManagerUtils.h" |
25 | | #include "nsString.h" |
26 | | |
27 | | class nsIURI; |
28 | | class nsIPrincipal; |
29 | | class nsIAsyncStreamCopier; |
30 | | class nsIAuthPrompt; |
31 | | class nsIAuthPrompt2; |
32 | | class nsIChannel; |
33 | | class nsIChannelPolicy; |
34 | | class nsIDownloadObserver; |
35 | | class nsIEventTarget; |
36 | | class nsIFileProtocolHandler; |
37 | | class nsIFileStream; |
38 | | class nsIInputStream; |
39 | | class nsIInputStreamPump; |
40 | | class nsIInterfaceRequestor; |
41 | | class nsINestedURI; |
42 | | class nsIOutputStream; |
43 | | class nsIParentChannel; |
44 | | class nsIPersistentProperties; |
45 | | class nsIProxyInfo; |
46 | | class nsIRequestObserver; |
47 | | class nsIStreamListener; |
48 | | class nsIStreamLoader; |
49 | | class nsIStreamLoaderObserver; |
50 | | class nsIIncrementalStreamLoader; |
51 | | class nsIIncrementalStreamLoaderObserver; |
52 | | |
53 | | namespace mozilla { |
54 | | class Encoding; |
55 | | class OriginAttributes; |
56 | | namespace dom { |
57 | | class ClientInfo; |
58 | | class PerformanceStorage; |
59 | | class ServiceWorkerDescriptor; |
60 | | } // namespace dom |
61 | | } // namespace mozilla |
62 | | |
63 | | template <class> class nsCOMPtr; |
64 | | template <typename> struct already_AddRefed; |
65 | | |
66 | | already_AddRefed<nsIIOService> do_GetIOService(nsresult *error = nullptr); |
67 | | |
68 | | already_AddRefed<nsINetUtil> do_GetNetUtil(nsresult *error = nullptr); |
69 | | |
70 | | // private little helper function... don't call this directly! |
71 | | nsresult net_EnsureIOService(nsIIOService **ios, nsCOMPtr<nsIIOService> &grip); |
72 | | |
73 | | nsresult NS_NewURI(nsIURI **result, |
74 | | const nsACString &spec, |
75 | | const char *charset = nullptr, |
76 | | nsIURI *baseURI = nullptr, |
77 | | nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers |
78 | | |
79 | | nsresult NS_NewURI(nsIURI **result, |
80 | | const nsACString &spec, |
81 | | mozilla::NotNull<const mozilla::Encoding*> encoding, |
82 | | nsIURI *baseURI = nullptr, |
83 | | nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers |
84 | | |
85 | | nsresult NS_NewURI(nsIURI **result, |
86 | | const nsAString &spec, |
87 | | const char *charset = nullptr, |
88 | | nsIURI *baseURI = nullptr, |
89 | | nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers |
90 | | |
91 | | nsresult NS_NewURI(nsIURI **result, |
92 | | const nsAString &spec, |
93 | | mozilla::NotNull<const mozilla::Encoding*> encoding, |
94 | | nsIURI *baseURI = nullptr, |
95 | | nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers |
96 | | |
97 | | nsresult NS_NewURI(nsIURI **result, |
98 | | const char *spec, |
99 | | nsIURI *baseURI = nullptr, |
100 | | nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers |
101 | | |
102 | | nsresult NS_NewFileURI(nsIURI **result, |
103 | | nsIFile *spec, |
104 | | nsIIOService *ioService = nullptr); // pass in nsIIOService to optimize callers |
105 | | |
106 | | // These methods will only mutate the URI if the ref of aInput doesn't already |
107 | | // match the ref we are trying to set. |
108 | | // If aInput has no ref, and we are calling NS_GetURIWithoutRef, or |
109 | | // NS_GetURIWithNewRef with an empty string, then aOutput will be the same |
110 | | // as aInput. The same is true if aRef is already equal to the ref of aInput. |
111 | | // This is OK because URIs are immutable and threadsafe. |
112 | | // If the URI doesn't support ref fragments aOutput will be the same as aInput. |
113 | | nsresult NS_GetURIWithNewRef(nsIURI* aInput, |
114 | | const nsACString& aRef, |
115 | | nsIURI** aOutput); |
116 | | nsresult NS_GetURIWithoutRef(nsIURI* aInput, |
117 | | nsIURI** aOutput); |
118 | | |
119 | | nsresult NS_GetSanitizedURIStringFromURI(nsIURI *aUri, |
120 | | nsAString &aSanitizedSpec); |
121 | | |
122 | | /* |
123 | | * How to create a new Channel, using NS_NewChannel, |
124 | | * NS_NewChannelWithTriggeringPrincipal, |
125 | | * NS_NewInputStreamChannel, NS_NewChannelInternal |
126 | | * and it's variations: |
127 | | * |
128 | | * What specific API function to use: |
129 | | * * The NS_NewChannelInternal functions should almost never be directly |
130 | | * called outside of necko code. |
131 | | * * If possible, use NS_NewChannel() providing a loading *nsINode* |
132 | | * * If no loading *nsINode* is available, try calling NS_NewChannel() providing |
133 | | * a loading *ClientInfo*. |
134 | | * * If no loading *nsINode* or *ClientInfo* are available, call NS_NewChannel() |
135 | | * providing a loading *nsIPrincipal*. |
136 | | * * Call NS_NewChannelWithTriggeringPrincipal if the triggeringPrincipal |
137 | | * is different from the loadingPrincipal. |
138 | | * * Call NS_NewChannelInternal() providing aLoadInfo object in cases where |
139 | | * you already have loadInfo object, e.g in case of a channel redirect. |
140 | | * |
141 | | * @param aURI |
142 | | * nsIURI from which to make a channel |
143 | | * @param aLoadingNode |
144 | | * @param aLoadingPrincipal |
145 | | * @param aTriggeringPrincipal |
146 | | * @param aSecurityFlags |
147 | | * @param aContentPolicyType |
148 | | * These will be used as values for the nsILoadInfo object on the |
149 | | * created channel. For details, see nsILoadInfo in nsILoadInfo.idl |
150 | | * |
151 | | * Please note, if you provide both a loadingNode and a loadingPrincipal, |
152 | | * then loadingPrincipal must be equal to loadingNode->NodePrincipal(). |
153 | | * But less error prone is to just supply a loadingNode. |
154 | | * |
155 | | * Note, if you provide a loading ClientInfo its principal must match the |
156 | | * loading principal. Currently you must pass both as the loading principal |
157 | | * may have additional mutable values like CSP on it. In the future these |
158 | | * will be removed from nsIPrincipal and the API can be changed to take just |
159 | | * the loading ClientInfo. |
160 | | * |
161 | | * Keep in mind that URIs coming from a webpage should *never* use the |
162 | | * systemPrincipal as the loadingPrincipal. |
163 | | */ |
164 | | nsresult NS_NewChannelInternal(nsIChannel **outChannel, |
165 | | nsIURI *aUri, |
166 | | nsINode *aLoadingNode, |
167 | | nsIPrincipal *aLoadingPrincipal, |
168 | | nsIPrincipal *aTriggeringPrincipal, |
169 | | const mozilla::Maybe<mozilla::dom::ClientInfo>& aLoadingClientInfo, |
170 | | const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor>& aController, |
171 | | nsSecurityFlags aSecurityFlags, |
172 | | nsContentPolicyType aContentPolicyType, |
173 | | mozilla::dom::PerformanceStorage* aPerformanceStorage = nullptr, |
174 | | nsILoadGroup *aLoadGroup = nullptr, |
175 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
176 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
177 | | nsIIOService *aIoService = nullptr); |
178 | | |
179 | | // See NS_NewChannelInternal for usage and argument description |
180 | | nsresult NS_NewChannelInternal(nsIChannel **outChannel, |
181 | | nsIURI *aUri, |
182 | | nsILoadInfo *aLoadInfo, |
183 | | mozilla::dom::PerformanceStorage* aPerformanceStorage = nullptr, |
184 | | nsILoadGroup *aLoadGroup = nullptr, |
185 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
186 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
187 | | nsIIOService *aIoService = nullptr); |
188 | | |
189 | | // See NS_NewChannelInternal for usage and argument description |
190 | | nsresult /*NS_NewChannelWithNodeAndTriggeringPrincipal */ |
191 | | NS_NewChannelWithTriggeringPrincipal(nsIChannel **outChannel, |
192 | | nsIURI *aUri, |
193 | | nsINode *aLoadingNode, |
194 | | nsIPrincipal *aTriggeringPrincipal, |
195 | | nsSecurityFlags aSecurityFlags, |
196 | | nsContentPolicyType aContentPolicyType, |
197 | | mozilla::dom::PerformanceStorage* aPerformanceStorage = nullptr, |
198 | | nsILoadGroup *aLoadGroup = nullptr, |
199 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
200 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
201 | | nsIIOService *aIoService = nullptr); |
202 | | |
203 | | // See NS_NewChannelInternal for usage and argument description |
204 | | nsresult |
205 | | NS_NewChannelWithTriggeringPrincipal(nsIChannel **outChannel, |
206 | | nsIURI *aUri, |
207 | | nsIPrincipal *aLoadingPrincipal, |
208 | | nsIPrincipal *aTriggeringPrincipal, |
209 | | nsSecurityFlags aSecurityFlags, |
210 | | nsContentPolicyType aContentPolicyType, |
211 | | mozilla::dom::PerformanceStorage* aPerformanceStorage = nullptr, |
212 | | nsILoadGroup *aLoadGroup = nullptr, |
213 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
214 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
215 | | nsIIOService *aIoService = nullptr); |
216 | | |
217 | | // See NS_NewChannelInternal for usage and argument description |
218 | | nsresult |
219 | | NS_NewChannelWithTriggeringPrincipal(nsIChannel **outChannel, |
220 | | nsIURI *aUri, |
221 | | nsIPrincipal *aLoadingPrincipal, |
222 | | nsIPrincipal *aTriggeringPrincipal, |
223 | | const mozilla::dom::ClientInfo& aLoadingClientInfo, |
224 | | const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor>& aController, |
225 | | nsSecurityFlags aSecurityFlags, |
226 | | nsContentPolicyType aContentPolicyType, |
227 | | mozilla::dom::PerformanceStorage* aPerformanceStorage = nullptr, |
228 | | nsILoadGroup *aLoadGroup = nullptr, |
229 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
230 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
231 | | nsIIOService *aIoService = nullptr); |
232 | | |
233 | | |
234 | | // See NS_NewChannelInternal for usage and argument description |
235 | | nsresult |
236 | | NS_NewChannel(nsIChannel **outChannel, |
237 | | nsIURI *aUri, |
238 | | nsINode *aLoadingNode, |
239 | | nsSecurityFlags aSecurityFlags, |
240 | | nsContentPolicyType aContentPolicyType, |
241 | | mozilla::dom::PerformanceStorage* aPerformanceStorage = nullptr, |
242 | | nsILoadGroup *aLoadGroup = nullptr, |
243 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
244 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
245 | | nsIIOService *aIoService = nullptr); |
246 | | |
247 | | // See NS_NewChannelInternal for usage and argument description |
248 | | nsresult |
249 | | NS_NewChannel(nsIChannel **outChannel, |
250 | | nsIURI *aUri, |
251 | | nsIPrincipal *aLoadingPrincipal, |
252 | | nsSecurityFlags aSecurityFlags, |
253 | | nsContentPolicyType aContentPolicyType, |
254 | | mozilla::dom::PerformanceStorage* aPerformanceStorage = nullptr, |
255 | | nsILoadGroup *aLoadGroup = nullptr, |
256 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
257 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
258 | | nsIIOService *aIoService = nullptr); |
259 | | |
260 | | // See NS_NewChannelInternal for usage and argument description |
261 | | nsresult |
262 | | NS_NewChannel(nsIChannel** outChannel, |
263 | | nsIURI* aUri, |
264 | | nsIPrincipal* aLoadingPrincipal, |
265 | | const mozilla::dom::ClientInfo& aLoadingClientInfo, |
266 | | const mozilla::Maybe<mozilla::dom::ServiceWorkerDescriptor>& aController, |
267 | | nsSecurityFlags aSecurityFlags, |
268 | | nsContentPolicyType aContentPolicyType, |
269 | | mozilla::dom::PerformanceStorage* aPerformanceStorage = nullptr, |
270 | | nsILoadGroup* aLoadGroup = nullptr, |
271 | | nsIInterfaceRequestor* aCallbacks = nullptr, |
272 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
273 | | nsIIOService* aIoService = nullptr); |
274 | | |
275 | | nsresult NS_GetIsDocumentChannel(nsIChannel * aChannel, bool *aIsDocument); |
276 | | |
277 | | nsresult NS_MakeAbsoluteURI(nsACString &result, |
278 | | const nsACString &spec, |
279 | | nsIURI *baseURI); |
280 | | |
281 | | nsresult NS_MakeAbsoluteURI(char **result, |
282 | | const char *spec, |
283 | | nsIURI *baseURI); |
284 | | |
285 | | nsresult NS_MakeAbsoluteURI(nsAString &result, |
286 | | const nsAString &spec, |
287 | | nsIURI *baseURI); |
288 | | |
289 | | /** |
290 | | * This function is a helper function to get a scheme's default port. |
291 | | */ |
292 | | int32_t NS_GetDefaultPort(const char *scheme, |
293 | | nsIIOService *ioService = nullptr); |
294 | | |
295 | | /** |
296 | | * This function is a helper function to apply the ToAscii conversion |
297 | | * to a string |
298 | | */ |
299 | | bool NS_StringToACE(const nsACString &idn, nsACString &result); |
300 | | |
301 | | /** |
302 | | * This function is a helper function to get a protocol's default port if the |
303 | | * URI does not specify a port explicitly. Returns -1 if this protocol has no |
304 | | * concept of ports or if there was an error getting the port. |
305 | | */ |
306 | | int32_t NS_GetRealPort(nsIURI *aURI); |
307 | | |
308 | | nsresult |
309 | | NS_NewInputStreamChannelInternal(nsIChannel** outChannel, |
310 | | nsIURI* aUri, |
311 | | already_AddRefed<nsIInputStream> aStream, |
312 | | const nsACString& aContentType, |
313 | | const nsACString& aContentCharset, |
314 | | nsILoadInfo* aLoadInfo); |
315 | | |
316 | | nsresult |
317 | | NS_NewInputStreamChannelInternal(nsIChannel** outChannel, |
318 | | nsIURI* aUri, |
319 | | already_AddRefed<nsIInputStream> aStream, |
320 | | const nsACString& aContentType, |
321 | | const nsACString& aContentCharset, |
322 | | nsINode* aLoadingNode, |
323 | | nsIPrincipal* aLoadingPrincipal, |
324 | | nsIPrincipal* aTriggeringPrincipal, |
325 | | nsSecurityFlags aSecurityFlags, |
326 | | nsContentPolicyType aContentPolicyType); |
327 | | |
328 | | |
329 | | nsresult |
330 | | NS_NewInputStreamChannel(nsIChannel* *outChannel, |
331 | | nsIURI* aUri, |
332 | | already_AddRefed<nsIInputStream> aStream, |
333 | | nsIPrincipal* aLoadingPrincipal, |
334 | | nsSecurityFlags aSecurityFlags, |
335 | | nsContentPolicyType aContentPolicyType, |
336 | | const nsACString& aContentType = EmptyCString(), |
337 | | const nsACString& aContentCharset = EmptyCString()); |
338 | | |
339 | | nsresult NS_NewInputStreamChannelInternal(nsIChannel **outChannel, |
340 | | nsIURI *aUri, |
341 | | const nsAString &aData, |
342 | | const nsACString &aContentType, |
343 | | nsINode *aLoadingNode, |
344 | | nsIPrincipal *aLoadingPrincipal, |
345 | | nsIPrincipal *aTriggeringPrincipal, |
346 | | nsSecurityFlags aSecurityFlags, |
347 | | nsContentPolicyType aContentPolicyType, |
348 | | bool aIsSrcdocChannel = false); |
349 | | |
350 | | nsresult |
351 | | NS_NewInputStreamChannelInternal(nsIChannel **outChannel, |
352 | | nsIURI *aUri, |
353 | | const nsAString &aData, |
354 | | const nsACString &aContentType, |
355 | | nsILoadInfo *aLoadInfo, |
356 | | bool aIsSrcdocChannel = false); |
357 | | |
358 | | nsresult NS_NewInputStreamChannel(nsIChannel **outChannel, |
359 | | nsIURI *aUri, |
360 | | const nsAString &aData, |
361 | | const nsACString &aContentType, |
362 | | nsIPrincipal *aLoadingPrincipal, |
363 | | nsSecurityFlags aSecurityFlags, |
364 | | nsContentPolicyType aContentPolicyType, |
365 | | bool aIsSrcdocChannel = false); |
366 | | |
367 | | nsresult |
368 | | NS_NewInputStreamPump(nsIInputStreamPump** aResult, |
369 | | already_AddRefed<nsIInputStream> aStream, |
370 | | uint32_t aSegsize = 0, |
371 | | uint32_t aSegcount = 0, |
372 | | bool aCloseWhenDone = false, |
373 | | nsIEventTarget *aMainThreadTarget = nullptr); |
374 | | |
375 | | nsresult NS_NewLoadGroup(nsILoadGroup **result, |
376 | | nsIRequestObserver *obs); |
377 | | |
378 | | // Create a new nsILoadGroup that will match the given principal. |
379 | | nsresult |
380 | | NS_NewLoadGroup(nsILoadGroup **aResult, nsIPrincipal* aPrincipal); |
381 | | |
382 | | // Determine if the given loadGroup/principal pair will produce a principal |
383 | | // with similar permissions when passed to NS_NewChannel(). This checks for |
384 | | // things like making sure the appId and browser element flags match. Without |
385 | | // an appropriate load group these values can be lost when getting the result |
386 | | // principal back out of the channel. Null principals are also always allowed |
387 | | // as they do not have permissions to actually use the load group. |
388 | | bool |
389 | | NS_LoadGroupMatchesPrincipal(nsILoadGroup *aLoadGroup, |
390 | | nsIPrincipal *aPrincipal); |
391 | | |
392 | | nsresult NS_NewDownloader(nsIStreamListener **result, |
393 | | nsIDownloadObserver *observer, |
394 | | nsIFile *downloadLocation = nullptr); |
395 | | |
396 | | nsresult NS_NewStreamLoader(nsIStreamLoader **result, |
397 | | nsIStreamLoaderObserver *observer, |
398 | | nsIRequestObserver *requestObserver = nullptr); |
399 | | |
400 | | nsresult NS_NewIncrementalStreamLoader(nsIIncrementalStreamLoader **result, |
401 | | nsIIncrementalStreamLoaderObserver *observer); |
402 | | |
403 | | nsresult NS_NewStreamLoaderInternal(nsIStreamLoader **outStream, |
404 | | nsIURI *aUri, |
405 | | nsIStreamLoaderObserver *aObserver, |
406 | | nsINode *aLoadingNode, |
407 | | nsIPrincipal *aLoadingPrincipal, |
408 | | nsSecurityFlags aSecurityFlags, |
409 | | nsContentPolicyType aContentPolicyType, |
410 | | nsILoadGroup *aLoadGroup = nullptr, |
411 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
412 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
413 | | nsIURI *aReferrer = nullptr); |
414 | | |
415 | | nsresult |
416 | | NS_NewStreamLoader(nsIStreamLoader **outStream, |
417 | | nsIURI *aUri, |
418 | | nsIStreamLoaderObserver *aObserver, |
419 | | nsINode *aLoadingNode, |
420 | | nsSecurityFlags aSecurityFlags, |
421 | | nsContentPolicyType aContentPolicyType, |
422 | | nsILoadGroup *aLoadGroup = nullptr, |
423 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
424 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
425 | | nsIURI *aReferrer = nullptr); |
426 | | |
427 | | nsresult |
428 | | NS_NewStreamLoader(nsIStreamLoader **outStream, |
429 | | nsIURI *aUri, |
430 | | nsIStreamLoaderObserver *aObserver, |
431 | | nsIPrincipal *aLoadingPrincipal, |
432 | | nsSecurityFlags aSecurityFlags, |
433 | | nsContentPolicyType aContentPolicyType, |
434 | | nsILoadGroup *aLoadGroup = nullptr, |
435 | | nsIInterfaceRequestor *aCallbacks = nullptr, |
436 | | nsLoadFlags aLoadFlags = nsIRequest::LOAD_NORMAL, |
437 | | nsIURI *aReferrer = nullptr); |
438 | | |
439 | | nsresult NS_NewSyncStreamListener(nsIStreamListener **result, |
440 | | nsIInputStream **stream); |
441 | | |
442 | | /** |
443 | | * Implement the nsIChannel::Open(nsIInputStream**) method using the channel's |
444 | | * AsyncOpen method. |
445 | | * |
446 | | * NOTE: Reading from the returned nsIInputStream may spin the current |
447 | | * thread's event queue, which could result in any event being processed. |
448 | | */ |
449 | | nsresult NS_ImplementChannelOpen(nsIChannel *channel, |
450 | | nsIInputStream **result); |
451 | | |
452 | | nsresult NS_NewRequestObserverProxy(nsIRequestObserver **result, |
453 | | nsIRequestObserver *observer, |
454 | | nsISupports *context); |
455 | | |
456 | | nsresult NS_NewSimpleStreamListener(nsIStreamListener **result, |
457 | | nsIOutputStream *sink, |
458 | | nsIRequestObserver *observer = nullptr); |
459 | | |
460 | | nsresult NS_CheckPortSafety(int32_t port, |
461 | | const char *scheme, |
462 | | nsIIOService *ioService = nullptr); |
463 | | |
464 | | // Determine if this URI is using a safe port. |
465 | | nsresult NS_CheckPortSafety(nsIURI *uri); |
466 | | |
467 | | nsresult NS_NewProxyInfo(const nsACString &type, |
468 | | const nsACString &host, |
469 | | int32_t port, |
470 | | uint32_t flags, |
471 | | nsIProxyInfo **result); |
472 | | |
473 | | nsresult NS_GetFileProtocolHandler(nsIFileProtocolHandler **result, |
474 | | nsIIOService *ioService = nullptr); |
475 | | |
476 | | nsresult NS_GetFileFromURLSpec(const nsACString &inURL, |
477 | | nsIFile **result, |
478 | | nsIIOService *ioService = nullptr); |
479 | | |
480 | | nsresult NS_GetURLSpecFromFile(nsIFile *file, |
481 | | nsACString &url, |
482 | | nsIIOService *ioService = nullptr); |
483 | | |
484 | | /** |
485 | | * Converts the nsIFile to the corresponding URL string. |
486 | | * Should only be called on files which are not directories, |
487 | | * is otherwise identical to NS_GetURLSpecFromFile, but is |
488 | | * usually more efficient. |
489 | | * Warning: this restriction may not be enforced at runtime! |
490 | | */ |
491 | | nsresult NS_GetURLSpecFromActualFile(nsIFile *file, |
492 | | nsACString &url, |
493 | | nsIIOService *ioService = nullptr); |
494 | | |
495 | | /** |
496 | | * Converts the nsIFile to the corresponding URL string. |
497 | | * Should only be called on files which are directories, |
498 | | * is otherwise identical to NS_GetURLSpecFromFile, but is |
499 | | * usually more efficient. |
500 | | * Warning: this restriction may not be enforced at runtime! |
501 | | */ |
502 | | nsresult NS_GetURLSpecFromDir(nsIFile *file, |
503 | | nsACString &url, |
504 | | nsIIOService *ioService = nullptr); |
505 | | |
506 | | /** |
507 | | * Obtains the referrer for a given channel. This first tries to obtain the |
508 | | * referrer from the property docshell.internalReferrer, and if that doesn't |
509 | | * work and the channel is an nsIHTTPChannel, we check it's referrer property. |
510 | | * |
511 | | * @returns NS_ERROR_NOT_AVAILABLE if no referrer is available. |
512 | | */ |
513 | | nsresult NS_GetReferrerFromChannel(nsIChannel *channel, |
514 | | nsIURI **referrer); |
515 | | |
516 | | nsresult NS_ParseRequestContentType(const nsACString &rawContentType, |
517 | | nsCString &contentType, |
518 | | nsCString &contentCharset); |
519 | | |
520 | | nsresult NS_ParseResponseContentType(const nsACString &rawContentType, |
521 | | nsCString &contentType, |
522 | | nsCString &contentCharset); |
523 | | |
524 | | nsresult NS_ExtractCharsetFromContentType(const nsACString &rawContentType, |
525 | | nsCString &contentCharset, |
526 | | bool *hadCharset, |
527 | | int32_t *charsetStart, |
528 | | int32_t *charsetEnd); |
529 | | |
530 | | nsresult NS_NewLocalFileInputStream(nsIInputStream **result, |
531 | | nsIFile *file, |
532 | | int32_t ioFlags = -1, |
533 | | int32_t perm = -1, |
534 | | int32_t behaviorFlags = 0); |
535 | | |
536 | | nsresult NS_NewLocalFileOutputStream(nsIOutputStream **result, |
537 | | nsIFile *file, |
538 | | int32_t ioFlags = -1, |
539 | | int32_t perm = -1, |
540 | | int32_t behaviorFlags = 0); |
541 | | |
542 | | // returns a file output stream which can be QI'ed to nsISafeOutputStream. |
543 | | nsresult NS_NewAtomicFileOutputStream(nsIOutputStream **result, |
544 | | nsIFile *file, |
545 | | int32_t ioFlags = -1, |
546 | | int32_t perm = -1, |
547 | | int32_t behaviorFlags = 0); |
548 | | |
549 | | // returns a file output stream which can be QI'ed to nsISafeOutputStream. |
550 | | nsresult NS_NewSafeLocalFileOutputStream(nsIOutputStream **result, |
551 | | nsIFile *file, |
552 | | int32_t ioFlags = -1, |
553 | | int32_t perm = -1, |
554 | | int32_t behaviorFlags = 0); |
555 | | |
556 | | nsresult NS_NewLocalFileStream(nsIFileStream **result, |
557 | | nsIFile *file, |
558 | | int32_t ioFlags = -1, |
559 | | int32_t perm = -1, |
560 | | int32_t behaviorFlags = 0); |
561 | | |
562 | | MOZ_MUST_USE nsresult |
563 | | NS_NewBufferedInputStream(nsIInputStream** aResult, |
564 | | already_AddRefed<nsIInputStream> aInputStream, |
565 | | uint32_t aBufferSize); |
566 | | |
567 | | // note: the resulting stream can be QI'ed to nsISafeOutputStream iff the |
568 | | // provided stream supports it. |
569 | | nsresult NS_NewBufferedOutputStream(nsIOutputStream** aResult, |
570 | | already_AddRefed<nsIOutputStream> aOutputStream, |
571 | | uint32_t aBufferSize); |
572 | | |
573 | | /** |
574 | | * This function reads an inputStream and stores its content into a buffer. In |
575 | | * general, you should avoid using this function because, it blocks the current |
576 | | * thread until the operation is done. |
577 | | * If the inputStream is async, the reading happens on an I/O thread. |
578 | | * |
579 | | * @param aInputStream the inputStream. |
580 | | * @param aDest the destination buffer. if *aDest is null, it will be allocated |
581 | | * with the size of the written data. if aDest is not null, aCount |
582 | | * must greater than 0. |
583 | | * @param aCount the amount of data to read. Use -1 if you want that all the |
584 | | * stream is read. |
585 | | * @param aWritten this pointer will be used to store the number of data |
586 | | * written in the buffer. If you don't need, pass nullptr. |
587 | | */ |
588 | | nsresult NS_ReadInputStreamToBuffer(nsIInputStream *aInputStream, |
589 | | void **aDest, |
590 | | int64_t aCount, |
591 | | uint64_t* aWritten = nullptr); |
592 | | |
593 | | /** |
594 | | * See the comment for NS_ReadInputStreamToBuffer |
595 | | */ |
596 | | nsresult NS_ReadInputStreamToString(nsIInputStream *aInputStream, |
597 | | nsACString &aDest, |
598 | | int64_t aCount, |
599 | | uint64_t* aWritten = nullptr); |
600 | | |
601 | | nsresult |
602 | | NS_LoadPersistentPropertiesFromURISpec(nsIPersistentProperties **outResult, |
603 | | const nsACString &aSpec); |
604 | | |
605 | | /** |
606 | | * NS_QueryNotificationCallbacks implements the canonical algorithm for |
607 | | * querying interfaces from a channel's notification callbacks. It first |
608 | | * searches the channel's notificationCallbacks attribute, and if the interface |
609 | | * is not found there, then it inspects the notificationCallbacks attribute of |
610 | | * the channel's loadGroup. |
611 | | * |
612 | | * Note: templatized only because nsIWebSocketChannel is currently not an |
613 | | * nsIChannel. |
614 | | */ |
615 | | template <class T> inline void |
616 | | NS_QueryNotificationCallbacks(T *channel, |
617 | | const nsIID &iid, |
618 | | void **result) |
619 | 0 | { |
620 | 0 | MOZ_ASSERT(channel, "null channel"); |
621 | 0 | *result = nullptr; |
622 | 0 |
|
623 | 0 | nsCOMPtr<nsIInterfaceRequestor> cbs; |
624 | 0 | mozilla::Unused << channel->GetNotificationCallbacks(getter_AddRefs(cbs)); |
625 | 0 | if (cbs) |
626 | 0 | cbs->GetInterface(iid, result); |
627 | 0 | if (!*result) { |
628 | 0 | // try load group's notification callbacks... |
629 | 0 | nsCOMPtr<nsILoadGroup> loadGroup; |
630 | 0 | mozilla::Unused << channel->GetLoadGroup(getter_AddRefs(loadGroup)); |
631 | 0 | if (loadGroup) { |
632 | 0 | loadGroup->GetNotificationCallbacks(getter_AddRefs(cbs)); |
633 | 0 | if (cbs) |
634 | 0 | cbs->GetInterface(iid, result); |
635 | 0 | } |
636 | 0 | } |
637 | 0 | } Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::net::HttpBaseChannel>(mozilla::net::HttpBaseChannel*, nsID const&, void**) Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::net::nsHttpChannel>(mozilla::net::nsHttpChannel*, nsID const&, void**) Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::net::WyciwygChannelChild>(mozilla::net::WyciwygChannelChild*, nsID const&, void**) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsWyciwygChannel>(nsWyciwygChannel*, nsID const&, void**) Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::dom::ExternalHelperAppParent>(mozilla::dom::ExternalHelperAppParent*, nsID const&, void**) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsIWebSocketChannel>(nsIWebSocketChannel*, nsID const&, void**) |
638 | | |
639 | | // template helper: |
640 | | // Note: "class C" templatized only because nsIWebSocketChannel is currently not |
641 | | // an nsIChannel. |
642 | | |
643 | | template <class C, class T> inline void |
644 | | NS_QueryNotificationCallbacks(C *channel, |
645 | | nsCOMPtr<T> &result) |
646 | 0 | { |
647 | 0 | NS_QueryNotificationCallbacks(channel, NS_GET_TEMPLATE_IID(T), |
648 | 0 | getter_AddRefs(result)); |
649 | 0 | } Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::net::HttpBaseChannel, nsILoadContext>(mozilla::net::HttpBaseChannel*, nsCOMPtr<nsILoadContext>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::net::nsHttpChannel, nsINetworkInterceptController>(mozilla::net::nsHttpChannel*, nsCOMPtr<nsINetworkInterceptController>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsIChannel, nsINetworkInterceptController>(nsIChannel*, nsCOMPtr<nsINetworkInterceptController>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::net::nsHttpChannel, nsIParentChannel>(mozilla::net::nsHttpChannel*, nsCOMPtr<nsIParentChannel>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::net::nsHttpChannel, nsILoadContext>(mozilla::net::nsHttpChannel*, nsCOMPtr<nsILoadContext>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsIChannel, nsITabChild>(nsIChannel*, nsCOMPtr<nsITabChild>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::net::WyciwygChannelChild, nsILoadContext>(mozilla::net::WyciwygChannelChild*, nsCOMPtr<nsILoadContext>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsWyciwygChannel, nsILoadContext>(nsWyciwygChannel*, nsCOMPtr<nsILoadContext>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<mozilla::dom::ExternalHelperAppParent, nsILoadContext>(mozilla::dom::ExternalHelperAppParent*, nsCOMPtr<nsILoadContext>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsIChannel, nsIDocShell>(nsIChannel*, nsCOMPtr<nsIDocShell>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsIChannel, nsIWebNavigation>(nsIChannel*, nsCOMPtr<nsIWebNavigation>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsIWebSocketChannel, nsILoadContext>(nsIWebSocketChannel*, nsCOMPtr<nsILoadContext>&) |
650 | | |
651 | | /** |
652 | | * Alternate form of NS_QueryNotificationCallbacks designed for use by |
653 | | * nsIChannel implementations. |
654 | | */ |
655 | | inline void |
656 | | NS_QueryNotificationCallbacks(nsIInterfaceRequestor *callbacks, |
657 | | nsILoadGroup *loadGroup, |
658 | | const nsIID &iid, |
659 | | void **result) |
660 | | { |
661 | | *result = nullptr; |
662 | | |
663 | | if (callbacks) |
664 | | callbacks->GetInterface(iid, result); |
665 | | if (!*result) { |
666 | | // try load group's notification callbacks... |
667 | | if (loadGroup) { |
668 | | nsCOMPtr<nsIInterfaceRequestor> cbs; |
669 | | loadGroup->GetNotificationCallbacks(getter_AddRefs(cbs)); |
670 | | if (cbs) |
671 | | cbs->GetInterface(iid, result); |
672 | | } |
673 | | } |
674 | | } |
675 | | |
676 | | /** |
677 | | * Returns true if channel is using Private Browsing, or false if not. |
678 | | * Returns false if channel's callbacks don't implement nsILoadContext. |
679 | | */ |
680 | | bool NS_UsePrivateBrowsing(nsIChannel *channel); |
681 | | |
682 | | /** |
683 | | * Extract the OriginAttributes from the channel's triggering principal. |
684 | | */ |
685 | | bool NS_GetOriginAttributes(nsIChannel *aChannel, |
686 | | mozilla::OriginAttributes &aAttributes); |
687 | | |
688 | | /** |
689 | | * Returns true if the channel has visited any cross-origin URLs on any |
690 | | * URLs that it was redirected through. |
691 | | */ |
692 | | bool NS_HasBeenCrossOrigin(nsIChannel* aChannel, bool aReport = false); |
693 | | |
694 | | /** |
695 | | * Returns true if the channel is a safe top-level navigation. |
696 | | */ |
697 | | bool NS_IsSafeTopLevelNav(nsIChannel* aChannel); |
698 | | |
699 | | /** |
700 | | * Returns true if the channel is a foreign with respect to the host-uri. |
701 | | * For loads of TYPE_DOCUMENT, this function returns true if it's a |
702 | | * cross origin navigation. |
703 | | */ |
704 | | bool NS_IsSameSiteForeign(nsIChannel* aChannel, nsIURI* aHostURI); |
705 | | |
706 | | // Constants duplicated from nsIScriptSecurityManager so we avoid having necko |
707 | | // know about script security manager. |
708 | 0 | #define NECKO_NO_APP_ID 0 |
709 | | #define NECKO_UNKNOWN_APP_ID UINT32_MAX |
710 | | |
711 | | // Unique first-party domain for separating the safebrowsing cookie. |
712 | | // Note if this value is changed, code in test_cookiejars_safebrowsing.js and |
713 | | // nsUrlClassifierHashCompleter.js should also be changed. |
714 | | #define NECKO_SAFEBROWSING_FIRST_PARTY_DOMAIN \ |
715 | | "safebrowsing.86868755-6b82-4842-b301-72671a0db32e.mozilla" |
716 | | |
717 | | // Unique first-party domain for separating about uri. |
718 | | #define ABOUT_URI_FIRST_PARTY_DOMAIN \ |
719 | 0 | "about.ef2a7dd5-93bc-417f-a698-142c3116864f.mozilla" |
720 | | |
721 | | /** |
722 | | * Determines whether appcache should be checked for a given principal. |
723 | | */ |
724 | | bool NS_ShouldCheckAppCache(nsIPrincipal *aPrincipal); |
725 | | |
726 | | /** |
727 | | * Wraps an nsIAuthPrompt so that it can be used as an nsIAuthPrompt2. This |
728 | | * method is provided mainly for use by other methods in this file. |
729 | | * |
730 | | * *aAuthPrompt2 should be set to null before calling this function. |
731 | | */ |
732 | | void NS_WrapAuthPrompt(nsIAuthPrompt *aAuthPrompt, |
733 | | nsIAuthPrompt2 **aAuthPrompt2); |
734 | | |
735 | | /** |
736 | | * Gets an auth prompt from an interface requestor. This takes care of wrapping |
737 | | * an nsIAuthPrompt so that it can be used as an nsIAuthPrompt2. |
738 | | */ |
739 | | void NS_QueryAuthPrompt2(nsIInterfaceRequestor *aCallbacks, |
740 | | nsIAuthPrompt2 **aAuthPrompt); |
741 | | |
742 | | /** |
743 | | * Gets an nsIAuthPrompt2 from a channel. Use this instead of |
744 | | * NS_QueryNotificationCallbacks for better backwards compatibility. |
745 | | */ |
746 | | void NS_QueryAuthPrompt2(nsIChannel *aChannel, |
747 | | nsIAuthPrompt2 **aAuthPrompt); |
748 | | |
749 | | /* template helper */ |
750 | | template <class T> inline void |
751 | | NS_QueryNotificationCallbacks(nsIInterfaceRequestor *callbacks, |
752 | | nsILoadGroup *loadGroup, |
753 | | nsCOMPtr<T> &result) |
754 | | { |
755 | | NS_QueryNotificationCallbacks(callbacks, loadGroup, |
756 | | NS_GET_TEMPLATE_IID(T), |
757 | | getter_AddRefs(result)); |
758 | | } |
759 | | |
760 | | /* template helper */ |
761 | | template <class T> inline void |
762 | | NS_QueryNotificationCallbacks(const nsCOMPtr<nsIInterfaceRequestor> &aCallbacks, |
763 | | const nsCOMPtr<nsILoadGroup> &aLoadGroup, |
764 | | nsCOMPtr<T> &aResult) |
765 | | { |
766 | | NS_QueryNotificationCallbacks(aCallbacks.get(), aLoadGroup.get(), aResult); |
767 | | } |
768 | | |
769 | | /* template helper */ |
770 | | template <class T> inline void |
771 | | NS_QueryNotificationCallbacks(const nsCOMPtr<nsIChannel> &aChannel, |
772 | | nsCOMPtr<T> &aResult) |
773 | 0 | { |
774 | 0 | NS_QueryNotificationCallbacks(aChannel.get(), aResult); |
775 | 0 | } Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsINetworkInterceptController>(nsCOMPtr<nsIChannel> const&, nsCOMPtr<nsINetworkInterceptController>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsIWebNavigation>(nsCOMPtr<nsIChannel> const&, nsCOMPtr<nsIWebNavigation>&) Unexecuted instantiation: void NS_QueryNotificationCallbacks<nsIDocShell>(nsCOMPtr<nsIChannel> const&, nsCOMPtr<nsIDocShell>&) |
776 | | |
777 | | /** |
778 | | * This function returns a nsIInterfaceRequestor instance that returns the |
779 | | * same result as NS_QueryNotificationCallbacks when queried. It is useful |
780 | | * as the value for nsISocketTransport::securityCallbacks. |
781 | | */ |
782 | | nsresult |
783 | | NS_NewNotificationCallbacksAggregation(nsIInterfaceRequestor *callbacks, |
784 | | nsILoadGroup *loadGroup, |
785 | | nsIEventTarget *target, |
786 | | nsIInterfaceRequestor **result); |
787 | | |
788 | | nsresult |
789 | | NS_NewNotificationCallbacksAggregation(nsIInterfaceRequestor *callbacks, |
790 | | nsILoadGroup *loadGroup, |
791 | | nsIInterfaceRequestor **result); |
792 | | |
793 | | /** |
794 | | * Helper function for testing online/offline state of the browser. |
795 | | */ |
796 | | bool NS_IsOffline(); |
797 | | |
798 | | /** |
799 | | * Helper functions for implementing nsINestedURI::innermostURI. |
800 | | * |
801 | | * Note that NS_DoImplGetInnermostURI is "private" -- call |
802 | | * NS_ImplGetInnermostURI instead. |
803 | | */ |
804 | | nsresult NS_DoImplGetInnermostURI(nsINestedURI *nestedURI, nsIURI **result); |
805 | | |
806 | | nsresult NS_ImplGetInnermostURI(nsINestedURI *nestedURI, nsIURI **result); |
807 | | |
808 | | /** |
809 | | * Helper function for testing whether the given URI, or any of its |
810 | | * inner URIs, has all the given protocol flags. |
811 | | */ |
812 | | nsresult NS_URIChainHasFlags(nsIURI *uri, |
813 | | uint32_t flags, |
814 | | bool *result); |
815 | | |
816 | | /** |
817 | | * Helper function for getting the innermost URI for a given URI. The return |
818 | | * value could be just the object passed in if it's not a nested URI. |
819 | | */ |
820 | | already_AddRefed<nsIURI> NS_GetInnermostURI(nsIURI *aURI); |
821 | | |
822 | | /** |
823 | | * Get the "final" URI for a channel. This is either channel's load info |
824 | | * resultPrincipalURI, if set, or GetOriginalURI. In most cases (but not all) load |
825 | | * info resultPrincipalURI, if set, corresponds to URI of the channel if it's required |
826 | | * to represent the actual principal for the channel. |
827 | | */ |
828 | | nsresult NS_GetFinalChannelURI(nsIChannel *channel, nsIURI **uri); |
829 | | |
830 | | // NS_SecurityHashURI must return the same hash value for any two URIs that |
831 | | // compare equal according to NS_SecurityCompareURIs. Unfortunately, in the |
832 | | // case of files, it's not clear we can do anything better than returning |
833 | | // the schemeHash, so hashing files degenerates to storing them in a list. |
834 | | uint32_t NS_SecurityHashURI(nsIURI *aURI); |
835 | | |
836 | | bool NS_SecurityCompareURIs(nsIURI *aSourceURI, |
837 | | nsIURI *aTargetURI, |
838 | | bool aStrictFileOriginPolicy); |
839 | | |
840 | | bool NS_URIIsLocalFile(nsIURI *aURI); |
841 | | |
842 | | // When strict file origin policy is enabled, SecurityCompareURIs will fail for |
843 | | // file URIs that do not point to the same local file. This call provides an |
844 | | // alternate file-specific origin check that allows target files that are |
845 | | // contained in the same directory as the source. |
846 | | // |
847 | | // https://developer.mozilla.org/en-US/docs/Same-origin_policy_for_file:_URIs |
848 | | bool NS_RelaxStrictFileOriginPolicy(nsIURI *aTargetURI, |
849 | | nsIURI *aSourceURI, |
850 | | bool aAllowDirectoryTarget = false); |
851 | | |
852 | | bool NS_IsInternalSameURIRedirect(nsIChannel *aOldChannel, |
853 | | nsIChannel *aNewChannel, |
854 | | uint32_t aFlags); |
855 | | |
856 | | bool NS_IsHSTSUpgradeRedirect(nsIChannel *aOldChannel, |
857 | | nsIChannel *aNewChannel, |
858 | | uint32_t aFlags); |
859 | | |
860 | | nsresult NS_LinkRedirectChannels(uint32_t channelId, |
861 | | nsIParentChannel *parentChannel, |
862 | | nsIChannel **_result); |
863 | | |
864 | | /** |
865 | | * Helper function which checks whether the channel can be |
866 | | * openend using Open2() or has to fall back to opening |
867 | | * the channel using Open(). |
868 | | */ |
869 | | nsresult NS_MaybeOpenChannelUsingOpen2(nsIChannel* aChannel, |
870 | | nsIInputStream **aStream); |
871 | | |
872 | | /** |
873 | | * Helper function which checks whether the channel can be |
874 | | * openend using AsyncOpen2() or has to fall back to opening |
875 | | * the channel using AsyncOpen(). |
876 | | */ |
877 | | nsresult NS_MaybeOpenChannelUsingAsyncOpen2(nsIChannel* aChannel, |
878 | | nsIStreamListener *aListener); |
879 | | |
880 | | /** Given the first (disposition) token from a Content-Disposition header, |
881 | | * tell whether it indicates the content is inline or attachment |
882 | | * @param aDispToken the disposition token from the content-disposition header |
883 | | */ |
884 | | uint32_t NS_GetContentDispositionFromToken(const nsAString &aDispToken); |
885 | | |
886 | | /** Determine the disposition (inline/attachment) of the content based on the |
887 | | * Content-Disposition header |
888 | | * @param aHeader the content-disposition header (full value) |
889 | | * @param aChan the channel the header came from |
890 | | */ |
891 | | uint32_t NS_GetContentDispositionFromHeader(const nsACString &aHeader, |
892 | | nsIChannel *aChan = nullptr); |
893 | | |
894 | | /** Extracts the filename out of a content-disposition header |
895 | | * @param aFilename [out] The filename. Can be empty on error. |
896 | | * @param aDisposition Value of a Content-Disposition header |
897 | | * @param aURI Optional. Will be used to get a fallback charset for the |
898 | | * filename, if it is QI'able to nsIURL |
899 | | */ |
900 | | nsresult NS_GetFilenameFromDisposition(nsAString &aFilename, |
901 | | const nsACString &aDisposition, |
902 | | nsIURI *aURI = nullptr); |
903 | | |
904 | | /** |
905 | | * Make sure Personal Security Manager is initialized |
906 | | */ |
907 | | void net_EnsurePSMInit(); |
908 | | |
909 | | /** |
910 | | * Test whether a URI is "about:blank". |uri| must not be null |
911 | | */ |
912 | | bool NS_IsAboutBlank(nsIURI *uri); |
913 | | |
914 | | nsresult NS_GenerateHostPort(const nsCString &host, int32_t port, |
915 | | nsACString &hostLine); |
916 | | |
917 | | /** |
918 | | * Sniff the content type for a given request or a given buffer. |
919 | | * |
920 | | * aSnifferType can be either NS_CONTENT_SNIFFER_CATEGORY or |
921 | | * NS_DATA_SNIFFER_CATEGORY. The function returns the sniffed content type |
922 | | * in the aSniffedType argument. This argument will not be modified if the |
923 | | * content type could not be sniffed. |
924 | | */ |
925 | | void NS_SniffContent(const char *aSnifferType, nsIRequest *aRequest, |
926 | | const uint8_t *aData, uint32_t aLength, |
927 | | nsACString &aSniffedType); |
928 | | |
929 | | /** |
930 | | * Whether the channel was created to load a srcdoc document. |
931 | | * Note that view-source:about:srcdoc is classified as a srcdoc document by |
932 | | * this function, which may not be applicable everywhere. |
933 | | */ |
934 | | bool NS_IsSrcdocChannel(nsIChannel *aChannel); |
935 | | |
936 | | /** |
937 | | * Return true if the given string is a reasonable HTTP header value given the |
938 | | * definition in RFC 2616 section 4.2. Currently we don't pay the cost to do |
939 | | * full, sctrict validation here since it would require fulling parsing the |
940 | | * value. |
941 | | */ |
942 | | bool NS_IsReasonableHTTPHeaderValue(const nsACString &aValue); |
943 | | |
944 | | /** |
945 | | * Return true if the given string is a valid HTTP token per RFC 2616 section |
946 | | * 2.2. |
947 | | */ |
948 | | bool NS_IsValidHTTPToken(const nsACString &aToken); |
949 | | |
950 | | /** |
951 | | * Strip the leading or trailing HTTP whitespace per fetch spec section 2.2. |
952 | | */ |
953 | | void NS_TrimHTTPWhitespace(const nsACString& aSource, nsACString& aDest); |
954 | | |
955 | | /** |
956 | | * Return true if the given request must be upgraded to HTTPS. |
957 | | */ |
958 | | nsresult NS_ShouldSecureUpgrade(nsIURI* aURI, |
959 | | nsILoadInfo* aLoadInfo, |
960 | | nsIPrincipal* aChannelResultPrincipal, |
961 | | bool aPrivateBrowsing, |
962 | | bool aAllowSTS, |
963 | | const mozilla::OriginAttributes& aOriginAttributes, |
964 | | bool& aShouldUpgrade); |
965 | | |
966 | | /** |
967 | | * Returns an https URI for channels that need to go through secure upgrades. |
968 | | */ |
969 | | nsresult NS_GetSecureUpgradedURI(nsIURI* aURI, nsIURI** aUpgradedURI); |
970 | | |
971 | | nsresult NS_CompareLoadInfoAndLoadContext(nsIChannel *aChannel); |
972 | | |
973 | | /** |
974 | | * Return default referrer policy which is controlled by user |
975 | | * prefs: |
976 | | * network.http.referer.defaultPolicy for regular mode |
977 | | * network.http.referer.defaultPolicy.pbmode for private mode |
978 | | */ |
979 | | uint32_t NS_GetDefaultReferrerPolicy(bool privateBrowsing = false); |
980 | | |
981 | | namespace mozilla { |
982 | | namespace net { |
983 | | |
984 | | const static uint64_t kJS_MAX_SAFE_UINTEGER = +9007199254740991ULL; |
985 | | const static int64_t kJS_MIN_SAFE_INTEGER = -9007199254740991LL; |
986 | | const static int64_t kJS_MAX_SAFE_INTEGER = +9007199254740991LL; |
987 | | |
988 | | // Make sure a 64bit value can be captured by JS MAX_SAFE_INTEGER |
989 | | bool InScriptableRange(int64_t val); |
990 | | |
991 | | // Make sure a 64bit value can be captured by JS MAX_SAFE_INTEGER |
992 | | bool InScriptableRange(uint64_t val); |
993 | | |
994 | | /** |
995 | | * Given the value of a single header field (such as |
996 | | * Content-Disposition and Content-Type) and the name of a parameter |
997 | | * (e.g. filename, name, charset), returns the value of the parameter. |
998 | | * See nsIMIMEHeaderParam.idl for more information. |
999 | | * |
1000 | | * @param aHeaderVal a header string to get the value of a parameter |
1001 | | * from. |
1002 | | * @param aParamName the name of a MIME header parameter (e.g. |
1003 | | * filename, name, charset). If empty or nullptr, |
1004 | | * returns the first (possibly) _unnamed_ 'parameter'. |
1005 | | * @return the value of <code>aParamName</code> in Unichar(UTF-16). |
1006 | | */ |
1007 | | nsresult |
1008 | | GetParameterHTTP(const nsACString& aHeaderVal, |
1009 | | const char* aParamName, |
1010 | | nsAString& aResult); |
1011 | | |
1012 | | } // namespace net |
1013 | | } // namespace mozilla |
1014 | | |
1015 | | #endif // !nsNetUtil_h__ |