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"
27 class nsIContentSecurityPolicy
;
28 class nsICookieJarSettings
;
31 class nsIReferrerInfo
;
33 class nsIScriptContext
;
34 class nsIBrowserChild
;
36 class nsPIDOMWindowInner
;
49 struct WorkerLoadInfoData
{
50 // All of these should be released in
51 // WorkerPrivateParent::ForgetMainThreadObjects.
52 nsCOMPtr
<nsIURI
> mBaseURI
;
53 nsCOMPtr
<nsIURI
> mResolvedScriptURI
;
55 // This is the principal of the global (parent worker or a window) loading
56 // the worker. It can be null if we are executing a ServiceWorker, otherwise,
57 // except for data: URL, it must subsumes the worker principal.
58 // If we load a data: URL, mPrincipal will be a null principal.
59 nsCOMPtr
<nsIPrincipal
> mLoadingPrincipal
;
60 nsCOMPtr
<nsIPrincipal
> mPrincipal
;
61 nsCOMPtr
<nsIPrincipal
> mPartitionedPrincipal
;
63 // Taken from the parent context.
64 nsCOMPtr
<nsICookieJarSettings
> mCookieJarSettings
;
66 // The CookieJarSettingsArgs of mCookieJarSettings.
67 // This is specific for accessing on worker thread.
68 net::CookieJarSettingsArgs mCookieJarSettingsArgs
;
70 nsCOMPtr
<nsIScriptContext
> mScriptContext
;
71 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
72 nsCOMPtr
<nsIContentSecurityPolicy
> mCSP
;
73 // Thread boundaries require us to not only store a CSP object, but also a
74 // serialized version of the CSP. Reason being: Serializing a CSP to a CSPInfo
75 // needs to happen on the main thread, but storing the CSPInfo needs to happen
76 // on the worker thread. We move the CSPInfo into the Client within
77 // ScriptLoader::PreRun().
78 UniquePtr
<mozilla::ipc::CSPInfo
> mCSPInfo
;
80 nsCOMPtr
<nsIChannel
> mChannel
;
81 nsCOMPtr
<nsILoadGroup
> mLoadGroup
;
83 class InterfaceRequestor final
: public nsIInterfaceRequestor
{
87 InterfaceRequestor(nsIPrincipal
* aPrincipal
, nsILoadGroup
* aLoadGroup
);
88 void MaybeAddBrowserChild(nsILoadGroup
* aLoadGroup
);
89 NS_IMETHOD
GetInterface(const nsIID
& aIID
, void** aSink
) override
;
91 void SetOuterRequestor(nsIInterfaceRequestor
* aOuterRequestor
) {
92 MOZ_ASSERT(!mOuterRequestor
);
93 MOZ_ASSERT(aOuterRequestor
);
94 mOuterRequestor
= aOuterRequestor
;
98 ~InterfaceRequestor() = default;
100 already_AddRefed
<nsIBrowserChild
> GetAnyLiveBrowserChild();
102 nsCOMPtr
<nsILoadContext
> mLoadContext
;
103 nsCOMPtr
<nsIInterfaceRequestor
> mOuterRequestor
;
105 // Array of weak references to nsIBrowserChild. We do not want to keep
106 // BrowserChild actors alive for long after their ActorDestroy() methods are
108 nsTArray
<nsWeakPtr
> mBrowserChildList
;
111 // Only set if we have a custom overriden load group
112 RefPtr
<InterfaceRequestor
> mInterfaceRequestor
;
114 UniquePtr
<mozilla::ipc::PrincipalInfo
> mPrincipalInfo
;
115 UniquePtr
<mozilla::ipc::PrincipalInfo
> mPartitionedPrincipalInfo
;
118 nsString mServiceWorkerCacheName
;
119 Maybe
<ServiceWorkerDescriptor
> mServiceWorkerDescriptor
;
120 Maybe
<ServiceWorkerRegistrationDescriptor
>
121 mServiceWorkerRegistrationDescriptor
;
123 Maybe
<ServiceWorkerDescriptor
> mParentController
;
125 nsID mAgentClusterId
;
127 ChannelInfo mChannelInfo
;
128 nsLoadFlags mLoadFlags
;
131 uint64_t mAssociatedBrowsingContextID
;
133 nsCOMPtr
<nsIReferrerInfo
> mReferrerInfo
;
134 OriginTrials mTrials
;
137 bool mReportEvalCSPViolations
;
138 bool mWasmEvalAllowed
;
139 bool mReportWasmEvalCSPViolations
;
140 bool mXHRParamsAllowed
;
141 bool mWatchedByDevTools
;
142 StorageAccess mStorageAccess
;
143 bool mUseRegularPrincipal
;
144 bool mUsingStorageAccess
;
145 bool mServiceWorkersTestingInWindow
;
146 bool mShouldResistFingerprinting
;
147 OriginAttributes mOriginAttributes
;
148 bool mIsThirdPartyContextToTopWindow
;
156 WorkerLoadInfoData();
157 WorkerLoadInfoData(WorkerLoadInfoData
&& aOther
) = default;
159 WorkerLoadInfoData
& operator=(WorkerLoadInfoData
&& aOther
) = default;
162 struct WorkerLoadInfo
: WorkerLoadInfoData
{
164 WorkerLoadInfo(WorkerLoadInfo
&& aOther
) noexcept
;
167 WorkerLoadInfo
& operator=(WorkerLoadInfo
&& aOther
) = default;
169 nsresult
SetPrincipalsAndCSPOnMainThread(nsIPrincipal
* aPrincipal
,
170 nsIPrincipal
* aPartitionedPrincipal
,
171 nsILoadGroup
* aLoadGroup
,
172 nsIContentSecurityPolicy
* aCSP
);
174 nsresult
GetPrincipalsAndLoadGroupFromChannel(
175 nsIChannel
* aChannel
, nsIPrincipal
** aPrincipalOut
,
176 nsIPrincipal
** aPartitionedPrincipalOut
, nsILoadGroup
** aLoadGroupOut
);
178 nsresult
SetPrincipalsAndCSPFromChannel(nsIChannel
* aChannel
);
180 bool FinalChannelPrincipalIsValid(nsIChannel
* aChannel
);
182 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
183 bool PrincipalIsValid() const;
185 bool PrincipalURIMatchesScriptURL();
188 bool ProxyReleaseMainThreadObjects(WorkerPrivate
* aWorkerPrivate
);
190 bool ProxyReleaseMainThreadObjects(
191 WorkerPrivate
* aWorkerPrivate
,
192 nsCOMPtr
<nsILoadGroup
>&& aLoadGroupToCancel
);
196 } // namespace mozilla
198 #endif // mozilla_dom_workers_WorkerLoadInfo_h