/src/mozilla-central/netwerk/base/LoadInfo.cpp
Line | Count | Source (jump to first uncovered line) |
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/. */ |
6 | | |
7 | | #include "mozilla/LoadInfo.h" |
8 | | |
9 | | #include "mozilla/Assertions.h" |
10 | | #include "mozilla/dom/ClientIPCTypes.h" |
11 | | #include "mozilla/dom/ClientSource.h" |
12 | | #include "mozilla/dom/PerformanceStorage.h" |
13 | | #include "mozilla/dom/TabChild.h" |
14 | | #include "mozilla/dom/ToJSValue.h" |
15 | | #include "mozilla/NullPrincipal.h" |
16 | | #include "mozIThirdPartyUtil.h" |
17 | | #include "nsFrameLoader.h" |
18 | | #include "nsIContentSecurityPolicy.h" |
19 | | #include "nsIDocShell.h" |
20 | | #include "nsIDocument.h" |
21 | | #include "nsIFrameLoaderOwner.h" |
22 | | #include "nsIInterfaceRequestorUtils.h" |
23 | | #include "nsISupportsImpl.h" |
24 | | #include "nsISupportsUtils.h" |
25 | | #include "nsIXPConnect.h" |
26 | | #include "nsContentUtils.h" |
27 | | #include "nsDocShell.h" |
28 | | #include "nsGlobalWindow.h" |
29 | | #include "nsMixedContentBlocker.h" |
30 | | #include "nsRedirectHistoryEntry.h" |
31 | | #include "LoadInfo.h" |
32 | | |
33 | | using namespace mozilla::dom; |
34 | | |
35 | | namespace mozilla { |
36 | | namespace net { |
37 | | |
38 | | static uint64_t |
39 | | FindTopOuterWindowID(nsPIDOMWindowOuter* aOuter) |
40 | 0 | { |
41 | 0 | nsCOMPtr<nsPIDOMWindowOuter> outer = aOuter; |
42 | 0 | while (nsCOMPtr<nsPIDOMWindowOuter> parent = outer->GetScriptableParentOrNull()) { |
43 | 0 | outer = parent; |
44 | 0 | } |
45 | 0 | return outer->WindowID(); |
46 | 0 | } |
47 | | |
48 | | LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, |
49 | | nsIPrincipal* aTriggeringPrincipal, |
50 | | nsINode* aLoadingContext, |
51 | | nsSecurityFlags aSecurityFlags, |
52 | | nsContentPolicyType aContentPolicyType, |
53 | | const Maybe<mozilla::dom::ClientInfo>& aLoadingClientInfo, |
54 | | const Maybe<mozilla::dom::ServiceWorkerDescriptor>& aController) |
55 | | : mLoadingPrincipal(aLoadingContext ? |
56 | | aLoadingContext->NodePrincipal() : aLoadingPrincipal) |
57 | | , mTriggeringPrincipal(aTriggeringPrincipal ? |
58 | | aTriggeringPrincipal : mLoadingPrincipal.get()) |
59 | | , mPrincipalToInherit(nullptr) |
60 | | , mClientInfo(aLoadingClientInfo) |
61 | | , mController(aController) |
62 | | , mLoadingContext(do_GetWeakReference(aLoadingContext)) |
63 | | , mContextForTopLevelLoad(nullptr) |
64 | | , mSecurityFlags(aSecurityFlags) |
65 | | , mInternalContentPolicyType(aContentPolicyType) |
66 | | , mTainting(LoadTainting::Basic) |
67 | | , mUpgradeInsecureRequests(false) |
68 | | , mBrowserUpgradeInsecureRequests(false) |
69 | | , mBrowserWouldUpgradeInsecureRequests(false) |
70 | | , mVerifySignedContent(false) |
71 | | , mEnforceSRI(false) |
72 | | , mForceAllowDataURI(false) |
73 | | , mAllowInsecureRedirectToDataURI(false) |
74 | | , mSkipContentPolicyCheckForWebRequest(false) |
75 | | , mOriginalFrameSrcLoad(false) |
76 | | , mForceInheritPrincipalDropped(false) |
77 | | , mInnerWindowID(0) |
78 | | , mOuterWindowID(0) |
79 | | , mParentOuterWindowID(0) |
80 | | , mTopOuterWindowID(0) |
81 | | , mFrameOuterWindowID(0) |
82 | | , mEnforceSecurity(false) |
83 | | , mInitialSecurityCheckDone(false) |
84 | | , mIsThirdPartyContext(false) |
85 | | , mIsDocshellReload(false) |
86 | | , mSendCSPViolationEvents(true) |
87 | | , mTrackerBlockedReason(mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED::all) |
88 | | , mForcePreflight(false) |
89 | | , mIsPreflight(false) |
90 | | , mLoadTriggeredFromExternal(false) |
91 | | , mServiceWorkerTaintingSynthesized(false) |
92 | | , mIsTracker(false) |
93 | | , mIsTrackerBlocked(false) |
94 | | , mDocumentHasUserInteracted(false) |
95 | 5 | { |
96 | 5 | MOZ_ASSERT(mLoadingPrincipal); |
97 | 5 | MOZ_ASSERT(mTriggeringPrincipal); |
98 | 5 | |
99 | | #ifdef DEBUG |
100 | | // TYPE_DOCUMENT loads initiated by javascript tests will go through |
101 | | // nsIOService and use the wrong constructor. Don't enforce the |
102 | | // !TYPE_DOCUMENT check in those cases |
103 | | bool skipContentTypeCheck = false; |
104 | | skipContentTypeCheck = Preferences::GetBool("network.loadinfo.skip_type_assertion"); |
105 | | #endif |
106 | | |
107 | 5 | // This constructor shouldn't be used for TYPE_DOCUMENT loads that don't |
108 | 5 | // have a loadingPrincipal |
109 | 5 | MOZ_ASSERT(skipContentTypeCheck || mLoadingPrincipal || |
110 | 5 | mInternalContentPolicyType != nsIContentPolicy::TYPE_DOCUMENT); |
111 | 5 | |
112 | 5 | // We should only get an explicit controller for subresource requests. |
113 | 5 | MOZ_DIAGNOSTIC_ASSERT( |
114 | 5 | aController.isNothing() || |
115 | 5 | !nsContentUtils::IsNonSubresourceInternalPolicyType(mInternalContentPolicyType)); |
116 | 5 | |
117 | 5 | // TODO(bug 1259873): Above, we initialize mIsThirdPartyContext to false meaning |
118 | 5 | // that consumers of LoadInfo that don't pass a context or pass a context from |
119 | 5 | // which we can't find a window will default to assuming that they're 1st |
120 | 5 | // party. It would be nice if we could default "safe" and assume that we are |
121 | 5 | // 3rd party until proven otherwise. |
122 | 5 | |
123 | 5 | // if consumers pass both, aLoadingContext and aLoadingPrincipal |
124 | 5 | // then the loadingPrincipal must be the same as the node's principal |
125 | 5 | MOZ_ASSERT(!aLoadingContext || !aLoadingPrincipal || |
126 | 5 | aLoadingContext->NodePrincipal() == aLoadingPrincipal); |
127 | 5 | |
128 | 5 | // if the load is sandboxed, we can not also inherit the principal |
129 | 5 | if (mSecurityFlags & nsILoadInfo::SEC_SANDBOXED) { |
130 | 0 | mForceInheritPrincipalDropped = |
131 | 0 | (mSecurityFlags & nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL); |
132 | 0 | mSecurityFlags &= ~nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL; |
133 | 0 | } |
134 | 5 | |
135 | 5 | if (aLoadingContext) { |
136 | 0 | // Ensure that all network requests for a window client have the ClientInfo |
137 | 0 | // properly set. Workers must currently pass the loading ClientInfo explicitly. |
138 | 0 | // We allow main thread requests to explicitly pass the value as well. |
139 | 0 | if (mClientInfo.isNothing()) { |
140 | 0 | mClientInfo = aLoadingContext->OwnerDoc()->GetClientInfo(); |
141 | 0 | } |
142 | 0 |
|
143 | 0 | // For subresource loads set the service worker based on the calling |
144 | 0 | // context's controller. Workers must currently pass the controller in |
145 | 0 | // explicitly. We allow main thread requests to explicitly pass the value |
146 | 0 | // as well, but otherwise extract from the loading context here. |
147 | 0 | if (mController.isNothing() && |
148 | 0 | !nsContentUtils::IsNonSubresourceInternalPolicyType(mInternalContentPolicyType)) { |
149 | 0 | mController = aLoadingContext->OwnerDoc()->GetController(); |
150 | 0 | } |
151 | 0 |
|
152 | 0 | nsCOMPtr<nsPIDOMWindowOuter> contextOuter = aLoadingContext->OwnerDoc()->GetWindow(); |
153 | 0 | if (contextOuter) { |
154 | 0 | ComputeIsThirdPartyContext(contextOuter); |
155 | 0 | mOuterWindowID = contextOuter->WindowID(); |
156 | 0 | nsCOMPtr<nsPIDOMWindowOuter> parent = contextOuter->GetScriptableParent(); |
157 | 0 | mParentOuterWindowID = parent ? parent->WindowID() : mOuterWindowID; |
158 | 0 | mTopOuterWindowID = FindTopOuterWindowID(contextOuter); |
159 | 0 |
|
160 | 0 | nsGlobalWindowInner* innerWindow = |
161 | 0 | nsGlobalWindowInner::Cast(contextOuter->GetCurrentInnerWindow()); |
162 | 0 | if (innerWindow) { |
163 | 0 | mTopLevelPrincipal = innerWindow->GetTopLevelPrincipal(); |
164 | 0 | mTopLevelStorageAreaPrincipal = |
165 | 0 | innerWindow->GetTopLevelStorageAreaPrincipal(); |
166 | 0 | } |
167 | 0 | } |
168 | 0 |
|
169 | 0 | mInnerWindowID = aLoadingContext->OwnerDoc()->InnerWindowID(); |
170 | 0 | mAncestorPrincipals = aLoadingContext->OwnerDoc()->AncestorPrincipals(); |
171 | 0 | mAncestorOuterWindowIDs = aLoadingContext->OwnerDoc()->AncestorOuterWindowIDs(); |
172 | 0 | MOZ_DIAGNOSTIC_ASSERT(mAncestorPrincipals.Length() == mAncestorOuterWindowIDs.Length()); |
173 | 0 | mDocumentHasUserInteracted = aLoadingContext->OwnerDoc()->UserHasInteracted(); |
174 | 0 |
|
175 | 0 | // When the element being loaded is a frame, we choose the frame's window |
176 | 0 | // for the window ID and the frame element's window as the parent |
177 | 0 | // window. This is the behavior that Chrome exposes to add-ons. |
178 | 0 | // NB: If the frameLoaderOwner doesn't have a frame loader, then the load |
179 | 0 | // must be coming from an object (such as a plugin) that's loaded into it |
180 | 0 | // instead of a document being loaded. In that case, treat this object like |
181 | 0 | // any other non-document-loading element. |
182 | 0 | nsCOMPtr<nsIFrameLoaderOwner> frameLoaderOwner = |
183 | 0 | do_QueryInterface(aLoadingContext); |
184 | 0 | RefPtr<nsFrameLoader> fl = frameLoaderOwner ? |
185 | 0 | frameLoaderOwner->GetFrameLoader() : nullptr; |
186 | 0 | if (fl) { |
187 | 0 | nsCOMPtr<nsIDocShell> docShell = fl->GetDocShell(IgnoreErrors()); |
188 | 0 | if (docShell) { |
189 | 0 | nsCOMPtr<nsPIDOMWindowOuter> outerWindow = do_GetInterface(docShell); |
190 | 0 | if (outerWindow) { |
191 | 0 | mFrameOuterWindowID = outerWindow->WindowID(); |
192 | 0 | } |
193 | 0 | } |
194 | 0 | } |
195 | 0 |
|
196 | 0 | // if the document forces all requests to be upgraded from http to https, then |
197 | 0 | // we should do that for all requests. If it only forces preloads to be upgraded |
198 | 0 | // then we should enforce upgrade insecure requests only for preloads. |
199 | 0 | mUpgradeInsecureRequests = |
200 | 0 | aLoadingContext->OwnerDoc()->GetUpgradeInsecureRequests(false) || |
201 | 0 | (nsContentUtils::IsPreloadType(mInternalContentPolicyType) && |
202 | 0 | aLoadingContext->OwnerDoc()->GetUpgradeInsecureRequests(true)); |
203 | 0 |
|
204 | 0 | uint32_t externalType = |
205 | 0 | nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType); |
206 | 0 | if (nsContentUtils::IsUpgradableDisplayType(externalType)) { |
207 | 0 | nsCOMPtr<nsIURI> uri; |
208 | 0 | mLoadingPrincipal->GetURI(getter_AddRefs(uri)); |
209 | 0 | if (uri) { |
210 | 0 | // Checking https not secure context as http://localhost can't be upgraded |
211 | 0 | bool isHttpsScheme; |
212 | 0 | nsresult rv = uri->SchemeIs("https", &isHttpsScheme); |
213 | 0 | if (NS_SUCCEEDED(rv) && isHttpsScheme) { |
214 | 0 | if (nsMixedContentBlocker::ShouldUpgradeMixedDisplayContent()) { |
215 | 0 | mBrowserUpgradeInsecureRequests = true; |
216 | 0 | } else { |
217 | 0 | mBrowserWouldUpgradeInsecureRequests = true; |
218 | 0 | } |
219 | 0 | } |
220 | 0 | } |
221 | 0 | } |
222 | 0 | // if owner doc has content signature, we enforce SRI |
223 | 0 | nsCOMPtr<nsIChannel> channel = aLoadingContext->OwnerDoc()->GetChannel(); |
224 | 0 | if (channel) { |
225 | 0 | nsCOMPtr<nsILoadInfo> loadInfo = channel->GetLoadInfo(); |
226 | 0 | if (loadInfo) { |
227 | 0 | mEnforceSRI = loadInfo->GetVerifySignedContent(); |
228 | 0 | } |
229 | 0 | } |
230 | 0 | } |
231 | 5 | |
232 | 5 | // If CSP requires SRI (require-sri-for), then store that information |
233 | 5 | // in the loadInfo so we can enforce SRI before loading the subresource. |
234 | 5 | if (!mEnforceSRI) { |
235 | 5 | // do not look into the CSP if already true: |
236 | 5 | // a CSP saying that SRI isn't needed should not |
237 | 5 | // overrule GetVerifySignedContent |
238 | 5 | if (aLoadingPrincipal) { |
239 | 5 | nsCOMPtr<nsIContentSecurityPolicy> csp; |
240 | 5 | aLoadingPrincipal->GetCsp(getter_AddRefs(csp)); |
241 | 5 | uint32_t externalType = |
242 | 5 | nsContentUtils::InternalContentPolicyTypeToExternal(aContentPolicyType); |
243 | 5 | // csp could be null if loading principal is system principal |
244 | 5 | if (csp) { |
245 | 0 | csp->RequireSRIForType(externalType, &mEnforceSRI); |
246 | 0 | } |
247 | 5 | // if CSP is delivered via a meta tag, it's speculatively available |
248 | 5 | // as 'preloadCSP'. If we are preloading a script or style, we have |
249 | 5 | // to apply that speculative 'preloadCSP' for such loads. |
250 | 5 | if (!mEnforceSRI && nsContentUtils::IsPreloadType(aContentPolicyType)) { |
251 | 0 | nsCOMPtr<nsIContentSecurityPolicy> preloadCSP; |
252 | 0 | aLoadingPrincipal->GetPreloadCsp(getter_AddRefs(preloadCSP)); |
253 | 0 | if (preloadCSP) { |
254 | 0 | preloadCSP->RequireSRIForType(externalType, &mEnforceSRI); |
255 | 0 | } |
256 | 0 | } |
257 | 5 | } |
258 | 5 | } |
259 | 5 | |
260 | 5 | mOriginAttributes = mLoadingPrincipal->OriginAttributesRef(); |
261 | 5 | |
262 | 5 | // We need to do this after inheriting the document's origin attributes |
263 | 5 | // above, in case the loading principal ends up being the system principal. |
264 | 5 | if (aLoadingContext) { |
265 | 0 | nsCOMPtr<nsILoadContext> loadContext = |
266 | 0 | aLoadingContext->OwnerDoc()->GetLoadContext(); |
267 | 0 | nsCOMPtr<nsIDocShell> docShell = aLoadingContext->OwnerDoc()->GetDocShell(); |
268 | 0 | if (loadContext && docShell && |
269 | 0 | docShell->ItemType() == nsIDocShellTreeItem::typeContent) { |
270 | 0 | bool usePrivateBrowsing; |
271 | 0 | nsresult rv = loadContext->GetUsePrivateBrowsing(&usePrivateBrowsing); |
272 | 0 | if (NS_SUCCEEDED(rv)) { |
273 | 0 | mOriginAttributes.SyncAttributesWithPrivateBrowsing(usePrivateBrowsing); |
274 | 0 | } |
275 | 0 | } |
276 | 0 | } |
277 | 5 | |
278 | 5 | // For chrome docshell, the mPrivateBrowsingId remains 0 even its |
279 | 5 | // UsePrivateBrowsing() is true, so we only update the mPrivateBrowsingId in |
280 | 5 | // origin attributes if the type of the docshell is content. |
281 | 5 | if (aLoadingContext) { |
282 | 0 | nsCOMPtr<nsIDocShell> docShell = aLoadingContext->OwnerDoc()->GetDocShell(); |
283 | 0 | if (docShell) { |
284 | 0 | if (docShell->ItemType() == nsIDocShellTreeItem::typeChrome) { |
285 | 0 | MOZ_ASSERT(mOriginAttributes.mPrivateBrowsingId == 0, |
286 | 0 | "chrome docshell shouldn't have mPrivateBrowsingId set."); |
287 | 0 | } |
288 | 0 | } |
289 | 0 | } |
290 | 5 | } |
291 | | |
292 | | /* Constructor takes an outer window, but no loadingNode or loadingPrincipal. |
293 | | * This constructor should only be used for TYPE_DOCUMENT loads, since they |
294 | | * have a null loadingNode and loadingPrincipal. |
295 | | */ |
296 | | LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow, |
297 | | nsIPrincipal* aTriggeringPrincipal, |
298 | | nsISupports* aContextForTopLevelLoad, |
299 | | nsSecurityFlags aSecurityFlags) |
300 | | : mLoadingPrincipal(nullptr) |
301 | | , mTriggeringPrincipal(aTriggeringPrincipal) |
302 | | , mPrincipalToInherit(nullptr) |
303 | | , mContextForTopLevelLoad(do_GetWeakReference(aContextForTopLevelLoad)) |
304 | | , mSecurityFlags(aSecurityFlags) |
305 | | , mInternalContentPolicyType(nsIContentPolicy::TYPE_DOCUMENT) |
306 | | , mTainting(LoadTainting::Basic) |
307 | | , mUpgradeInsecureRequests(false) |
308 | | , mBrowserUpgradeInsecureRequests(false) |
309 | | , mBrowserWouldUpgradeInsecureRequests(false) |
310 | | , mVerifySignedContent(false) |
311 | | , mEnforceSRI(false) |
312 | | , mForceAllowDataURI(false) |
313 | | , mAllowInsecureRedirectToDataURI(false) |
314 | | , mSkipContentPolicyCheckForWebRequest(false) |
315 | | , mOriginalFrameSrcLoad(false) |
316 | | , mForceInheritPrincipalDropped(false) |
317 | | , mInnerWindowID(0) |
318 | | , mOuterWindowID(0) |
319 | | , mParentOuterWindowID(0) |
320 | | , mTopOuterWindowID(0) |
321 | | , mFrameOuterWindowID(0) |
322 | | , mEnforceSecurity(false) |
323 | | , mInitialSecurityCheckDone(false) |
324 | | , mIsThirdPartyContext(false) // NB: TYPE_DOCUMENT implies not third-party. |
325 | | , mIsDocshellReload(false) |
326 | | , mSendCSPViolationEvents(true) |
327 | | , mTrackerBlockedReason(mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED::all) |
328 | | , mForcePreflight(false) |
329 | | , mIsPreflight(false) |
330 | | , mLoadTriggeredFromExternal(false) |
331 | | , mServiceWorkerTaintingSynthesized(false) |
332 | | , mIsTracker(false) |
333 | | , mIsTrackerBlocked(false) |
334 | | , mDocumentHasUserInteracted(false) |
335 | 0 | { |
336 | 0 | // Top-level loads are never third-party |
337 | 0 | // Grab the information we can out of the window. |
338 | 0 | MOZ_ASSERT(aOuterWindow); |
339 | 0 | MOZ_ASSERT(mTriggeringPrincipal); |
340 | 0 |
|
341 | 0 | // if the load is sandboxed, we can not also inherit the principal |
342 | 0 | if (mSecurityFlags & nsILoadInfo::SEC_SANDBOXED) { |
343 | 0 | mForceInheritPrincipalDropped = |
344 | 0 | (mSecurityFlags & nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL); |
345 | 0 | mSecurityFlags &= ~nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL; |
346 | 0 | } |
347 | 0 |
|
348 | 0 | // NB: Ignore the current inner window since we're navigating away from it. |
349 | 0 | mOuterWindowID = aOuterWindow->WindowID(); |
350 | 0 |
|
351 | 0 | // TODO We can have a parent without a frame element in some cases dealing |
352 | 0 | // with the hidden window. |
353 | 0 | nsCOMPtr<nsPIDOMWindowOuter> parent = aOuterWindow->GetScriptableParent(); |
354 | 0 | mParentOuterWindowID = parent ? parent->WindowID() : 0; |
355 | 0 | mTopOuterWindowID = FindTopOuterWindowID(aOuterWindow); |
356 | 0 |
|
357 | 0 | nsGlobalWindowInner* innerWindow = |
358 | 0 | nsGlobalWindowInner::Cast(aOuterWindow->GetCurrentInnerWindow()); |
359 | 0 | if (innerWindow) { |
360 | 0 | mTopLevelPrincipal = innerWindow->GetTopLevelPrincipal(); |
361 | 0 | mTopLevelStorageAreaPrincipal = |
362 | 0 | innerWindow->GetTopLevelStorageAreaPrincipal(); |
363 | 0 | } |
364 | 0 |
|
365 | 0 | // get the docshell from the outerwindow, and then get the originattributes |
366 | 0 | nsCOMPtr<nsIDocShell> docShell = aOuterWindow->GetDocShell(); |
367 | 0 | MOZ_ASSERT(docShell); |
368 | 0 | mOriginAttributes = nsDocShell::Cast(docShell)->GetOriginAttributes(); |
369 | 0 | mAncestorPrincipals = nsDocShell::Cast(docShell)->AncestorPrincipals(); |
370 | 0 | mAncestorOuterWindowIDs = nsDocShell::Cast(docShell)->AncestorOuterWindowIDs(); |
371 | 0 | MOZ_DIAGNOSTIC_ASSERT(mAncestorPrincipals.Length() == mAncestorOuterWindowIDs.Length()); |
372 | 0 |
|
373 | | #ifdef DEBUG |
374 | | if (docShell->ItemType() == nsIDocShellTreeItem::typeChrome) { |
375 | | MOZ_ASSERT(mOriginAttributes.mPrivateBrowsingId == 0, |
376 | | "chrome docshell shouldn't have mPrivateBrowsingId set."); |
377 | | } |
378 | | #endif |
379 | | } |
380 | | |
381 | | LoadInfo::LoadInfo(const LoadInfo& rhs) |
382 | | : mLoadingPrincipal(rhs.mLoadingPrincipal) |
383 | | , mTriggeringPrincipal(rhs.mTriggeringPrincipal) |
384 | | , mPrincipalToInherit(rhs.mPrincipalToInherit) |
385 | | , mSandboxedLoadingPrincipal(rhs.mSandboxedLoadingPrincipal) |
386 | | , mTopLevelPrincipal(rhs.mTopLevelPrincipal) |
387 | | , mTopLevelStorageAreaPrincipal(rhs.mTopLevelStorageAreaPrincipal) |
388 | | , mResultPrincipalURI(rhs.mResultPrincipalURI) |
389 | | , mClientInfo(rhs.mClientInfo) |
390 | | // mReservedClientSource must be handled specially during redirect |
391 | | // mReservedClientInfo must be handled specially during redirect |
392 | | // mInitialClientInfo must be handled specially during redirect |
393 | | , mController(rhs.mController) |
394 | | , mPerformanceStorage(rhs.mPerformanceStorage) |
395 | | , mLoadingContext(rhs.mLoadingContext) |
396 | | , mContextForTopLevelLoad(rhs.mContextForTopLevelLoad) |
397 | | , mSecurityFlags(rhs.mSecurityFlags) |
398 | | , mInternalContentPolicyType(rhs.mInternalContentPolicyType) |
399 | | , mTainting(rhs.mTainting) |
400 | | , mUpgradeInsecureRequests(rhs.mUpgradeInsecureRequests) |
401 | | , mBrowserUpgradeInsecureRequests(rhs.mBrowserUpgradeInsecureRequests) |
402 | | , mBrowserWouldUpgradeInsecureRequests(rhs.mBrowserWouldUpgradeInsecureRequests) |
403 | | , mVerifySignedContent(rhs.mVerifySignedContent) |
404 | | , mEnforceSRI(rhs.mEnforceSRI) |
405 | | , mForceAllowDataURI(rhs.mForceAllowDataURI) |
406 | | , mAllowInsecureRedirectToDataURI(rhs.mAllowInsecureRedirectToDataURI) |
407 | | , mSkipContentPolicyCheckForWebRequest(rhs.mSkipContentPolicyCheckForWebRequest) |
408 | | , mOriginalFrameSrcLoad(rhs.mOriginalFrameSrcLoad) |
409 | | , mForceInheritPrincipalDropped(rhs.mForceInheritPrincipalDropped) |
410 | | , mInnerWindowID(rhs.mInnerWindowID) |
411 | | , mOuterWindowID(rhs.mOuterWindowID) |
412 | | , mParentOuterWindowID(rhs.mParentOuterWindowID) |
413 | | , mTopOuterWindowID(rhs.mTopOuterWindowID) |
414 | | , mFrameOuterWindowID(rhs.mFrameOuterWindowID) |
415 | | , mEnforceSecurity(rhs.mEnforceSecurity) |
416 | | , mInitialSecurityCheckDone(rhs.mInitialSecurityCheckDone) |
417 | | , mIsThirdPartyContext(rhs.mIsThirdPartyContext) |
418 | | , mIsDocshellReload(rhs.mIsDocshellReload) |
419 | | , mSendCSPViolationEvents(rhs.mSendCSPViolationEvents) |
420 | | , mOriginAttributes(rhs.mOriginAttributes) |
421 | | , mRedirectChainIncludingInternalRedirects( |
422 | | rhs.mRedirectChainIncludingInternalRedirects) |
423 | | , mRedirectChain(rhs.mRedirectChain) |
424 | | , mAncestorPrincipals(rhs.mAncestorPrincipals) |
425 | | , mAncestorOuterWindowIDs(rhs.mAncestorOuterWindowIDs) |
426 | | , mCorsUnsafeHeaders(rhs.mCorsUnsafeHeaders) |
427 | | , mTrackerBlockedReason(rhs.mTrackerBlockedReason) |
428 | | , mForcePreflight(rhs.mForcePreflight) |
429 | | , mIsPreflight(rhs.mIsPreflight) |
430 | | , mLoadTriggeredFromExternal(rhs.mLoadTriggeredFromExternal) |
431 | | // mServiceWorkerTaintingSynthesized must be handled specially during redirect |
432 | | , mServiceWorkerTaintingSynthesized(false) |
433 | | , mIsTracker(rhs.mIsTracker) |
434 | | , mIsTrackerBlocked(rhs.mIsTrackerBlocked) |
435 | | , mDocumentHasUserInteracted(rhs.mDocumentHasUserInteracted) |
436 | 0 | { |
437 | 0 | } |
438 | | |
439 | | LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, |
440 | | nsIPrincipal* aTriggeringPrincipal, |
441 | | nsIPrincipal* aPrincipalToInherit, |
442 | | nsIPrincipal* aSandboxedLoadingPrincipal, |
443 | | nsIPrincipal* aTopLevelPrincipal, |
444 | | nsIPrincipal* aTopLevelStorageAreaPrincipal, |
445 | | nsIURI* aResultPrincipalURI, |
446 | | const Maybe<ClientInfo>& aClientInfo, |
447 | | const Maybe<ClientInfo>& aReservedClientInfo, |
448 | | const Maybe<ClientInfo>& aInitialClientInfo, |
449 | | const Maybe<ServiceWorkerDescriptor>& aController, |
450 | | nsSecurityFlags aSecurityFlags, |
451 | | nsContentPolicyType aContentPolicyType, |
452 | | LoadTainting aTainting, |
453 | | bool aUpgradeInsecureRequests, |
454 | | bool aBrowserUpgradeInsecureRequests, |
455 | | bool aBrowserWouldUpgradeInsecureRequests, |
456 | | bool aVerifySignedContent, |
457 | | bool aEnforceSRI, |
458 | | bool aForceAllowDataURI, |
459 | | bool aAllowInsecureRedirectToDataURI, |
460 | | bool aSkipContentPolicyCheckForWebRequest, |
461 | | bool aForceInheritPrincipalDropped, |
462 | | uint64_t aInnerWindowID, |
463 | | uint64_t aOuterWindowID, |
464 | | uint64_t aParentOuterWindowID, |
465 | | uint64_t aTopOuterWindowID, |
466 | | uint64_t aFrameOuterWindowID, |
467 | | bool aEnforceSecurity, |
468 | | bool aInitialSecurityCheckDone, |
469 | | bool aIsThirdPartyContext, |
470 | | bool aIsDocshellReload, |
471 | | bool aSendCSPViolationEvents, |
472 | | const OriginAttributes& aOriginAttributes, |
473 | | RedirectHistoryArray& aRedirectChainIncludingInternalRedirects, |
474 | | RedirectHistoryArray& aRedirectChain, |
475 | | nsTArray<nsCOMPtr<nsIPrincipal>>&& aAncestorPrincipals, |
476 | | const nsTArray<uint64_t>& aAncestorOuterWindowIDs, |
477 | | const nsTArray<nsCString>& aCorsUnsafeHeaders, |
478 | | bool aForcePreflight, |
479 | | bool aIsPreflight, |
480 | | bool aLoadTriggeredFromExternal, |
481 | | bool aServiceWorkerTaintingSynthesized, |
482 | | bool aDocumentHasUserInteracted) |
483 | | : mLoadingPrincipal(aLoadingPrincipal) |
484 | | , mTriggeringPrincipal(aTriggeringPrincipal) |
485 | | , mPrincipalToInherit(aPrincipalToInherit) |
486 | | , mTopLevelPrincipal(aTopLevelPrincipal) |
487 | | , mTopLevelStorageAreaPrincipal(aTopLevelStorageAreaPrincipal) |
488 | | , mResultPrincipalURI(aResultPrincipalURI) |
489 | | , mClientInfo(aClientInfo) |
490 | | , mReservedClientInfo(aReservedClientInfo) |
491 | | , mInitialClientInfo(aInitialClientInfo) |
492 | | , mController(aController) |
493 | | , mSecurityFlags(aSecurityFlags) |
494 | | , mInternalContentPolicyType(aContentPolicyType) |
495 | | , mTainting(aTainting) |
496 | | , mUpgradeInsecureRequests(aUpgradeInsecureRequests) |
497 | | , mBrowserUpgradeInsecureRequests(aBrowserUpgradeInsecureRequests) |
498 | | , mBrowserWouldUpgradeInsecureRequests(aBrowserWouldUpgradeInsecureRequests) |
499 | | , mVerifySignedContent(aVerifySignedContent) |
500 | | , mEnforceSRI(aEnforceSRI) |
501 | | , mForceAllowDataURI(aForceAllowDataURI) |
502 | | , mAllowInsecureRedirectToDataURI(aAllowInsecureRedirectToDataURI) |
503 | | , mSkipContentPolicyCheckForWebRequest(aSkipContentPolicyCheckForWebRequest) |
504 | | , mOriginalFrameSrcLoad(false) |
505 | | , mForceInheritPrincipalDropped(aForceInheritPrincipalDropped) |
506 | | , mInnerWindowID(aInnerWindowID) |
507 | | , mOuterWindowID(aOuterWindowID) |
508 | | , mParentOuterWindowID(aParentOuterWindowID) |
509 | | , mTopOuterWindowID(aTopOuterWindowID) |
510 | | , mFrameOuterWindowID(aFrameOuterWindowID) |
511 | | , mEnforceSecurity(aEnforceSecurity) |
512 | | , mInitialSecurityCheckDone(aInitialSecurityCheckDone) |
513 | | , mIsThirdPartyContext(aIsThirdPartyContext) |
514 | | , mIsDocshellReload(aIsDocshellReload) |
515 | | , mSendCSPViolationEvents(aSendCSPViolationEvents) |
516 | | , mOriginAttributes(aOriginAttributes) |
517 | | , mAncestorPrincipals(std::move(aAncestorPrincipals)) |
518 | | , mAncestorOuterWindowIDs(aAncestorOuterWindowIDs) |
519 | | , mCorsUnsafeHeaders(aCorsUnsafeHeaders) |
520 | | , mTrackerBlockedReason(mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED::all) |
521 | | , mForcePreflight(aForcePreflight) |
522 | | , mIsPreflight(aIsPreflight) |
523 | | , mLoadTriggeredFromExternal(aLoadTriggeredFromExternal) |
524 | | , mServiceWorkerTaintingSynthesized(aServiceWorkerTaintingSynthesized) |
525 | | , mIsTracker(false) |
526 | | , mIsTrackerBlocked(false) |
527 | | , mDocumentHasUserInteracted(aDocumentHasUserInteracted) |
528 | 0 | { |
529 | 0 | // Only top level TYPE_DOCUMENT loads can have a null loadingPrincipal |
530 | 0 | MOZ_ASSERT(mLoadingPrincipal || aContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT); |
531 | 0 | MOZ_ASSERT(mTriggeringPrincipal); |
532 | 0 |
|
533 | 0 | mRedirectChainIncludingInternalRedirects.SwapElements( |
534 | 0 | aRedirectChainIncludingInternalRedirects); |
535 | 0 |
|
536 | 0 | mRedirectChain.SwapElements(aRedirectChain); |
537 | 0 | } |
538 | | |
539 | | void |
540 | | LoadInfo::ComputeIsThirdPartyContext(nsPIDOMWindowOuter* aOuterWindow) |
541 | 0 | { |
542 | 0 | nsContentPolicyType type = |
543 | 0 | nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType); |
544 | 0 | if (type == nsIContentPolicy::TYPE_DOCUMENT) { |
545 | 0 | // Top-level loads are never third-party. |
546 | 0 | mIsThirdPartyContext = false; |
547 | 0 | return; |
548 | 0 | } |
549 | 0 | |
550 | 0 | nsCOMPtr<mozIThirdPartyUtil> util(do_GetService(THIRDPARTYUTIL_CONTRACTID)); |
551 | 0 | if (NS_WARN_IF(!util)) { |
552 | 0 | return; |
553 | 0 | } |
554 | 0 | |
555 | 0 | util->IsThirdPartyWindow(aOuterWindow, nullptr, &mIsThirdPartyContext); |
556 | 0 | } |
557 | | |
558 | | NS_IMPL_ISUPPORTS(LoadInfo, nsILoadInfo) |
559 | | |
560 | | already_AddRefed<nsILoadInfo> |
561 | | LoadInfo::Clone() const |
562 | 0 | { |
563 | 0 | RefPtr<LoadInfo> copy(new LoadInfo(*this)); |
564 | 0 | return copy.forget(); |
565 | 0 | } |
566 | | |
567 | | already_AddRefed<nsILoadInfo> |
568 | | LoadInfo::CloneWithNewSecFlags(nsSecurityFlags aSecurityFlags) const |
569 | 0 | { |
570 | 0 | RefPtr<LoadInfo> copy(new LoadInfo(*this)); |
571 | 0 | copy->mSecurityFlags = aSecurityFlags; |
572 | 0 | return copy.forget(); |
573 | 0 | } |
574 | | |
575 | | already_AddRefed<nsILoadInfo> |
576 | | LoadInfo::CloneForNewRequest() const |
577 | 0 | { |
578 | 0 | RefPtr<LoadInfo> copy(new LoadInfo(*this)); |
579 | 0 | copy->mEnforceSecurity = false; |
580 | 0 | copy->mInitialSecurityCheckDone = false; |
581 | 0 | copy->mRedirectChainIncludingInternalRedirects.Clear(); |
582 | 0 | copy->mRedirectChain.Clear(); |
583 | 0 | copy->mResultPrincipalURI = nullptr; |
584 | 0 | return copy.forget(); |
585 | 0 | } |
586 | | |
587 | | NS_IMETHODIMP |
588 | | LoadInfo::GetLoadingPrincipal(nsIPrincipal** aLoadingPrincipal) |
589 | 0 | { |
590 | 0 | NS_IF_ADDREF(*aLoadingPrincipal = mLoadingPrincipal); |
591 | 0 | return NS_OK; |
592 | 0 | } |
593 | | |
594 | | nsIPrincipal* |
595 | | LoadInfo::LoadingPrincipal() |
596 | 5 | { |
597 | 5 | return mLoadingPrincipal; |
598 | 5 | } |
599 | | |
600 | | NS_IMETHODIMP |
601 | | LoadInfo::GetTriggeringPrincipal(nsIPrincipal** aTriggeringPrincipal) |
602 | 0 | { |
603 | 0 | NS_ADDREF(*aTriggeringPrincipal = mTriggeringPrincipal); |
604 | 0 | return NS_OK; |
605 | 0 | } |
606 | | |
607 | | nsIPrincipal* |
608 | | LoadInfo::TriggeringPrincipal() |
609 | 10 | { |
610 | 10 | return mTriggeringPrincipal; |
611 | 10 | } |
612 | | |
613 | | NS_IMETHODIMP |
614 | | LoadInfo::GetPrincipalToInherit(nsIPrincipal** aPrincipalToInherit) |
615 | 0 | { |
616 | 0 | NS_IF_ADDREF(*aPrincipalToInherit = mPrincipalToInherit); |
617 | 0 | return NS_OK; |
618 | 0 | } |
619 | | |
620 | | NS_IMETHODIMP |
621 | | LoadInfo::SetPrincipalToInherit(nsIPrincipal* aPrincipalToInherit) |
622 | 0 | { |
623 | 0 | MOZ_ASSERT(aPrincipalToInherit, "must be a valid principal to inherit"); |
624 | 0 | mPrincipalToInherit = aPrincipalToInherit; |
625 | 0 | return NS_OK; |
626 | 0 | } |
627 | | |
628 | | nsIPrincipal* |
629 | | LoadInfo::PrincipalToInherit() |
630 | 0 | { |
631 | 0 | return mPrincipalToInherit; |
632 | 0 | } |
633 | | |
634 | | nsIPrincipal* |
635 | | LoadInfo::FindPrincipalToInherit(nsIChannel* aChannel) |
636 | 0 | { |
637 | 0 | if (mPrincipalToInherit) { |
638 | 0 | return mPrincipalToInherit; |
639 | 0 | } |
640 | 0 | |
641 | 0 | nsCOMPtr<nsIURI> uri = mResultPrincipalURI; |
642 | 0 | if (!uri) { |
643 | 0 | Unused << aChannel->GetOriginalURI(getter_AddRefs(uri)); |
644 | 0 | } |
645 | 0 |
|
646 | 0 | auto prin = BasePrincipal::Cast(mTriggeringPrincipal); |
647 | 0 | return prin->PrincipalToInherit(uri); |
648 | 0 | } |
649 | | |
650 | | NS_IMETHODIMP |
651 | | LoadInfo::GetSandboxedLoadingPrincipal(nsIPrincipal** aPrincipal) |
652 | 0 | { |
653 | 0 | if (!(mSecurityFlags & nsILoadInfo::SEC_SANDBOXED)) { |
654 | 0 | *aPrincipal = nullptr; |
655 | 0 | return NS_OK; |
656 | 0 | } |
657 | 0 | |
658 | 0 | if (!mSandboxedLoadingPrincipal) { |
659 | 0 | if (mLoadingPrincipal) { |
660 | 0 | mSandboxedLoadingPrincipal = |
661 | 0 | NullPrincipal::CreateWithInheritedAttributes(mLoadingPrincipal); |
662 | 0 | } else { |
663 | 0 | OriginAttributes attrs(mOriginAttributes); |
664 | 0 | mSandboxedLoadingPrincipal = NullPrincipal::Create(attrs); |
665 | 0 | } |
666 | 0 | } |
667 | 0 | MOZ_ASSERT(mSandboxedLoadingPrincipal); |
668 | 0 |
|
669 | 0 | nsCOMPtr<nsIPrincipal> copy(mSandboxedLoadingPrincipal); |
670 | 0 | copy.forget(aPrincipal); |
671 | 0 | return NS_OK; |
672 | 0 | } |
673 | | |
674 | | NS_IMETHODIMP |
675 | | LoadInfo::GetTopLevelPrincipal(nsIPrincipal** aTopLevelPrincipal) |
676 | 0 | { |
677 | 0 | NS_IF_ADDREF(*aTopLevelPrincipal = mTopLevelPrincipal); |
678 | 0 | return NS_OK; |
679 | 0 | } |
680 | | |
681 | | nsIPrincipal* |
682 | | LoadInfo::TopLevelPrincipal() |
683 | 0 | { |
684 | 0 | return mTopLevelPrincipal; |
685 | 0 | } |
686 | | |
687 | | NS_IMETHODIMP |
688 | | LoadInfo::GetTopLevelStorageAreaPrincipal(nsIPrincipal** aTopLevelStorageAreaPrincipal) |
689 | 0 | { |
690 | 0 | NS_IF_ADDREF(*aTopLevelStorageAreaPrincipal = mTopLevelStorageAreaPrincipal); |
691 | 0 | return NS_OK; |
692 | 0 | } |
693 | | |
694 | | nsIPrincipal* |
695 | | LoadInfo::TopLevelStorageAreaPrincipal() |
696 | 0 | { |
697 | 0 | return mTopLevelStorageAreaPrincipal; |
698 | 0 | } |
699 | | |
700 | | NS_IMETHODIMP |
701 | | LoadInfo::GetLoadingDocument(nsIDocument** aResult) |
702 | 0 | { |
703 | 0 | nsCOMPtr<nsINode> node = do_QueryReferent(mLoadingContext); |
704 | 0 | if (node) { |
705 | 0 | nsCOMPtr<nsIDocument> context = node->OwnerDoc(); |
706 | 0 | context.forget(aResult); |
707 | 0 | } |
708 | 0 | return NS_OK; |
709 | 0 | } |
710 | | |
711 | | nsINode* |
712 | | LoadInfo::LoadingNode() |
713 | 5 | { |
714 | 5 | nsCOMPtr<nsINode> node = do_QueryReferent(mLoadingContext); |
715 | 5 | return node; |
716 | 5 | } |
717 | | |
718 | | already_AddRefed<nsISupports> |
719 | | LoadInfo::ContextForTopLevelLoad() |
720 | 0 | { |
721 | 0 | // Most likely you want to query LoadingNode() instead of |
722 | 0 | // ContextForTopLevelLoad() if this assertion fires. |
723 | 0 | MOZ_ASSERT(mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT, |
724 | 0 | "should only query this context for top level document loads"); |
725 | 0 | nsCOMPtr<nsISupports> context = do_QueryReferent(mContextForTopLevelLoad); |
726 | 0 | return context.forget(); |
727 | 0 | } |
728 | | |
729 | | already_AddRefed<nsISupports> |
730 | | LoadInfo::GetLoadingContext() |
731 | 5 | { |
732 | 5 | nsCOMPtr<nsISupports> context; |
733 | 5 | if (mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT) { |
734 | 0 | context = ContextForTopLevelLoad(); |
735 | 0 | } |
736 | 5 | else { |
737 | 5 | context = LoadingNode(); |
738 | 5 | } |
739 | 5 | return context.forget(); |
740 | 5 | } |
741 | | |
742 | | NS_IMETHODIMP |
743 | | LoadInfo::GetLoadingContextXPCOM(nsISupports** aResult) |
744 | 0 | { |
745 | 0 | nsCOMPtr<nsISupports> context = GetLoadingContext(); |
746 | 0 | context.forget(aResult); |
747 | 0 | return NS_OK; |
748 | 0 | } |
749 | | |
750 | | NS_IMETHODIMP |
751 | | LoadInfo::GetSecurityFlags(nsSecurityFlags* aResult) |
752 | 0 | { |
753 | 0 | *aResult = mSecurityFlags; |
754 | 0 | return NS_OK; |
755 | 0 | } |
756 | | |
757 | | NS_IMETHODIMP |
758 | | LoadInfo::GetSecurityMode(uint32_t* aFlags) |
759 | 20 | { |
760 | 20 | *aFlags = (mSecurityFlags & |
761 | 20 | (nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_INHERITS | |
762 | 20 | nsILoadInfo::SEC_REQUIRE_SAME_ORIGIN_DATA_IS_BLOCKED | |
763 | 20 | nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_INHERITS | |
764 | 20 | nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL | |
765 | 20 | nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS)); |
766 | 20 | return NS_OK; |
767 | 20 | } |
768 | | |
769 | | NS_IMETHODIMP |
770 | | LoadInfo::GetIsInThirdPartyContext(bool* aIsInThirdPartyContext) |
771 | 0 | { |
772 | 0 | *aIsInThirdPartyContext = mIsThirdPartyContext; |
773 | 0 | return NS_OK; |
774 | 0 | } |
775 | | |
776 | | static const uint32_t sCookiePolicyMask = |
777 | | nsILoadInfo::SEC_COOKIES_DEFAULT | |
778 | | nsILoadInfo::SEC_COOKIES_INCLUDE | |
779 | | nsILoadInfo::SEC_COOKIES_SAME_ORIGIN | |
780 | | nsILoadInfo::SEC_COOKIES_OMIT; |
781 | | |
782 | | NS_IMETHODIMP |
783 | | LoadInfo::GetCookiePolicy(uint32_t *aResult) |
784 | 5 | { |
785 | 5 | uint32_t policy = mSecurityFlags & sCookiePolicyMask; |
786 | 5 | if (policy == nsILoadInfo::SEC_COOKIES_DEFAULT) { |
787 | 5 | policy = (mSecurityFlags & SEC_REQUIRE_CORS_DATA_INHERITS) ? |
788 | 5 | nsILoadInfo::SEC_COOKIES_SAME_ORIGIN : nsILoadInfo::SEC_COOKIES_INCLUDE; |
789 | 5 | } |
790 | 5 | |
791 | 5 | *aResult = policy; |
792 | 5 | return NS_OK; |
793 | 5 | } |
794 | | |
795 | | void |
796 | | LoadInfo::SetIncludeCookiesSecFlag() |
797 | 0 | { |
798 | 0 | MOZ_ASSERT(!mEnforceSecurity, |
799 | 0 | "Request should not have been opened yet"); |
800 | 0 | MOZ_ASSERT((mSecurityFlags & sCookiePolicyMask) == |
801 | 0 | nsILoadInfo::SEC_COOKIES_DEFAULT); |
802 | 0 | mSecurityFlags = (mSecurityFlags & ~sCookiePolicyMask) | |
803 | 0 | nsILoadInfo::SEC_COOKIES_INCLUDE; |
804 | 0 | } |
805 | | |
806 | | NS_IMETHODIMP |
807 | | LoadInfo::GetForceInheritPrincipal(bool* aInheritPrincipal) |
808 | 0 | { |
809 | 0 | *aInheritPrincipal = |
810 | 0 | (mSecurityFlags & nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL); |
811 | 0 | return NS_OK; |
812 | 0 | } |
813 | | |
814 | | NS_IMETHODIMP |
815 | | LoadInfo::GetForceInheritPrincipalOverruleOwner(bool* aInheritPrincipal) |
816 | 0 | { |
817 | 0 | *aInheritPrincipal = |
818 | 0 | (mSecurityFlags & nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL_OVERRULE_OWNER); |
819 | 0 | return NS_OK; |
820 | 0 | } |
821 | | |
822 | | NS_IMETHODIMP |
823 | | LoadInfo::GetLoadingSandboxed(bool* aLoadingSandboxed) |
824 | 9 | { |
825 | 9 | *aLoadingSandboxed = (mSecurityFlags & nsILoadInfo::SEC_SANDBOXED); |
826 | 9 | return NS_OK; |
827 | 9 | } |
828 | | |
829 | | NS_IMETHODIMP |
830 | | LoadInfo::GetAboutBlankInherits(bool* aResult) |
831 | 0 | { |
832 | 0 | *aResult = |
833 | 0 | (mSecurityFlags & nsILoadInfo::SEC_ABOUT_BLANK_INHERITS); |
834 | 0 | return NS_OK; |
835 | 0 | } |
836 | | |
837 | | NS_IMETHODIMP |
838 | | LoadInfo::GetAllowChrome(bool* aResult) |
839 | 0 | { |
840 | 0 | *aResult = |
841 | 0 | (mSecurityFlags & nsILoadInfo::SEC_ALLOW_CHROME); |
842 | 0 | return NS_OK; |
843 | 0 | } |
844 | | |
845 | | NS_IMETHODIMP |
846 | | LoadInfo::GetDisallowScript(bool* aResult) |
847 | 0 | { |
848 | 0 | *aResult = |
849 | 0 | (mSecurityFlags & nsILoadInfo::SEC_DISALLOW_SCRIPT); |
850 | 0 | return NS_OK; |
851 | 0 | } |
852 | | |
853 | | |
854 | | NS_IMETHODIMP |
855 | | LoadInfo::GetDontFollowRedirects(bool* aResult) |
856 | 0 | { |
857 | 0 | *aResult = |
858 | 0 | (mSecurityFlags & nsILoadInfo::SEC_DONT_FOLLOW_REDIRECTS); |
859 | 0 | return NS_OK; |
860 | 0 | } |
861 | | |
862 | | NS_IMETHODIMP |
863 | | LoadInfo::GetLoadErrorPage(bool* aResult) |
864 | 0 | { |
865 | 0 | *aResult = |
866 | 0 | (mSecurityFlags & nsILoadInfo::SEC_LOAD_ERROR_PAGE); |
867 | 0 | return NS_OK; |
868 | 0 | } |
869 | | |
870 | | NS_IMETHODIMP |
871 | | LoadInfo::GetIsDocshellReload(bool* aResult) |
872 | 0 | { |
873 | 0 | *aResult = mIsDocshellReload; |
874 | 0 | return NS_OK; |
875 | 0 | } |
876 | | |
877 | | NS_IMETHODIMP |
878 | | LoadInfo::SetIsDocshellReload(bool aValue) |
879 | 0 | { |
880 | 0 | mIsDocshellReload = aValue; |
881 | 0 | return NS_OK; |
882 | 0 | } |
883 | | |
884 | | NS_IMETHODIMP |
885 | | LoadInfo::GetSendCSPViolationEvents(bool* aResult) |
886 | 0 | { |
887 | 0 | *aResult = mSendCSPViolationEvents; |
888 | 0 | return NS_OK; |
889 | 0 | } |
890 | | |
891 | | NS_IMETHODIMP |
892 | | LoadInfo::SetSendCSPViolationEvents(bool aValue) |
893 | 0 | { |
894 | 0 | mSendCSPViolationEvents = aValue; |
895 | 0 | return NS_OK; |
896 | 0 | } |
897 | | |
898 | | NS_IMETHODIMP |
899 | | LoadInfo::GetExternalContentPolicyType(nsContentPolicyType* aResult) |
900 | 25 | { |
901 | 25 | *aResult = nsContentUtils::InternalContentPolicyTypeToExternal(mInternalContentPolicyType); |
902 | 25 | return NS_OK; |
903 | 25 | } |
904 | | |
905 | | nsContentPolicyType |
906 | | LoadInfo::InternalContentPolicyType() |
907 | 10 | { |
908 | 10 | return mInternalContentPolicyType; |
909 | 10 | } |
910 | | |
911 | | NS_IMETHODIMP |
912 | | LoadInfo::GetUpgradeInsecureRequests(bool* aResult) |
913 | 0 | { |
914 | 0 | *aResult = mUpgradeInsecureRequests; |
915 | 0 | return NS_OK; |
916 | 0 | } |
917 | | |
918 | | NS_IMETHODIMP |
919 | | LoadInfo::GetBrowserUpgradeInsecureRequests(bool* aResult) |
920 | 0 | { |
921 | 0 | *aResult = mBrowserUpgradeInsecureRequests; |
922 | 0 | return NS_OK; |
923 | 0 | } |
924 | | |
925 | | NS_IMETHODIMP |
926 | | LoadInfo::GetBrowserWouldUpgradeInsecureRequests(bool* aResult) |
927 | 0 | { |
928 | 0 | *aResult = mBrowserWouldUpgradeInsecureRequests; |
929 | 0 | return NS_OK; |
930 | 0 | } |
931 | | |
932 | | NS_IMETHODIMP |
933 | | LoadInfo::SetVerifySignedContent(bool aVerifySignedContent) |
934 | 0 | { |
935 | 0 | MOZ_ASSERT(mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT, |
936 | 0 | "can only verify content for TYPE_DOCUMENT"); |
937 | 0 | mVerifySignedContent = aVerifySignedContent; |
938 | 0 | return NS_OK; |
939 | 0 | } |
940 | | |
941 | | NS_IMETHODIMP |
942 | | LoadInfo::GetVerifySignedContent(bool* aResult) |
943 | 0 | { |
944 | 0 | *aResult = mVerifySignedContent; |
945 | 0 | return NS_OK; |
946 | 0 | } |
947 | | |
948 | | NS_IMETHODIMP |
949 | | LoadInfo::SetEnforceSRI(bool aEnforceSRI) |
950 | 0 | { |
951 | 0 | mEnforceSRI = aEnforceSRI; |
952 | 0 | return NS_OK; |
953 | 0 | } |
954 | | |
955 | | NS_IMETHODIMP |
956 | | LoadInfo::GetEnforceSRI(bool* aResult) |
957 | 0 | { |
958 | 0 | *aResult = mEnforceSRI; |
959 | 0 | return NS_OK; |
960 | 0 | } |
961 | | |
962 | | NS_IMETHODIMP |
963 | | LoadInfo::SetForceAllowDataURI(bool aForceAllowDataURI) |
964 | 0 | { |
965 | 0 | MOZ_ASSERT(!mForceAllowDataURI || |
966 | 0 | mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT, |
967 | 0 | "can only allow data URI navigation for TYPE_DOCUMENT"); |
968 | 0 | mForceAllowDataURI = aForceAllowDataURI; |
969 | 0 | return NS_OK; |
970 | 0 | } |
971 | | |
972 | | NS_IMETHODIMP |
973 | | LoadInfo::GetForceAllowDataURI(bool* aForceAllowDataURI) |
974 | 0 | { |
975 | 0 | *aForceAllowDataURI = mForceAllowDataURI; |
976 | 0 | return NS_OK; |
977 | 0 | } |
978 | | |
979 | | NS_IMETHODIMP |
980 | | LoadInfo::SetAllowInsecureRedirectToDataURI(bool aAllowInsecureRedirectToDataURI) |
981 | 0 | { |
982 | 0 | mAllowInsecureRedirectToDataURI = aAllowInsecureRedirectToDataURI; |
983 | 0 | return NS_OK; |
984 | 0 | } |
985 | | |
986 | | NS_IMETHODIMP |
987 | | LoadInfo::GetAllowInsecureRedirectToDataURI(bool* aAllowInsecureRedirectToDataURI) |
988 | 0 | { |
989 | 0 | *aAllowInsecureRedirectToDataURI = mAllowInsecureRedirectToDataURI; |
990 | 0 | return NS_OK; |
991 | 0 | } |
992 | | |
993 | | NS_IMETHODIMP |
994 | | LoadInfo::SetSkipContentPolicyCheckForWebRequest(bool aSkip) |
995 | 0 | { |
996 | 0 | mSkipContentPolicyCheckForWebRequest = aSkip; |
997 | 0 | return NS_OK; |
998 | 0 | } |
999 | | |
1000 | | NS_IMETHODIMP |
1001 | | LoadInfo::GetSkipContentPolicyCheckForWebRequest(bool* aSkip) |
1002 | 0 | { |
1003 | 0 | *aSkip = mSkipContentPolicyCheckForWebRequest; |
1004 | 0 | return NS_OK; |
1005 | 0 | } |
1006 | | |
1007 | | NS_IMETHODIMP |
1008 | | LoadInfo::SetOriginalFrameSrcLoad(bool aOriginalFrameSrcLoad) |
1009 | 0 | { |
1010 | 0 | mOriginalFrameSrcLoad = aOriginalFrameSrcLoad; |
1011 | 0 | return NS_OK; |
1012 | 0 | } |
1013 | | |
1014 | | NS_IMETHODIMP |
1015 | | LoadInfo::GetOriginalFrameSrcLoad(bool* aOriginalFrameSrcLoad) |
1016 | 0 | { |
1017 | 0 | *aOriginalFrameSrcLoad = mOriginalFrameSrcLoad; |
1018 | 0 | return NS_OK; |
1019 | 0 | } |
1020 | | |
1021 | | NS_IMETHODIMP |
1022 | | LoadInfo::GetForceInheritPrincipalDropped(bool* aResult) |
1023 | 0 | { |
1024 | 0 | *aResult = mForceInheritPrincipalDropped; |
1025 | 0 | return NS_OK; |
1026 | 0 | } |
1027 | | |
1028 | | NS_IMETHODIMP |
1029 | | LoadInfo::GetInnerWindowID(uint64_t* aResult) |
1030 | 0 | { |
1031 | 0 | *aResult = mInnerWindowID; |
1032 | 0 | return NS_OK; |
1033 | 0 | } |
1034 | | |
1035 | | NS_IMETHODIMP |
1036 | | LoadInfo::GetOuterWindowID(uint64_t* aResult) |
1037 | 0 | { |
1038 | 0 | *aResult = mOuterWindowID; |
1039 | 0 | return NS_OK; |
1040 | 0 | } |
1041 | | |
1042 | | NS_IMETHODIMP |
1043 | | LoadInfo::GetParentOuterWindowID(uint64_t* aResult) |
1044 | 0 | { |
1045 | 0 | *aResult = mParentOuterWindowID; |
1046 | 0 | return NS_OK; |
1047 | 0 | } |
1048 | | |
1049 | | NS_IMETHODIMP |
1050 | | LoadInfo::GetTopOuterWindowID(uint64_t* aResult) |
1051 | 0 | { |
1052 | 0 | *aResult = mTopOuterWindowID; |
1053 | 0 | return NS_OK; |
1054 | 0 | } |
1055 | | |
1056 | | NS_IMETHODIMP |
1057 | | LoadInfo::GetFrameOuterWindowID(uint64_t* aResult) |
1058 | 0 | { |
1059 | 0 | *aResult = mFrameOuterWindowID; |
1060 | 0 | return NS_OK; |
1061 | 0 | } |
1062 | | |
1063 | | NS_IMETHODIMP |
1064 | | LoadInfo::GetScriptableOriginAttributes(JSContext* aCx, |
1065 | | JS::MutableHandle<JS::Value> aOriginAttributes) |
1066 | 0 | { |
1067 | 0 | if (NS_WARN_IF(!ToJSValue(aCx, mOriginAttributes, aOriginAttributes))) { |
1068 | 0 | return NS_ERROR_FAILURE; |
1069 | 0 | } |
1070 | 0 | return NS_OK; |
1071 | 0 | } |
1072 | | |
1073 | | NS_IMETHODIMP |
1074 | | LoadInfo::ResetPrincipalToInheritToNullPrincipal() |
1075 | 0 | { |
1076 | 0 | // take the originAttributes from the LoadInfo and create |
1077 | 0 | // a new NullPrincipal using those origin attributes. |
1078 | 0 | nsCOMPtr<nsIPrincipal> newNullPrincipal = |
1079 | 0 | NullPrincipal::Create(mOriginAttributes); |
1080 | 0 |
|
1081 | 0 | mPrincipalToInherit = newNullPrincipal; |
1082 | 0 |
|
1083 | 0 | // setting SEC_FORCE_INHERIT_PRINCIPAL_OVERRULE_OWNER will overrule |
1084 | 0 | // any non null owner set on the channel and will return the principal |
1085 | 0 | // form the loadinfo instead. |
1086 | 0 | mSecurityFlags |= SEC_FORCE_INHERIT_PRINCIPAL_OVERRULE_OWNER; |
1087 | 0 |
|
1088 | 0 | return NS_OK; |
1089 | 0 | } |
1090 | | |
1091 | | NS_IMETHODIMP |
1092 | | LoadInfo::SetScriptableOriginAttributes(JSContext* aCx, |
1093 | | JS::Handle<JS::Value> aOriginAttributes) |
1094 | 0 | { |
1095 | 0 | OriginAttributes attrs; |
1096 | 0 | if (!aOriginAttributes.isObject() || !attrs.Init(aCx, aOriginAttributes)) { |
1097 | 0 | return NS_ERROR_INVALID_ARG; |
1098 | 0 | } |
1099 | 0 | |
1100 | 0 | mOriginAttributes = attrs; |
1101 | 0 | return NS_OK; |
1102 | 0 | } |
1103 | | |
1104 | | nsresult |
1105 | | LoadInfo::GetOriginAttributes(mozilla::OriginAttributes* aOriginAttributes) |
1106 | 0 | { |
1107 | 0 | NS_ENSURE_ARG(aOriginAttributes); |
1108 | 0 | *aOriginAttributes = mOriginAttributes; |
1109 | 0 | return NS_OK; |
1110 | 0 | } |
1111 | | |
1112 | | nsresult |
1113 | | LoadInfo::SetOriginAttributes(const mozilla::OriginAttributes& aOriginAttributes) |
1114 | 0 | { |
1115 | 0 | mOriginAttributes = aOriginAttributes; |
1116 | 0 | return NS_OK; |
1117 | 0 | } |
1118 | | |
1119 | | NS_IMETHODIMP |
1120 | | LoadInfo::SetEnforceSecurity(bool aEnforceSecurity) |
1121 | 5 | { |
1122 | 5 | // Indicates whether the channel was openend using AsyncOpen2. Once set |
1123 | 5 | // to true, it must remain true throughout the lifetime of the channel. |
1124 | 5 | // Setting it to anything else than true will be discarded. |
1125 | 5 | MOZ_ASSERT(aEnforceSecurity, "aEnforceSecurity must be true"); |
1126 | 5 | mEnforceSecurity = mEnforceSecurity || aEnforceSecurity; |
1127 | 5 | return NS_OK; |
1128 | 5 | } |
1129 | | |
1130 | | NS_IMETHODIMP |
1131 | | LoadInfo::GetEnforceSecurity(bool* aResult) |
1132 | 0 | { |
1133 | 0 | *aResult = mEnforceSecurity; |
1134 | 0 | return NS_OK; |
1135 | 0 | } |
1136 | | |
1137 | | NS_IMETHODIMP |
1138 | | LoadInfo::SetInitialSecurityCheckDone(bool aInitialSecurityCheckDone) |
1139 | 5 | { |
1140 | 5 | // Indicates whether the channel was ever evaluated by the |
1141 | 5 | // ContentSecurityManager. Once set to true, this flag must |
1142 | 5 | // remain true throughout the lifetime of the channel. |
1143 | 5 | // Setting it to anything else than true will be discarded. |
1144 | 5 | MOZ_ASSERT(aInitialSecurityCheckDone, "aInitialSecurityCheckDone must be true"); |
1145 | 5 | mInitialSecurityCheckDone = mInitialSecurityCheckDone || aInitialSecurityCheckDone; |
1146 | 5 | return NS_OK; |
1147 | 5 | } |
1148 | | |
1149 | | NS_IMETHODIMP |
1150 | | LoadInfo::GetInitialSecurityCheckDone(bool* aResult) |
1151 | 5 | { |
1152 | 5 | *aResult = mInitialSecurityCheckDone; |
1153 | 5 | return NS_OK; |
1154 | 5 | } |
1155 | | |
1156 | | NS_IMETHODIMP |
1157 | | LoadInfo::AppendRedirectHistoryEntry(nsIRedirectHistoryEntry* aEntry, |
1158 | | bool aIsInternalRedirect) |
1159 | 0 | { |
1160 | 0 | NS_ENSURE_ARG(aEntry); |
1161 | 0 | MOZ_ASSERT(NS_IsMainThread()); |
1162 | 0 |
|
1163 | 0 | mRedirectChainIncludingInternalRedirects.AppendElement(aEntry); |
1164 | 0 | if (!aIsInternalRedirect) { |
1165 | 0 | mRedirectChain.AppendElement(aEntry); |
1166 | 0 | } |
1167 | 0 | return NS_OK; |
1168 | 0 | } |
1169 | | |
1170 | | NS_IMETHODIMP |
1171 | | LoadInfo::GetRedirects(JSContext* aCx, JS::MutableHandle<JS::Value> aRedirects, |
1172 | | const RedirectHistoryArray& aArray) |
1173 | 0 | { |
1174 | 0 | JS::Rooted<JSObject*> redirects(aCx, JS_NewArrayObject(aCx, aArray.Length())); |
1175 | 0 | NS_ENSURE_TRUE(redirects, NS_ERROR_OUT_OF_MEMORY); |
1176 | 0 |
|
1177 | 0 | JS::Rooted<JSObject*> global(aCx, JS::CurrentGlobalOrNull(aCx)); |
1178 | 0 | NS_ENSURE_TRUE(global, NS_ERROR_UNEXPECTED); |
1179 | 0 |
|
1180 | 0 | nsCOMPtr<nsIXPConnect> xpc = nsIXPConnect::XPConnect(); |
1181 | 0 |
|
1182 | 0 | for (size_t idx = 0; idx < aArray.Length(); idx++) { |
1183 | 0 | JS::RootedObject jsobj(aCx); |
1184 | 0 | nsresult rv = xpc->WrapNative(aCx, global, aArray[idx], |
1185 | 0 | NS_GET_IID(nsIRedirectHistoryEntry), |
1186 | 0 | jsobj.address()); |
1187 | 0 | NS_ENSURE_SUCCESS(rv, rv); |
1188 | 0 | NS_ENSURE_STATE(jsobj); |
1189 | 0 |
|
1190 | 0 | bool rc = JS_DefineElement(aCx, redirects, idx, jsobj, JSPROP_ENUMERATE); |
1191 | 0 | NS_ENSURE_TRUE(rc, NS_ERROR_UNEXPECTED); |
1192 | 0 | } |
1193 | 0 |
|
1194 | 0 | aRedirects.setObject(*redirects); |
1195 | 0 | return NS_OK; |
1196 | 0 | } |
1197 | | |
1198 | | NS_IMETHODIMP |
1199 | | LoadInfo::GetRedirectChainIncludingInternalRedirects(JSContext* aCx, JS::MutableHandle<JS::Value> aChain) |
1200 | 0 | { |
1201 | 0 | return GetRedirects(aCx, aChain, mRedirectChainIncludingInternalRedirects); |
1202 | 0 | } |
1203 | | |
1204 | | const RedirectHistoryArray& |
1205 | | LoadInfo::RedirectChainIncludingInternalRedirects() |
1206 | 0 | { |
1207 | 0 | return mRedirectChainIncludingInternalRedirects; |
1208 | 0 | } |
1209 | | |
1210 | | NS_IMETHODIMP |
1211 | | LoadInfo::GetRedirectChain(JSContext* aCx, JS::MutableHandle<JS::Value> aChain) |
1212 | 0 | { |
1213 | 0 | return GetRedirects(aCx, aChain, mRedirectChain); |
1214 | 0 | } |
1215 | | |
1216 | | const RedirectHistoryArray& |
1217 | | LoadInfo::RedirectChain() |
1218 | 0 | { |
1219 | 0 | return mRedirectChain; |
1220 | 0 | } |
1221 | | |
1222 | | const nsTArray<nsCOMPtr<nsIPrincipal>>& |
1223 | | LoadInfo::AncestorPrincipals() |
1224 | 0 | { |
1225 | 0 | return mAncestorPrincipals; |
1226 | 0 | } |
1227 | | |
1228 | | const nsTArray<uint64_t>& |
1229 | | LoadInfo::AncestorOuterWindowIDs() |
1230 | 0 | { |
1231 | 0 | return mAncestorOuterWindowIDs; |
1232 | 0 | } |
1233 | | |
1234 | | void |
1235 | | LoadInfo::SetCorsPreflightInfo(const nsTArray<nsCString>& aHeaders, |
1236 | | bool aForcePreflight) |
1237 | 0 | { |
1238 | 0 | MOZ_ASSERT(GetSecurityMode() == nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS); |
1239 | 0 | MOZ_ASSERT(!mInitialSecurityCheckDone); |
1240 | 0 | mCorsUnsafeHeaders = aHeaders; |
1241 | 0 | mForcePreflight = aForcePreflight; |
1242 | 0 | } |
1243 | | |
1244 | | const nsTArray<nsCString>& |
1245 | | LoadInfo::CorsUnsafeHeaders() |
1246 | 0 | { |
1247 | 0 | return mCorsUnsafeHeaders; |
1248 | 0 | } |
1249 | | |
1250 | | NS_IMETHODIMP |
1251 | | LoadInfo::GetForcePreflight(bool* aForcePreflight) |
1252 | 0 | { |
1253 | 0 | *aForcePreflight = mForcePreflight; |
1254 | 0 | return NS_OK; |
1255 | 0 | } |
1256 | | |
1257 | | void |
1258 | | LoadInfo::SetIsPreflight() |
1259 | 0 | { |
1260 | 0 | MOZ_ASSERT(GetSecurityMode() == nsILoadInfo::SEC_REQUIRE_CORS_DATA_INHERITS); |
1261 | 0 | MOZ_ASSERT(!mInitialSecurityCheckDone); |
1262 | 0 | mIsPreflight = true; |
1263 | 0 | } |
1264 | | |
1265 | | void |
1266 | | LoadInfo::SetUpgradeInsecureRequests() |
1267 | 0 | { |
1268 | 0 | mUpgradeInsecureRequests = true; |
1269 | 0 | } |
1270 | | |
1271 | | void |
1272 | | LoadInfo::SetBrowserUpgradeInsecureRequests() |
1273 | 0 | { |
1274 | 0 | mBrowserUpgradeInsecureRequests = true; |
1275 | 0 | } |
1276 | | |
1277 | | void |
1278 | | LoadInfo::SetBrowserWouldUpgradeInsecureRequests() |
1279 | 0 | { |
1280 | 0 | mBrowserWouldUpgradeInsecureRequests = true; |
1281 | 0 | } |
1282 | | |
1283 | | NS_IMETHODIMP |
1284 | | LoadInfo::GetIsPreflight(bool* aIsPreflight) |
1285 | 0 | { |
1286 | 0 | *aIsPreflight = mIsPreflight; |
1287 | 0 | return NS_OK; |
1288 | 0 | } |
1289 | | |
1290 | | NS_IMETHODIMP |
1291 | | LoadInfo::SetLoadTriggeredFromExternal(bool aLoadTriggeredFromExternal) |
1292 | 0 | { |
1293 | 0 | MOZ_ASSERT(!aLoadTriggeredFromExternal || |
1294 | 0 | mInternalContentPolicyType == nsIContentPolicy::TYPE_DOCUMENT, |
1295 | 0 | "can only set load triggered from external for TYPE_DOCUMENT"); |
1296 | 0 | mLoadTriggeredFromExternal = aLoadTriggeredFromExternal; |
1297 | 0 | return NS_OK; |
1298 | 0 | } |
1299 | | |
1300 | | NS_IMETHODIMP |
1301 | | LoadInfo::GetLoadTriggeredFromExternal(bool* aLoadTriggeredFromExternal) |
1302 | 0 | { |
1303 | 0 | *aLoadTriggeredFromExternal = mLoadTriggeredFromExternal; |
1304 | 0 | return NS_OK; |
1305 | 0 | } |
1306 | | |
1307 | | NS_IMETHODIMP |
1308 | | LoadInfo::GetServiceWorkerTaintingSynthesized(bool* aServiceWorkerTaintingSynthesized) |
1309 | 0 | { |
1310 | 0 | MOZ_ASSERT(aServiceWorkerTaintingSynthesized); |
1311 | 0 | *aServiceWorkerTaintingSynthesized = mServiceWorkerTaintingSynthesized; |
1312 | 0 | return NS_OK; |
1313 | 0 | } |
1314 | | |
1315 | | NS_IMETHODIMP |
1316 | | LoadInfo::GetTainting(uint32_t* aTaintingOut) |
1317 | 0 | { |
1318 | 0 | MOZ_ASSERT(aTaintingOut); |
1319 | 0 | *aTaintingOut = static_cast<uint32_t>(mTainting); |
1320 | 0 | return NS_OK; |
1321 | 0 | } |
1322 | | |
1323 | | NS_IMETHODIMP |
1324 | | LoadInfo::MaybeIncreaseTainting(uint32_t aTainting) |
1325 | 0 | { |
1326 | 0 | NS_ENSURE_ARG(aTainting <= TAINTING_OPAQUE); |
1327 | 0 |
|
1328 | 0 | // Skip if the tainting has been set by the service worker. |
1329 | 0 | if (mServiceWorkerTaintingSynthesized) { |
1330 | 0 | return NS_OK; |
1331 | 0 | } |
1332 | 0 | |
1333 | 0 | LoadTainting tainting = static_cast<LoadTainting>(aTainting); |
1334 | 0 | if (tainting > mTainting) { |
1335 | 0 | mTainting = tainting; |
1336 | 0 | } |
1337 | 0 | return NS_OK; |
1338 | 0 | } |
1339 | | |
1340 | | void |
1341 | | LoadInfo::SynthesizeServiceWorkerTainting(LoadTainting aTainting) |
1342 | 0 | { |
1343 | 0 | MOZ_DIAGNOSTIC_ASSERT(aTainting <= LoadTainting::Opaque); |
1344 | 0 | mTainting = aTainting; |
1345 | 0 |
|
1346 | 0 | // Flag to prevent the tainting from being increased. |
1347 | 0 | mServiceWorkerTaintingSynthesized = true; |
1348 | 0 | } |
1349 | | |
1350 | | NS_IMETHODIMP |
1351 | | LoadInfo::GetIsTracker(bool *aIsTracker) |
1352 | 0 | { |
1353 | 0 | MOZ_ASSERT(aIsTracker); |
1354 | 0 | *aIsTracker = mIsTracker; |
1355 | 0 | return NS_OK; |
1356 | 0 | } |
1357 | | |
1358 | | NS_IMETHODIMP |
1359 | | LoadInfo::SetIsTracker(bool aIsTracker) |
1360 | 0 | { |
1361 | 0 | mIsTracker = aIsTracker; |
1362 | 0 | return NS_OK; |
1363 | 0 | } |
1364 | | |
1365 | | NS_IMETHODIMP |
1366 | | LoadInfo::GetIsTrackerBlocked(bool *aIsTrackerBlocked) |
1367 | 0 | { |
1368 | 0 | MOZ_ASSERT(aIsTrackerBlocked); |
1369 | 0 | *aIsTrackerBlocked = mIsTrackerBlocked; |
1370 | 0 | return NS_OK; |
1371 | 0 | } |
1372 | | |
1373 | | NS_IMETHODIMP |
1374 | | LoadInfo::SetIsTrackerBlocked(bool aIsTrackerBlocked) |
1375 | 0 | { |
1376 | 0 | mIsTrackerBlocked = aIsTrackerBlocked; |
1377 | 0 | return NS_OK; |
1378 | 0 | } |
1379 | | |
1380 | | NS_IMETHODIMP |
1381 | | LoadInfo::GetTrackerBlockedReason(mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED *aLabel) |
1382 | 0 | { |
1383 | 0 | MOZ_ASSERT(aLabel); |
1384 | 0 | *aLabel = mTrackerBlockedReason; |
1385 | 0 | return NS_OK; |
1386 | 0 | } |
1387 | | |
1388 | | NS_IMETHODIMP |
1389 | | LoadInfo::SetTrackerBlockedReason(mozilla::Telemetry::LABELS_DOCUMENT_ANALYTICS_TRACKER_FASTBLOCKED aLabel) |
1390 | 0 | { |
1391 | 0 | mTrackerBlockedReason = aLabel; |
1392 | 0 | return NS_OK; |
1393 | 0 | } |
1394 | | |
1395 | | NS_IMETHODIMP |
1396 | | LoadInfo::GetDocumentHasUserInteracted(bool *aDocumentHasUserInteracted) |
1397 | 0 | { |
1398 | 0 | MOZ_ASSERT(aDocumentHasUserInteracted); |
1399 | 0 | *aDocumentHasUserInteracted = mDocumentHasUserInteracted; |
1400 | 0 | return NS_OK; |
1401 | 0 | } |
1402 | | |
1403 | | NS_IMETHODIMP |
1404 | | LoadInfo::SetDocumentHasUserInteracted(bool aDocumentHasUserInteracted) |
1405 | 0 | { |
1406 | 0 | mDocumentHasUserInteracted = aDocumentHasUserInteracted; |
1407 | 0 | return NS_OK; |
1408 | 0 | } |
1409 | | |
1410 | | NS_IMETHODIMP |
1411 | | LoadInfo::GetIsTopLevelLoad(bool *aResult) |
1412 | 0 | { |
1413 | 0 | *aResult = mFrameOuterWindowID ? mFrameOuterWindowID == mOuterWindowID |
1414 | 0 | : mParentOuterWindowID == mOuterWindowID; |
1415 | 0 | return NS_OK; |
1416 | 0 | } |
1417 | | |
1418 | | NS_IMETHODIMP |
1419 | | LoadInfo::GetResultPrincipalURI(nsIURI **aURI) |
1420 | 14 | { |
1421 | 14 | NS_IF_ADDREF(*aURI = mResultPrincipalURI); |
1422 | 14 | return NS_OK; |
1423 | 14 | } |
1424 | | |
1425 | | NS_IMETHODIMP |
1426 | | LoadInfo::SetResultPrincipalURI(nsIURI *aURI) |
1427 | 4 | { |
1428 | 4 | mResultPrincipalURI = aURI; |
1429 | 4 | return NS_OK; |
1430 | 4 | } |
1431 | | |
1432 | | void |
1433 | | LoadInfo::SetClientInfo(const ClientInfo& aClientInfo) |
1434 | 0 | { |
1435 | 0 | mClientInfo.emplace(aClientInfo); |
1436 | 0 | } |
1437 | | |
1438 | | const Maybe<ClientInfo>& |
1439 | | LoadInfo::GetClientInfo() |
1440 | 0 | { |
1441 | 0 | return mClientInfo; |
1442 | 0 | } |
1443 | | |
1444 | | void |
1445 | | LoadInfo::GiveReservedClientSource(UniquePtr<ClientSource>&& aClientSource) |
1446 | 0 | { |
1447 | 0 | MOZ_DIAGNOSTIC_ASSERT(aClientSource); |
1448 | 0 | mReservedClientSource = std::move(aClientSource); |
1449 | 0 | SetReservedClientInfo(mReservedClientSource->Info()); |
1450 | 0 | } |
1451 | | |
1452 | | UniquePtr<ClientSource> |
1453 | | LoadInfo::TakeReservedClientSource() |
1454 | 0 | { |
1455 | 0 | if (mReservedClientSource) { |
1456 | 0 | // If the reserved ClientInfo was set due to a ClientSource being present, |
1457 | 0 | // then clear that info object when the ClientSource is taken. |
1458 | 0 | mReservedClientInfo.reset(); |
1459 | 0 | } |
1460 | 0 | return std::move(mReservedClientSource); |
1461 | 0 | } |
1462 | | |
1463 | | void |
1464 | | LoadInfo::SetReservedClientInfo(const ClientInfo& aClientInfo) |
1465 | 0 | { |
1466 | 0 | MOZ_DIAGNOSTIC_ASSERT(mInitialClientInfo.isNothing()); |
1467 | 0 | // Treat assignments of the same value as a no-op. The emplace below |
1468 | 0 | // will normally assert when overwriting an existing value. |
1469 | 0 | if (mReservedClientInfo.isSome() && mReservedClientInfo.ref() == aClientInfo) { |
1470 | 0 | return; |
1471 | 0 | } |
1472 | 0 | mReservedClientInfo.emplace(aClientInfo); |
1473 | 0 | } |
1474 | | |
1475 | | void |
1476 | | LoadInfo::OverrideReservedClientInfoInParent(const ClientInfo& aClientInfo) |
1477 | 0 | { |
1478 | 0 | // This should only be called to handle redirects in the parent process. |
1479 | 0 | MOZ_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default); |
1480 | 0 |
|
1481 | 0 | mInitialClientInfo.reset(); |
1482 | 0 | mReservedClientInfo.reset(); |
1483 | 0 | mReservedClientInfo.emplace(aClientInfo); |
1484 | 0 | } |
1485 | | |
1486 | | const Maybe<ClientInfo>& |
1487 | | LoadInfo::GetReservedClientInfo() |
1488 | 0 | { |
1489 | 0 | return mReservedClientInfo; |
1490 | 0 | } |
1491 | | |
1492 | | void |
1493 | | LoadInfo::SetInitialClientInfo(const ClientInfo& aClientInfo) |
1494 | 0 | { |
1495 | 0 | MOZ_DIAGNOSTIC_ASSERT(!mReservedClientSource); |
1496 | 0 | MOZ_DIAGNOSTIC_ASSERT(mReservedClientInfo.isNothing()); |
1497 | 0 | // Treat assignments of the same value as a no-op. The emplace below |
1498 | 0 | // will normally assert when overwriting an existing value. |
1499 | 0 | if (mInitialClientInfo.isSome() && mInitialClientInfo.ref() == aClientInfo) { |
1500 | 0 | return; |
1501 | 0 | } |
1502 | 0 | mInitialClientInfo.emplace(aClientInfo); |
1503 | 0 | } |
1504 | | |
1505 | | const Maybe<ClientInfo>& |
1506 | | LoadInfo::GetInitialClientInfo() |
1507 | 0 | { |
1508 | 0 | return mInitialClientInfo; |
1509 | 0 | } |
1510 | | |
1511 | | void |
1512 | | LoadInfo::SetController(const ServiceWorkerDescriptor& aServiceWorker) |
1513 | 0 | { |
1514 | 0 | mController.emplace(aServiceWorker); |
1515 | 0 | } |
1516 | | |
1517 | | void |
1518 | | LoadInfo::ClearController() |
1519 | 0 | { |
1520 | 0 | mController.reset(); |
1521 | 0 | } |
1522 | | |
1523 | | const Maybe<ServiceWorkerDescriptor>& |
1524 | | LoadInfo::GetController() |
1525 | 0 | { |
1526 | 0 | return mController; |
1527 | 0 | } |
1528 | | |
1529 | | void |
1530 | | LoadInfo::SetPerformanceStorage(PerformanceStorage* aPerformanceStorage) |
1531 | 0 | { |
1532 | 0 | mPerformanceStorage = aPerformanceStorage; |
1533 | 0 | } |
1534 | | |
1535 | | PerformanceStorage* |
1536 | | LoadInfo::GetPerformanceStorage() |
1537 | 0 | { |
1538 | 0 | return mPerformanceStorage; |
1539 | 0 | } |
1540 | | |
1541 | | } // namespace net |
1542 | | } // namespace mozilla |