1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:set ts=4 sw=2 sts=2 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/. */
11 #include "mozilla/Maybe.h"
12 #include "mozilla/ResultExtensions.h"
13 #include "nsAttrValue.h"
15 #include "nsIInterfaceRequestor.h"
16 #include "nsIInterfaceRequestorUtils.h"
17 #include "nsILoadGroup.h"
18 #include "nsINestedURI.h"
19 #include "nsINetUtil.h"
20 #include "nsIRequest.h"
21 #include "nsILoadInfo.h"
22 #include "nsIIOService.h"
24 #include "mozilla/NotNull.h"
25 #include "mozilla/Services.h"
26 #include "mozilla/Unused.h"
28 #include "nsReadableUtils.h"
29 #include "nsServiceManagerUtils.h"
32 #include "mozilla/net/idna_glue.h"
33 #include "mozilla/net/MozURL_ffi.h"
36 class nsIAsyncStreamCopier
;
40 class nsIChannelPolicy
;
41 class nsICookieJarSettings
;
42 class nsIDownloadObserver
;
44 class nsIFileProtocolHandler
;
45 class nsIFileRandomAccessStream
;
48 class nsIInputStreamPump
;
49 class nsIInterfaceRequestor
;
50 class nsIOutputStream
;
51 class nsIParentChannel
;
52 class nsIPersistentProperties
;
54 class nsIRandomAccessStream
;
55 class nsIRequestObserver
;
56 class nsISerialEventTarget
;
57 class nsIStreamListener
;
58 class nsIStreamLoader
;
59 class nsIStreamLoaderObserver
;
60 class nsIIncrementalStreamLoader
;
61 class nsIIncrementalStreamLoaderObserver
;
65 class OriginAttributes
;
69 class PerformanceStorage
;
70 class ServiceWorkerDescriptor
;
77 } // namespace mozilla
82 struct already_AddRefed
;
84 already_AddRefed
<nsIIOService
> do_GetIOService(nsresult
* error
= nullptr);
86 already_AddRefed
<nsINetUtil
> do_GetNetUtil(nsresult
* error
= nullptr);
88 // private little helper function... don't call this directly!
89 nsresult
net_EnsureIOService(nsIIOService
** ios
, nsCOMPtr
<nsIIOService
>& grip
);
91 nsresult
NS_NewURI(nsIURI
** aURI
, const nsACString
& spec
,
92 const char* charset
= nullptr, nsIURI
* baseURI
= nullptr);
94 nsresult
NS_NewURI(nsIURI
** result
, const nsACString
& spec
,
95 mozilla::NotNull
<const mozilla::Encoding
*> encoding
,
96 nsIURI
* baseURI
= nullptr);
98 nsresult
NS_NewURI(nsIURI
** result
, const nsAString
& spec
,
99 const char* charset
= nullptr, nsIURI
* baseURI
= nullptr);
101 nsresult
NS_NewURI(nsIURI
** result
, const nsAString
& spec
,
102 mozilla::NotNull
<const mozilla::Encoding
*> encoding
,
103 nsIURI
* baseURI
= nullptr);
105 nsresult
NS_NewURI(nsIURI
** result
, const char* spec
,
106 nsIURI
* baseURI
= nullptr);
108 nsresult
NS_NewFileURI(
109 nsIURI
** result
, nsIFile
* spec
,
110 nsIIOService
* ioService
=
111 nullptr); // pass in nsIIOService to optimize callers
113 // Functions for adding additional encoding to a URL for compatibility with
114 // Apple's NSURL class URLWithString method.
117 // Out parameter for the encoded URL spec
119 // The spec for the URL to be encoded
120 nsresult
NS_GetSpecWithNSURLEncoding(nsACString
& aResult
,
121 const nsACString
& aSpec
);
123 // Out parameter for the encoded URI
125 // The spec for the URL to be encoded
126 nsresult
NS_NewURIWithNSURLEncoding(nsIURI
** aResult
, const nsACString
& aSpec
);
128 // These methods will only mutate the URI if the ref of aInput doesn't already
129 // match the ref we are trying to set.
130 // If aInput has no ref, and we are calling NS_GetURIWithoutRef, or
131 // NS_GetURIWithNewRef with an empty string, then aOutput will be the same
132 // as aInput. The same is true if aRef is already equal to the ref of aInput.
133 // This is OK because URIs are immutable and threadsafe.
134 // If the URI doesn't support ref fragments aOutput will be the same as aInput.
135 nsresult
NS_GetURIWithNewRef(nsIURI
* aInput
, const nsACString
& aRef
,
137 nsresult
NS_GetURIWithoutRef(nsIURI
* aInput
, nsIURI
** aOutput
);
139 nsresult
NS_GetSanitizedURIStringFromURI(nsIURI
* aUri
,
140 nsACString
& aSanitizedSpec
);
143 * How to create a new Channel, using NS_NewChannel,
144 * NS_NewChannelWithTriggeringPrincipal,
145 * NS_NewInputStreamChannel, NS_NewChannelInternal
146 * and it's variations:
148 * What specific API function to use:
149 * * The NS_NewChannelInternal functions should almost never be directly
150 * called outside of necko code.
151 * * If possible, use NS_NewChannel() providing a loading *nsINode*
152 * * If no loading *nsINode* is available, try calling NS_NewChannel() providing
153 * a loading *ClientInfo*.
154 * * If no loading *nsINode* or *ClientInfo* are available, call NS_NewChannel()
155 * providing a loading *nsIPrincipal*.
156 * * Call NS_NewChannelWithTriggeringPrincipal if the triggeringPrincipal
157 * is different from the loadingPrincipal.
158 * * Call NS_NewChannelInternal() providing aLoadInfo object in cases where
159 * you already have loadInfo object, e.g in case of a channel redirect.
162 * nsIURI from which to make a channel
163 * @param aLoadingNode
164 * @param aLoadingPrincipal
165 * @param aTriggeringPrincipal
166 * @param aSecurityFlags
167 * @param aContentPolicyType
168 * These will be used as values for the nsILoadInfo object on the
169 * created channel. For details, see nsILoadInfo in nsILoadInfo.idl
171 * Please note, if you provide both a loadingNode and a loadingPrincipal,
172 * then loadingPrincipal must be equal to loadingNode->NodePrincipal().
173 * But less error prone is to just supply a loadingNode.
175 * Note, if you provide a loading ClientInfo its principal must match the
176 * loading principal. Currently you must pass both as the loading principal
177 * may have additional mutable values like CSP on it. In the future these
178 * will be removed from nsIPrincipal and the API can be changed to take just
179 * the loading ClientInfo.
181 * Keep in mind that URIs coming from a webpage should *never* use the
182 * systemPrincipal as the loadingPrincipal.
184 nsresult
NS_NewChannelInternal(
185 nsIChannel
** outChannel
, nsIURI
* aUri
, nsINode
* aLoadingNode
,
186 nsIPrincipal
* aLoadingPrincipal
, nsIPrincipal
* aTriggeringPrincipal
,
187 const mozilla::Maybe
<mozilla::dom::ClientInfo
>& aLoadingClientInfo
,
188 const mozilla::Maybe
<mozilla::dom::ServiceWorkerDescriptor
>& aController
,
189 nsSecurityFlags aSecurityFlags
, nsContentPolicyType aContentPolicyType
,
190 nsICookieJarSettings
* aCookieJarSettings
= nullptr,
191 mozilla::dom::PerformanceStorage
* aPerformanceStorage
= nullptr,
192 nsILoadGroup
* aLoadGroup
= nullptr,
193 nsIInterfaceRequestor
* aCallbacks
= nullptr,
194 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
,
195 nsIIOService
* aIoService
= nullptr, uint32_t aSandboxFlags
= 0);
197 // See NS_NewChannelInternal for usage and argument description
198 nsresult
NS_NewChannelInternal(
199 nsIChannel
** outChannel
, nsIURI
* aUri
, nsILoadInfo
* aLoadInfo
,
200 mozilla::dom::PerformanceStorage
* aPerformanceStorage
= nullptr,
201 nsILoadGroup
* aLoadGroup
= nullptr,
202 nsIInterfaceRequestor
* aCallbacks
= nullptr,
203 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
,
204 nsIIOService
* aIoService
= nullptr);
206 // See NS_NewChannelInternal for usage and argument description
207 nsresult
/*NS_NewChannelWithNodeAndTriggeringPrincipal */
208 NS_NewChannelWithTriggeringPrincipal(
209 nsIChannel
** outChannel
, nsIURI
* aUri
, nsINode
* aLoadingNode
,
210 nsIPrincipal
* aTriggeringPrincipal
, nsSecurityFlags aSecurityFlags
,
211 nsContentPolicyType aContentPolicyType
,
212 mozilla::dom::PerformanceStorage
* aPerformanceStorage
= nullptr,
213 nsILoadGroup
* aLoadGroup
= nullptr,
214 nsIInterfaceRequestor
* aCallbacks
= nullptr,
215 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
,
216 nsIIOService
* aIoService
= nullptr);
218 // See NS_NewChannelInternal for usage and argument description
219 nsresult
NS_NewChannelWithTriggeringPrincipal(
220 nsIChannel
** outChannel
, nsIURI
* aUri
, nsIPrincipal
* aLoadingPrincipal
,
221 nsIPrincipal
* aTriggeringPrincipal
, nsSecurityFlags aSecurityFlags
,
222 nsContentPolicyType aContentPolicyType
,
223 nsICookieJarSettings
* aCookieJarSettings
= nullptr,
224 mozilla::dom::PerformanceStorage
* aPerformanceStorage
= nullptr,
225 nsILoadGroup
* aLoadGroup
= nullptr,
226 nsIInterfaceRequestor
* aCallbacks
= nullptr,
227 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
,
228 nsIIOService
* aIoService
= nullptr);
230 // See NS_NewChannelInternal for usage and argument description
231 nsresult
NS_NewChannelWithTriggeringPrincipal(
232 nsIChannel
** outChannel
, nsIURI
* aUri
, nsIPrincipal
* aLoadingPrincipal
,
233 nsIPrincipal
* aTriggeringPrincipal
,
234 const mozilla::dom::ClientInfo
& aLoadingClientInfo
,
235 const mozilla::Maybe
<mozilla::dom::ServiceWorkerDescriptor
>& aController
,
236 nsSecurityFlags aSecurityFlags
, nsContentPolicyType aContentPolicyType
,
237 nsICookieJarSettings
* aCookieJarSettings
= nullptr,
238 mozilla::dom::PerformanceStorage
* aPerformanceStorage
= nullptr,
239 nsILoadGroup
* aLoadGroup
= nullptr,
240 nsIInterfaceRequestor
* aCallbacks
= nullptr,
241 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
,
242 nsIIOService
* aIoService
= nullptr);
244 // See NS_NewChannelInternal for usage and argument description
245 nsresult
NS_NewChannel(
246 nsIChannel
** outChannel
, nsIURI
* aUri
, nsINode
* aLoadingNode
,
247 nsSecurityFlags aSecurityFlags
, nsContentPolicyType aContentPolicyType
,
248 mozilla::dom::PerformanceStorage
* aPerformanceStorage
= nullptr,
249 nsILoadGroup
* aLoadGroup
= nullptr,
250 nsIInterfaceRequestor
* aCallbacks
= nullptr,
251 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
,
252 nsIIOService
* aIoService
= nullptr, uint32_t aSandboxFlags
= 0);
254 // See NS_NewChannelInternal for usage and argument description
255 nsresult
NS_NewChannel(
256 nsIChannel
** outChannel
, nsIURI
* aUri
, nsIPrincipal
* aLoadingPrincipal
,
257 nsSecurityFlags aSecurityFlags
, nsContentPolicyType aContentPolicyType
,
258 nsICookieJarSettings
* aCookieJarSettings
= nullptr,
259 mozilla::dom::PerformanceStorage
* aPerformanceStorage
= nullptr,
260 nsILoadGroup
* aLoadGroup
= nullptr,
261 nsIInterfaceRequestor
* aCallbacks
= nullptr,
262 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
,
263 nsIIOService
* aIoService
= nullptr, uint32_t aSandboxFlags
= 0);
265 // See NS_NewChannelInternal for usage and argument description
266 nsresult
NS_NewChannel(
267 nsIChannel
** outChannel
, nsIURI
* aUri
, nsIPrincipal
* aLoadingPrincipal
,
268 const mozilla::dom::ClientInfo
& aLoadingClientInfo
,
269 const mozilla::Maybe
<mozilla::dom::ServiceWorkerDescriptor
>& aController
,
270 nsSecurityFlags aSecurityFlags
, nsContentPolicyType aContentPolicyType
,
271 nsICookieJarSettings
* aCookieJarSettings
= nullptr,
272 mozilla::dom::PerformanceStorage
* aPerformanceStorage
= nullptr,
273 nsILoadGroup
* aLoadGroup
= nullptr,
274 nsIInterfaceRequestor
* aCallbacks
= nullptr,
275 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
,
276 nsIIOService
* aIoService
= nullptr, uint32_t aSandboxFlags
= 0);
278 nsresult
NS_GetIsDocumentChannel(nsIChannel
* aChannel
, bool* aIsDocument
);
280 nsresult
NS_MakeAbsoluteURI(nsACString
& result
, const nsACString
& spec
,
283 nsresult
NS_MakeAbsoluteURI(char** result
, const char* spec
, nsIURI
* baseURI
);
285 nsresult
NS_MakeAbsoluteURI(nsAString
& result
, const nsAString
& spec
,
289 * This function is a helper function to get a scheme's default port.
291 int32_t NS_GetDefaultPort(const char* scheme
,
292 nsIIOService
* ioService
= nullptr);
295 * The UTS #46 ToASCII operation as parametrized by the WHATWG URL Standard.
297 * Use this function to prepare a host name for network protocols.
299 * Do not try to optimize and avoid calling this function if you already
300 * have ASCII. This function optimizes internally, and calling it is
301 * required for correctness!
303 * Use `NS_DomainToDisplayAndASCII` if you need both this function and
304 * `NS_DomainToDisplay` together.
306 * The function is available to privileged JavaScript callers via
309 * Rust callers that don't happen to be using XPCOM strings are better
310 * off using the `idna` crate directly.
312 inline nsresult
NS_DomainToASCII(const nsACString
& aDomain
,
313 nsACString
& aASCII
) {
314 return mozilla_net_domain_to_ascii_impl(&aDomain
, false, &aASCII
);
318 * Bogus variant for callers that try pass through IPv6 addresses or even port
321 inline nsresult
NS_DomainToASCIIAllowAnyGlyphfulASCII(const nsACString
& aDomain
,
322 nsACString
& aASCII
) {
323 return mozilla_net_domain_to_ascii_impl(&aDomain
, true, &aASCII
);
327 * The UTS #46 ToUnicode operation as parametrized by the WHATWG URL Standard,
328 * except potentially misleading labels are treated according to ToASCII
331 * Use this function to prepare a host name for display to the user.
333 * Use `NS_DomainToDisplayAndASCII` if you need both this function and
334 * `NS_DomainToASCII` together.
336 * The function is available to privileged JavaScript callers via
339 * Rust callers that don't happen to be using XPCOM strings are better
340 * off using the `idna` crate directly. (See `idna_glue` for what policy
343 inline nsresult
NS_DomainToDisplay(const nsACString
& aDomain
,
344 nsACString
& aDisplay
) {
345 return mozilla_net_domain_to_display_impl(&aDomain
, false, &aDisplay
);
349 * Bogus variant for callers that try pass through IPv6 addresses or even port
352 inline nsresult
NS_DomainToDisplayAllowAnyGlyphfulASCII(
353 const nsACString
& aDomain
, nsACString
& aDisplay
) {
354 return mozilla_net_domain_to_display_impl(&aDomain
, true, &aDisplay
);
358 * The UTS #46 ToUnicode operation as parametrized by the WHATWG URL Standard.
360 * It's most likely INCORRECT to call this function, and `NS_DomainToDisplay`
361 * should typically be called instead. Please avoid adding new callers, so
362 * that this conversion could be removed entirely!
364 * The function is available to privileged JavaScript callers via
367 * Rust callers that don't happen to be using XPCOM strings are better
368 * off using the `idna` crate directly.
370 inline nsresult
NS_DomainToUnicode(const nsACString
& aDomain
,
371 nsACString
& aUnicode
) {
372 return mozilla_net_domain_to_unicode_impl(&aDomain
, false, &aUnicode
);
376 * Bogus variant for callers that try pass through IPv6 addresses or even port
379 inline nsresult
NS_DomainToUnicodeAllowAnyGlyphfulASCII(
380 const nsACString
& aDomain
, nsACString
& aDisplay
) {
381 return mozilla_net_domain_to_unicode_impl(&aDomain
, true, &aDisplay
);
385 * This function is a helper function to get a protocol's default port if the
386 * URI does not specify a port explicitly. Returns -1 if this protocol has no
387 * concept of ports or if there was an error getting the port.
389 int32_t NS_GetRealPort(nsIURI
* aURI
);
391 nsresult
NS_NewInputStreamChannelInternal(
392 nsIChannel
** outChannel
, nsIURI
* aUri
,
393 already_AddRefed
<nsIInputStream
> aStream
, const nsACString
& aContentType
,
394 const nsACString
& aContentCharset
, nsILoadInfo
* aLoadInfo
);
396 nsresult
NS_NewInputStreamChannelInternal(
397 nsIChannel
** outChannel
, nsIURI
* aUri
,
398 already_AddRefed
<nsIInputStream
> aStream
, const nsACString
& aContentType
,
399 const nsACString
& aContentCharset
, nsINode
* aLoadingNode
,
400 nsIPrincipal
* aLoadingPrincipal
, nsIPrincipal
* aTriggeringPrincipal
,
401 nsSecurityFlags aSecurityFlags
, nsContentPolicyType aContentPolicyType
);
403 nsresult
NS_NewInputStreamChannel(nsIChannel
** outChannel
, nsIURI
* aUri
,
404 already_AddRefed
<nsIInputStream
> aStream
,
405 nsIPrincipal
* aLoadingPrincipal
,
406 nsSecurityFlags aSecurityFlags
,
407 nsContentPolicyType aContentPolicyType
,
408 const nsACString
& aContentType
= ""_ns
,
409 const nsACString
& aContentCharset
= ""_ns
);
411 nsresult
NS_NewInputStreamChannelInternal(
412 nsIChannel
** outChannel
, nsIURI
* aUri
, const nsAString
& aData
,
413 const nsACString
& aContentType
, nsINode
* aLoadingNode
,
414 nsIPrincipal
* aLoadingPrincipal
, nsIPrincipal
* aTriggeringPrincipal
,
415 nsSecurityFlags aSecurityFlags
, nsContentPolicyType aContentPolicyType
,
416 bool aIsSrcdocChannel
= false);
418 nsresult
NS_NewInputStreamChannelInternal(nsIChannel
** outChannel
, nsIURI
* aUri
,
419 const nsAString
& aData
,
420 const nsACString
& aContentType
,
421 nsILoadInfo
* aLoadInfo
,
422 bool aIsSrcdocChannel
= false);
424 nsresult
NS_NewInputStreamChannel(nsIChannel
** outChannel
, nsIURI
* aUri
,
425 const nsAString
& aData
,
426 const nsACString
& aContentType
,
427 nsIPrincipal
* aLoadingPrincipal
,
428 nsSecurityFlags aSecurityFlags
,
429 nsContentPolicyType aContentPolicyType
,
430 bool aIsSrcdocChannel
= false);
432 nsresult
NS_NewInputStreamPump(
433 nsIInputStreamPump
** aResult
, already_AddRefed
<nsIInputStream
> aStream
,
434 uint32_t aSegsize
= 0, uint32_t aSegcount
= 0, bool aCloseWhenDone
= false,
435 nsISerialEventTarget
* aMainThreadTarget
= nullptr);
437 nsresult
NS_NewLoadGroup(nsILoadGroup
** result
, nsIRequestObserver
* obs
);
439 // Create a new nsILoadGroup that will match the given principal.
440 nsresult
NS_NewLoadGroup(nsILoadGroup
** aResult
, nsIPrincipal
* aPrincipal
);
442 // Determine if the given loadGroup/principal pair will produce a principal
443 // with similar permissions when passed to NS_NewChannel(). This checks for
444 // things like making sure the browser element flag matches. Without
445 // an appropriate load group these values can be lost when getting the result
446 // principal back out of the channel. Null principals are also always allowed
447 // as they do not have permissions to actually use the load group.
448 bool NS_LoadGroupMatchesPrincipal(nsILoadGroup
* aLoadGroup
,
449 nsIPrincipal
* aPrincipal
);
451 nsresult
NS_NewDownloader(nsIStreamListener
** result
,
452 nsIDownloadObserver
* observer
,
453 nsIFile
* downloadLocation
= nullptr);
455 nsresult
NS_NewStreamLoader(nsIStreamLoader
** result
,
456 nsIStreamLoaderObserver
* observer
,
457 nsIRequestObserver
* requestObserver
= nullptr);
459 nsresult
NS_NewIncrementalStreamLoader(
460 nsIIncrementalStreamLoader
** result
,
461 nsIIncrementalStreamLoaderObserver
* observer
);
463 nsresult
NS_NewStreamLoaderInternal(
464 nsIStreamLoader
** outStream
, nsIURI
* aUri
,
465 nsIStreamLoaderObserver
* aObserver
, nsINode
* aLoadingNode
,
466 nsIPrincipal
* aLoadingPrincipal
, nsSecurityFlags aSecurityFlags
,
467 nsContentPolicyType aContentPolicyType
, nsILoadGroup
* aLoadGroup
= nullptr,
468 nsIInterfaceRequestor
* aCallbacks
= nullptr,
469 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
);
471 nsresult
NS_NewStreamLoader(nsIStreamLoader
** outStream
, nsIURI
* aUri
,
472 nsIStreamLoaderObserver
* aObserver
,
473 nsINode
* aLoadingNode
,
474 nsSecurityFlags aSecurityFlags
,
475 nsContentPolicyType aContentPolicyType
,
476 nsILoadGroup
* aLoadGroup
= nullptr,
477 nsIInterfaceRequestor
* aCallbacks
= nullptr,
478 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
);
480 nsresult
NS_NewStreamLoader(nsIStreamLoader
** outStream
, nsIURI
* aUri
,
481 nsIStreamLoaderObserver
* aObserver
,
482 nsIPrincipal
* aLoadingPrincipal
,
483 nsSecurityFlags aSecurityFlags
,
484 nsContentPolicyType aContentPolicyType
,
485 nsILoadGroup
* aLoadGroup
= nullptr,
486 nsIInterfaceRequestor
* aCallbacks
= nullptr,
487 nsLoadFlags aLoadFlags
= nsIRequest::LOAD_NORMAL
);
489 nsresult
NS_NewSyncStreamListener(nsIStreamListener
** result
,
490 nsIInputStream
** stream
);
493 * Implement the nsIChannel::Open(nsIInputStream**) method using the channel's
496 * NOTE: Reading from the returned nsIInputStream may spin the current
497 * thread's event queue, which could result in any event being processed.
499 nsresult
NS_ImplementChannelOpen(nsIChannel
* channel
, nsIInputStream
** result
);
501 nsresult
NS_NewRequestObserverProxy(nsIRequestObserver
** result
,
502 nsIRequestObserver
* observer
,
503 nsISupports
* context
);
505 nsresult
NS_NewSimpleStreamListener(nsIStreamListener
** result
,
506 nsIOutputStream
* sink
,
507 nsIRequestObserver
* observer
= nullptr);
509 nsresult
NS_CheckPortSafety(int32_t port
, const char* scheme
,
510 nsIIOService
* ioService
= nullptr);
512 // Determine if this URI is using a safe port.
513 nsresult
NS_CheckPortSafety(nsIURI
* uri
);
515 nsresult
NS_NewProxyInfo(const nsACString
& type
, const nsACString
& host
,
516 int32_t port
, uint32_t flags
, nsIProxyInfo
** result
);
518 nsresult
NS_GetFileProtocolHandler(nsIFileProtocolHandler
** result
,
519 nsIIOService
* ioService
= nullptr);
521 nsresult
NS_GetFileFromURLSpec(const nsACString
& inURL
, nsIFile
** result
,
522 nsIIOService
* ioService
= nullptr);
524 nsresult
NS_GetURLSpecFromFile(nsIFile
* file
, nsACString
& url
,
525 nsIIOService
* ioService
= nullptr);
528 * Converts the nsIFile to the corresponding URL string.
529 * Should only be called on files which are not directories,
530 * is otherwise identical to NS_GetURLSpecFromFile, but is
531 * usually more efficient.
532 * Warning: this restriction may not be enforced at runtime!
534 nsresult
NS_GetURLSpecFromActualFile(nsIFile
* file
, nsACString
& url
,
535 nsIIOService
* ioService
= nullptr);
538 * Converts the nsIFile to the corresponding URL string.
539 * Should only be called on files which are directories,
540 * is otherwise identical to NS_GetURLSpecFromFile, but is
541 * usually more efficient.
542 * Warning: this restriction may not be enforced at runtime!
544 nsresult
NS_GetURLSpecFromDir(nsIFile
* file
, nsACString
& url
,
545 nsIIOService
* ioService
= nullptr);
548 * Obtains the referrer for a given channel. This first tries to obtain the
549 * referrer from the property docshell.internalReferrer, and if that doesn't
550 * work and the channel is an nsIHTTPChannel, we check it's referrer property.
553 void NS_GetReferrerFromChannel(nsIChannel
* channel
, nsIURI
** referrer
);
555 nsresult
NS_ParseRequestContentType(const nsACString
& rawContentType
,
556 nsCString
& contentType
,
557 nsCString
& contentCharset
);
559 nsresult
NS_ParseResponseContentType(const nsACString
& rawContentType
,
560 nsCString
& contentType
,
561 nsCString
& contentCharset
);
563 nsresult
NS_ExtractCharsetFromContentType(const nsACString
& rawContentType
,
564 nsCString
& contentCharset
,
566 int32_t* charsetStart
,
567 int32_t* charsetEnd
);
569 nsresult
NS_NewLocalFileInputStream(nsIInputStream
** result
, nsIFile
* file
,
570 int32_t ioFlags
= -1, int32_t perm
= -1,
571 int32_t behaviorFlags
= 0);
573 mozilla::Result
<nsCOMPtr
<nsIInputStream
>, nsresult
> NS_NewLocalFileInputStream(
574 nsIFile
* file
, int32_t ioFlags
= -1, int32_t perm
= -1,
575 int32_t behaviorFlags
= 0);
577 nsresult
NS_NewLocalFileOutputStream(nsIOutputStream
** result
, nsIFile
* file
,
578 int32_t ioFlags
= -1, int32_t perm
= -1,
579 int32_t behaviorFlags
= 0);
581 mozilla::Result
<nsCOMPtr
<nsIOutputStream
>, nsresult
>
582 NS_NewLocalFileOutputStream(nsIFile
* file
, int32_t ioFlags
= -1,
583 int32_t perm
= -1, int32_t behaviorFlags
= 0);
585 nsresult
NS_NewLocalFileOutputStream(nsIOutputStream
** result
,
586 const mozilla::ipc::FileDescriptor
& fd
);
588 // returns a file output stream which can be QI'ed to nsISafeOutputStream.
589 nsresult
NS_NewAtomicFileOutputStream(nsIOutputStream
** result
, nsIFile
* file
,
590 int32_t ioFlags
= -1, int32_t perm
= -1,
591 int32_t behaviorFlags
= 0);
593 // returns a file output stream which can be QI'ed to nsISafeOutputStream.
594 nsresult
NS_NewSafeLocalFileOutputStream(nsIOutputStream
** result
,
595 nsIFile
* file
, int32_t ioFlags
= -1,
597 int32_t behaviorFlags
= 0);
599 nsresult
NS_NewLocalFileRandomAccessStream(nsIRandomAccessStream
** result
,
600 nsIFile
* file
, int32_t ioFlags
= -1,
602 int32_t behaviorFlags
= 0);
604 mozilla::Result
<nsCOMPtr
<nsIRandomAccessStream
>, nsresult
>
605 NS_NewLocalFileRandomAccessStream(nsIFile
* file
, int32_t ioFlags
= -1,
606 int32_t perm
= -1, int32_t behaviorFlags
= 0);
608 [[nodiscard
]] nsresult
NS_NewBufferedInputStream(
609 nsIInputStream
** aResult
, already_AddRefed
<nsIInputStream
> aInputStream
,
610 uint32_t aBufferSize
);
612 mozilla::Result
<nsCOMPtr
<nsIInputStream
>, nsresult
> NS_NewBufferedInputStream(
613 already_AddRefed
<nsIInputStream
> aInputStream
, uint32_t aBufferSize
);
615 // note: the resulting stream can be QI'ed to nsISafeOutputStream iff the
616 // provided stream supports it.
617 nsresult
NS_NewBufferedOutputStream(
618 nsIOutputStream
** aResult
, already_AddRefed
<nsIOutputStream
> aOutputStream
,
619 uint32_t aBufferSize
);
622 * This function reads an inputStream and stores its content into a buffer. In
623 * general, you should avoid using this function because, it blocks the current
624 * thread until the operation is done.
625 * If the inputStream is async, the reading happens on an I/O thread.
627 * @param aInputStream the inputStream.
628 * @param aDest the destination buffer. if *aDest is null, it will be allocated
629 * with the size of the written data. if aDest is not null, aCount
630 * must greater than 0.
631 * @param aCount the amount of data to read. Use -1 if you want that all the
633 * @param aWritten this pointer will be used to store the number of data
634 * written in the buffer. If you don't need, pass nullptr.
636 nsresult
NS_ReadInputStreamToBuffer(nsIInputStream
* aInputStream
, void** aDest
,
638 uint64_t* aWritten
= nullptr);
641 * See the comment for NS_ReadInputStreamToBuffer
643 nsresult
NS_ReadInputStreamToString(nsIInputStream
* aInputStream
,
644 nsACString
& aDest
, int64_t aCount
,
645 uint64_t* aWritten
= nullptr);
647 nsresult
NS_LoadPersistentPropertiesFromURISpec(
648 nsIPersistentProperties
** outResult
, const nsACString
& aSpec
);
651 * NS_QueryNotificationCallbacks implements the canonical algorithm for
652 * querying interfaces from a channel's notification callbacks. It first
653 * searches the channel's notificationCallbacks attribute, and if the interface
654 * is not found there, then it inspects the notificationCallbacks attribute of
655 * the channel's loadGroup.
657 * Note: templatized only because nsIWebSocketChannel is currently not an
661 inline void NS_QueryNotificationCallbacks(T
* channel
, const nsIID
& iid
,
663 MOZ_ASSERT(channel
, "null channel");
666 nsCOMPtr
<nsIInterfaceRequestor
> cbs
;
667 mozilla::Unused
<< channel
->GetNotificationCallbacks(getter_AddRefs(cbs
));
668 if (cbs
) cbs
->GetInterface(iid
, result
);
670 // try load group's notification callbacks...
671 nsCOMPtr
<nsILoadGroup
> loadGroup
;
672 mozilla::Unused
<< channel
->GetLoadGroup(getter_AddRefs(loadGroup
));
674 loadGroup
->GetNotificationCallbacks(getter_AddRefs(cbs
));
675 if (cbs
) cbs
->GetInterface(iid
, result
);
681 // Note: "class C" templatized only because nsIWebSocketChannel is currently not
684 template <class C
, class T
>
685 inline void NS_QueryNotificationCallbacks(C
* channel
, nsCOMPtr
<T
>& result
) {
686 NS_QueryNotificationCallbacks(channel
, NS_GET_TEMPLATE_IID(T
),
687 getter_AddRefs(result
));
691 * Alternate form of NS_QueryNotificationCallbacks designed for use by
692 * nsIChannel implementations.
694 inline void NS_QueryNotificationCallbacks(nsIInterfaceRequestor
* callbacks
,
695 nsILoadGroup
* loadGroup
,
696 const nsIID
& iid
, void** result
) {
699 if (callbacks
) callbacks
->GetInterface(iid
, result
);
701 // try load group's notification callbacks...
703 nsCOMPtr
<nsIInterfaceRequestor
> cbs
;
704 loadGroup
->GetNotificationCallbacks(getter_AddRefs(cbs
));
705 if (cbs
) cbs
->GetInterface(iid
, result
);
711 * Returns true if channel is using Private Browsing, or false if not.
712 * Returns false if channel's callbacks don't implement nsILoadContext.
714 bool NS_UsePrivateBrowsing(nsIChannel
* channel
);
717 * Returns true if the channel has visited any cross-origin URLs on any
718 * URLs that it was redirected through.
720 bool NS_HasBeenCrossOrigin(nsIChannel
* aChannel
, bool aReport
= false);
723 * Returns true if the channel has a safe method.
725 bool NS_IsSafeMethodNav(nsIChannel
* aChannel
);
727 // Unique first-party domain for separating the safebrowsing cookie.
728 // Note if this value is changed, code in test_cookiejars_safebrowsing.js and
729 // nsUrlClassifierHashCompleter.js should also be changed.
730 #define NECKO_SAFEBROWSING_FIRST_PARTY_DOMAIN \
731 "safebrowsing.86868755-6b82-4842-b301-72671a0db32e.mozilla"
733 // Unique first-party domain for separating about uri.
734 #define ABOUT_URI_FIRST_PARTY_DOMAIN \
735 "about.ef2a7dd5-93bc-417f-a698-142c3116864f.mozilla"
738 * Wraps an nsIAuthPrompt so that it can be used as an nsIAuthPrompt2. This
739 * method is provided mainly for use by other methods in this file.
741 * *aAuthPrompt2 should be set to null before calling this function.
743 void NS_WrapAuthPrompt(nsIAuthPrompt
* aAuthPrompt
,
744 nsIAuthPrompt2
** aAuthPrompt2
);
747 * Gets an auth prompt from an interface requestor. This takes care of wrapping
748 * an nsIAuthPrompt so that it can be used as an nsIAuthPrompt2.
750 void NS_QueryAuthPrompt2(nsIInterfaceRequestor
* aCallbacks
,
751 nsIAuthPrompt2
** aAuthPrompt
);
754 * Gets an nsIAuthPrompt2 from a channel. Use this instead of
755 * NS_QueryNotificationCallbacks for better backwards compatibility.
757 void NS_QueryAuthPrompt2(nsIChannel
* aChannel
, nsIAuthPrompt2
** aAuthPrompt
);
759 /* template helper */
761 inline void NS_QueryNotificationCallbacks(nsIInterfaceRequestor
* callbacks
,
762 nsILoadGroup
* loadGroup
,
763 nsCOMPtr
<T
>& result
) {
764 NS_QueryNotificationCallbacks(callbacks
, loadGroup
, NS_GET_TEMPLATE_IID(T
),
765 getter_AddRefs(result
));
768 /* template helper */
770 inline void NS_QueryNotificationCallbacks(
771 const nsCOMPtr
<nsIInterfaceRequestor
>& aCallbacks
,
772 const nsCOMPtr
<nsILoadGroup
>& aLoadGroup
, nsCOMPtr
<T
>& aResult
) {
773 NS_QueryNotificationCallbacks(aCallbacks
.get(), aLoadGroup
.get(), aResult
);
776 /* template helper */
778 inline void NS_QueryNotificationCallbacks(const nsCOMPtr
<nsIChannel
>& aChannel
,
779 nsCOMPtr
<T
>& aResult
) {
780 NS_QueryNotificationCallbacks(aChannel
.get(), aResult
);
784 * This function returns a nsIInterfaceRequestor instance that returns the
785 * same result as NS_QueryNotificationCallbacks when queried. It is useful
786 * as the value for nsISocketTransport::securityCallbacks.
788 nsresult
NS_NewNotificationCallbacksAggregation(
789 nsIInterfaceRequestor
* callbacks
, nsILoadGroup
* loadGroup
,
790 nsIEventTarget
* target
, nsIInterfaceRequestor
** result
);
792 nsresult
NS_NewNotificationCallbacksAggregation(
793 nsIInterfaceRequestor
* callbacks
, nsILoadGroup
* loadGroup
,
794 nsIInterfaceRequestor
** result
);
797 * Helper function for testing online/offline state of the browser.
802 * Helper functions for implementing nsINestedURI::innermostURI.
804 * Note that NS_DoImplGetInnermostURI is "private" -- call
805 * NS_ImplGetInnermostURI instead.
807 nsresult
NS_DoImplGetInnermostURI(nsINestedURI
* nestedURI
, nsIURI
** result
);
809 nsresult
NS_ImplGetInnermostURI(nsINestedURI
* nestedURI
, nsIURI
** result
);
812 * Helper function for testing whether the given URI, or any of its
813 * inner URIs, has all the given protocol flags.
815 nsresult
NS_URIChainHasFlags(nsIURI
* uri
, uint32_t flags
, bool* result
);
818 * Helper function for getting the innermost URI for a given URI. The return
819 * value could be just the object passed in if it's not a nested URI.
821 already_AddRefed
<nsIURI
> NS_GetInnermostURI(nsIURI
* aURI
);
824 * Helper function for getting the host name of the innermost URI for a given
825 * URI. The return value could be the host name of the URI passed in if it's
828 inline nsresult
NS_GetInnermostURIHost(nsIURI
* aURI
, nsACString
& aHost
) {
831 // This block is optimized in order to avoid the overhead of calling
832 // NS_GetInnermostURI() which incurs a lot of overhead in terms of
833 // AddRef/Release calls.
834 nsCOMPtr
<nsINestedURI
> nestedURI
= do_QueryInterface(aURI
);
836 // We have a nested URI!
837 nsCOMPtr
<nsIURI
> uri
;
838 nsresult rv
= nestedURI
->GetInnermostURI(getter_AddRefs(uri
));
843 rv
= uri
->GetAsciiHost(aHost
);
848 // We have a non-nested URI!
849 nsresult rv
= aURI
->GetAsciiHost(aHost
);
859 * Get the "final" URI for a channel. This is either channel's load info
860 * resultPrincipalURI, if set, or GetOriginalURI. In most cases (but not all)
861 * load info resultPrincipalURI, if set, corresponds to URI of the channel if
862 * it's required to represent the actual principal for the channel.
864 nsresult
NS_GetFinalChannelURI(nsIChannel
* channel
, nsIURI
** uri
);
866 // NS_SecurityHashURI must return the same hash value for any two URIs that
867 // compare equal according to NS_SecurityCompareURIs. Unfortunately, in the
868 // case of files, it's not clear we can do anything better than returning
869 // the schemeHash, so hashing files degenerates to storing them in a list.
870 uint32_t NS_SecurityHashURI(nsIURI
* aURI
);
872 bool NS_SecurityCompareURIs(nsIURI
* aSourceURI
, nsIURI
* aTargetURI
,
873 bool aStrictFileOriginPolicy
);
875 bool NS_URIIsLocalFile(nsIURI
* aURI
);
877 bool NS_IsInternalSameURIRedirect(nsIChannel
* aOldChannel
,
878 nsIChannel
* aNewChannel
, uint32_t aFlags
);
880 bool NS_IsHSTSUpgradeRedirect(nsIChannel
* aOldChannel
, nsIChannel
* aNewChannel
,
883 bool NS_ShouldRemoveAuthHeaderOnRedirect(nsIChannel
* aOldChannel
,
884 nsIChannel
* aNewChannel
,
887 nsresult
NS_LinkRedirectChannels(uint64_t channelId
,
888 nsIParentChannel
* parentChannel
,
889 nsIChannel
** _result
);
892 * Returns nsILoadInfo::EMBEDDER_POLICY_REQUIRE_CORP if `aHeader` is
893 * "require-corp" and nsILoadInfo::EMBEDDER_POLICY_NULL otherwise.
895 * See: https://mikewest.github.io/corpp/#parsing
897 nsILoadInfo::CrossOriginEmbedderPolicy
898 NS_GetCrossOriginEmbedderPolicyFromHeader(
899 const nsACString
& aHeader
, bool aIsOriginTrialCoepCredentiallessEnabled
);
902 * Return true if the header is a dictionary where the key force-load-at-top
903 * has the value true. Otherwise, return false.
905 bool NS_GetForceLoadAtTopFromHeader(const nsACString
& aHeader
);
907 /** Given the first (disposition) token from a Content-Disposition header,
908 * tell whether it indicates the content is inline or attachment
909 * @param aDispToken the disposition token from the content-disposition header
911 uint32_t NS_GetContentDispositionFromToken(const nsAString
& aDispToken
);
913 /** Determine the disposition (inline/attachment) of the content based on the
914 * Content-Disposition header
915 * @param aHeader the content-disposition header (full value)
916 * @param aChan the channel the header came from
918 uint32_t NS_GetContentDispositionFromHeader(const nsACString
& aHeader
,
919 nsIChannel
* aChan
= nullptr);
921 /** Extracts the filename out of a content-disposition header
922 * @param aFilename [out] The filename. Can be empty on error.
923 * @param aDisposition Value of a Content-Disposition header
926 nsresult
NS_GetFilenameFromDisposition(nsAString
& aFilename
,
927 const nsACString
& aDisposition
);
930 * Make sure Personal Security Manager is initialized
932 void net_EnsurePSMInit();
935 * Test whether a URI is "about:blank". |uri| must not be null
937 bool NS_IsAboutBlank(nsIURI
* uri
);
940 * Test whether a URI is "about:blank", possibly with fragment or query. |uri|
943 bool NS_IsAboutBlankAllowQueryAndFragment(nsIURI
* uri
);
946 * Test whether a URI is "about:srcdoc". |uri| must not be null
948 bool NS_IsAboutSrcdoc(nsIURI
* uri
);
950 nsresult
NS_GenerateHostPort(const nsCString
& host
, int32_t port
,
951 nsACString
& hostLine
);
954 * Sniff the content type for a given request or a given buffer.
956 * aSnifferType can be either NS_CONTENT_SNIFFER_CATEGORY or
957 * NS_DATA_SNIFFER_CATEGORY. The function returns the sniffed content type
958 * in the aSniffedType argument. This argument will not be modified if the
959 * content type could not be sniffed.
961 void NS_SniffContent(const char* aSnifferType
, nsIRequest
* aRequest
,
962 const uint8_t* aData
, uint32_t aLength
,
963 nsACString
& aSniffedType
);
966 * Whether the channel was created to load a srcdoc document.
967 * Note that view-source:about:srcdoc is classified as a srcdoc document by
968 * this function, which may not be applicable everywhere.
970 bool NS_IsSrcdocChannel(nsIChannel
* aChannel
);
973 * Return true if the given string is a reasonable HTTP header value given the
974 * definition in RFC 2616 section 4.2. Currently we don't pay the cost to do
975 * full, sctrict validation here since it would require fulling parsing the
978 bool NS_IsReasonableHTTPHeaderValue(const nsACString
& aValue
);
981 * Return true if the given string is a valid HTTP token per RFC 2616 section
984 bool NS_IsValidHTTPToken(const nsACString
& aToken
);
987 * Strip the leading or trailing HTTP whitespace per fetch spec section 2.2.
989 void NS_TrimHTTPWhitespace(const nsACString
& aSource
, nsACString
& aDest
);
991 template <typename Char
>
992 constexpr bool NS_IsHTTPTokenPoint(Char aChar
) {
993 using UnsignedChar
= typename
mozilla::detail::MakeUnsignedChar
<Char
>::Type
;
994 auto c
= static_cast<UnsignedChar
>(aChar
);
995 return c
== '!' || c
== '#' || c
== '$' || c
== '%' || c
== '&' ||
996 c
== '\'' || c
== '*' || c
== '+' || c
== '-' || c
== '.' ||
997 c
== '^' || c
== '_' || c
== '`' || c
== '|' || c
== '~' ||
998 mozilla::IsAsciiAlphanumeric(c
);
1001 template <typename Char
>
1002 constexpr bool NS_IsHTTPQuotedStringTokenPoint(Char aChar
) {
1003 using UnsignedChar
= typename
mozilla::detail::MakeUnsignedChar
<Char
>::Type
;
1004 auto c
= static_cast<UnsignedChar
>(aChar
);
1005 return c
== 0x9 || (c
>= ' ' && c
<= '~') || mozilla::IsNonAsciiLatin1(c
);
1008 template <typename Char
>
1009 constexpr bool NS_IsHTTPWhitespace(Char aChar
) {
1010 using UnsignedChar
= typename
mozilla::detail::MakeUnsignedChar
<Char
>::Type
;
1011 auto c
= static_cast<UnsignedChar
>(aChar
);
1012 return c
== 0x9 || c
== 0xA || c
== 0xD || c
== 0x20;
1016 * Return true if the given request must be upgraded to HTTPS.
1017 * If |aResultCallback| is provided and the storage is not ready to read, the
1018 * result will be sent back through the callback and |aWillCallback| will be
1019 * true. Otherwiew, the result will be set to |aShouldUpgrade| and
1020 * |aWillCallback| is false.
1022 nsresult
NS_ShouldSecureUpgrade(
1023 nsIURI
* aURI
, nsILoadInfo
* aLoadInfo
, nsIPrincipal
* aChannelResultPrincipal
,
1024 bool aAllowSTS
, const mozilla::OriginAttributes
& aOriginAttributes
,
1025 bool& aShouldUpgrade
, std::function
<void(bool, nsresult
)>&& aResultCallback
,
1026 bool& aWillCallback
);
1029 * Returns an https URI for channels that need to go through secure upgrades.
1031 nsresult
NS_GetSecureUpgradedURI(nsIURI
* aURI
, nsIURI
** aUpgradedURI
);
1033 nsresult
NS_CompareLoadInfoAndLoadContext(nsIChannel
* aChannel
);
1036 * Return true if this channel should be classified by the URL classifier.
1038 bool NS_ShouldClassifyChannel(nsIChannel
* aChannel
);
1041 * Helper to set the blocking reason on loadinfo of the channel.
1043 nsresult
NS_SetRequestBlockingReason(nsIChannel
* channel
, uint32_t reason
);
1044 nsresult
NS_SetRequestBlockingReason(nsILoadInfo
* loadInfo
, uint32_t reason
);
1045 nsresult
NS_SetRequestBlockingReasonIfNull(nsILoadInfo
* loadInfo
,
1051 const static uint64_t kJS_MAX_SAFE_UINTEGER
= +9007199254740991ULL;
1052 const static int64_t kJS_MIN_SAFE_INTEGER
= -9007199254740991LL;
1053 const static int64_t kJS_MAX_SAFE_INTEGER
= +9007199254740991LL;
1055 // Make sure a 64bit value can be captured by JS MAX_SAFE_INTEGER
1056 bool InScriptableRange(int64_t val
);
1058 // Make sure a 64bit value can be captured by JS MAX_SAFE_INTEGER
1059 bool InScriptableRange(uint64_t val
);
1062 * Given the value of a single header field (such as
1063 * Content-Disposition and Content-Type) and the name of a parameter
1064 * (e.g. filename, name, charset), returns the value of the parameter.
1065 * See nsIMIMEHeaderParam.idl for more information.
1067 * @param aHeaderVal a header string to get the value of a parameter
1069 * @param aParamName the name of a MIME header parameter (e.g.
1070 * filename, name, charset). If empty or nullptr,
1071 * returns the first (possibly) _unnamed_ 'parameter'.
1072 * @return the value of <code>aParamName</code> in Unichar(UTF-16).
1074 nsresult
GetParameterHTTP(const nsACString
& aHeaderVal
, const char* aParamName
,
1075 nsAString
& aResult
);
1078 * Helper function that determines if channel is an HTTP POST.
1081 * The channel to test
1083 * @return True if channel is an HTTP post.
1085 bool ChannelIsPost(nsIChannel
* aChannel
);
1088 * Convenience functions for verifying nsIURI schemes. These functions simply
1089 * wrap aURI->SchemeIs(), but specify the protocol as part of the function name.
1092 bool SchemeIsHTTP(nsIURI
* aURI
);
1093 bool SchemeIsHTTPS(nsIURI
* aURI
);
1094 bool SchemeIsJavascript(nsIURI
* aURI
);
1095 bool SchemeIsChrome(nsIURI
* aURI
);
1096 bool SchemeIsAbout(nsIURI
* aURI
);
1097 bool SchemeIsBlob(nsIURI
* aURI
);
1098 bool SchemeIsFile(nsIURI
* aURI
);
1099 bool SchemeIsData(nsIURI
* aURI
);
1100 bool SchemeIsViewSource(nsIURI
* aURI
);
1101 bool SchemeIsResource(nsIURI
* aURI
);
1102 bool SchemeIsFTP(nsIURI
* aURI
);
1104 // Helper functions for SetProtocol methods to follow
1105 // step 2.1 in https://url.spec.whatwg.org/#scheme-state
1106 bool SchemeIsSpecial(const nsACString
&);
1107 bool IsSchemeChangePermitted(nsIURI
*, const nsACString
&);
1108 already_AddRefed
<nsIURI
> TryChangeProtocol(nsIURI
*, const nsACString
&);
1115 nsString mIntegrity
;
1121 nsString mCrossOrigin
;
1122 nsString mReferrerPolicy
;
1124 nsString mFetchPriority
;
1129 nsresult
NewResolveHref(nsIURI
** aOutURI
, nsIURI
* aBaseURI
) const;
1131 bool operator==(const LinkHeader
& rhs
) const;
1133 void MaybeUpdateAttribute(const nsAString
& aAttribute
,
1134 const char16_t
* aValue
);
1137 // Implements roughly step 2 to 4 of
1138 // <https://httpwg.org/specs/rfc8288.html#parse-set>.
1139 nsTArray
<LinkHeader
> ParseLinkHeader(const nsAString
& aLinkData
);
1141 enum ASDestination
: uint8_t {
1142 DESTINATION_INVALID
,
1144 DESTINATION_DOCUMENT
,
1148 DESTINATION_MANIFEST
,
1152 DESTINATION_SERVICEWORKER
,
1153 DESTINATION_SHAREDWORKER
,
1162 void ParseAsValue(const nsAString
& aValue
, nsAttrValue
& aResult
);
1163 nsContentPolicyType
AsValueToContentPolicy(const nsAttrValue
& aValue
);
1164 bool IsScriptLikeOrInvalid(const nsAString
& aAs
);
1166 bool CheckPreloadAttrs(const nsAttrValue
& aAs
, const nsAString
& aType
,
1167 const nsAString
& aMedia
,
1168 mozilla::dom::Document
* aDocument
);
1169 void WarnIgnoredPreload(const mozilla::dom::Document
&, nsIURI
&);
1172 * Returns true if the |aInput| in is part of the root domain of |aHost|.
1173 * For example, if |aInput| is "www.mozilla.org", and we pass in
1174 * "mozilla.org" as |aHost|, this will return true. It would return false
1175 * the other way around.
1177 * @param aInput The host to be analyzed.
1178 * @param aHost The host to compare to.
1180 nsresult
HasRootDomain(const nsACString
& aInput
, const nsACString
& aHost
,
1183 void CheckForBrokenChromeURL(nsILoadInfo
* aLoadInfo
, nsIURI
* aURI
);
1185 bool IsCoepCredentiallessEnabled(bool aIsOriginTrialCoepCredentiallessEnabled
);
1187 void ParseSimpleURISchemes(const nsACString
& schemeList
);
1189 nsresult
AddExtraHeaders(nsIHttpChannel
* aHttpChannel
,
1190 const nsACString
& aExtraHeaders
, bool aMerge
= true);
1192 } // namespace mozilla
1194 #endif // !nsNetUtil_h__