tor-browser

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

WorkletGlobalScope.h (2888B)


      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_WorkletGlobalScope_h
      8 #define mozilla_dom_WorkletGlobalScope_h
      9 
     10 #include "mozilla/Maybe.h"
     11 #include "mozilla/TimeStamp.h"
     12 #include "mozilla/dom/BindingDeclarations.h"
     13 #include "nsDOMNavigationTiming.h"
     14 #include "nsIGlobalObject.h"
     15 #include "nsWrapperCache.h"
     16 
     17 #define WORKLET_IID \
     18  {0x1b3f62e7, 0xe357, 0x44be, {0xbf, 0xe0, 0xdf, 0x85, 0xe6, 0x56, 0x85, 0xac}}
     19 
     20 namespace JS {
     21 class RealmOptions;
     22 }
     23 
     24 namespace JS::loader {
     25 class ModuleLoaderBase;
     26 }
     27 
     28 namespace mozilla {
     29 
     30 class ErrorResult;
     31 class WorkletImpl;
     32 
     33 namespace dom {
     34 
     35 namespace loader {
     36 class WorkletModuleLoader;
     37 }
     38 
     39 class Console;
     40 
     41 class WorkletGlobalScope : public nsIGlobalObject, public nsWrapperCache {
     42 public:
     43  NS_INLINE_DECL_STATIC_IID(WORKLET_IID)
     44 
     45  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     46  NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(WorkletGlobalScope)
     47 
     48  WorkletGlobalScope(WorkletImpl*);
     49 
     50  nsIGlobalObject* GetParentObject() const { return nullptr; }
     51 
     52  JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
     53  virtual bool WrapGlobalObject(JSContext* aCx,
     54                                JS::MutableHandle<JSObject*> aReflector) = 0;
     55 
     56  JSObject* GetGlobalJSObject() override { return GetWrapper(); }
     57  JSObject* GetGlobalJSObjectPreserveColor() const override {
     58    return GetWrapperPreserveColor();
     59  }
     60 
     61  nsISerialEventTarget* SerialEventTarget() const final;
     62  nsresult Dispatch(already_AddRefed<nsIRunnable>&&) const final;
     63 
     64  already_AddRefed<Console> GetConsole(JSContext* aCx, ErrorResult& aRv);
     65 
     66  WorkletImpl* Impl() const { return mImpl.get(); }
     67 
     68  void Dump(const Optional<nsAString>& aString) const;
     69 
     70  DOMHighResTimeStamp TimeStampToDOMHighRes(const TimeStamp& aTimeStamp) const {
     71    MOZ_ASSERT(!aTimeStamp.IsNull());
     72    TimeDuration duration = aTimeStamp - mCreationTimeStamp;
     73    return duration.ToMilliseconds();
     74  }
     75 
     76  void InitModuleLoader(loader::WorkletModuleLoader* aModuleLoader);
     77 
     78  JS::loader::ModuleLoaderBase* GetModuleLoader(
     79      JSContext* aCx = nullptr) override;
     80 
     81  OriginTrials Trials() const override;
     82  Maybe<nsID> GetAgentClusterId() const override;
     83  bool IsSharedMemoryAllowed() const override;
     84  bool ShouldResistFingerprinting(RFPTarget aTarget) const override;
     85 
     86 protected:
     87  ~WorkletGlobalScope();
     88 
     89  JS::RealmOptions CreateRealmOptions() const;
     90 
     91  const RefPtr<WorkletImpl> mImpl;
     92 
     93 private:
     94  TimeStamp mCreationTimeStamp;
     95  RefPtr<Console> mConsole;
     96  RefPtr<loader::WorkletModuleLoader> mModuleLoader;
     97 };
     98 
     99 }  // namespace dom
    100 }  // namespace mozilla
    101 
    102 #endif  // mozilla_dom_WorkletGlobalScope_h