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"
20 0x1b3f62e7, 0xe357, 0x44be, { \
21 0xbf, 0xe0, 0xdf, 0x85, 0xe6, 0x56, 0x85, 0xac \
25 namespace JS::loader
{
26 class ModuleLoaderBase
;
37 class WorkletModuleLoader
;
42 class WorkletGlobalScope
: public nsIGlobalObject
, public nsWrapperCache
{
44 NS_DECLARE_STATIC_IID_ACCESSOR(WORKLET_IID
)
46 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
47 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(WorkletGlobalScope
)
49 WorkletGlobalScope(WorkletImpl
*);
51 nsIGlobalObject
* GetParentObject() const { return nullptr; }
53 virtual JSObject
* WrapObject(JSContext
* aCx
,
54 JS::Handle
<JSObject
*> aGivenProto
) override
;
56 virtual bool WrapGlobalObject(JSContext
* aCx
,
57 JS::MutableHandle
<JSObject
*> aReflector
) = 0;
59 JSObject
* GetGlobalJSObject() override
{ return GetWrapper(); }
60 JSObject
* GetGlobalJSObjectPreserveColor() const override
{
61 return GetWrapperPreserveColor();
64 already_AddRefed
<Console
> GetConsole(JSContext
* aCx
, ErrorResult
& aRv
);
66 WorkletImpl
* Impl() const { return mImpl
.get(); }
68 void Dump(const Optional
<nsAString
>& aString
) const;
70 DOMHighResTimeStamp
TimeStampToDOMHighRes(const TimeStamp
& aTimeStamp
) const {
71 MOZ_ASSERT(!aTimeStamp
.IsNull());
72 TimeDuration duration
= aTimeStamp
- mCreationTimeStamp
;
73 return duration
.ToMilliseconds();
76 void InitModuleLoader(loader::WorkletModuleLoader
* aModuleLoader
);
78 JS::loader::ModuleLoaderBase
* GetModuleLoader(
79 JSContext
* aCx
= nullptr) override
;
81 OriginTrials
Trials() const override
;
82 Maybe
<nsID
> GetAgentClusterId() const override
;
83 bool IsSharedMemoryAllowed() const override
;
84 bool ShouldResistFingerprinting(RFPTarget aTarget
) const override
;
87 ~WorkletGlobalScope();
89 const RefPtr
<WorkletImpl
> mImpl
;
92 TimeStamp mCreationTimeStamp
;
93 RefPtr
<Console
> mConsole
;
94 RefPtr
<loader::WorkletModuleLoader
> mModuleLoader
;
97 NS_DEFINE_STATIC_IID_ACCESSOR(WorkletGlobalScope
, WORKLET_IID
)
100 } // namespace mozilla
102 #endif // mozilla_dom_WorkletGlobalScope_h