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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_LoadInfo_h
8 #define mozilla_LoadInfo_h
10 #include "mozilla/dom/FeaturePolicy.h"
11 #include "mozilla/dom/UserNavigationInvolvement.h"
12 #include "nsIInterceptionInfo.h"
13 #include "nsILoadInfo.h"
14 #include "nsIPrincipal.h"
15 #include "nsIWeakReferenceUtils.h" // for nsWeakPtr
17 #include "nsContentUtils.h"
21 #include "mozilla/BasePrincipal.h"
22 #include "mozilla/dom/ClientInfo.h"
23 #include "mozilla/dom/ServiceWorkerDescriptor.h"
26 class nsICookieJarSettings
;
28 class nsPIDOMWindowOuter
;
33 class PerformanceStorage
;
34 class XMLHttpRequestMainThread
;
35 class CanonicalBrowsingContext
;
36 class WindowGlobalParent
;
40 class EarlyHintPreloader
;
46 // we have to forward declare that function so we can use it as a friend.
47 nsresult
LoadInfoArgsToLoadInfo(const mozilla::net::LoadInfoArgs
& aLoadInfoArgs
,
48 const nsACString
& aOriginRemoteType
,
49 nsINode
* aCspToInheritLoadingContext
,
50 net::LoadInfo
** outLoadInfo
);
56 using RedirectHistoryArray
= nsTArray
<nsCOMPtr
<nsIRedirectHistoryEntry
>>;
59 * Class that provides an nsILoadInfo implementation.
61 class LoadInfo final
: public nsILoadInfo
{
62 template <typename T
, typename
... Args
>
63 friend already_AddRefed
<T
> mozilla::MakeAndAddRef(Args
&&... aArgs
);
69 // Used for TYPE_DOCUMENT load.
70 static already_AddRefed
<LoadInfo
> CreateForDocument(
71 dom::CanonicalBrowsingContext
* aBrowsingContext
, nsIURI
* aURI
,
72 nsIPrincipal
* aTriggeringPrincipal
,
73 const nsACString
& aTriggeringRemoteType
,
74 const OriginAttributes
& aOriginAttributes
, nsSecurityFlags aSecurityFlags
,
75 uint32_t aSandboxFlags
);
77 // Used for TYPE_FRAME or TYPE_IFRAME load.
78 static already_AddRefed
<LoadInfo
> CreateForFrame(
79 dom::CanonicalBrowsingContext
* aBrowsingContext
,
80 nsIPrincipal
* aTriggeringPrincipal
,
81 const nsACString
& aTriggeringRemoteType
, nsSecurityFlags aSecurityFlags
,
82 uint32_t aSandboxFlags
);
84 // Use for non-{TYPE_DOCUMENT|TYPE_FRAME|TYPE_IFRAME} load.
85 static already_AddRefed
<LoadInfo
> CreateForNonDocument(
86 dom::WindowGlobalParent
* aParentWGP
, nsIPrincipal
* aTriggeringPrincipal
,
87 nsContentPolicyType aContentPolicyType
, nsSecurityFlags aSecurityFlags
,
88 uint32_t aSandboxFlags
);
90 // aLoadingPrincipal MUST NOT BE NULL.
91 LoadInfo(nsIPrincipal
* aLoadingPrincipal
, nsIPrincipal
* aTriggeringPrincipal
,
92 nsINode
* aLoadingContext
, nsSecurityFlags aSecurityFlags
,
93 nsContentPolicyType aContentPolicyType
,
94 const Maybe
<mozilla::dom::ClientInfo
>& aLoadingClientInfo
=
95 Maybe
<mozilla::dom::ClientInfo
>(),
96 const Maybe
<mozilla::dom::ServiceWorkerDescriptor
>& aController
=
97 Maybe
<mozilla::dom::ServiceWorkerDescriptor
>(),
98 uint32_t aSandboxFlags
= 0);
100 // Constructor used for TYPE_DOCUMENT loads which have a different
101 // loadingContext than other loads. This ContextForTopLevelLoad is
102 // only used for content policy checks.
103 LoadInfo(nsPIDOMWindowOuter
* aOuterWindow
, nsIURI
* aURI
,
104 nsIPrincipal
* aTriggeringPrincipal
,
105 nsISupports
* aContextForTopLevelLoad
, nsSecurityFlags aSecurityFlags
,
106 uint32_t aSandboxFlags
);
109 // Use factory function CreateForDocument
110 // Used for TYPE_DOCUMENT load.
111 LoadInfo(dom::CanonicalBrowsingContext
* aBrowsingContext
, nsIURI
* aURI
,
112 nsIPrincipal
* aTriggeringPrincipal
,
113 const nsACString
& aTriggeringRemoteType
,
114 const OriginAttributes
& aOriginAttributes
,
115 nsSecurityFlags aSecurityFlags
, uint32_t aSandboxFlags
);
117 // Use factory function CreateForFrame
118 // Used for TYPE_FRAME or TYPE_IFRAME load.
119 LoadInfo(dom::CanonicalBrowsingContext
* aBrowsingContext
,
120 nsIPrincipal
* aTriggeringPrincipal
,
121 const nsACString
& aTriggeringRemoteType
,
122 nsSecurityFlags aSecurityFlags
, uint32_t aSandboxFlags
);
124 // Used for loads initiated by DocumentLoadListener that are not TYPE_DOCUMENT
125 // | TYPE_FRAME | TYPE_FRAME.
126 LoadInfo(dom::WindowGlobalParent
* aParentWGP
,
127 nsIPrincipal
* aTriggeringPrincipal
,
128 const nsACString
& aTriggeringRemoteType
,
129 nsContentPolicyType aContentPolicyType
,
130 nsSecurityFlags aSecurityFlags
, uint32_t aSandboxFlags
);
133 // Compute a list of ancestor principals and BrowsingContext IDs.
134 // See methods AncestorPrincipals and AncestorBrowsingContextIDs
135 // in nsILoadInfo.idl for details.
136 static void ComputeAncestors(
137 dom::CanonicalBrowsingContext
* aBC
,
138 nsTArray
<nsCOMPtr
<nsIPrincipal
>>& aAncestorPrincipals
,
139 nsTArray
<uint64_t>& aBrowsingContextIDs
);
141 // create an exact copy of the loadinfo
142 already_AddRefed
<nsILoadInfo
> Clone() const;
144 // hands off!!! don't use CloneWithNewSecFlags unless you know
145 // exactly what you are doing - it should only be used within
146 // nsBaseChannel::Redirect()
147 already_AddRefed
<nsILoadInfo
> CloneWithNewSecFlags(
148 nsSecurityFlags aSecurityFlags
) const;
149 // creates a copy of the loadinfo which is appropriate to use for a
150 // separate request. I.e. not for a redirect or an inner channel, but
151 // when a separate request is made with the same security properties.
152 already_AddRefed
<nsILoadInfo
> CloneForNewRequest() const;
154 // The `nsContentPolicyType GetExternalContentPolicyType()` version in the
155 // base class is hidden by the implementation of
156 // `GetExternalContentPolicyType(nsContentPolicyType* aResult)` in
157 // LoadInfo.cpp. Explicit mark it visible.
158 using nsILoadInfo::GetExternalContentPolicyType
;
160 void SetIsPreflight();
161 void SetUpgradeInsecureRequests(bool aValue
);
162 void SetBrowserUpgradeInsecureRequests();
163 void SetBrowserWouldUpgradeInsecureRequests();
164 void SetIsFromProcessingFrameAttributes();
166 // Hands off from the cspToInherit functionality!
168 // For navigations, GetCSPToInherit returns what the spec calls the
169 // "request's client's global object's CSP list", or more precisely
170 // a snapshot of it taken when the navigation starts. For navigations
171 // that need to inherit their CSP, this is the right CSP to use for
172 // the new document. We need a way to transfer the CSP from the
173 // docshell (where the navigation starts) to the point where the new
174 // document is created and decides whether to inherit its CSP, and
175 // this is the mechanism we use for that.
178 // A document with a CSP triggers a new top-level data: URI load.
179 // We pass the CSP of the document that triggered the load all the
180 // way to docshell. Within docshell we call SetCSPToInherit() on the
181 // loadinfo. Within Document::InitCSP() we check if the newly created
182 // document needs to inherit the CSP. If so, we call GetCSPToInherit()
183 // and set the inherited CSP as the CSP for the new document. Please
184 // note that any additonal Meta CSP in that document will be merged
185 // into that CSP. Any subresource loads within that document
186 // subesquently will receive the correct CSP by querying
187 // loadinfo->GetCsp() from that point on.
188 void SetCSPToInherit(nsIContentSecurityPolicy
* aCspToInherit
) {
189 mCspToInherit
= aCspToInherit
;
192 bool HasIsThirdPartyContextToTopWindowSet() {
193 return mIsThirdPartyContextToTopWindow
.isSome();
195 void ClearIsThirdPartyContextToTopWindow() {
196 mIsThirdPartyContextToTopWindow
.reset();
199 void SetContinerFeaturePolicy(
200 const Maybe
<dom::FeaturePolicyInfo
>& aContainerFeaturePolicy
) {
201 mContainerFeaturePolicyInfo
= aContainerFeaturePolicy
;
205 void MarkOverriddenFingerprintingSettingsAsSet() {
206 mOverriddenFingerprintingSettingsIsSet
= true;
211 // private constructor that is only allowed to be called from within
212 // HttpChannelParent and FTPChannelParent declared as friends undeneath.
213 // In e10s we can not serialize nsINode, hence we store the innerWindowID.
214 // Please note that aRedirectChain uses swapElements.
216 nsIPrincipal
* aLoadingPrincipal
, nsIPrincipal
* aTriggeringPrincipal
,
217 nsIPrincipal
* aPrincipalToInherit
, nsIPrincipal
* aTopLevelPrincipal
,
218 nsIURI
* aResultPrincipalURI
, nsICookieJarSettings
* aCookieJarSettings
,
219 nsIContentSecurityPolicy
* aCspToInherit
,
220 const nsACString
& aTriggeringRemoteType
,
221 const nsID
& aSandboxedNullPrincipalID
,
222 const Maybe
<mozilla::dom::ClientInfo
>& aClientInfo
,
223 const Maybe
<mozilla::dom::ClientInfo
>& aReservedClientInfo
,
224 const Maybe
<mozilla::dom::ClientInfo
>& aInitialClientInfo
,
225 const Maybe
<mozilla::dom::ServiceWorkerDescriptor
>& aController
,
226 nsSecurityFlags aSecurityFlags
, uint32_t aSandboxFlags
,
227 uint32_t aTriggeringSandboxFlags
, uint64_t aTriggeringWindowId
,
228 bool aTriggeringStorageAccess
, nsContentPolicyType aContentPolicyType
,
229 LoadTainting aTainting
, bool aBlockAllMixedContent
,
230 bool aUpgradeInsecureRequests
, bool aBrowserUpgradeInsecureRequests
,
231 bool aBrowserDidUpgradeInsecureRequests
,
232 bool aBrowserWouldUpgradeInsecureRequests
, bool aForceAllowDataURI
,
233 bool aAllowInsecureRedirectToDataURI
,
234 bool aSkipContentPolicyCheckForWebRequest
, bool aOriginalFrameSrcLoad
,
235 bool aForceInheritPrincipalDropped
, uint64_t aInnerWindowID
,
236 uint64_t aBrowsingContextID
, uint64_t aFrameBrowsingContextID
,
237 bool aInitialSecurityCheckDone
, bool aIsThirdPartyContext
,
238 const Maybe
<bool>& aIsThirdPartyContextToTopWindow
,
239 bool aIsOn3PCBExceptionList
, bool aIsFormSubmission
, bool aIsGETRequest
,
240 bool aSendCSPViolationEvents
, const OriginAttributes
& aOriginAttributes
,
241 RedirectHistoryArray
&& aRedirectChainIncludingInternalRedirects
,
242 RedirectHistoryArray
&& aRedirectChain
,
243 nsTArray
<nsCOMPtr
<nsIPrincipal
>>&& aAncestorPrincipals
,
244 const nsTArray
<uint64_t>& aAncestorBrowsingContextIDs
,
245 const nsTArray
<nsCString
>& aCorsUnsafeHeaders
, bool aForcePreflight
,
246 bool aIsPreflight
, bool aLoadTriggeredFromExternal
,
247 bool aServiceWorkerTaintingSynthesized
, bool aDocumentHasUserInteracted
,
248 bool aAllowListFutureDocumentsCreatedFromThisRedirectChain
,
249 bool aNeedForCheckingAntiTrackingHeuristic
, const nsAString
& aCspNonce
,
250 const nsAString
& aIntegrityMetadata
, bool aSkipContentSniffing
,
251 uint32_t aHttpsOnlyStatus
, bool aHstsStatus
,
252 bool aHasValidUserGestureActivation
, bool aTextDirectiveUserActivation
,
253 bool aIsSameDocumentNavigation
, bool aAllowDeprecatedSystemRequests
,
254 bool aIsInDevToolsContext
, bool aParserCreatedScript
,
255 nsILoadInfo::StoragePermissionState aStoragePermission
,
256 const Maybe
<RFPTargetSet
>& aOverriddenFingerprintingSettings
,
257 bool aIsMetaRefresh
, uint32_t aRequestBlockingReason
,
258 nsINode
* aLoadingContext
,
259 nsILoadInfo::CrossOriginEmbedderPolicy aLoadingEmbedderPolicy
,
260 bool aIsOriginTrialCoepCredentiallessEnabledForTopLevel
,
261 nsIURI
* aUnstrippedURI
, nsIInterceptionInfo
* aInterceptionInfo
,
262 bool aHasInjectedCookieForCookieBannerHandling
,
263 nsILoadInfo::SchemelessInputType aSchemelessInput
,
264 nsILoadInfo::HTTPSUpgradeTelemetryType aHttpsUpgradeTelemetry
,
265 bool aIsNewWindowTarget
,
266 dom::UserNavigationInvolvement aUserNavigationInvolvement
);
268 LoadInfo(const LoadInfo
& rhs
);
270 NS_IMETHOD
GetRedirects(JSContext
* aCx
,
271 JS::MutableHandle
<JS::Value
> aRedirects
,
272 const RedirectHistoryArray
& aArra
);
274 friend nsresult
mozilla::ipc::LoadInfoArgsToLoadInfo(
275 const mozilla::net::LoadInfoArgs
& aLoadInfoArgs
,
276 const nsACString
& aOriginRemoteType
, nsINode
* aCspToInheritLoadingContext
,
277 net::LoadInfo
** outLoadInfo
);
281 void ComputeIsThirdPartyContext(nsPIDOMWindowOuter
* aOuterWindow
);
282 void ComputeIsThirdPartyContext(dom::WindowGlobalParent
* aGlobal
);
284 // This function is the *only* function which can change the securityflags
285 // of a loadinfo. It only exists because of the XHR code. Don't call it
286 // from anywhere else!
287 void SetIncludeCookiesSecFlag();
288 friend class mozilla::dom::XMLHttpRequestMainThread
;
290 // nsDocShell::OpenInitializedChannel and EarlyHintPreloader::OpenChannel
291 // needs to update the loadInfo with the correct browsingContext.
292 friend class ::nsDocShell
;
293 friend class mozilla::net::EarlyHintPreloader
;
294 void UpdateBrowsingContextID(uint64_t aBrowsingContextID
) {
295 mBrowsingContextID
= aBrowsingContextID
;
297 void UpdateFrameBrowsingContextID(uint64_t aFrameBrowsingContextID
) {
298 mFrameBrowsingContextID
= aFrameBrowsingContextID
;
300 MOZ_NEVER_INLINE
void ReleaseMembers();
302 // if you add a member, please also update the copy constructor and consider
303 // if it should be merged from parent channel through
304 // ParentLoadInfoForwarderArgs.
305 nsCOMPtr
<nsIPrincipal
> mLoadingPrincipal
;
306 nsCOMPtr
<nsIPrincipal
> mTriggeringPrincipal
;
307 nsCOMPtr
<nsIPrincipal
> mPrincipalToInherit
;
308 nsCOMPtr
<nsIPrincipal
> mTopLevelPrincipal
;
309 nsCOMPtr
<nsIURI
> mResultPrincipalURI
;
310 nsCOMPtr
<nsIURI
> mChannelCreationOriginalURI
;
311 nsCOMPtr
<nsICSPEventListener
> mCSPEventListener
;
312 nsCOMPtr
<nsICookieJarSettings
> mCookieJarSettings
;
313 nsCOMPtr
<nsIContentSecurityPolicy
> mCspToInherit
;
314 Maybe
<dom::FeaturePolicyInfo
> mContainerFeaturePolicyInfo
;
315 nsCString mTriggeringRemoteType
;
316 nsID mSandboxedNullPrincipalID
;
318 Maybe
<mozilla::dom::ClientInfo
> mClientInfo
;
319 UniquePtr
<mozilla::dom::ClientSource
> mReservedClientSource
;
320 Maybe
<mozilla::dom::ClientInfo
> mReservedClientInfo
;
321 Maybe
<mozilla::dom::ClientInfo
> mInitialClientInfo
;
322 Maybe
<mozilla::dom::ServiceWorkerDescriptor
> mController
;
323 RefPtr
<mozilla::dom::PerformanceStorage
> mPerformanceStorage
;
325 nsWeakPtr mLoadingContext
;
326 nsWeakPtr mContextForTopLevelLoad
;
327 nsSecurityFlags mSecurityFlags
;
328 uint32_t mSandboxFlags
;
329 uint32_t mTriggeringSandboxFlags
= 0;
330 uint64_t mTriggeringWindowId
= 0;
331 bool mTriggeringStorageAccess
= false;
332 nsContentPolicyType mInternalContentPolicyType
;
333 LoadTainting mTainting
= LoadTainting::Basic
;
334 bool mBlockAllMixedContent
= false;
335 bool mUpgradeInsecureRequests
= false;
336 bool mBrowserUpgradeInsecureRequests
= false;
337 bool mBrowserDidUpgradeInsecureRequests
= false;
338 bool mBrowserWouldUpgradeInsecureRequests
= false;
339 bool mForceAllowDataURI
= false;
340 bool mAllowInsecureRedirectToDataURI
= false;
341 bool mSkipContentPolicyCheckForWebRequest
= false;
342 bool mOriginalFrameSrcLoad
= false;
343 bool mForceInheritPrincipalDropped
= false;
344 uint64_t mInnerWindowID
= 0;
345 uint64_t mBrowsingContextID
= 0;
346 uint64_t mWorkerAssociatedBrowsingContextID
= 0;
347 uint64_t mFrameBrowsingContextID
= 0;
348 bool mInitialSecurityCheckDone
= false;
349 // NB: TYPE_DOCUMENT implies !third-party.
350 bool mIsThirdPartyContext
= false;
351 Maybe
<bool> mIsThirdPartyContextToTopWindow
;
352 bool mIsOn3PCBExceptionList
= false;
353 bool mIsFormSubmission
= false;
354 bool mIsGETRequest
= true;
355 bool mSendCSPViolationEvents
= true;
356 OriginAttributes mOriginAttributes
;
357 RedirectHistoryArray mRedirectChainIncludingInternalRedirects
;
358 RedirectHistoryArray mRedirectChain
;
359 nsTArray
<nsCOMPtr
<nsIPrincipal
>> mAncestorPrincipals
;
360 nsTArray
<uint64_t> mAncestorBrowsingContextIDs
;
361 nsTArray
<nsCString
> mCorsUnsafeHeaders
;
362 uint32_t mRequestBlockingReason
= BLOCKING_REASON_NONE
;
363 bool mForcePreflight
= false;
364 bool mIsPreflight
= false;
365 bool mLoadTriggeredFromExternal
= false;
366 bool mServiceWorkerTaintingSynthesized
= false;
367 bool mDocumentHasUserInteracted
= false;
368 bool mAllowListFutureDocumentsCreatedFromThisRedirectChain
= false;
369 bool mNeedForCheckingAntiTrackingHeuristic
= false;
371 nsString mIntegrityMetadata
;
372 bool mSkipContentSniffing
= false;
373 uint32_t mHttpsOnlyStatus
= nsILoadInfo::HTTPS_ONLY_UNINITIALIZED
;
374 bool mHstsStatus
= false;
375 bool mHasValidUserGestureActivation
= false;
376 bool mTextDirectiveUserActivation
= false;
377 bool mIsSameDocumentNavigation
= false;
378 bool mAllowDeprecatedSystemRequests
= false;
379 bool mIsUserTriggeredSave
= false;
380 bool mIsInDevToolsContext
= false;
381 bool mParserCreatedScript
= false;
382 nsILoadInfo::StoragePermissionState mStoragePermission
=
383 nsILoadInfo::NoStoragePermission
;
384 Maybe
<RFPTargetSet
> mOverriddenFingerprintingSettings
;
386 // A boolean used to ensure the mOverriddenFingerprintingSettings is set
388 bool mOverriddenFingerprintingSettingsIsSet
= false;
390 bool mIsMetaRefresh
= false;
392 // Is true if this load was triggered by processing the attributes of the
393 // browsing context container.
394 // See nsILoadInfo.isFromProcessingFrameAttributes
395 bool mIsFromProcessingFrameAttributes
= false;
397 // See nsILoadInfo.isMediaRequest and nsILoadInfo.isMediaInitialRequest.
398 bool mIsMediaRequest
= false;
399 bool mIsMediaInitialRequest
= false;
401 // See nsILoadInfo.isFromObjectOrEmbed
402 bool mIsFromObjectOrEmbed
= false;
404 // The cross origin embedder policy that the loading need to respect.
405 // If the value is nsILoadInfo::EMBEDDER_POLICY_REQUIRE_CORP, CORP checking
406 // must be performed for the loading.
407 // See https://wicg.github.io/cross-origin-embedder-policy/#corp-check.
408 nsILoadInfo::CrossOriginEmbedderPolicy mLoadingEmbedderPolicy
=
409 nsILoadInfo::EMBEDDER_POLICY_NULL
;
411 bool mIsOriginTrialCoepCredentiallessEnabledForTopLevel
= false;
413 nsCOMPtr
<nsIURI
> mUnstrippedURI
;
415 nsCOMPtr
<nsIInterceptionInfo
> mInterceptionInfo
;
417 bool mHasInjectedCookieForCookieBannerHandling
= false;
418 nsILoadInfo::SchemelessInputType mSchemelessInput
=
419 nsILoadInfo::SchemelessInputTypeUnset
;
421 nsILoadInfo::HTTPSUpgradeTelemetryType mHttpsUpgradeTelemetry
=
422 nsILoadInfo::NOT_INITIALIZED
;
424 dom::UserNavigationInvolvement mUserNavigationInvolvement
=
425 dom::UserNavigationInvolvement::None
;
427 bool mIsNewWindowTarget
= false;
428 bool mSkipHTTPSUpgrade
= false;
431 // This is exposed solely for testing purposes and should not be used outside of
433 already_AddRefed
<nsIPrincipal
> CreateTruncatedPrincipal(nsIPrincipal
*);
436 } // namespace mozilla
438 #endif // mozilla_LoadInfo_h