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/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" 17 18 #define WORKLET_IID \ 19 { \ 20 0x1b3f62e7, 0xe357, 0x44be, { \ 21 0xbf, 0xe0, 0xdf, 0x85, 0xe6, 0x56, 0x85, 0xac \ 22 } \ 23 } 24 25 namespace mozilla { 26 27 class ErrorResult; 28 class WorkletImpl; 29 30 namespace dom { 31 32 class Console; 33 34 class WorkletGlobalScope : public nsIGlobalObject, public nsWrapperCache { 35 public: 36 NS_DECLARE_STATIC_IID_ACCESSOR(WORKLET_IID) 37 38 NS_DECL_CYCLE_COLLECTING_ISUPPORTS 39 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(WorkletGlobalScope) 40 41 WorkletGlobalScope(const Maybe<nsID>& aAgentClusterId, 42 bool aSharedMemoryAllowed); 43 GetParentObject()44 nsIGlobalObject* GetParentObject() const { return nullptr; } 45 46 virtual JSObject* WrapObject(JSContext* aCx, 47 JS::Handle<JSObject*> aGivenProto) override; 48 49 virtual bool WrapGlobalObject(JSContext* aCx, 50 JS::MutableHandle<JSObject*> aReflector) = 0; 51 GetGlobalJSObject()52 JSObject* GetGlobalJSObject() override { return GetWrapper(); } GetGlobalJSObjectPreserveColor()53 JSObject* GetGlobalJSObjectPreserveColor() const override { 54 return GetWrapperPreserveColor(); 55 } 56 57 already_AddRefed<Console> GetConsole(JSContext* aCx, ErrorResult& aRv); 58 59 virtual WorkletImpl* Impl() const = 0; 60 61 void Dump(const Optional<nsAString>& aString) const; 62 TimeStampToDOMHighRes(const TimeStamp & aTimeStamp)63 DOMHighResTimeStamp TimeStampToDOMHighRes(const TimeStamp& aTimeStamp) const { 64 MOZ_ASSERT(!aTimeStamp.IsNull()); 65 TimeDuration duration = aTimeStamp - mCreationTimeStamp; 66 return duration.ToMilliseconds(); 67 } 68 GetAgentClusterId()69 Maybe<nsID> GetAgentClusterId() const override { return mAgentClusterId; } 70 IsSharedMemoryAllowed()71 bool IsSharedMemoryAllowed() const override { return mSharedMemoryAllowed; } 72 73 protected: 74 ~WorkletGlobalScope(); 75 ; 76 77 private: 78 TimeStamp mCreationTimeStamp; 79 Maybe<nsID> mAgentClusterId; 80 RefPtr<Console> mConsole; 81 bool mSharedMemoryAllowed; 82 }; 83 84 NS_DEFINE_STATIC_IID_ACCESSOR(WorkletGlobalScope, WORKLET_IID) 85 86 } // namespace dom 87 } // namespace mozilla 88 89 #endif // mozilla_dom_WorkletGlobalScope_h 90