2018-01-30 09:12:04 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
|
|
|
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_dom_workers_WorkerLoadInfo_h
|
|
|
|
#define mozilla_dom_workers_WorkerLoadInfo_h
|
|
|
|
|
2019-05-27 14:06:49 +00:00
|
|
|
#include "mozilla/StorageAccess.h"
|
2020-04-03 21:04:51 +00:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2018-01-30 09:14:00 +00:00
|
|
|
#include "mozilla/dom/ChannelInfo.h"
|
2018-02-14 19:23:15 +00:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
|
2018-01-31 07:24:59 +00:00
|
|
|
#include "mozilla/dom/WorkerCommon.h"
|
2019-08-21 13:24:45 +00:00
|
|
|
|
2018-01-30 09:12:04 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2018-01-30 09:14:00 +00:00
|
|
|
#include "nsILoadContext.h"
|
2018-01-30 09:12:04 +00:00
|
|
|
#include "nsISupportsImpl.h"
|
2018-01-30 09:14:00 +00:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2018-01-30 09:12:04 +00:00
|
|
|
|
|
|
|
class nsIChannel;
|
|
|
|
class nsIContentSecurityPolicy;
|
2020-03-04 08:59:08 +00:00
|
|
|
class nsICookieJarSettings;
|
2018-01-30 09:12:04 +00:00
|
|
|
class nsILoadGroup;
|
|
|
|
class nsIPrincipal;
|
|
|
|
class nsIRunnable;
|
|
|
|
class nsIScriptContext;
|
2019-04-09 23:15:02 +00:00
|
|
|
class nsIBrowserChild;
|
2018-01-30 09:12:04 +00:00
|
|
|
class nsIURI;
|
|
|
|
class nsPIDOMWindowInner;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2018-01-31 07:21:46 +00:00
|
|
|
|
2018-01-30 09:12:04 +00:00
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
2019-05-21 23:14:50 +00:00
|
|
|
class CSPInfo;
|
2018-01-30 09:12:04 +00:00
|
|
|
} // namespace ipc
|
|
|
|
|
2018-01-31 07:21:46 +00:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class WorkerPrivate;
|
2018-01-30 09:12:04 +00:00
|
|
|
|
2018-11-21 20:02:51 +00:00
|
|
|
struct WorkerLoadInfoData {
|
2018-01-30 09:12:04 +00:00
|
|
|
// All of these should be released in
|
|
|
|
// WorkerPrivateParent::ForgetMainThreadObjects.
|
|
|
|
nsCOMPtr<nsIURI> mBaseURI;
|
|
|
|
nsCOMPtr<nsIURI> mResolvedScriptURI;
|
|
|
|
|
|
|
|
// This is the principal of the global (parent worker or a window) loading
|
|
|
|
// the worker. It can be null if we are executing a ServiceWorker, otherwise,
|
|
|
|
// except for data: URL, it must subsumes the worker principal.
|
|
|
|
// If we load a data: URL, mPrincipal will be a null principal.
|
|
|
|
nsCOMPtr<nsIPrincipal> mLoadingPrincipal;
|
|
|
|
nsCOMPtr<nsIPrincipal> mPrincipal;
|
2020-06-03 06:09:52 +00:00
|
|
|
nsCOMPtr<nsIPrincipal> mPartitionedPrincipal;
|
2018-01-30 09:12:04 +00:00
|
|
|
|
2019-03-08 09:04:11 +00:00
|
|
|
// Taken from the parent context.
|
2020-03-04 08:59:08 +00:00
|
|
|
nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
|
2019-03-08 09:04:11 +00:00
|
|
|
|
2018-01-30 09:12:04 +00:00
|
|
|
nsCOMPtr<nsIScriptContext> mScriptContext;
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> mCSP;
|
2019-05-21 23:14:50 +00:00
|
|
|
// Thread boundaries require us to not only store a CSP object, but also a
|
|
|
|
// serialized version of the CSP. Reason being: Serializing a CSP to a CSPInfo
|
|
|
|
// needs to happen on the main thread, but storing the CSPInfo needs to happen
|
|
|
|
// on the worker thread. We move the CSPInfo into the Client within
|
|
|
|
// ScriptLoader::PreRun().
|
2020-04-03 21:04:51 +00:00
|
|
|
UniquePtr<mozilla::ipc::CSPInfo> mCSPInfo;
|
2019-05-21 23:14:50 +00:00
|
|
|
|
2018-01-30 09:12:04 +00:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
|
|
|
|
class InterfaceRequestor final : public nsIInterfaceRequestor {
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
public:
|
|
|
|
InterfaceRequestor(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup);
|
2019-04-09 22:39:01 +00:00
|
|
|
void MaybeAddBrowserChild(nsILoadGroup* aLoadGroup);
|
2018-01-30 09:12:04 +00:00
|
|
|
NS_IMETHOD GetInterface(const nsIID& aIID, void** aSink) override;
|
|
|
|
|
2018-11-19 23:18:32 +00:00
|
|
|
void SetOuterRequestor(nsIInterfaceRequestor* aOuterRequestor) {
|
|
|
|
MOZ_ASSERT(!mOuterRequestor);
|
|
|
|
MOZ_ASSERT(aOuterRequestor);
|
|
|
|
mOuterRequestor = aOuterRequestor;
|
|
|
|
}
|
|
|
|
|
2018-01-30 09:12:04 +00:00
|
|
|
private:
|
2020-02-12 10:38:22 +00:00
|
|
|
~InterfaceRequestor() = default;
|
2018-01-30 09:12:04 +00:00
|
|
|
|
2019-04-09 22:39:01 +00:00
|
|
|
already_AddRefed<nsIBrowserChild> GetAnyLiveBrowserChild();
|
2018-01-30 09:12:04 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsILoadContext> mLoadContext;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mOuterRequestor;
|
|
|
|
|
2019-04-09 23:15:02 +00:00
|
|
|
// Array of weak references to nsIBrowserChild. We do not want to keep
|
2019-04-09 22:39:01 +00:00
|
|
|
// BrowserChild actors alive for long after their ActorDestroy() methods are
|
2019-04-09 23:15:02 +00:00
|
|
|
// called.
|
2019-04-09 22:39:01 +00:00
|
|
|
nsTArray<nsWeakPtr> mBrowserChildList;
|
2018-01-30 09:12:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Only set if we have a custom overriden load group
|
|
|
|
RefPtr<InterfaceRequestor> mInterfaceRequestor;
|
|
|
|
|
2020-04-03 21:04:51 +00:00
|
|
|
UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
|
2020-06-03 06:09:52 +00:00
|
|
|
UniquePtr<mozilla::ipc::PrincipalInfo> mPartitionedPrincipalInfo;
|
2018-01-30 09:12:04 +00:00
|
|
|
nsCString mDomain;
|
2020-06-03 06:08:51 +00:00
|
|
|
nsString mOriginNoSuffix; // Derived from mPrincipal; can be used on worker
|
|
|
|
// thread.
|
|
|
|
nsCString mOrigin; // Derived from mPrincipal; can be used on worker thread.
|
|
|
|
nsCString mPartitionedOrigin; // Derived from mPartitionedPrincipal; can be
|
|
|
|
// used on worker thread.
|
2018-01-30 09:12:04 +00:00
|
|
|
|
|
|
|
nsString mServiceWorkerCacheName;
|
|
|
|
Maybe<ServiceWorkerDescriptor> mServiceWorkerDescriptor;
|
2018-02-14 19:23:15 +00:00
|
|
|
Maybe<ServiceWorkerRegistrationDescriptor>
|
|
|
|
mServiceWorkerRegistrationDescriptor;
|
2018-01-30 09:12:04 +00:00
|
|
|
|
|
|
|
Maybe<ServiceWorkerDescriptor> mParentController;
|
|
|
|
|
2019-09-23 09:57:23 +00:00
|
|
|
nsID mAgentClusterId;
|
|
|
|
|
2018-01-30 09:12:04 +00:00
|
|
|
ChannelInfo mChannelInfo;
|
|
|
|
nsLoadFlags mLoadFlags;
|
|
|
|
|
|
|
|
uint64_t mWindowID;
|
|
|
|
|
2019-06-13 20:37:34 +00:00
|
|
|
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
|
2018-01-30 09:12:04 +00:00
|
|
|
bool mFromWindow;
|
|
|
|
bool mEvalAllowed;
|
|
|
|
bool mReportCSPViolations;
|
|
|
|
bool mXHRParamsAllowed;
|
|
|
|
bool mPrincipalIsSystem;
|
2019-10-04 17:37:09 +00:00
|
|
|
bool mPrincipalIsAddonOrExpandedAddon;
|
2020-05-12 09:18:26 +00:00
|
|
|
bool mWatchedByDevTools;
|
2019-05-27 14:06:49 +00:00
|
|
|
StorageAccess mStorageAccess;
|
2020-06-03 06:10:58 +00:00
|
|
|
bool mUseRegularPrincipal;
|
|
|
|
bool mHasStorageAccessPermissionGranted;
|
2018-01-30 09:12:04 +00:00
|
|
|
bool mServiceWorkersTestingInWindow;
|
|
|
|
OriginAttributes mOriginAttributes;
|
|
|
|
|
2018-11-19 23:18:21 +00:00
|
|
|
enum {
|
|
|
|
eNotSet,
|
|
|
|
eInsecureContext,
|
|
|
|
eSecureContext,
|
|
|
|
} mSecureContext;
|
|
|
|
|
2018-11-21 20:02:51 +00:00
|
|
|
WorkerLoadInfoData();
|
|
|
|
WorkerLoadInfoData(WorkerLoadInfoData&& aOther) = default;
|
|
|
|
|
|
|
|
WorkerLoadInfoData& operator=(WorkerLoadInfoData&& aOther) = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WorkerLoadInfo : WorkerLoadInfoData {
|
2018-01-30 09:12:04 +00:00
|
|
|
WorkerLoadInfo();
|
2018-11-21 20:02:51 +00:00
|
|
|
WorkerLoadInfo(WorkerLoadInfo&& aOther) noexcept;
|
2018-01-30 09:12:04 +00:00
|
|
|
~WorkerLoadInfo();
|
|
|
|
|
2018-11-21 20:02:51 +00:00
|
|
|
WorkerLoadInfo& operator=(WorkerLoadInfo&& aOther) = default;
|
2018-01-30 09:12:04 +00:00
|
|
|
|
2019-05-21 23:14:50 +00:00
|
|
|
nsresult SetPrincipalsAndCSPOnMainThread(nsIPrincipal* aPrincipal,
|
2020-06-03 06:09:52 +00:00
|
|
|
nsIPrincipal* aPartitionedPrincipal,
|
2019-05-21 23:14:50 +00:00
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsIContentSecurityPolicy* aCSP);
|
2018-01-30 09:12:04 +00:00
|
|
|
|
2019-04-12 05:31:25 +00:00
|
|
|
nsresult GetPrincipalsAndLoadGroupFromChannel(
|
|
|
|
nsIChannel* aChannel, nsIPrincipal** aPrincipalOut,
|
2020-06-03 06:09:52 +00:00
|
|
|
nsIPrincipal** aPartitionedPrincipalOut, nsILoadGroup** aLoadGroupOut);
|
2018-01-30 09:12:04 +00:00
|
|
|
|
2019-05-21 23:14:50 +00:00
|
|
|
nsresult SetPrincipalsAndCSPFromChannel(nsIChannel* aChannel);
|
2018-01-30 09:12:04 +00:00
|
|
|
|
|
|
|
bool FinalChannelPrincipalIsValid(nsIChannel* aChannel);
|
|
|
|
|
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
bool PrincipalIsValid() const;
|
|
|
|
|
|
|
|
bool PrincipalURIMatchesScriptURL();
|
|
|
|
#endif
|
|
|
|
|
2018-01-31 07:24:08 +00:00
|
|
|
bool ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate);
|
2018-01-30 09:12:04 +00:00
|
|
|
|
2018-01-31 07:24:08 +00:00
|
|
|
bool ProxyReleaseMainThreadObjects(
|
|
|
|
WorkerPrivate* aWorkerPrivate,
|
2020-08-03 19:09:36 +00:00
|
|
|
nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel);
|
2018-01-30 09:12:04 +00:00
|
|
|
};
|
|
|
|
|
2018-01-31 07:21:46 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2018-01-30 09:12:04 +00:00
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_WorkerLoadInfo_h
|