2018-01-30 12:12:04 +03: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 17:06:49 +03:00
|
|
|
#include "mozilla/StorageAccess.h"
|
2018-01-30 12:14:00 +03:00
|
|
|
#include "mozilla/dom/ChannelInfo.h"
|
2018-02-14 22:23:15 +03:00
|
|
|
#include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
|
2018-01-31 10:24:59 +03:00
|
|
|
#include "mozilla/dom/WorkerCommon.h"
|
2018-01-30 12:14:00 +03:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2018-01-30 12:12:04 +03:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2018-01-30 12:14:00 +03:00
|
|
|
#include "nsILoadContext.h"
|
|
|
|
#include "nsIRequest.h"
|
2018-01-30 12:12:04 +03:00
|
|
|
#include "nsISupportsImpl.h"
|
2018-01-30 12:14:00 +03:00
|
|
|
#include "nsIWeakReferenceUtils.h"
|
2018-01-30 12:12:04 +03:00
|
|
|
|
|
|
|
class nsIChannel;
|
|
|
|
class nsIContentSecurityPolicy;
|
2019-03-08 12:04:11 +03:00
|
|
|
class nsICookieSettings;
|
2018-01-30 12:12:04 +03:00
|
|
|
class nsILoadGroup;
|
|
|
|
class nsIPrincipal;
|
|
|
|
class nsIRunnable;
|
|
|
|
class nsIScriptContext;
|
2019-04-10 02:15:02 +03:00
|
|
|
class nsIBrowserChild;
|
2018-01-30 12:12:04 +03:00
|
|
|
class nsIURI;
|
|
|
|
class nsPIDOMWindowInner;
|
|
|
|
|
|
|
|
namespace mozilla {
|
2018-01-31 10:21:46 +03:00
|
|
|
|
2018-01-30 12:12:04 +03:00
|
|
|
namespace ipc {
|
|
|
|
class PrincipalInfo;
|
2019-05-22 02:14:50 +03:00
|
|
|
class CSPInfo;
|
2018-01-30 12:12:04 +03:00
|
|
|
} // namespace ipc
|
|
|
|
|
2018-01-31 10:21:46 +03:00
|
|
|
namespace dom {
|
|
|
|
|
|
|
|
class WorkerPrivate;
|
2018-01-30 12:12:04 +03:00
|
|
|
|
2018-11-21 23:02:51 +03:00
|
|
|
struct WorkerLoadInfoData {
|
2018-01-30 12:12:04 +03: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;
|
2019-04-12 08:31:25 +03:00
|
|
|
nsCOMPtr<nsIPrincipal> mStoragePrincipal;
|
2018-01-30 12:12:04 +03:00
|
|
|
|
2019-03-08 12:04:11 +03:00
|
|
|
// Taken from the parent context.
|
|
|
|
nsCOMPtr<nsICookieSettings> mCookieSettings;
|
|
|
|
|
2018-01-30 12:12:04 +03:00
|
|
|
nsCOMPtr<nsIScriptContext> mScriptContext;
|
|
|
|
nsCOMPtr<nsPIDOMWindowInner> mWindow;
|
|
|
|
nsCOMPtr<nsIContentSecurityPolicy> mCSP;
|
2019-05-22 02:14:50 +03: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().
|
|
|
|
nsAutoPtr<mozilla::ipc::CSPInfo> mCSPInfo;
|
|
|
|
|
2018-01-30 12:12:04 +03:00
|
|
|
nsCOMPtr<nsIChannel> mChannel;
|
|
|
|
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
|
|
|
|
|
|
|
class InterfaceRequestor final : public nsIInterfaceRequestor {
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
public:
|
|
|
|
InterfaceRequestor(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup);
|
2019-04-10 01:39:01 +03:00
|
|
|
void MaybeAddBrowserChild(nsILoadGroup* aLoadGroup);
|
2018-01-30 12:12:04 +03:00
|
|
|
NS_IMETHOD GetInterface(const nsIID& aIID, void** aSink) override;
|
|
|
|
|
2018-11-20 02:18:32 +03:00
|
|
|
void SetOuterRequestor(nsIInterfaceRequestor* aOuterRequestor) {
|
|
|
|
MOZ_ASSERT(!mOuterRequestor);
|
|
|
|
MOZ_ASSERT(aOuterRequestor);
|
|
|
|
mOuterRequestor = aOuterRequestor;
|
|
|
|
}
|
|
|
|
|
2018-01-30 12:12:04 +03:00
|
|
|
private:
|
|
|
|
~InterfaceRequestor() {}
|
|
|
|
|
2019-04-10 01:39:01 +03:00
|
|
|
already_AddRefed<nsIBrowserChild> GetAnyLiveBrowserChild();
|
2018-01-30 12:12:04 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsILoadContext> mLoadContext;
|
|
|
|
nsCOMPtr<nsIInterfaceRequestor> mOuterRequestor;
|
|
|
|
|
2019-04-10 02:15:02 +03:00
|
|
|
// Array of weak references to nsIBrowserChild. We do not want to keep
|
2019-04-10 01:39:01 +03:00
|
|
|
// BrowserChild actors alive for long after their ActorDestroy() methods are
|
2019-04-10 02:15:02 +03:00
|
|
|
// called.
|
2019-04-10 01:39:01 +03:00
|
|
|
nsTArray<nsWeakPtr> mBrowserChildList;
|
2018-01-30 12:12:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// Only set if we have a custom overriden load group
|
|
|
|
RefPtr<InterfaceRequestor> mInterfaceRequestor;
|
|
|
|
|
|
|
|
nsAutoPtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
|
2019-04-12 08:31:25 +03:00
|
|
|
nsAutoPtr<mozilla::ipc::PrincipalInfo> mStoragePrincipalInfo;
|
2018-01-30 12:12:04 +03:00
|
|
|
nsCString mDomain;
|
|
|
|
nsString mOrigin; // Derived from mPrincipal; can be used on worker thread.
|
|
|
|
|
|
|
|
nsString mServiceWorkerCacheName;
|
|
|
|
Maybe<ServiceWorkerDescriptor> mServiceWorkerDescriptor;
|
2018-02-14 22:23:15 +03:00
|
|
|
Maybe<ServiceWorkerRegistrationDescriptor>
|
|
|
|
mServiceWorkerRegistrationDescriptor;
|
2018-01-30 12:12:04 +03:00
|
|
|
|
|
|
|
Maybe<ServiceWorkerDescriptor> mParentController;
|
|
|
|
|
|
|
|
ChannelInfo mChannelInfo;
|
|
|
|
nsLoadFlags mLoadFlags;
|
|
|
|
|
|
|
|
uint64_t mWindowID;
|
|
|
|
|
2019-06-13 23:37:34 +03:00
|
|
|
nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
|
2018-01-30 12:12:04 +03:00
|
|
|
bool mFromWindow;
|
|
|
|
bool mEvalAllowed;
|
|
|
|
bool mReportCSPViolations;
|
|
|
|
bool mXHRParamsAllowed;
|
|
|
|
bool mPrincipalIsSystem;
|
2019-05-08 22:27:32 +03:00
|
|
|
bool mWatchedByDevtools;
|
2019-05-27 17:06:49 +03:00
|
|
|
StorageAccess mStorageAccess;
|
2018-07-10 11:09:59 +03:00
|
|
|
bool mFirstPartyStorageAccessGranted;
|
2018-01-30 12:12:04 +03:00
|
|
|
bool mServiceWorkersTestingInWindow;
|
|
|
|
OriginAttributes mOriginAttributes;
|
|
|
|
|
2018-11-20 02:18:21 +03:00
|
|
|
enum {
|
|
|
|
eNotSet,
|
|
|
|
eInsecureContext,
|
|
|
|
eSecureContext,
|
|
|
|
} mSecureContext;
|
|
|
|
|
2018-11-21 23:02:51 +03:00
|
|
|
WorkerLoadInfoData();
|
|
|
|
WorkerLoadInfoData(WorkerLoadInfoData&& aOther) = default;
|
|
|
|
|
|
|
|
WorkerLoadInfoData& operator=(WorkerLoadInfoData&& aOther) = default;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct WorkerLoadInfo : WorkerLoadInfoData {
|
2018-01-30 12:12:04 +03:00
|
|
|
WorkerLoadInfo();
|
2018-11-21 23:02:51 +03:00
|
|
|
WorkerLoadInfo(WorkerLoadInfo&& aOther) noexcept;
|
2018-01-30 12:12:04 +03:00
|
|
|
~WorkerLoadInfo();
|
|
|
|
|
2018-11-21 23:02:51 +03:00
|
|
|
WorkerLoadInfo& operator=(WorkerLoadInfo&& aOther) = default;
|
2018-01-30 12:12:04 +03:00
|
|
|
|
2019-05-22 02:14:50 +03:00
|
|
|
nsresult SetPrincipalsAndCSPOnMainThread(nsIPrincipal* aPrincipal,
|
|
|
|
nsIPrincipal* aStoragePrincipal,
|
|
|
|
nsILoadGroup* aLoadGroup,
|
|
|
|
nsIContentSecurityPolicy* aCSP);
|
2018-01-30 12:12:04 +03:00
|
|
|
|
2019-04-12 08:31:25 +03:00
|
|
|
nsresult GetPrincipalsAndLoadGroupFromChannel(
|
|
|
|
nsIChannel* aChannel, nsIPrincipal** aPrincipalOut,
|
|
|
|
nsIPrincipal** aStoragePrincipalOut, nsILoadGroup** aLoadGroupOut);
|
2018-01-30 12:12:04 +03:00
|
|
|
|
2019-05-22 02:14:50 +03:00
|
|
|
nsresult SetPrincipalsAndCSPFromChannel(nsIChannel* aChannel);
|
2018-01-30 12:12:04 +03:00
|
|
|
|
|
|
|
bool FinalChannelPrincipalIsValid(nsIChannel* aChannel);
|
|
|
|
|
|
|
|
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
|
|
|
|
bool PrincipalIsValid() const;
|
|
|
|
|
|
|
|
bool PrincipalURIMatchesScriptURL();
|
|
|
|
#endif
|
|
|
|
|
2018-01-31 10:24:08 +03:00
|
|
|
bool ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate);
|
2018-01-30 12:12:04 +03:00
|
|
|
|
2018-01-31 10:24:08 +03:00
|
|
|
bool ProxyReleaseMainThreadObjects(
|
|
|
|
WorkerPrivate* aWorkerPrivate,
|
2018-01-30 12:12:04 +03:00
|
|
|
nsCOMPtr<nsILoadGroup>& aLoadGroupToCancel);
|
|
|
|
};
|
|
|
|
|
2018-01-31 10:21:46 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
2018-01-30 12:12:04 +03:00
|
|
|
|
|
|
|
#endif // mozilla_dom_workers_WorkerLoadInfo_h
|