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_Worklet_h
8 #define mozilla_dom_Worklet_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/ErrorResult.h"
12 #include "nsRefPtrHashtable.h"
13 #include "nsWrapperCache.h"
16 class nsPIDOMWindowInner
;
25 class WorkletFetchHandler
;
26 struct WorkletOptions
;
27 enum class CallerType
: uint32_t;
29 class Worklet final
: public nsISupports
, public nsWrapperCache
{
31 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
32 NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Worklet
)
34 // |aOwnedObject| may be provided by the WorkletImpl as a parent thread
35 // object to keep alive and traverse for CC as long as the Worklet has
36 // references remaining.
37 Worklet(nsPIDOMWindowInner
* aWindow
, RefPtr
<WorkletImpl
> aImpl
,
38 nsISupports
* aOwnedObject
= nullptr);
40 nsPIDOMWindowInner
* GetParentObject() const { return mWindow
; }
42 virtual JSObject
* WrapObject(JSContext
* aCx
,
43 JS::Handle
<JSObject
*> aGivenProto
) override
;
45 already_AddRefed
<Promise
> AddModule(JSContext
* aCx
,
46 const nsAString
& aModuleURL
,
47 const WorkletOptions
& aOptions
,
48 CallerType aCallerType
, ErrorResult
& aRv
);
50 WorkletImpl
* Impl() const { return mImpl
; }
55 WorkletFetchHandler
* GetImportFetchHandler(const nsACString
& aURI
);
57 void AddImportFetchHandler(const nsACString
& aURI
,
58 WorkletFetchHandler
* aHandler
);
60 nsCOMPtr
<nsPIDOMWindowInner
> mWindow
;
61 nsCOMPtr
<nsISupports
> mOwnedObject
;
63 nsRefPtrHashtable
<nsCStringHashKey
, WorkletFetchHandler
> mImportHandlers
;
65 const RefPtr
<WorkletImpl
> mImpl
;
67 friend class WorkletFetchHandler
;
71 } // namespace mozilla
73 #endif // mozilla_dom_Worklet_h