tor-browser

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

ShadowRealmGlobalScope.h (3148B)


      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 mozilla_dom_ShadowRealmGlobalScope_h
      8 #define mozilla_dom_ShadowRealmGlobalScope_h
      9 
     10 #include "js/TypeDecls.h"
     11 #include "js/loader/ModuleLoaderBase.h"
     12 #include "mozilla/OriginTrials.h"
     13 #include "mozilla/SchedulerGroup.h"
     14 #include "mozilla/dom/BindingDeclarations.h"
     15 #include "nsContentUtils.h"
     16 #include "nsIGlobalObject.h"
     17 #include "nsWrapperCache.h"
     18 
     19 namespace mozilla::dom {
     20 
     21 #define SHADOWREALMGLOBALSCOPE_IID            \
     22  {/* 1b0a59dd-c1cb-429a-bb90-cea17994dba2 */ \
     23   0x1b0a59dd,                                \
     24   0xc1cb,                                    \
     25   0x429a,                                    \
     26   {0xbb, 0x90, 0xce, 0xa1, 0x79, 0x94, 0xdb, 0xa2}}
     27 
     28 // Required for providing the wrapper, as this is the global used inside a Gecko
     29 // backed ShadowRealm, but also required to power module resolution.
     30 class ShadowRealmGlobalScope final : public nsIGlobalObject,
     31                                     public nsWrapperCache {
     32 public:
     33  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     34  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(ShadowRealmGlobalScope)
     35 
     36  NS_INLINE_DECL_STATIC_IID(SHADOWREALMGLOBALSCOPE_IID)
     37 
     38  explicit ShadowRealmGlobalScope(nsIGlobalObject* aCreatingGlobal)
     39      : mCreatingGlobal(aCreatingGlobal) {};
     40 
     41  nsIGlobalObject* GetCreatingGlobal() const { return mCreatingGlobal; }
     42  OriginTrials Trials() const override { return {}; }
     43 
     44  JSObject* GetGlobalJSObject() override { return GetWrapper(); }
     45  JSObject* GetGlobalJSObjectPreserveColor() const override {
     46    return GetWrapperPreserveColor();
     47  }
     48 
     49  virtual JSObject* WrapObject(JSContext* aCx,
     50                               JS::Handle<JSObject*> aGivenProto) override {
     51    MOZ_CRASH("Shouldn't be here");
     52    return nullptr;
     53  }
     54 
     55  JS::loader::ModuleLoaderBase* GetModuleLoader(JSContext* aCx) override;
     56 
     57  bool ShouldResistFingerprinting(RFPTarget aTarget) const override {
     58    return nsContentUtils::ShouldResistFingerprinting(
     59        "Presently we don't have enough context to make an informed decision"
     60        "on JS Sandboxes. See 1782853",
     61        aTarget);
     62  }
     63 
     64  nsISerialEventTarget* SerialEventTarget() const final {
     65    return mozilla::GetMainThreadSerialEventTarget();
     66  }
     67  nsresult Dispatch(already_AddRefed<nsIRunnable>&& aRunnable) const final {
     68    return mozilla::SchedulerGroup::Dispatch(std::move(aRunnable));
     69  }
     70 
     71 private:
     72  virtual ~ShadowRealmGlobalScope() = default;
     73 
     74  RefPtr<JS::loader::ModuleLoaderBase> mModuleLoader;
     75 
     76  // The global which created this ShadowRealm
     77  nsCOMPtr<nsIGlobalObject> mCreatingGlobal;
     78 };
     79 
     80 JSObject* NewShadowRealmGlobal(JSContext* aCx, JS::RealmOptions& aOptions,
     81                               JSPrincipals* aPrincipals,
     82                               JS::Handle<JSObject*> aGlobalObj);
     83 
     84 bool IsShadowRealmGlobal(JSObject* aObject);
     85 
     86 }  // namespace mozilla::dom
     87 
     88 #endif