| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 MainThreadWorklet_h | 5 #ifndef MainThreadWorklet_h |
| 6 #define MainThreadWorklet_h | 6 #define MainThreadWorklet_h |
| 7 | 7 |
| 8 #include "core/workers/Worklet.h" | 8 #include "core/workers/Worklet.h" |
| 9 | 9 |
| 10 #include "bindings/core/v8/ScriptPromiseResolver.h" | 10 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 11 #include "core/CoreExport.h" | 11 #include "core/CoreExport.h" |
| 12 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
| 13 | 13 |
| 14 namespace blink { | 14 namespace blink { |
| 15 | 15 |
| 16 class LocalFrame; | 16 class LocalFrame; |
| 17 class WorkletGlobalScopeProxy; |
| 17 | 18 |
| 18 // A MainThreadWorklet is a worklet that runs only on the main thread. | 19 // A MainThreadWorklet is a worklet that runs only on the main thread. |
| 19 // TODO(nhiroki): This is a temporary class to support module loading for main | 20 // TODO(nhiroki): This is a temporary class to support module loading for main |
| 20 // thread worklets. This and ThreadedWorklet will be merged into the base | 21 // thread worklets. This and ThreadedWorklet will be merged into the base |
| 21 // Worklet class once threaded worklets are ready to use module loading. | 22 // Worklet class once threaded worklets are ready to use module loading. |
| 22 class CORE_EXPORT MainThreadWorklet : public Worklet { | 23 class CORE_EXPORT MainThreadWorklet : public Worklet { |
| 23 USING_GARBAGE_COLLECTED_MIXIN(MainThreadWorklet); | 24 USING_GARBAGE_COLLECTED_MIXIN(MainThreadWorklet); |
| 24 WTF_MAKE_NONCOPYABLE(MainThreadWorklet); | 25 WTF_MAKE_NONCOPYABLE(MainThreadWorklet); |
| 25 | 26 |
| 26 public: | 27 public: |
| 27 virtual ~MainThreadWorklet() = default; | 28 virtual ~MainThreadWorklet() = default; |
| 28 | 29 |
| 29 // Worklet | 30 // Worklet |
| 30 ScriptPromise addModule(ScriptState*, const String& module_url) final; | 31 ScriptPromise addModule(ScriptState*, const String& module_url) final; |
| 31 | 32 |
| 32 // ContextLifecycleObserver | 33 // ContextLifecycleObserver |
| 33 void ContextDestroyed(ExecutionContext*) final; | 34 void ContextDestroyed(ExecutionContext*) final; |
| 34 | 35 |
| 35 DECLARE_VIRTUAL_TRACE(); | 36 DECLARE_VIRTUAL_TRACE(); |
| 36 | 37 |
| 37 protected: | 38 protected: |
| 38 explicit MainThreadWorklet(LocalFrame*); | 39 explicit MainThreadWorklet(LocalFrame*); |
| 40 |
| 41 // Instantiates WorkletGlobalScope and adds it into |global_scope_proxies_| if |
| 42 // there are no global scopes or additional global scopes are necessary. |
| 43 virtual void MayAddWorkletGlobalScopes() = 0; |
| 44 |
| 45 // "A Worklet has a list of the worklet's WorkletGlobalScopes. Initially this |
| 46 // list is empty; it is populated when the user agent chooses to create its |
| 47 // WorkletGlobalScope." |
| 48 WTF::HashSet<std::unique_ptr<WorkletGlobalScopeProxy>> global_scope_proxies_; |
| 39 }; | 49 }; |
| 40 | 50 |
| 41 } // namespace blink | 51 } // namespace blink |
| 42 | 52 |
| 43 #endif // MainThreadWorklet_h | 53 #endif // MainThreadWorklet_h |
| OLD | NEW |