OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef Worklet_h | 5 #ifndef Worklet_h |
6 #define Worklet_h | 6 #define Worklet_h |
7 | 7 |
8 #include "bindings/core/v8/ScriptPromise.h" | 8 #include "bindings/core/v8/ScriptPromise.h" |
9 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
10 #include "core/dom/ContextLifecycleObserver.h" | 10 #include "core/dom/ContextLifecycleObserver.h" |
11 #include "core/workers/WorkletOptions.h" | 11 #include "core/workers/WorkletOptions.h" |
12 #include "platform/bindings/ScriptWrappable.h" | 12 #include "platform/bindings/ScriptWrappable.h" |
13 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
14 | 14 |
15 namespace blink { | 15 namespace blink { |
16 | 16 |
17 class LocalFrame; | 17 class LocalFrame; |
18 class ScriptPromiseResolver; | 18 class ScriptPromiseResolver; |
19 class WorkletGlobalScopeProxy; | |
20 | 19 |
21 // This is the base implementation of Worklet interface defined in the spec: | 20 // This is the base implementation of Worklet interface defined in the spec: |
22 // https://drafts.css-houdini.org/worklets/#worklet | 21 // https://drafts.css-houdini.org/worklets/#worklet |
23 // Although some worklets run off the main thread, this must be created and | 22 // Although some worklets run off the main thread, this must be created and |
24 // destroyed on the main thread. | 23 // destroyed on the main thread. |
25 class CORE_EXPORT Worklet : public GarbageCollectedFinalized<Worklet>, | 24 class CORE_EXPORT Worklet : public GarbageCollectedFinalized<Worklet>, |
26 public ScriptWrappable, | 25 public ScriptWrappable, |
27 public ContextLifecycleObserver { | 26 public ContextLifecycleObserver { |
28 DEFINE_WRAPPERTYPEINFO(); | 27 DEFINE_WRAPPERTYPEINFO(); |
29 USING_GARBAGE_COLLECTED_MIXIN(Worklet); | 28 USING_GARBAGE_COLLECTED_MIXIN(Worklet); |
30 WTF_MAKE_NONCOPYABLE(Worklet); | 29 WTF_MAKE_NONCOPYABLE(Worklet); |
31 | 30 |
32 public: | 31 public: |
33 virtual ~Worklet() = default; | 32 virtual ~Worklet() = default; |
34 | 33 |
35 // Worklet.idl | 34 // Worklet.idl |
36 // addModule() imports ES6 module scripts. | 35 // addModule() imports ES6 module scripts. |
37 virtual ScriptPromise addModule(ScriptState*, | 36 virtual ScriptPromise addModule(ScriptState*, |
38 const String& module_url, | 37 const String& module_url, |
39 const WorkletOptions&); | 38 const WorkletOptions&); |
40 | 39 |
41 // Returns a proxy to WorkletGlobalScope on the context thread. | |
42 virtual WorkletGlobalScopeProxy* GetWorkletGlobalScopeProxy() const = 0; | |
43 | |
44 DECLARE_VIRTUAL_TRACE(); | 40 DECLARE_VIRTUAL_TRACE(); |
45 | 41 |
46 protected: | 42 protected: |
47 // The Worklet inherits the url and userAgent from the frame->document(). | 43 // The Worklet inherits the url and userAgent from the frame->document(). |
48 explicit Worklet(LocalFrame*); | 44 explicit Worklet(LocalFrame*); |
49 | 45 |
50 private: | 46 private: |
51 virtual void FetchAndInvokeScript(const KURL& module_url_record, | 47 virtual void FetchAndInvokeScript(const KURL& module_url_record, |
52 const WorkletOptions&, | 48 const WorkletOptions&, |
53 ScriptPromiseResolver*) = 0; | 49 ScriptPromiseResolver*) = 0; |
54 }; | 50 }; |
55 | 51 |
56 } // namespace blink | 52 } // namespace blink |
57 | 53 |
58 #endif // Worklet_h | 54 #endif // Worklet_h |
OLD | NEW |