Line data Source code
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_Worklet_h
8 : #define mozilla_dom_Worklet_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/ErrorResult.h"
12 : #include "nsRefPtrHashtable.h"
13 : #include "nsWrapperCache.h"
14 : #include "nsCOMPtr.h"
15 :
16 : class nsPIDOMWindowInner;
17 : class nsIPrincipal;
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 : class Promise;
23 : class WorkletGlobalScope;
24 : class WorkletFetchHandler;
25 : enum class CallerType : uint32_t;
26 :
27 : class Worklet final : public nsISupports
28 : , public nsWrapperCache
29 : {
30 : public:
31 : NS_DECL_CYCLE_COLLECTING_ISUPPORTS
32 2 : NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Worklet)
33 :
34 : enum WorkletType {
35 : eAudioWorklet,
36 : ePaintWorklet,
37 : };
38 :
39 : Worklet(nsPIDOMWindowInner* aWindow, nsIPrincipal* aPrincipal,
40 : WorkletType aWorkletType);
41 :
42 0 : nsPIDOMWindowInner* GetParentObject() const
43 : {
44 0 : return mWindow;
45 : }
46 :
47 : virtual JSObject*
48 : WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
49 :
50 : already_AddRefed<Promise>
51 : Import(const nsAString& aModuleURL, CallerType aCallerType,
52 : ErrorResult& aRv);
53 :
54 : WorkletGlobalScope*
55 : GetOrCreateGlobalScope(JSContext* aCx);
56 :
57 : private:
58 : ~Worklet();
59 :
60 : WorkletFetchHandler*
61 : GetImportFetchHandler(const nsACString& aURI);
62 :
63 : void
64 : AddImportFetchHandler(const nsACString& aURI, WorkletFetchHandler* aHandler);
65 :
66 : nsCOMPtr<nsPIDOMWindowInner> mWindow;
67 : nsCOMPtr<nsIPrincipal> mPrincipal;
68 :
69 : WorkletType mWorkletType;
70 :
71 : RefPtr<WorkletGlobalScope> mScope;
72 : nsRefPtrHashtable<nsCStringHashKey, WorkletFetchHandler> mImportHandlers;
73 :
74 : friend class WorkletFetchHandler;
75 : };
76 :
77 : } // namespace dom
78 : } // namespace mozilla
79 :
80 : #endif // mozilla_dom_Worklet_h
|