| 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 ThreadedWorklet_h | 5 #ifndef ThreadedWorklet_h |
| 6 #define ThreadedWorklet_h | 6 #define ThreadedWorklet_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 "core/loader/WorkletScriptLoader.h" | |
| 13 #include "platform/heap/Handle.h" | 12 #include "platform/heap/Handle.h" |
| 14 | 13 |
| 15 namespace blink { | 14 namespace blink { |
| 16 | 15 |
| 17 class LocalFrame; | 16 class LocalFrame; |
| 18 class WorkletGlobalScopeProxy; | 17 class WorkletGlobalScopeProxy; |
| 19 | 18 |
| 20 // A ThreadedWorklet is a worklet that runs off the main thread. | 19 // A ThreadedWorklet is a worklet that runs off the main thread. |
| 21 // TODO(nhiroki): This is a temporary class to keep classic script loading for | 20 // TODO(nhiroki): This is a temporary class to keep classic script loading for |
| 22 // threaded worklets while module loading is being implemented for main thread | 21 // threaded worklets while module loading is being implemented for main thread |
| 23 // worklets. This and MainThreadWorklet will be merged into the base Worklet | 22 // worklets. This and MainThreadWorklet will be merged into the base Worklet |
| 24 // class once threaded worklets are also ready to use module loading. | 23 // class once threaded worklets are also ready to use module loading. |
| 25 class CORE_EXPORT ThreadedWorklet : public Worklet, | 24 class CORE_EXPORT ThreadedWorklet : public Worklet { |
| 26 public WorkletScriptLoader::Client { | |
| 27 USING_GARBAGE_COLLECTED_MIXIN(ThreadedWorklet); | 25 USING_GARBAGE_COLLECTED_MIXIN(ThreadedWorklet); |
| 28 WTF_MAKE_NONCOPYABLE(ThreadedWorklet); | 26 WTF_MAKE_NONCOPYABLE(ThreadedWorklet); |
| 29 | 27 |
| 30 public: | 28 public: |
| 31 virtual ~ThreadedWorklet() = default; | 29 virtual ~ThreadedWorklet() = default; |
| 32 | 30 |
| 33 // WorkletScriptLoader::Client | |
| 34 void NotifyWorkletScriptLoadingFinished(WorkletScriptLoader*, | |
| 35 const ScriptSourceCode&) final; | |
| 36 | |
| 37 // ContextLifecycleObserver | 31 // ContextLifecycleObserver |
| 38 void ContextDestroyed(ExecutionContext*) final; | 32 void ContextDestroyed(ExecutionContext*) final; |
| 39 | 33 |
| 40 // Returns a proxy to WorkletGlobalScope on the context thread. | 34 // Returns a proxy to WorkletGlobalScope on the context thread. |
| 41 virtual WorkletGlobalScopeProxy* GetWorkletGlobalScopeProxy() const = 0; | 35 virtual WorkletGlobalScopeProxy* GetWorkletGlobalScopeProxy() const = 0; |
| 42 | 36 |
| 43 DECLARE_VIRTUAL_TRACE(); | 37 DECLARE_VIRTUAL_TRACE(); |
| 44 | 38 |
| 45 protected: | 39 protected: |
| 46 explicit ThreadedWorklet(LocalFrame*); | 40 explicit ThreadedWorklet(LocalFrame*); |
| 47 | 41 |
| 48 private: | 42 private: |
| 49 // Worklet | 43 // Worklet |
| 50 void FetchAndInvokeScript(const KURL& module_url_record, | 44 void FetchAndInvokeScript(const KURL& module_url_record, |
| 51 const WorkletOptions&, | 45 const WorkletOptions&, |
| 52 ScriptPromiseResolver*) override; | 46 ScriptPromiseResolver*) override; |
| 53 | 47 |
| 54 // Called when addModule() is called for the first time. | 48 // Called when addModule() is called for the first time. |
| 55 virtual void Initialize() = 0; | 49 virtual void Initialize() = 0; |
| 56 virtual bool IsInitialized() const = 0; | 50 virtual bool IsInitialized() const = 0; |
| 57 | |
| 58 HeapHashMap<Member<WorkletScriptLoader>, Member<ScriptPromiseResolver>> | |
| 59 loader_to_resolver_map_; | |
| 60 }; | 51 }; |
| 61 | 52 |
| 62 } // namespace blink | 53 } // namespace blink |
| 63 | 54 |
| 64 #endif // ThreadedWorklet_h | 55 #endif // ThreadedWorklet_h |
| OLD | NEW |