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 #ifndef mozilla_dom_workers_WorkerLoadInfo_h
8 #define mozilla_dom_workers_WorkerLoadInfo_h
10 #include "mozilla/OriginAttributes.h"
11 #include "mozilla/StorageAccess.h"
12 #include "mozilla/OriginTrials.h"
13 #include "mozilla/UniquePtr.h"
14 #include "mozilla/dom/ChannelInfo.h"
15 #include "mozilla/net/NeckoChannelParams.h"
16 #include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
17 #include "mozilla/dom/WorkerCommon.h"
19 #include "nsIInterfaceRequestor.h"
20 #include "nsILoadContext.h"
21 #include "nsIRequest.h"
22 #include "nsISupportsImpl.h"
23 #include "nsIWeakReferenceUtils.h"
24 #include "nsRFPService.h"
28 class nsIContentSecurityPolicy
;
29 class nsICookieJarSettings
;
32 class nsIReferrerInfo
;
34 class nsIScriptContext
;
35 class nsIBrowserChild
;
37 class nsPIDOMWindowInner
;
50 struct WorkerLoadInfoData
{
51 // All of these should be released in
52 // WorkerPrivateParent::ForgetMainThreadObjects.
53 nsCOMPtr
<nsIURI
> mBaseURI
;
54 nsCOMPtr
<nsIURI
> mResolvedScriptURI
;
56 // This is the principal of the global (parent worker or a window) loading
57 // the worker. It can be null if we are executing a ServiceWorker, otherwise,
58 // except for data: URL, it must subsumes the worker principal.
59 // If we load a data: URL, mPrincipal will be a null principal.
60 nsCOMPtr
<nsIPrincipal
> mLoadingPrincipal
;
61 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
62 nsCOMPtr
<nsIPrincipal
> mPartitionedPrincipal
;
64 // Taken from the parent context.
65 nsCOMPtr
<nsICookieJarSettings
> mCookieJarSettings
;
67 // The CookieJarSettingsArgs of mCookieJarSettings.
68 // This is specific for accessing on worker thread.
69 net::CookieJarSettingsArgs mCookieJarSettingsArgs
;
71 nsCOMPtr
<nsIScriptContext
> mScriptContext
;
72 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
73 nsCOMPtr
<nsIContentSecurityPolicy
> mCSP
;
74 // Thread boundaries require us to not only store a CSP object, but also a
75 // serialized version of the CSP. Reason being: Serializing a CSP to a CSPInfo
76 // needs to happen on the main thread, but storing the CSPInfo needs to happen
77 // on the worker thread. We move the CSPInfo into the Client within
78 // ScriptLoader::PreRun().
79 UniquePtr
<mozilla::ipc::CSPInfo
> mCSPInfo
;
81 nsCOMPtr
<nsIChannel
> mChannel
;
82 nsCOMPtr
<nsILoadGroup
> mLoadGroup
;
84 class InterfaceRequestor final
: public nsIInterfaceRequestor
{
88 InterfaceRequestor(nsIPrincipal
* aPrincipal
, nsILoadGroup
* aLoadGroup
);
89 void MaybeAddBrowserChild(nsILoadGroup
* aLoadGroup
);
90 NS_IMETHOD
GetInterface(const nsIID
& aIID
, void** aSink
) override
;
92 void SetOuterRequestor(nsIInterfaceRequestor
* aOuterRequestor
) {
93 MOZ_ASSERT(!mOuterRequestor
);
94 MOZ_ASSERT(aOuterRequestor
);
95 mOuterRequestor
= aOuterRequestor
;
99 ~InterfaceRequestor() = default;
101 already_AddRefed
<nsIBrowserChild
> GetAnyLiveBrowserChild();
103 nsCOMPtr
<nsILoadContext
> mLoadContext
;
104 nsCOMPtr
<nsIInterfaceRequestor
> mOuterRequestor
;
106 // Array of weak references to nsIBrowserChild. We do not want to keep
107 // BrowserChild actors alive for long after their ActorDestroy() methods are
109 nsTArray
<nsWeakPtr
> mBrowserChildList
;
112 // Only set if we have a custom overriden load group
113 RefPtr
<InterfaceRequestor
> mInterfaceRequestor
;
115 UniquePtr
<mozilla::ipc::PrincipalInfo
> mPrincipalInfo
;
116 UniquePtr
<mozilla::ipc::PrincipalInfo
> mPartitionedPrincipalInfo
;
119 nsString mServiceWorkerCacheName
;
120 Maybe
<ServiceWorkerDescriptor
> mServiceWorkerDescriptor
;
121 Maybe
<ServiceWorkerRegistrationDescriptor
>
122 mServiceWorkerRegistrationDescriptor
;
124 Maybe
<ServiceWorkerDescriptor
> mParentController
;
126 nsID mAgentClusterId
;
128 ChannelInfo mChannelInfo
;
129 nsLoadFlags mLoadFlags
;
132 uint64_t mAssociatedBrowsingContextID
;
134 nsCOMPtr
<nsIReferrerInfo
> mReferrerInfo
;
135 OriginTrials mTrials
;
138 bool mReportEvalCSPViolations
;
139 bool mWasmEvalAllowed
;
140 bool mReportWasmEvalCSPViolations
;
141 bool mXHRParamsAllowed
;
142 bool mWatchedByDevTools
;
143 StorageAccess mStorageAccess
;
144 bool mUseRegularPrincipal
;
145 bool mUsingStorageAccess
;
146 bool mServiceWorkersTestingInWindow
;
147 bool mShouldResistFingerprinting
;
148 Maybe
<RFPTarget
> mOverriddenFingerprintingSettings
;
149 OriginAttributes mOriginAttributes
;
150 bool mIsThirdPartyContext
;
158 WorkerLoadInfoData();
159 WorkerLoadInfoData(WorkerLoadInfoData
&& aOther
) = default;
161 WorkerLoadInfoData
& operator=(WorkerLoadInfoData
&& aOther
) = default;
164 struct WorkerLoadInfo
: WorkerLoadInfoData
{
166 WorkerLoadInfo(WorkerLoadInfo
&& aOther
) noexcept
;
169 WorkerLoadInfo
& operator=(WorkerLoadInfo
&& aOther
) = default;
171 nsresult
SetPrincipalsAndCSPOnMainThread(nsIPrincipal
* aPrincipal
,
172 nsIPrincipal
* aPartitionedPrincipal
,
173 nsILoadGroup
* aLoadGroup
,
174 nsIContentSecurityPolicy
* aCSP
);
176 nsresult
GetPrincipalsAndLoadGroupFromChannel(
177 nsIChannel
* aChannel
, nsIPrincipal
** aPrincipalOut
,
178 nsIPrincipal
** aPartitionedPrincipalOut
, nsILoadGroup
** aLoadGroupOut
);
180 nsresult
SetPrincipalsAndCSPFromChannel(nsIChannel
* aChannel
);
182 bool FinalChannelPrincipalIsValid(nsIChannel
* aChannel
);
184 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
185 bool PrincipalIsValid() const;
187 bool PrincipalURIMatchesScriptURL();
190 bool ProxyReleaseMainThreadObjects(WorkerPrivate
* aWorkerPrivate
);
192 bool ProxyReleaseMainThreadObjects(
193 WorkerPrivate
* aWorkerPrivate
,
194 nsCOMPtr
<nsILoadGroup
>&& aLoadGroupToCancel
);
198 } // namespace mozilla
200 #endif // mozilla_dom_workers_WorkerLoadInfo_h