| 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/ScriptPromise.h" | 10 #include "bindings/core/v8/ScriptPromise.h" |
| 11 #include "core/CoreExport.h" | 11 #include "core/CoreExport.h" |
| 12 #include "core/workers/WorkletGlobalScopeManager.h" |
| 12 #include "platform/heap/Handle.h" | 13 #include "platform/heap/Handle.h" |
| 13 | 14 |
| 14 namespace blink { | 15 namespace blink { |
| 15 | 16 |
| 16 class LocalFrame; | 17 class LocalFrame; |
| 17 class ScriptPromiseResolver; | 18 class ScriptPromiseResolver; |
| 19 class WorkletGlobalScopeProxy; |
| 18 | 20 |
| 19 // A MainThreadWorklet is a worklet that runs only on the main thread. | 21 // A MainThreadWorklet is a worklet that runs only on the main thread. |
| 20 // TODO(nhiroki): This is a temporary class to support module loading for main | 22 // TODO(nhiroki): This is a temporary class to support module loading for main |
| 21 // thread worklets. This and ThreadedWorklet will be merged into the base | 23 // thread worklets. This and ThreadedWorklet will be merged into the base |
| 22 // Worklet class once threaded worklets are ready to use module loading. | 24 // Worklet class once threaded worklets are ready to use module loading. |
| 23 class CORE_EXPORT MainThreadWorklet : public Worklet { | 25 class CORE_EXPORT MainThreadWorklet : public Worklet { |
| 24 USING_GARBAGE_COLLECTED_MIXIN(MainThreadWorklet); | 26 USING_GARBAGE_COLLECTED_MIXIN(MainThreadWorklet); |
| 25 WTF_MAKE_NONCOPYABLE(MainThreadWorklet); | 27 WTF_MAKE_NONCOPYABLE(MainThreadWorklet); |
| 26 | 28 |
| 27 public: | 29 public: |
| 28 virtual ~MainThreadWorklet() = default; | 30 virtual ~MainThreadWorklet() = default; |
| 29 | 31 |
| 30 // ContextLifecycleObserver | 32 // ContextLifecycleObserver |
| 31 void ContextDestroyed(ExecutionContext*) final; | 33 void ContextDestroyed(ExecutionContext*) final; |
| 32 | 34 |
| 35 WorkletGlobalScopeManager& GetGlobalScopeManager() { |
| 36 return *global_scope_manager_; |
| 37 } |
| 38 |
| 33 DECLARE_VIRTUAL_TRACE(); | 39 DECLARE_VIRTUAL_TRACE(); |
| 34 | 40 |
| 35 protected: | 41 protected: |
| 36 explicit MainThreadWorklet(LocalFrame*); | 42 explicit MainThreadWorklet(LocalFrame*); |
| 37 | 43 |
| 38 private: | 44 private: |
| 39 // Worklet. | 45 // Worklet. |
| 40 void FetchAndInvokeScript(const KURL& module_url_record, | 46 void FetchAndInvokeScript(const KURL& module_url_record, |
| 41 const WorkletOptions&, | 47 const WorkletOptions&, |
| 42 ScriptPromiseResolver*) override; | 48 ScriptPromiseResolver*) override; |
| 49 |
| 50 // Returns true if there are no global scopes or additional global scopes are |
| 51 // necessary. CreateGlobalScope() will be called in that case. Each worklet |
| 52 // can define how to pool global scopes here. |
| 53 virtual bool NeedsToCreateGlobalScope() = 0; |
| 54 virtual std::unique_ptr<WorkletGlobalScopeProxy> CreateGlobalScope() = 0; |
| 55 |
| 56 Member<WorkletGlobalScopeManager> global_scope_manager_; |
| 43 }; | 57 }; |
| 44 | 58 |
| 45 } // namespace blink | 59 } // namespace blink |
| 46 | 60 |
| 47 #endif // MainThreadWorklet_h | 61 #endif // MainThreadWorklet_h |
| OLD | NEW |