Bug 1639230: Remove vendor prefix for printing with webdriver r=jgraham,webdriver...
[gecko.git] / dom / worklet / Worklet.h
bloba0e1f8058cea7d0fc4442f2d711e432252fd7060
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"
14 #include "nsCOMPtr.h"
16 class nsPIDOMWindowInner;
18 namespace mozilla {
20 class WorkletImpl;
22 namespace dom {
24 class Promise;
25 class WorkletFetchHandler;
26 struct WorkletOptions;
27 enum class CallerType : uint32_t;
29 class Worklet final : public nsISupports, public nsWrapperCache {
30 public:
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; }
52 private:
53 ~Worklet();
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;
70 } // namespace dom
71 } // namespace mozilla
73 #endif // mozilla_dom_Worklet_h