tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

WorkerLoadInfo.h (5970B)


      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/. */
      6 
      7 #ifndef mozilla_dom_workers_WorkerLoadInfo_h
      8 #define mozilla_dom_workers_WorkerLoadInfo_h
      9 
     10 #include "mozilla/OriginAttributes.h"
     11 #include "mozilla/OriginTrials.h"
     12 #include "mozilla/StorageAccess.h"
     13 #include "mozilla/UniquePtr.h"
     14 #include "mozilla/dom/ChannelInfo.h"
     15 #include "mozilla/dom/ServiceWorkerRegistrationDescriptor.h"
     16 #include "mozilla/dom/WorkerCSPContext.h"
     17 #include "mozilla/dom/WorkerCommon.h"
     18 #include "mozilla/net/NeckoChannelParams.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"
     25 #include "nsTArray.h"
     26 
     27 class nsIChannel;
     28 class nsIContentSecurityPolicy;
     29 class nsICookieJarSettings;
     30 class nsILoadGroup;
     31 class nsIPrincipal;
     32 class nsIReferrerInfo;
     33 class nsIRunnable;
     34 class nsIScriptContext;
     35 class nsIBrowserChild;
     36 class nsIURI;
     37 class nsPIDOMWindowInner;
     38 
     39 namespace mozilla {
     40 
     41 namespace ipc {
     42 class PrincipalInfo;
     43 }  // namespace ipc
     44 
     45 namespace dom {
     46 
     47 class WorkerPrivate;
     48 
     49 struct WorkerLoadInfoData {
     50  // All of these should be released in
     51  // WorkerPrivateParent::ForgetMainThreadObjects.
     52  nsCOMPtr<nsIURI> mBaseURI;
     53  nsCOMPtr<nsIURI> mResolvedScriptURI;
     54 
     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;
     62 
     63  // Taken from the parent context.
     64  nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
     65 
     66  // The CookieJarSettingsArgs of mCookieJarSettings.
     67  // This is specific for accessing on worker thread.
     68  net::CookieJarSettingsArgs mCookieJarSettingsArgs;
     69 
     70  nsCOMPtr<nsIScriptContext> mScriptContext;
     71  nsCOMPtr<nsPIDOMWindowInner> mWindow;
     72  nsCOMPtr<nsIContentSecurityPolicy> mCSP;
     73  UniquePtr<WorkerCSPContext> mCSPContext;
     74 
     75  nsCOMPtr<nsIChannel> mChannel;
     76  nsCOMPtr<nsILoadGroup> mLoadGroup;
     77 
     78  class InterfaceRequestor final : public nsIInterfaceRequestor {
     79    NS_DECL_ISUPPORTS
     80 
     81   public:
     82    InterfaceRequestor(nsIPrincipal* aPrincipal, nsILoadGroup* aLoadGroup);
     83    void MaybeAddBrowserChild(nsILoadGroup* aLoadGroup);
     84    NS_IMETHOD GetInterface(const nsIID& aIID, void** aSink) override;
     85 
     86    void SetOuterRequestor(nsIInterfaceRequestor* aOuterRequestor) {
     87      MOZ_ASSERT(!mOuterRequestor);
     88      MOZ_ASSERT(aOuterRequestor);
     89      mOuterRequestor = aOuterRequestor;
     90    }
     91 
     92   private:
     93    ~InterfaceRequestor() = default;
     94 
     95    already_AddRefed<nsIBrowserChild> GetAnyLiveBrowserChild();
     96 
     97    nsCOMPtr<nsILoadContext> mLoadContext;
     98    nsCOMPtr<nsIInterfaceRequestor> mOuterRequestor;
     99 
    100    // Array of weak references to nsIBrowserChild.  We do not want to keep
    101    // BrowserChild actors alive for long after their ActorDestroy() methods are
    102    // called.
    103    nsTArray<nsWeakPtr> mBrowserChildList;
    104  };
    105 
    106  // Only set if we have a custom overriden load group
    107  RefPtr<InterfaceRequestor> mInterfaceRequestor;
    108 
    109  UniquePtr<mozilla::ipc::PrincipalInfo> mPrincipalInfo;
    110  UniquePtr<mozilla::ipc::PrincipalInfo> mPartitionedPrincipalInfo;
    111  nsCString mDomain;
    112 
    113  nsString mServiceWorkerCacheName;
    114  Maybe<ServiceWorkerDescriptor> mServiceWorkerDescriptor;
    115  Maybe<ServiceWorkerRegistrationDescriptor>
    116      mServiceWorkerRegistrationDescriptor;
    117  Maybe<ClientInfo> mSourceInfo;
    118 
    119  Maybe<ServiceWorkerDescriptor> mParentController;
    120 
    121  nsID mAgentClusterId;
    122 
    123  ChannelInfo mChannelInfo;
    124  nsLoadFlags mLoadFlags;
    125 
    126  uint64_t mWindowID;
    127  uint64_t mAssociatedBrowsingContextID;
    128 
    129  nsCOMPtr<nsIReferrerInfo> mReferrerInfo;
    130  OriginTrials mTrials;
    131  bool mFromWindow;
    132  bool mXHRParamsAllowed;
    133  bool mWatchedByDevTools;
    134  StorageAccess mStorageAccess;
    135  bool mUseRegularPrincipal;
    136  bool mUsingStorageAccess;
    137  bool mServiceWorkersTestingInWindow;
    138  bool mShouldResistFingerprinting;
    139  Maybe<RFPTargetSet> mOverriddenFingerprintingSettings;
    140  OriginAttributes mOriginAttributes;
    141  bool mIsThirdPartyContext;
    142  bool mIsOn3PCBExceptionList;
    143 
    144  enum {
    145    eNotSet,
    146    eInsecureContext,
    147    eSecureContext,
    148  } mSecureContext;
    149 
    150  WorkerLoadInfoData();
    151  WorkerLoadInfoData(WorkerLoadInfoData&& aOther) = default;
    152 
    153  WorkerLoadInfoData& operator=(WorkerLoadInfoData&& aOther) = default;
    154 };
    155 
    156 struct WorkerLoadInfo : WorkerLoadInfoData {
    157  WorkerLoadInfo();
    158  WorkerLoadInfo(WorkerLoadInfo&& aOther) noexcept;
    159  ~WorkerLoadInfo();
    160 
    161  WorkerLoadInfo& operator=(WorkerLoadInfo&& aOther) = default;
    162 
    163  nsresult SetPrincipalsAndCSPOnMainThread(nsIPrincipal* aPrincipal,
    164                                           nsIPrincipal* aPartitionedPrincipal,
    165                                           nsILoadGroup* aLoadGroup,
    166                                           nsIContentSecurityPolicy* aCSP);
    167 
    168  nsresult GetPrincipalsAndLoadGroupFromChannel(
    169      nsIChannel* aChannel, nsIPrincipal** aPrincipalOut,
    170      nsIPrincipal** aPartitionedPrincipalOut, nsILoadGroup** aLoadGroupOut);
    171 
    172  nsresult SetPrincipalsAndCSPFromChannel(nsIChannel* aChannel);
    173 
    174  bool FinalChannelPrincipalIsValid(nsIChannel* aChannel);
    175 
    176 #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
    177  bool PrincipalIsValid() const;
    178 
    179  bool PrincipalURIMatchesScriptURL();
    180 #endif
    181 
    182  bool ProxyReleaseMainThreadObjects(WorkerPrivate* aWorkerPrivate);
    183 
    184  bool ProxyReleaseMainThreadObjects(
    185      WorkerPrivate* aWorkerPrivate,
    186      nsCOMPtr<nsILoadGroup>&& aLoadGroupToCancel);
    187 };
    188 
    189 }  // namespace dom
    190 }  // namespace mozilla
    191 
    192 #endif  // mozilla_dom_workers_WorkerLoadInfo_h