Backed out changeset b09d48d2b473 (bug 1655101) for causing mochitest webgl failures...
[gecko.git] / dom / workers / WorkerLoadInfo.h
blob7bdb86c596eb8b44c738e81e9add39d75f47f197
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 "nsTArray.h"
26 class nsIChannel;
27 class nsIContentSecurityPolicy;
28 class nsICookieJarSettings;
29 class nsILoadGroup;
30 class nsIPrincipal;
31 class nsIReferrerInfo;
32 class nsIRunnable;
33 class nsIScriptContext;
34 class nsIBrowserChild;
35 class nsIURI;
36 class nsPIDOMWindowInner;
38 namespace mozilla {
40 namespace ipc {
41 class PrincipalInfo;
42 class CSPInfo;
43 } // namespace ipc
45 namespace dom {
47 class WorkerPrivate;
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 {
84 NS_DECL_ISUPPORTS
86 public:
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;
97 private:
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
107 // called.
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;
116 nsCString mDomain;
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;
130 uint64_t mWindowID;
131 uint64_t mAssociatedBrowsingContextID;
133 nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
134 OriginTrials mTrials;
135 bool mFromWindow;
136 bool mEvalAllowed;
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;
150 enum {
151 eNotSet,
152 eInsecureContext,
153 eSecureContext,
154 } mSecureContext;
156 WorkerLoadInfoData();
157 WorkerLoadInfoData(WorkerLoadInfoData&& aOther) = default;
159 WorkerLoadInfoData& operator=(WorkerLoadInfoData&& aOther) = default;
162 struct WorkerLoadInfo : WorkerLoadInfoData {
163 WorkerLoadInfo();
164 WorkerLoadInfo(WorkerLoadInfo&& aOther) noexcept;
165 ~WorkerLoadInfo();
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();
186 #endif
188 bool ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate);
190 bool ProxyReleaseMainThreadObjects(
191 WorkerPrivate* aWorkerPrivate,
192 nsCOMPtr<nsILoadGroup>&& aLoadGroupToCancel);
195 } // namespace dom
196 } // namespace mozilla
198 #endif // mozilla_dom_workers_WorkerLoadInfo_h