tor-browser

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

SystemGlobal.h (3345B)


      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
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #ifndef SystemGlobal_h__
      8 #define SystemGlobal_h__
      9 
     10 #include "js/loader/ModuleLoaderBase.h"
     11 #include "mozilla/BasePrincipal.h"
     12 #include "mozilla/SchedulerGroup.h"
     13 #include "mozilla/StorageAccess.h"
     14 #include "nsISupports.h"
     15 #include "nsWeakReference.h"
     16 #include "nsIGlobalObject.h"
     17 #include "nsIScriptObjectPrincipal.h"
     18 #include "nsIXPCScriptable.h"
     19 
     20 #include "js/HeapAPI.h"
     21 
     22 class nsICookieJarSettings;
     23 class XPCWrappedNative;
     24 
     25 // The shared system global (used by ChromeUtils.importESModule), and also
     26 // the xpcshell's global.
     27 class SystemGlobal final : public nsIGlobalObject,
     28                           public nsIScriptObjectPrincipal,
     29                           public nsIXPCScriptable,
     30                           public nsIClassInfo,
     31                           public nsSupportsWeakReference {
     32 public:
     33  SystemGlobal();
     34 
     35  NS_DECL_ISUPPORTS
     36  NS_DECL_NSIXPCSCRIPTABLE
     37  NS_DECL_NSICLASSINFO
     38 
     39  using ModuleLoaderBase = JS::loader::ModuleLoaderBase;
     40 
     41  nsIPrincipal* GetPrincipal() override { return mPrincipal; }
     42 
     43  nsIPrincipal* GetEffectiveCookiePrincipal() override { return mPrincipal; }
     44 
     45  nsIPrincipal* GetEffectiveStoragePrincipal() override { return mPrincipal; }
     46 
     47  nsIPrincipal* PartitionedPrincipal() override { return mPrincipal; }
     48 
     49  mozilla::Maybe<nsID> GetAgentClusterId() const override {
     50    return mozilla::Some(mAgentClusterId);
     51  }
     52 
     53  mozilla::OriginTrials Trials() const override { return {}; }
     54 
     55  JSObject* GetGlobalJSObject() override;
     56  JSObject* GetGlobalJSObjectPreserveColor() const override;
     57 
     58  ModuleLoaderBase* GetModuleLoader(JSContext* aCx) override {
     59    return mModuleLoader;
     60  }
     61 
     62  nsICookieJarSettings* GetCookieJarSettings() override {
     63    MOZ_ASSERT(NS_IsMainThread());
     64    return mCookieJarSettings;
     65  }
     66 
     67  mozilla::StorageAccess GetStorageAccess() final {
     68    MOZ_ASSERT(NS_IsMainThread());
     69    return mozilla::StorageAccess::eAllow;
     70  }
     71 
     72  mozilla::Result<mozilla::ipc::PrincipalInfo, nsresult> GetStorageKey()
     73      override;
     74 
     75  void ForgetGlobalObject() { mWrapper = nullptr; }
     76 
     77  void SetGlobalObject(JSObject* global);
     78 
     79  void InitModuleLoader(ModuleLoaderBase* aModuleLoader) {
     80    MOZ_ASSERT(!mModuleLoader);
     81    mModuleLoader = aModuleLoader;
     82  }
     83 
     84  nsISerialEventTarget* SerialEventTarget() const final {
     85    return mozilla::GetMainThreadSerialEventTarget();
     86  }
     87  nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const final {
     88    return mozilla::SchedulerGroup::Dispatch(std::move(aRunnable));
     89  }
     90 
     91  bool IsSharedMemoryAllowed() const override { return true; }
     92 
     93  bool ShouldResistFingerprinting(RFPTarget aTarget) const override {
     94    // SystemGlobal is always the System Principal
     95    MOZ_RELEASE_ASSERT(mPrincipal->IsSystemPrincipal());
     96    return false;
     97  }
     98 
     99 private:
    100  virtual ~SystemGlobal() = default;
    101 
    102  const nsID mAgentClusterId;
    103  nsCOMPtr<nsIPrincipal> mPrincipal;
    104  nsCOMPtr<nsICookieJarSettings> mCookieJarSettings;
    105  XPCWrappedNative* mWrapper;
    106 
    107  RefPtr<JS::loader::ModuleLoaderBase> mModuleLoader;
    108 };
    109 
    110 #endif  // SystemGlobal_h__