1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
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 file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "BackgroundUtils.h"
9 #include "MainThreadUtils.h"
10 #include "mozilla/Assertions.h"
11 #include "mozilla/BasePrincipal.h"
12 #include "mozilla/ContentPrincipal.h"
13 #include "mozilla/NullPrincipal.h"
14 #include "mozilla/SystemPrincipal.h"
15 #include "mozilla/ipc/PBackgroundSharedTypes.h"
16 #include "mozilla/ipc/URIUtils.h"
17 #include "mozilla/net/CookieJarSettings.h"
18 #include "mozilla/net/InterceptionInfo.h"
19 #include "mozilla/net/NeckoChannelParams.h"
20 #include "ExpandedPrincipal.h"
21 #include "nsIScriptSecurityManager.h"
23 #include "nsNetUtil.h"
24 #include "mozilla/LoadInfo.h"
25 #include "nsContentUtils.h"
28 #include "mozilla/nsRedirectHistoryEntry.h"
29 #include "mozilla/dom/nsCSPUtils.h"
30 #include "mozilla/dom/nsCSPContext.h"
31 #include "mozilla/dom/BrowsingContext.h"
32 #include "mozilla/dom/CanonicalBrowsingContext.h"
33 #include "mozilla/dom/Document.h"
34 #include "mozilla/dom/WindowGlobalParent.h"
35 #include "mozilla/LoadInfo.h"
37 using namespace mozilla::dom
;
38 using namespace mozilla::net
;
44 Result
<nsCOMPtr
<nsIPrincipal
>, nsresult
> PrincipalInfoToPrincipal(
45 const PrincipalInfo
& aPrincipalInfo
) {
46 MOZ_ASSERT(aPrincipalInfo
.type() != PrincipalInfo::T__None
);
48 nsCOMPtr
<nsIPrincipal
> principal
;
51 switch (aPrincipalInfo
.type()) {
52 case PrincipalInfo::TSystemPrincipalInfo
: {
53 principal
= SystemPrincipal::Get();
54 if (NS_WARN_IF(!principal
)) {
55 return Err(NS_ERROR_NOT_INITIALIZED
);
61 case PrincipalInfo::TNullPrincipalInfo
: {
62 const NullPrincipalInfo
& info
= aPrincipalInfo
.get_NullPrincipalInfo();
65 rv
= NS_NewURI(getter_AddRefs(uri
), info
.spec());
66 if (NS_WARN_IF(NS_FAILED(rv
))) {
70 if (!uri
->SchemeIs(NS_NULLPRINCIPAL_SCHEME
)) {
71 return Err(NS_ERROR_ILLEGAL_VALUE
);
74 principal
= NullPrincipal::Create(info
.attrs(), uri
);
78 case PrincipalInfo::TContentPrincipalInfo
: {
79 const ContentPrincipalInfo
& info
=
80 aPrincipalInfo
.get_ContentPrincipalInfo();
83 rv
= NS_NewURI(getter_AddRefs(uri
), info
.spec());
84 if (NS_WARN_IF(NS_FAILED(rv
))) {
88 nsCOMPtr
<nsIURI
> domain
;
90 rv
= NS_NewURI(getter_AddRefs(domain
), *info
.domain());
91 if (NS_WARN_IF(NS_FAILED(rv
))) {
97 BasePrincipal::CreateContentPrincipal(uri
, info
.attrs(), domain
);
98 if (NS_WARN_IF(!principal
)) {
99 return Err(NS_ERROR_NULL_POINTER
);
102 // Origin must match what the_new_principal.getOrigin returns.
103 nsAutoCString originNoSuffix
;
104 rv
= principal
->GetOriginNoSuffix(originNoSuffix
);
105 if (NS_WARN_IF(NS_FAILED(rv
))) {
109 if (NS_WARN_IF(!info
.originNoSuffix().Equals(originNoSuffix
))) {
110 return Err(NS_ERROR_FAILURE
);
113 if (!info
.baseDomain().IsVoid()) {
114 nsAutoCString baseDomain
;
115 rv
= principal
->GetBaseDomain(baseDomain
);
116 if (NS_WARN_IF(NS_FAILED(rv
))) {
120 if (NS_WARN_IF(!info
.baseDomain().Equals(baseDomain
))) {
121 return Err(NS_ERROR_FAILURE
);
127 case PrincipalInfo::TExpandedPrincipalInfo
: {
128 const ExpandedPrincipalInfo
& info
=
129 aPrincipalInfo
.get_ExpandedPrincipalInfo();
131 nsTArray
<nsCOMPtr
<nsIPrincipal
>> allowlist
;
132 nsCOMPtr
<nsIPrincipal
> alPrincipal
;
134 for (uint32_t i
= 0; i
< info
.allowlist().Length(); i
++) {
135 auto principalOrErr
= PrincipalInfoToPrincipal(info
.allowlist()[i
]);
136 if (NS_WARN_IF(principalOrErr
.isErr())) {
137 nsresult ret
= principalOrErr
.unwrapErr();
140 // append that principal to the allowlist
141 allowlist
.AppendElement(principalOrErr
.unwrap());
144 RefPtr
<ExpandedPrincipal
> expandedPrincipal
=
145 ExpandedPrincipal::Create(allowlist
, info
.attrs());
146 if (!expandedPrincipal
) {
147 return Err(NS_ERROR_FAILURE
);
150 principal
= expandedPrincipal
;
155 return Err(NS_ERROR_FAILURE
);
159 bool StorageKeysEqual(const PrincipalInfo
& aLeft
, const PrincipalInfo
& aRight
) {
160 MOZ_RELEASE_ASSERT(aLeft
.type() == PrincipalInfo::TContentPrincipalInfo
||
161 aLeft
.type() == PrincipalInfo::TSystemPrincipalInfo
);
162 MOZ_RELEASE_ASSERT(aRight
.type() == PrincipalInfo::TContentPrincipalInfo
||
163 aRight
.type() == PrincipalInfo::TSystemPrincipalInfo
);
165 if (aLeft
.type() != aRight
.type()) {
169 if (aLeft
.type() == PrincipalInfo::TContentPrincipalInfo
) {
170 const ContentPrincipalInfo
& leftContent
= aLeft
.get_ContentPrincipalInfo();
171 const ContentPrincipalInfo
& rightContent
=
172 aRight
.get_ContentPrincipalInfo();
174 return leftContent
.attrs() == rightContent
.attrs() &&
175 leftContent
.originNoSuffix() == rightContent
.originNoSuffix();
178 // Storage keys for the System principal always equal.
182 already_AddRefed
<nsIContentSecurityPolicy
> CSPInfoToCSP(
183 const CSPInfo
& aCSPInfo
, Document
* aRequestingDoc
,
184 nsresult
* aOptionalResult
) {
185 MOZ_ASSERT(NS_IsMainThread());
187 nsresult stackResult
;
188 nsresult
& rv
= aOptionalResult
? *aOptionalResult
: stackResult
;
190 RefPtr
<nsCSPContext
> csp
= new nsCSPContext();
192 if (aRequestingDoc
) {
193 rv
= csp
->SetRequestContextWithDocument(aRequestingDoc
);
194 if (NS_WARN_IF(NS_FAILED(rv
))) {
198 auto principalOrErr
=
199 PrincipalInfoToPrincipal(aCSPInfo
.requestPrincipalInfo());
200 if (NS_WARN_IF(principalOrErr
.isErr())) {
204 nsCOMPtr
<nsIURI
> selfURI
;
205 if (!aCSPInfo
.selfURISpec().IsEmpty()) {
206 rv
= NS_NewURI(getter_AddRefs(selfURI
), aCSPInfo
.selfURISpec());
207 if (NS_WARN_IF(NS_FAILED(rv
))) {
212 nsCOMPtr
<nsIPrincipal
> principal
= principalOrErr
.unwrap();
214 rv
= csp
->SetRequestContextWithPrincipal(
215 principal
, selfURI
, aCSPInfo
.referrer(), aCSPInfo
.innerWindowID());
216 if (NS_WARN_IF(NS_FAILED(rv
))) {
220 csp
->SetSkipAllowInlineStyleCheck(aCSPInfo
.skipAllowInlineStyleCheck());
222 for (uint32_t i
= 0; i
< aCSPInfo
.policyInfos().Length(); i
++) {
223 csp
->AddIPCPolicy(aCSPInfo
.policyInfos()[i
]);
228 nsresult
CSPToCSPInfo(nsIContentSecurityPolicy
* aCSP
, CSPInfo
* aCSPInfo
) {
229 MOZ_ASSERT(NS_IsMainThread());
231 MOZ_ASSERT(aCSPInfo
);
233 if (!aCSP
|| !aCSPInfo
) {
234 return NS_ERROR_FAILURE
;
237 nsCOMPtr
<nsIPrincipal
> requestPrincipal
= aCSP
->GetRequestPrincipal();
239 PrincipalInfo requestingPrincipalInfo
;
241 PrincipalToPrincipalInfo(requestPrincipal
, &requestingPrincipalInfo
);
242 if (NS_WARN_IF(NS_FAILED(rv
))) {
246 nsCOMPtr
<nsIURI
> selfURI
= aCSP
->GetSelfURI();
247 nsAutoCString selfURISpec
;
249 selfURI
->GetSpec(selfURISpec
);
252 nsAutoString referrer
;
253 aCSP
->GetReferrer(referrer
);
255 uint64_t windowID
= aCSP
->GetInnerWindowID();
256 bool skipAllowInlineStyleCheck
= aCSP
->GetSkipAllowInlineStyleCheck();
258 nsTArray
<ContentSecurityPolicy
> policies
;
259 static_cast<nsCSPContext
*>(aCSP
)->SerializePolicies(policies
);
261 *aCSPInfo
= CSPInfo(std::move(policies
), requestingPrincipalInfo
, selfURISpec
,
262 referrer
, windowID
, skipAllowInlineStyleCheck
);
266 nsresult
PrincipalToPrincipalInfo(nsIPrincipal
* aPrincipal
,
267 PrincipalInfo
* aPrincipalInfo
,
268 bool aSkipBaseDomain
) {
269 MOZ_ASSERT(aPrincipal
);
270 MOZ_ASSERT(aPrincipalInfo
);
273 if (aPrincipal
->GetIsNullPrincipal()) {
275 rv
= aPrincipal
->GetAsciiSpec(spec
);
276 if (NS_WARN_IF(NS_FAILED(rv
))) {
281 NullPrincipalInfo(aPrincipal
->OriginAttributesRef(), spec
);
285 if (aPrincipal
->IsSystemPrincipal()) {
286 *aPrincipalInfo
= SystemPrincipalInfo();
290 // might be an expanded principal
291 auto* basePrin
= BasePrincipal::Cast(aPrincipal
);
292 if (basePrin
->Is
<ExpandedPrincipal
>()) {
293 auto* expanded
= basePrin
->As
<ExpandedPrincipal
>();
295 nsTArray
<PrincipalInfo
> allowlistInfo
;
298 for (auto& prin
: expanded
->AllowList()) {
299 rv
= PrincipalToPrincipalInfo(prin
, &info
, aSkipBaseDomain
);
300 if (NS_WARN_IF(NS_FAILED(rv
))) {
303 // append that spec to the allowlist
304 allowlistInfo
.AppendElement(info
);
307 *aPrincipalInfo
= ExpandedPrincipalInfo(aPrincipal
->OriginAttributesRef(),
308 std::move(allowlistInfo
));
313 rv
= aPrincipal
->GetAsciiSpec(spec
);
314 if (NS_WARN_IF(NS_FAILED(rv
))) {
318 nsCString originNoSuffix
;
319 rv
= aPrincipal
->GetOriginNoSuffix(originNoSuffix
);
320 if (NS_WARN_IF(NS_FAILED(rv
))) {
324 nsCOMPtr
<nsIURI
> domainUri
;
325 rv
= aPrincipal
->GetDomain(getter_AddRefs(domainUri
));
326 if (NS_WARN_IF(NS_FAILED(rv
))) {
330 Maybe
<nsCString
> domain
;
333 rv
= domainUri
->GetSpec(domain
.ref());
334 if (NS_WARN_IF(NS_FAILED(rv
))) {
339 // This attribute is not crucial.
340 nsCString baseDomain
;
341 if (aSkipBaseDomain
) {
342 baseDomain
.SetIsVoid(true);
344 if (NS_FAILED(aPrincipal
->GetBaseDomain(baseDomain
))) {
345 // No warning here. Some principal URLs do not have a base-domain.
346 baseDomain
.SetIsVoid(true);
351 ContentPrincipalInfo(aPrincipal
->OriginAttributesRef(), originNoSuffix
,
352 spec
, domain
, baseDomain
);
356 bool IsPrincipalInfoPrivate(const PrincipalInfo
& aPrincipalInfo
) {
357 if (aPrincipalInfo
.type() != ipc::PrincipalInfo::TContentPrincipalInfo
) {
361 const ContentPrincipalInfo
& info
= aPrincipalInfo
.get_ContentPrincipalInfo();
362 return !!info
.attrs().mPrivateBrowsingId
;
365 already_AddRefed
<nsIRedirectHistoryEntry
> RHEntryInfoToRHEntry(
366 const RedirectHistoryEntryInfo
& aRHEntryInfo
) {
367 auto principalOrErr
= PrincipalInfoToPrincipal(aRHEntryInfo
.principalInfo());
368 if (NS_WARN_IF(principalOrErr
.isErr())) {
372 nsCOMPtr
<nsIPrincipal
> principal
= principalOrErr
.unwrap();
373 nsCOMPtr
<nsIURI
> referrerUri
= DeserializeURI(aRHEntryInfo
.referrerUri());
375 nsCOMPtr
<nsIRedirectHistoryEntry
> entry
= new nsRedirectHistoryEntry(
376 principal
, referrerUri
, aRHEntryInfo
.remoteAddress());
378 return entry
.forget();
381 nsresult
RHEntryToRHEntryInfo(nsIRedirectHistoryEntry
* aRHEntry
,
382 RedirectHistoryEntryInfo
* aRHEntryInfo
) {
383 MOZ_ASSERT(aRHEntry
);
384 MOZ_ASSERT(aRHEntryInfo
);
387 aRHEntry
->GetRemoteAddress(aRHEntryInfo
->remoteAddress());
389 nsCOMPtr
<nsIURI
> referrerUri
;
390 rv
= aRHEntry
->GetReferrerURI(getter_AddRefs(referrerUri
));
391 NS_ENSURE_SUCCESS(rv
, rv
);
392 SerializeURI(referrerUri
, aRHEntryInfo
->referrerUri());
394 nsCOMPtr
<nsIPrincipal
> principal
;
395 rv
= aRHEntry
->GetPrincipal(getter_AddRefs(principal
));
396 NS_ENSURE_SUCCESS(rv
, rv
);
398 return PrincipalToPrincipalInfo(principal
, &aRHEntryInfo
->principalInfo());
401 nsresult
LoadInfoToLoadInfoArgs(nsILoadInfo
* aLoadInfo
,
402 LoadInfoArgs
* outLoadInfoArgs
) {
404 Maybe
<PrincipalInfo
> loadingPrincipalInfo
;
405 if (nsIPrincipal
* loadingPrin
= aLoadInfo
->GetLoadingPrincipal()) {
406 loadingPrincipalInfo
.emplace();
407 rv
= PrincipalToPrincipalInfo(loadingPrin
, loadingPrincipalInfo
.ptr());
408 NS_ENSURE_SUCCESS(rv
, rv
);
411 PrincipalInfo triggeringPrincipalInfo
;
412 rv
= PrincipalToPrincipalInfo(aLoadInfo
->TriggeringPrincipal(),
413 &triggeringPrincipalInfo
);
414 NS_ENSURE_SUCCESS(rv
, rv
);
416 Maybe
<PrincipalInfo
> principalToInheritInfo
;
417 if (nsIPrincipal
* principalToInherit
= aLoadInfo
->PrincipalToInherit()) {
418 principalToInheritInfo
.emplace();
419 rv
= PrincipalToPrincipalInfo(principalToInherit
,
420 principalToInheritInfo
.ptr());
421 NS_ENSURE_SUCCESS(rv
, rv
);
424 Maybe
<PrincipalInfo
> topLevelPrincipalInfo
;
425 if (nsIPrincipal
* topLevenPrin
= aLoadInfo
->GetTopLevelPrincipal()) {
426 topLevelPrincipalInfo
.emplace();
427 rv
= PrincipalToPrincipalInfo(topLevenPrin
, topLevelPrincipalInfo
.ptr());
428 NS_ENSURE_SUCCESS(rv
, rv
);
431 Maybe
<URIParams
> optionalResultPrincipalURI
;
432 nsCOMPtr
<nsIURI
> resultPrincipalURI
;
433 Unused
<< aLoadInfo
->GetResultPrincipalURI(
434 getter_AddRefs(resultPrincipalURI
));
435 if (resultPrincipalURI
) {
436 SerializeURI(resultPrincipalURI
, optionalResultPrincipalURI
);
439 nsCString triggeringRemoteType
;
440 rv
= aLoadInfo
->GetTriggeringRemoteType(triggeringRemoteType
);
441 NS_ENSURE_SUCCESS(rv
, rv
);
443 nsTArray
<RedirectHistoryEntryInfo
> redirectChainIncludingInternalRedirects
;
444 for (const nsCOMPtr
<nsIRedirectHistoryEntry
>& redirectEntry
:
445 aLoadInfo
->RedirectChainIncludingInternalRedirects()) {
446 RedirectHistoryEntryInfo
* entry
=
447 redirectChainIncludingInternalRedirects
.AppendElement();
448 rv
= RHEntryToRHEntryInfo(redirectEntry
, entry
);
449 NS_ENSURE_SUCCESS(rv
, rv
);
452 nsTArray
<RedirectHistoryEntryInfo
> redirectChain
;
453 for (const nsCOMPtr
<nsIRedirectHistoryEntry
>& redirectEntry
:
454 aLoadInfo
->RedirectChain()) {
455 RedirectHistoryEntryInfo
* entry
= redirectChain
.AppendElement();
456 rv
= RHEntryToRHEntryInfo(redirectEntry
, entry
);
457 NS_ENSURE_SUCCESS(rv
, rv
);
460 Maybe
<IPCClientInfo
> ipcClientInfo
;
461 const Maybe
<ClientInfo
>& clientInfo
= aLoadInfo
->GetClientInfo();
462 if (clientInfo
.isSome()) {
463 ipcClientInfo
.emplace(clientInfo
.ref().ToIPC());
466 Maybe
<IPCClientInfo
> ipcReservedClientInfo
;
467 const Maybe
<ClientInfo
>& reservedClientInfo
=
468 aLoadInfo
->GetReservedClientInfo();
469 if (reservedClientInfo
.isSome()) {
470 ipcReservedClientInfo
.emplace(reservedClientInfo
.ref().ToIPC());
473 Maybe
<IPCClientInfo
> ipcInitialClientInfo
;
474 const Maybe
<ClientInfo
>& initialClientInfo
=
475 aLoadInfo
->GetInitialClientInfo();
476 if (initialClientInfo
.isSome()) {
477 ipcInitialClientInfo
.emplace(initialClientInfo
.ref().ToIPC());
480 Maybe
<IPCServiceWorkerDescriptor
> ipcController
;
481 const Maybe
<ServiceWorkerDescriptor
>& controller
= aLoadInfo
->GetController();
482 if (controller
.isSome()) {
483 ipcController
.emplace(controller
.ref().ToIPC());
486 nsAutoString cspNonce
;
487 Unused
<< NS_WARN_IF(NS_FAILED(aLoadInfo
->GetCspNonce(cspNonce
)));
489 nsAutoString integrityMetadata
;
490 Unused
<< NS_WARN_IF(
491 NS_FAILED(aLoadInfo
->GetIntegrityMetadata(integrityMetadata
)));
493 nsCOMPtr
<nsICookieJarSettings
> cookieJarSettings
;
494 rv
= aLoadInfo
->GetCookieJarSettings(getter_AddRefs(cookieJarSettings
));
495 NS_ENSURE_SUCCESS(rv
, rv
);
497 CookieJarSettingsArgs cookieJarSettingsArgs
;
498 static_cast<CookieJarSettings
*>(cookieJarSettings
.get())
499 ->Serialize(cookieJarSettingsArgs
);
501 Maybe
<CSPInfo
> maybeCspToInheritInfo
;
502 nsCOMPtr
<nsIContentSecurityPolicy
> cspToInherit
=
503 aLoadInfo
->GetCspToInherit();
505 CSPInfo cspToInheritInfo
;
506 Unused
<< NS_WARN_IF(
507 NS_FAILED(CSPToCSPInfo(cspToInherit
, &cspToInheritInfo
)));
508 maybeCspToInheritInfo
.emplace(cspToInheritInfo
);
511 nsCOMPtr
<nsIURI
> unstrippedURI
;
512 Unused
<< aLoadInfo
->GetUnstrippedURI(getter_AddRefs(unstrippedURI
));
514 Maybe
<bool> isThirdPartyContextToTopWindow
;
515 if (static_cast<LoadInfo
*>(aLoadInfo
)
516 ->HasIsThirdPartyContextToTopWindowSet()) {
517 isThirdPartyContextToTopWindow
.emplace(
518 aLoadInfo
->GetIsThirdPartyContextToTopWindow());
521 Maybe
<InterceptionInfoArg
> interceptionInfoArg
;
522 nsIInterceptionInfo
* interceptionInfo
= aLoadInfo
->InterceptionInfo();
523 if (interceptionInfo
) {
524 Maybe
<PrincipalInfo
> triggeringPrincipalInfo
;
525 if (interceptionInfo
->TriggeringPrincipal()) {
526 triggeringPrincipalInfo
.emplace();
527 rv
= PrincipalToPrincipalInfo(interceptionInfo
->TriggeringPrincipal(),
528 triggeringPrincipalInfo
.ptr());
531 nsTArray
<RedirectHistoryEntryInfo
> redirectChain
;
532 for (const nsCOMPtr
<nsIRedirectHistoryEntry
>& redirectEntry
:
533 interceptionInfo
->RedirectChain()) {
534 RedirectHistoryEntryInfo
* entry
= redirectChain
.AppendElement();
535 rv
= RHEntryToRHEntryInfo(redirectEntry
, entry
);
536 NS_ENSURE_SUCCESS(rv
, rv
);
539 interceptionInfoArg
= Some(InterceptionInfoArg(
540 triggeringPrincipalInfo
, interceptionInfo
->ContentPolicyType(),
541 redirectChain
, interceptionInfo
->FromThirdParty()));
544 Maybe
<uint64_t> overriddenFingerprintingSettingsArg
;
545 Maybe
<RFPTarget
> overriddenFingerprintingSettings
=
546 aLoadInfo
->GetOverriddenFingerprintingSettings();
548 if (overriddenFingerprintingSettings
) {
549 overriddenFingerprintingSettingsArg
=
550 Some(uint64_t(overriddenFingerprintingSettings
.ref()));
553 *outLoadInfoArgs
= LoadInfoArgs(
554 loadingPrincipalInfo
, triggeringPrincipalInfo
, principalToInheritInfo
,
555 topLevelPrincipalInfo
, optionalResultPrincipalURI
, triggeringRemoteType
,
556 aLoadInfo
->GetSandboxedNullPrincipalID(), aLoadInfo
->GetSecurityFlags(),
557 aLoadInfo
->GetSandboxFlags(), aLoadInfo
->GetTriggeringSandboxFlags(),
558 aLoadInfo
->GetTriggeringWindowId(),
559 aLoadInfo
->GetTriggeringStorageAccess(),
560 aLoadInfo
->InternalContentPolicyType(),
561 static_cast<uint32_t>(aLoadInfo
->GetTainting()),
562 aLoadInfo
->GetBlockAllMixedContent(),
563 aLoadInfo
->GetUpgradeInsecureRequests(),
564 aLoadInfo
->GetBrowserUpgradeInsecureRequests(),
565 aLoadInfo
->GetBrowserDidUpgradeInsecureRequests(),
566 aLoadInfo
->GetBrowserWouldUpgradeInsecureRequests(),
567 aLoadInfo
->GetForceAllowDataURI(),
568 aLoadInfo
->GetAllowInsecureRedirectToDataURI(),
569 aLoadInfo
->GetSkipContentPolicyCheckForWebRequest(),
570 aLoadInfo
->GetOriginalFrameSrcLoad(),
571 aLoadInfo
->GetForceInheritPrincipalDropped(),
572 aLoadInfo
->GetInnerWindowID(), aLoadInfo
->GetBrowsingContextID(),
573 aLoadInfo
->GetFrameBrowsingContextID(),
574 aLoadInfo
->GetInitialSecurityCheckDone(),
575 aLoadInfo
->GetIsInThirdPartyContext(), isThirdPartyContextToTopWindow
,
576 aLoadInfo
->GetIsFormSubmission(), aLoadInfo
->GetSendCSPViolationEvents(),
577 aLoadInfo
->GetOriginAttributes(), redirectChainIncludingInternalRedirects
,
578 redirectChain
, aLoadInfo
->GetHasInjectedCookieForCookieBannerHandling(),
579 aLoadInfo
->GetWasSchemelessInput(), ipcClientInfo
, ipcReservedClientInfo
,
580 ipcInitialClientInfo
, ipcController
, aLoadInfo
->CorsUnsafeHeaders(),
581 aLoadInfo
->GetForcePreflight(), aLoadInfo
->GetIsPreflight(),
582 aLoadInfo
->GetLoadTriggeredFromExternal(),
583 aLoadInfo
->GetServiceWorkerTaintingSynthesized(),
584 aLoadInfo
->GetDocumentHasUserInteracted(),
585 aLoadInfo
->GetAllowListFutureDocumentsCreatedFromThisRedirectChain(),
586 aLoadInfo
->GetNeedForCheckingAntiTrackingHeuristic(), cspNonce
,
587 integrityMetadata
, aLoadInfo
->GetSkipContentSniffing(),
588 aLoadInfo
->GetHttpsOnlyStatus(), aLoadInfo
->GetHstsStatus(),
589 aLoadInfo
->GetHasValidUserGestureActivation(),
590 aLoadInfo
->GetAllowDeprecatedSystemRequests(),
591 aLoadInfo
->GetIsInDevToolsContext(), aLoadInfo
->GetParserCreatedScript(),
592 aLoadInfo
->GetIsFromProcessingFrameAttributes(),
593 aLoadInfo
->GetIsMediaRequest(), aLoadInfo
->GetIsMediaInitialRequest(),
594 aLoadInfo
->GetIsFromObjectOrEmbed(), cookieJarSettingsArgs
,
595 aLoadInfo
->GetRequestBlockingReason(), maybeCspToInheritInfo
,
596 aLoadInfo
->GetStoragePermission(), overriddenFingerprintingSettingsArg
,
597 aLoadInfo
->GetIsMetaRefresh(), aLoadInfo
->GetLoadingEmbedderPolicy(),
598 aLoadInfo
->GetIsOriginTrialCoepCredentiallessEnabledForTopLevel(),
599 unstrippedURI
, interceptionInfoArg
);
604 nsresult
LoadInfoArgsToLoadInfo(const LoadInfoArgs
& aLoadInfoArgs
,
605 const nsACString
& aOriginRemoteType
,
606 nsILoadInfo
** outLoadInfo
) {
607 return LoadInfoArgsToLoadInfo(aLoadInfoArgs
, aOriginRemoteType
, nullptr,
610 nsresult
LoadInfoArgsToLoadInfo(const LoadInfoArgs
& aLoadInfoArgs
,
611 const nsACString
& aOriginRemoteType
,
612 nsINode
* aCspToInheritLoadingContext
,
613 nsILoadInfo
** outLoadInfo
) {
614 RefPtr
<LoadInfo
> loadInfo
;
615 nsresult rv
= LoadInfoArgsToLoadInfo(aLoadInfoArgs
, aOriginRemoteType
,
616 aCspToInheritLoadingContext
,
617 getter_AddRefs(loadInfo
));
618 NS_ENSURE_SUCCESS(rv
, rv
);
620 loadInfo
.forget(outLoadInfo
);
624 nsresult
LoadInfoArgsToLoadInfo(const LoadInfoArgs
& aLoadInfoArgs
,
625 const nsACString
& aOriginRemoteType
,
626 LoadInfo
** outLoadInfo
) {
627 return LoadInfoArgsToLoadInfo(aLoadInfoArgs
, aOriginRemoteType
, nullptr,
630 nsresult
LoadInfoArgsToLoadInfo(const LoadInfoArgs
& loadInfoArgs
,
631 const nsACString
& aOriginRemoteType
,
632 nsINode
* aCspToInheritLoadingContext
,
633 LoadInfo
** outLoadInfo
) {
634 nsCOMPtr
<nsIPrincipal
> loadingPrincipal
;
635 if (loadInfoArgs
.requestingPrincipalInfo().isSome()) {
636 auto loadingPrincipalOrErr
=
637 PrincipalInfoToPrincipal(loadInfoArgs
.requestingPrincipalInfo().ref());
638 if (NS_WARN_IF(loadingPrincipalOrErr
.isErr())) {
639 return loadingPrincipalOrErr
.unwrapErr();
641 loadingPrincipal
= loadingPrincipalOrErr
.unwrap();
644 auto triggeringPrincipalOrErr
=
645 PrincipalInfoToPrincipal(loadInfoArgs
.triggeringPrincipalInfo());
646 if (NS_WARN_IF(triggeringPrincipalOrErr
.isErr())) {
647 return triggeringPrincipalOrErr
.unwrapErr();
649 nsCOMPtr
<nsIPrincipal
> triggeringPrincipal
=
650 triggeringPrincipalOrErr
.unwrap();
652 nsCOMPtr
<nsIPrincipal
> principalToInherit
;
653 nsCOMPtr
<nsIPrincipal
> flattenedPrincipalToInherit
;
654 if (loadInfoArgs
.principalToInheritInfo().isSome()) {
655 auto principalToInheritOrErr
=
656 PrincipalInfoToPrincipal(loadInfoArgs
.principalToInheritInfo().ref());
657 if (NS_WARN_IF(principalToInheritOrErr
.isErr())) {
658 return principalToInheritOrErr
.unwrapErr();
660 flattenedPrincipalToInherit
= principalToInheritOrErr
.unwrap();
663 if (XRE_IsContentProcess()) {
664 auto targetBrowsingContextId
= loadInfoArgs
.frameBrowsingContextID()
665 ? loadInfoArgs
.frameBrowsingContextID()
666 : loadInfoArgs
.browsingContextID();
667 if (RefPtr
<BrowsingContext
> bc
=
668 BrowsingContext::Get(targetBrowsingContextId
)) {
669 auto [originalTriggeringPrincipal
, originalPrincipalToInherit
] =
670 bc
->GetTriggeringAndInheritPrincipalsForCurrentLoad();
672 if (originalTriggeringPrincipal
&&
673 originalTriggeringPrincipal
->Equals(triggeringPrincipal
)) {
674 triggeringPrincipal
= originalTriggeringPrincipal
;
676 if (originalPrincipalToInherit
&&
677 (loadInfoArgs
.securityFlags() &
678 nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL
) &&
679 originalPrincipalToInherit
->Equals(flattenedPrincipalToInherit
)) {
680 principalToInherit
= originalPrincipalToInherit
;
684 if (!principalToInherit
&& loadInfoArgs
.principalToInheritInfo().isSome()) {
685 principalToInherit
= flattenedPrincipalToInherit
;
688 nsCOMPtr
<nsIPrincipal
> topLevelPrincipal
;
689 if (loadInfoArgs
.topLevelPrincipalInfo().isSome()) {
690 auto topLevelPrincipalOrErr
=
691 PrincipalInfoToPrincipal(loadInfoArgs
.topLevelPrincipalInfo().ref());
692 if (NS_WARN_IF(topLevelPrincipalOrErr
.isErr())) {
693 return topLevelPrincipalOrErr
.unwrapErr();
695 topLevelPrincipal
= topLevelPrincipalOrErr
.unwrap();
698 nsCOMPtr
<nsIURI
> resultPrincipalURI
;
699 if (loadInfoArgs
.resultPrincipalURI().isSome()) {
700 resultPrincipalURI
= DeserializeURI(loadInfoArgs
.resultPrincipalURI());
701 NS_ENSURE_TRUE(resultPrincipalURI
, NS_ERROR_UNEXPECTED
);
704 // If we received this message from a content process, reset
705 // triggeringRemoteType to the process which sent us the message. If the
706 // parent sent us the message, we trust it to provide the correct triggering
709 // This means that the triggering remote type will be reset if a LoadInfo is
710 // bounced through a content process, as the LoadInfo can no longer be
711 // validated to be coming from the originally specified remote type.
712 nsCString triggeringRemoteType
= loadInfoArgs
.triggeringRemoteType();
713 if (aOriginRemoteType
!= NOT_REMOTE_TYPE
&&
714 aOriginRemoteType
!= triggeringRemoteType
) {
715 triggeringRemoteType
= aOriginRemoteType
;
718 RedirectHistoryArray redirectChainIncludingInternalRedirects
;
719 for (const RedirectHistoryEntryInfo
& entryInfo
:
720 loadInfoArgs
.redirectChainIncludingInternalRedirects()) {
721 nsCOMPtr
<nsIRedirectHistoryEntry
> redirectHistoryEntry
=
722 RHEntryInfoToRHEntry(entryInfo
);
723 NS_ENSURE_TRUE(redirectHistoryEntry
, NS_ERROR_UNEXPECTED
);
724 redirectChainIncludingInternalRedirects
.AppendElement(
725 redirectHistoryEntry
.forget());
728 RedirectHistoryArray redirectChain
;
729 for (const RedirectHistoryEntryInfo
& entryInfo
:
730 loadInfoArgs
.redirectChain()) {
731 nsCOMPtr
<nsIRedirectHistoryEntry
> redirectHistoryEntry
=
732 RHEntryInfoToRHEntry(entryInfo
);
733 NS_ENSURE_TRUE(redirectHistoryEntry
, NS_ERROR_UNEXPECTED
);
734 redirectChain
.AppendElement(redirectHistoryEntry
.forget());
736 nsTArray
<nsCOMPtr
<nsIPrincipal
>> ancestorPrincipals
;
737 nsTArray
<uint64_t> ancestorBrowsingContextIDs
;
738 if (XRE_IsParentProcess() &&
739 (nsContentUtils::InternalContentPolicyTypeToExternal(
740 loadInfoArgs
.contentPolicyType()) !=
741 ExtContentPolicy::TYPE_DOCUMENT
)) {
742 // Only fill out ancestor principals and browsing context IDs when we
743 // are deserializing LoadInfoArgs to be LoadInfo for a subresource
744 RefPtr
<BrowsingContext
> parentBC
=
745 BrowsingContext::Get(loadInfoArgs
.browsingContextID());
747 LoadInfo::ComputeAncestors(parentBC
->Canonical(), ancestorPrincipals
,
748 ancestorBrowsingContextIDs
);
752 Maybe
<ClientInfo
> clientInfo
;
753 if (loadInfoArgs
.clientInfo().isSome()) {
754 clientInfo
.emplace(ClientInfo(loadInfoArgs
.clientInfo().ref()));
757 Maybe
<ClientInfo
> reservedClientInfo
;
758 if (loadInfoArgs
.reservedClientInfo().isSome()) {
759 reservedClientInfo
.emplace(
760 ClientInfo(loadInfoArgs
.reservedClientInfo().ref()));
763 Maybe
<ClientInfo
> initialClientInfo
;
764 if (loadInfoArgs
.initialClientInfo().isSome()) {
765 initialClientInfo
.emplace(
766 ClientInfo(loadInfoArgs
.initialClientInfo().ref()));
769 // We can have an initial client info or a reserved client info, but not both.
770 MOZ_DIAGNOSTIC_ASSERT(reservedClientInfo
.isNothing() ||
771 initialClientInfo
.isNothing());
773 reservedClientInfo
.isNothing() || initialClientInfo
.isNothing(),
774 NS_ERROR_UNEXPECTED
);
776 Maybe
<ServiceWorkerDescriptor
> controller
;
777 if (loadInfoArgs
.controller().isSome()) {
779 ServiceWorkerDescriptor(loadInfoArgs
.controller().ref()));
782 nsCOMPtr
<nsICookieJarSettings
> cookieJarSettings
;
783 CookieJarSettings::Deserialize(loadInfoArgs
.cookieJarSettings(),
784 getter_AddRefs(cookieJarSettings
));
786 Maybe
<RFPTarget
> overriddenFingerprintingSettings
;
787 if (loadInfoArgs
.overriddenFingerprintingSettings().isSome()) {
788 overriddenFingerprintingSettings
.emplace(
789 RFPTarget(loadInfoArgs
.overriddenFingerprintingSettings().ref()));
792 nsCOMPtr
<nsIContentSecurityPolicy
> cspToInherit
;
793 Maybe
<mozilla::ipc::CSPInfo
> cspToInheritInfo
=
794 loadInfoArgs
.cspToInheritInfo();
795 if (cspToInheritInfo
.isSome()) {
796 nsCOMPtr
<Document
> doc
= do_QueryInterface(aCspToInheritLoadingContext
);
797 cspToInherit
= CSPInfoToCSP(cspToInheritInfo
.ref(), doc
);
800 // Restore the loadingContext for frames using the BrowsingContext's
801 // embedder element. Note that this only works if the embedder is
802 // same-process, so won't be fission compatible.
803 nsCOMPtr
<nsINode
> loadingContext
;
804 RefPtr
<BrowsingContext
> frameBrowsingContext
=
805 BrowsingContext::Get(loadInfoArgs
.frameBrowsingContextID());
806 if (frameBrowsingContext
) {
807 loadingContext
= frameBrowsingContext
->GetEmbedderElement();
810 Maybe
<bool> isThirdPartyContextToTopWindow
;
811 if (loadInfoArgs
.isThirdPartyContextToTopWindow().isSome()) {
812 isThirdPartyContextToTopWindow
.emplace(
813 loadInfoArgs
.isThirdPartyContextToTopWindow().ref());
816 nsCOMPtr
<nsIInterceptionInfo
> interceptionInfo
;
817 if (loadInfoArgs
.interceptionInfo().isSome()) {
818 const InterceptionInfoArg
& interceptionInfoArg
=
819 loadInfoArgs
.interceptionInfo().ref();
820 nsCOMPtr
<nsIPrincipal
> triggeringPrincipal
;
821 if (interceptionInfoArg
.triggeringPrincipalInfo().isSome()) {
822 auto triggeringPrincipalOrErr
= PrincipalInfoToPrincipal(
823 interceptionInfoArg
.triggeringPrincipalInfo().ref());
824 if (NS_WARN_IF(triggeringPrincipalOrErr
.isErr())) {
825 return triggeringPrincipalOrErr
.unwrapErr();
827 triggeringPrincipal
= triggeringPrincipalOrErr
.unwrap();
830 RedirectHistoryArray redirectChain
;
831 for (const RedirectHistoryEntryInfo
& entryInfo
:
832 interceptionInfoArg
.redirectChain()) {
833 nsCOMPtr
<nsIRedirectHistoryEntry
> redirectHistoryEntry
=
834 RHEntryInfoToRHEntry(entryInfo
);
835 NS_ENSURE_TRUE(redirectHistoryEntry
, NS_ERROR_UNEXPECTED
);
836 redirectChain
.AppendElement(redirectHistoryEntry
.forget());
839 interceptionInfo
= new InterceptionInfo(
840 triggeringPrincipal
, interceptionInfoArg
.contentPolicyType(),
841 redirectChain
, interceptionInfoArg
.fromThirdParty());
844 RefPtr
<mozilla::net::LoadInfo
> loadInfo
= new mozilla::net::LoadInfo(
845 loadingPrincipal
, triggeringPrincipal
, principalToInherit
,
846 topLevelPrincipal
, resultPrincipalURI
, cookieJarSettings
, cspToInherit
,
847 triggeringRemoteType
, loadInfoArgs
.sandboxedNullPrincipalID(), clientInfo
,
848 reservedClientInfo
, initialClientInfo
, controller
,
849 loadInfoArgs
.securityFlags(), loadInfoArgs
.sandboxFlags(),
850 loadInfoArgs
.triggeringSandboxFlags(), loadInfoArgs
.triggeringWindowId(),
851 loadInfoArgs
.triggeringStorageAccess(), loadInfoArgs
.contentPolicyType(),
852 static_cast<LoadTainting
>(loadInfoArgs
.tainting()),
853 loadInfoArgs
.blockAllMixedContent(),
854 loadInfoArgs
.upgradeInsecureRequests(),
855 loadInfoArgs
.browserUpgradeInsecureRequests(),
856 loadInfoArgs
.browserDidUpgradeInsecureRequests(),
857 loadInfoArgs
.browserWouldUpgradeInsecureRequests(),
858 loadInfoArgs
.forceAllowDataURI(),
859 loadInfoArgs
.allowInsecureRedirectToDataURI(),
860 loadInfoArgs
.skipContentPolicyCheckForWebRequest(),
861 loadInfoArgs
.originalFrameSrcLoad(),
862 loadInfoArgs
.forceInheritPrincipalDropped(), loadInfoArgs
.innerWindowID(),
863 loadInfoArgs
.browsingContextID(), loadInfoArgs
.frameBrowsingContextID(),
864 loadInfoArgs
.initialSecurityCheckDone(),
865 loadInfoArgs
.isInThirdPartyContext(), isThirdPartyContextToTopWindow
,
866 loadInfoArgs
.isFormSubmission(), loadInfoArgs
.sendCSPViolationEvents(),
867 loadInfoArgs
.originAttributes(),
868 std::move(redirectChainIncludingInternalRedirects
),
869 std::move(redirectChain
), std::move(ancestorPrincipals
),
870 ancestorBrowsingContextIDs
, loadInfoArgs
.corsUnsafeHeaders(),
871 loadInfoArgs
.forcePreflight(), loadInfoArgs
.isPreflight(),
872 loadInfoArgs
.loadTriggeredFromExternal(),
873 loadInfoArgs
.serviceWorkerTaintingSynthesized(),
874 loadInfoArgs
.documentHasUserInteracted(),
875 loadInfoArgs
.allowListFutureDocumentsCreatedFromThisRedirectChain(),
876 loadInfoArgs
.needForCheckingAntiTrackingHeuristic(),
877 loadInfoArgs
.cspNonce(), loadInfoArgs
.integrityMetadata(),
878 loadInfoArgs
.skipContentSniffing(), loadInfoArgs
.httpsOnlyStatus(),
879 loadInfoArgs
.hstsStatus(), loadInfoArgs
.hasValidUserGestureActivation(),
880 loadInfoArgs
.allowDeprecatedSystemRequests(),
881 loadInfoArgs
.isInDevToolsContext(), loadInfoArgs
.parserCreatedScript(),
882 loadInfoArgs
.storagePermission(), overriddenFingerprintingSettings
,
883 loadInfoArgs
.isMetaRefresh(), loadInfoArgs
.requestBlockingReason(),
884 loadingContext
, loadInfoArgs
.loadingEmbedderPolicy(),
885 loadInfoArgs
.originTrialCoepCredentiallessEnabledForTopLevel(),
886 loadInfoArgs
.unstrippedURI(), interceptionInfo
,
887 loadInfoArgs
.hasInjectedCookieForCookieBannerHandling(),
888 loadInfoArgs
.wasSchemelessInput());
890 if (loadInfoArgs
.isFromProcessingFrameAttributes()) {
891 loadInfo
->SetIsFromProcessingFrameAttributes();
894 if (loadInfoArgs
.isMediaRequest()) {
895 loadInfo
->SetIsMediaRequest(true);
897 if (loadInfoArgs
.isMediaInitialRequest()) {
898 loadInfo
->SetIsMediaInitialRequest(true);
902 if (loadInfoArgs
.isFromObjectOrEmbed()) {
903 loadInfo
->SetIsFromObjectOrEmbed(true);
906 loadInfo
.forget(outLoadInfo
);
910 void LoadInfoToParentLoadInfoForwarder(
911 nsILoadInfo
* aLoadInfo
, ParentLoadInfoForwarderArgs
* aForwarderArgsOut
) {
912 Maybe
<IPCServiceWorkerDescriptor
> ipcController
;
913 Maybe
<ServiceWorkerDescriptor
> controller(aLoadInfo
->GetController());
914 if (controller
.isSome()) {
915 ipcController
.emplace(controller
.ref().ToIPC());
918 uint32_t tainting
= nsILoadInfo::TAINTING_BASIC
;
919 Unused
<< aLoadInfo
->GetTainting(&tainting
);
921 Maybe
<CookieJarSettingsArgs
> cookieJarSettingsArgs
;
923 nsCOMPtr
<nsICookieJarSettings
> cookieJarSettings
;
925 aLoadInfo
->GetCookieJarSettings(getter_AddRefs(cookieJarSettings
));
926 CookieJarSettings
* cs
=
927 static_cast<CookieJarSettings
*>(cookieJarSettings
.get());
928 if (NS_SUCCEEDED(rv
) && cookieJarSettings
&& cs
->HasBeenChanged()) {
929 CookieJarSettingsArgs args
;
931 cookieJarSettingsArgs
= Some(args
);
934 nsCOMPtr
<nsIURI
> unstrippedURI
;
935 Unused
<< aLoadInfo
->GetUnstrippedURI(getter_AddRefs(unstrippedURI
));
937 Maybe
<bool> isThirdPartyContextToTopWindow
;
938 if (static_cast<LoadInfo
*>(aLoadInfo
)
939 ->HasIsThirdPartyContextToTopWindowSet()) {
940 isThirdPartyContextToTopWindow
.emplace(
941 aLoadInfo
->GetIsThirdPartyContextToTopWindow());
944 Maybe
<uint64_t> overriddenFingerprintingSettingsArg
;
945 Maybe
<RFPTarget
> overriddenFingerprintingSettings
=
946 aLoadInfo
->GetOverriddenFingerprintingSettings();
948 if (overriddenFingerprintingSettings
) {
949 overriddenFingerprintingSettingsArg
=
950 Some(uint64_t(overriddenFingerprintingSettings
.ref()));
953 *aForwarderArgsOut
= ParentLoadInfoForwarderArgs(
954 aLoadInfo
->GetAllowInsecureRedirectToDataURI(), ipcController
, tainting
,
955 aLoadInfo
->GetSkipContentSniffing(), aLoadInfo
->GetHttpsOnlyStatus(),
956 aLoadInfo
->GetHstsStatus(), aLoadInfo
->GetHasValidUserGestureActivation(),
957 aLoadInfo
->GetAllowDeprecatedSystemRequests(),
958 aLoadInfo
->GetIsInDevToolsContext(), aLoadInfo
->GetParserCreatedScript(),
959 aLoadInfo
->GetTriggeringSandboxFlags(),
960 aLoadInfo
->GetTriggeringWindowId(),
961 aLoadInfo
->GetTriggeringStorageAccess(),
962 aLoadInfo
->GetServiceWorkerTaintingSynthesized(),
963 aLoadInfo
->GetDocumentHasUserInteracted(),
964 aLoadInfo
->GetAllowListFutureDocumentsCreatedFromThisRedirectChain(),
965 cookieJarSettingsArgs
, aLoadInfo
->GetRequestBlockingReason(),
966 aLoadInfo
->GetStoragePermission(), overriddenFingerprintingSettingsArg
,
967 aLoadInfo
->GetIsMetaRefresh(), isThirdPartyContextToTopWindow
,
968 aLoadInfo
->GetIsInThirdPartyContext(), unstrippedURI
);
971 nsresult
MergeParentLoadInfoForwarder(
972 ParentLoadInfoForwarderArgs
const& aForwarderArgs
, nsILoadInfo
* aLoadInfo
) {
975 rv
= aLoadInfo
->SetAllowInsecureRedirectToDataURI(
976 aForwarderArgs
.allowInsecureRedirectToDataURI());
977 NS_ENSURE_SUCCESS(rv
, rv
);
979 aLoadInfo
->ClearController();
980 auto& controller
= aForwarderArgs
.controller();
981 if (controller
.isSome()) {
982 aLoadInfo
->SetController(ServiceWorkerDescriptor(controller
.ref()));
985 if (aForwarderArgs
.serviceWorkerTaintingSynthesized()) {
986 aLoadInfo
->SynthesizeServiceWorkerTainting(
987 static_cast<LoadTainting
>(aForwarderArgs
.tainting()));
989 aLoadInfo
->MaybeIncreaseTainting(aForwarderArgs
.tainting());
992 rv
= aLoadInfo
->SetSkipContentSniffing(aForwarderArgs
.skipContentSniffing());
993 NS_ENSURE_SUCCESS(rv
, rv
);
995 rv
= aLoadInfo
->SetHttpsOnlyStatus(aForwarderArgs
.httpsOnlyStatus());
996 NS_ENSURE_SUCCESS(rv
, rv
);
998 rv
= aLoadInfo
->SetHstsStatus(aForwarderArgs
.hstsStatus());
999 NS_ENSURE_SUCCESS(rv
, rv
);
1001 rv
= aLoadInfo
->SetTriggeringSandboxFlags(
1002 aForwarderArgs
.triggeringSandboxFlags());
1003 NS_ENSURE_SUCCESS(rv
, rv
);
1005 rv
= aLoadInfo
->SetTriggeringWindowId(aForwarderArgs
.triggeringWindowId());
1006 NS_ENSURE_SUCCESS(rv
, rv
);
1008 rv
= aLoadInfo
->SetTriggeringStorageAccess(
1009 aForwarderArgs
.triggeringStorageAccess());
1010 NS_ENSURE_SUCCESS(rv
, rv
);
1012 rv
= aLoadInfo
->SetHasValidUserGestureActivation(
1013 aForwarderArgs
.hasValidUserGestureActivation());
1014 NS_ENSURE_SUCCESS(rv
, rv
);
1016 rv
= aLoadInfo
->SetAllowDeprecatedSystemRequests(
1017 aForwarderArgs
.allowDeprecatedSystemRequests());
1018 NS_ENSURE_SUCCESS(rv
, rv
);
1020 rv
= aLoadInfo
->SetIsInDevToolsContext(aForwarderArgs
.isInDevToolsContext());
1021 NS_ENSURE_SUCCESS(rv
, rv
);
1023 rv
= aLoadInfo
->SetParserCreatedScript(aForwarderArgs
.parserCreatedScript());
1024 NS_ENSURE_SUCCESS(rv
, rv
);
1026 MOZ_ALWAYS_SUCCEEDS(aLoadInfo
->SetDocumentHasUserInteracted(
1027 aForwarderArgs
.documentHasUserInteracted()));
1028 MOZ_ALWAYS_SUCCEEDS(
1029 aLoadInfo
->SetAllowListFutureDocumentsCreatedFromThisRedirectChain(
1031 .allowListFutureDocumentsCreatedFromThisRedirectChain()));
1032 MOZ_ALWAYS_SUCCEEDS(aLoadInfo
->SetRequestBlockingReason(
1033 aForwarderArgs
.requestBlockingReason()));
1035 const Maybe
<CookieJarSettingsArgs
>& cookieJarSettingsArgs
=
1036 aForwarderArgs
.cookieJarSettings();
1037 if (cookieJarSettingsArgs
.isSome()) {
1038 nsCOMPtr
<nsICookieJarSettings
> cookieJarSettings
;
1040 aLoadInfo
->GetCookieJarSettings(getter_AddRefs(cookieJarSettings
));
1041 if (NS_SUCCEEDED(rv
) && cookieJarSettings
) {
1042 static_cast<CookieJarSettings
*>(cookieJarSettings
.get())
1043 ->Merge(cookieJarSettingsArgs
.ref());
1047 rv
= aLoadInfo
->SetStoragePermission(aForwarderArgs
.storagePermission());
1048 NS_ENSURE_SUCCESS(rv
, rv
);
1050 rv
= aLoadInfo
->SetIsMetaRefresh(aForwarderArgs
.isMetaRefresh());
1051 NS_ENSURE_SUCCESS(rv
, rv
);
1053 const Maybe
<uint64_t> overriddenFingerprintingSettings
=
1054 aForwarderArgs
.overriddenFingerprintingSettings();
1055 if (overriddenFingerprintingSettings
.isSome()) {
1056 aLoadInfo
->SetOverriddenFingerprintingSettings(
1057 RFPTarget(overriddenFingerprintingSettings
.ref()));
1060 static_cast<LoadInfo
*>(aLoadInfo
)->ClearIsThirdPartyContextToTopWindow();
1061 if (aForwarderArgs
.isThirdPartyContextToTopWindow().isSome()) {
1062 rv
= aLoadInfo
->SetIsThirdPartyContextToTopWindow(
1063 aForwarderArgs
.isThirdPartyContextToTopWindow().ref());
1065 NS_ENSURE_SUCCESS(rv
, rv
);
1067 rv
= aLoadInfo
->SetIsInThirdPartyContext(
1068 aForwarderArgs
.isInThirdPartyContext());
1069 NS_ENSURE_SUCCESS(rv
, rv
);
1071 rv
= aLoadInfo
->SetUnstrippedURI(aForwarderArgs
.unstrippedURI());
1072 NS_ENSURE_SUCCESS(rv
, rv
);
1077 void LoadInfoToChildLoadInfoForwarder(
1078 nsILoadInfo
* aLoadInfo
, ChildLoadInfoForwarderArgs
* aForwarderArgsOut
) {
1079 Maybe
<IPCClientInfo
> ipcReserved
;
1080 Maybe
<ClientInfo
> reserved(aLoadInfo
->GetReservedClientInfo());
1081 if (reserved
.isSome()) {
1082 ipcReserved
.emplace(reserved
.ref().ToIPC());
1085 Maybe
<IPCClientInfo
> ipcInitial
;
1086 Maybe
<ClientInfo
> initial(aLoadInfo
->GetInitialClientInfo());
1087 if (initial
.isSome()) {
1088 ipcInitial
.emplace(initial
.ref().ToIPC());
1091 Maybe
<IPCServiceWorkerDescriptor
> ipcController
;
1092 Maybe
<ServiceWorkerDescriptor
> controller(aLoadInfo
->GetController());
1093 if (controller
.isSome()) {
1094 ipcController
.emplace(controller
.ref().ToIPC());
1097 *aForwarderArgsOut
=
1098 ChildLoadInfoForwarderArgs(ipcReserved
, ipcInitial
, ipcController
,
1099 aLoadInfo
->GetRequestBlockingReason());
1102 nsresult
MergeChildLoadInfoForwarder(
1103 const ChildLoadInfoForwarderArgs
& aForwarderArgs
, nsILoadInfo
* aLoadInfo
) {
1104 Maybe
<ClientInfo
> reservedClientInfo
;
1105 auto& ipcReserved
= aForwarderArgs
.reservedClientInfo();
1106 if (ipcReserved
.isSome()) {
1107 reservedClientInfo
.emplace(ClientInfo(ipcReserved
.ref()));
1110 Maybe
<ClientInfo
> initialClientInfo
;
1111 auto& ipcInitial
= aForwarderArgs
.initialClientInfo();
1112 if (ipcInitial
.isSome()) {
1113 initialClientInfo
.emplace(ClientInfo(ipcInitial
.ref()));
1116 // There should only be at most one reserved or initial ClientInfo.
1117 if (NS_WARN_IF(reservedClientInfo
.isSome() && initialClientInfo
.isSome())) {
1118 return NS_ERROR_FAILURE
;
1121 // If we received no reserved or initial ClientInfo, then we must not
1122 // already have one set. There are no use cases where this should
1123 // happen and we don't have a way to clear the current value.
1124 if (NS_WARN_IF(reservedClientInfo
.isNothing() &&
1125 initialClientInfo
.isNothing() &&
1126 (aLoadInfo
->GetReservedClientInfo().isSome() ||
1127 aLoadInfo
->GetInitialClientInfo().isSome()))) {
1128 return NS_ERROR_FAILURE
;
1131 if (reservedClientInfo
.isSome()) {
1132 // We need to override here instead of simply set the value. This
1133 // allows us to change the reserved client. This is necessary when
1134 // the ClientChannelHelper created a new reserved client in the
1135 // child-side of the redirect.
1136 aLoadInfo
->OverrideReservedClientInfoInParent(reservedClientInfo
.ref());
1137 } else if (initialClientInfo
.isSome()) {
1138 aLoadInfo
->SetInitialClientInfo(initialClientInfo
.ref());
1141 aLoadInfo
->ClearController();
1142 auto& controller
= aForwarderArgs
.controller();
1143 if (controller
.isSome()) {
1144 aLoadInfo
->SetController(ServiceWorkerDescriptor(controller
.ref()));
1147 uint32_t blockingReason
= aForwarderArgs
.requestBlockingReason();
1148 if (blockingReason
) {
1149 // We only want to override when non-null, so that any earlier set non-null
1150 // value is not reverted to 0.
1151 aLoadInfo
->SetRequestBlockingReason(blockingReason
);
1158 } // namespace mozilla