no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / dom / worklet / WorkletGlobalScope.h
blob7cb86f12d4a8dbbe664a3e3a72330b9ca409f388
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/. */
7 #ifndef mozilla_dom_WorkletGlobalScope_h
8 #define mozilla_dom_WorkletGlobalScope_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/Maybe.h"
12 #include "mozilla/TimeStamp.h"
13 #include "mozilla/dom/BindingDeclarations.h"
14 #include "nsDOMNavigationTiming.h"
15 #include "nsIGlobalObject.h"
16 #include "nsWrapperCache.h"
18 #define WORKLET_IID \
19 { \
20 0x1b3f62e7, 0xe357, 0x44be, { \
21 0xbf, 0xe0, 0xdf, 0x85, 0xe6, 0x56, 0x85, 0xac \
22 } \
25 namespace JS {
26 class RealmOptions;
29 namespace JS::loader {
30 class ModuleLoaderBase;
33 namespace mozilla {
35 class ErrorResult;
36 class WorkletImpl;
38 namespace dom {
40 namespace loader {
41 class WorkletModuleLoader;
44 class Console;
46 class WorkletGlobalScope : public nsIGlobalObject, public nsWrapperCache {
47 public:
48 NS_DECLARE_STATIC_IID_ACCESSOR(WORKLET_IID)
50 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
51 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(WorkletGlobalScope)
53 WorkletGlobalScope(WorkletImpl*);
55 nsIGlobalObject* GetParentObject() const { return nullptr; }
57 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
58 virtual bool WrapGlobalObject(JSContext* aCx,
59 JS::MutableHandle<JSObject*> aReflector) = 0;
61 JSObject* GetGlobalJSObject() override { return GetWrapper(); }
62 JSObject* GetGlobalJSObjectPreserveColor() const override {
63 return GetWrapperPreserveColor();
66 nsISerialEventTarget* SerialEventTarget() const final;
67 nsresult Dispatch(already_AddRefed<nsIRunnable>&&) const final;
69 already_AddRefed<Console> GetConsole(JSContext* aCx, ErrorResult& aRv);
71 WorkletImpl* Impl() const { return mImpl.get(); }
73 void Dump(const Optional<nsAString>& aString) const;
75 DOMHighResTimeStamp TimeStampToDOMHighRes(const TimeStamp& aTimeStamp) const {
76 MOZ_ASSERT(!aTimeStamp.IsNull());
77 TimeDuration duration = aTimeStamp - mCreationTimeStamp;
78 return duration.ToMilliseconds();
81 void InitModuleLoader(loader::WorkletModuleLoader* aModuleLoader);
83 JS::loader::ModuleLoaderBase* GetModuleLoader(
84 JSContext* aCx = nullptr) override;
86 OriginTrials Trials() const override;
87 Maybe<nsID> GetAgentClusterId() const override;
88 bool IsSharedMemoryAllowed() const override;
89 bool ShouldResistFingerprinting(RFPTarget aTarget) const override;
91 protected:
92 ~WorkletGlobalScope();
94 JS::RealmOptions CreateRealmOptions() const;
96 const RefPtr<WorkletImpl> mImpl;
98 private:
99 TimeStamp mCreationTimeStamp;
100 RefPtr<Console> mConsole;
101 RefPtr<loader::WorkletModuleLoader> mModuleLoader;
104 NS_DEFINE_STATIC_IID_ACCESSOR(WorkletGlobalScope, WORKLET_IID)
106 } // namespace dom
107 } // namespace mozilla
109 #endif // mozilla_dom_WorkletGlobalScope_h