Index: third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp |
diff --git a/third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp b/third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp |
index c91165cfbcdabafb90c1713a189f6cdbbd77fa73..4d20ca7c9e0e41accc19df433ac856f2498065d9 100644 |
--- a/third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp |
+++ b/third_party/WebKit/Source/core/workers/MainThreadWorkletGlobalScope.cpp |
@@ -7,14 +7,62 @@ |
#include "bindings/core/v8/ScriptSourceCode.h" |
#include "bindings/core/v8/WorkerOrWorkletScriptController.h" |
#include "core/dom/Document.h" |
+#include "core/dom/Modulator.h" |
+#include "core/dom/ModuleScript.h" |
#include "core/frame/Deprecation.h" |
#include "core/frame/FrameConsole.h" |
#include "core/frame/LocalFrame.h" |
#include "core/inspector/MainThreadDebugger.h" |
+#include "core/loader/modulescript/ModuleScriptFetchRequest.h" |
#include "core/probe/CoreProbes.h" |
+#include "public/platform/WebURLRequest.h" |
namespace blink { |
+class WorkletModuleTreeClient final |
+ : public GarbageCollectedFinalized<WorkletModuleTreeClient>, |
+ public ModuleTreeClient { |
+ USING_GARBAGE_COLLECTED_MIXIN(WorkletModuleTreeClient); |
+ |
+ public: |
+ explicit WorkletModuleTreeClient(WorkletPendingTasks* pending_tasks) |
+ : pending_tasks_(pending_tasks) {} |
+ |
+ // ModuleTreeClient |
+ // Implementation of the second half of the "fetch and invoke a worklet |
+ // script" algorithm: |
+ // https://drafts.css-houdini.org/worklets/#fetch-and-invoke-a-worklet-script |
+ void NotifyModuleTreeLoadFinished(ModuleScript* module_script) final { |
+ DCHECK(IsMainThread()); |
+ if (!module_script) { |
+ // Step 3: "If script is null, then queue a task on outsideSettings's |
+ // responsible event loop to run these steps:" |
+ // The steps are implemented in WorkletPendingTasks::Abort(). |
+ // TODO(nhiroki): Queue a task instead of executing this here. |
+ pending_tasks_->Abort(); |
+ return; |
+ } |
+ |
+ // Step 4: "Run a module script given script." |
+ Script* script = module_script; |
+ script->RunScript(nullptr, nullptr); |
+ |
+ // Step 5: "Queue a task on outsideSettings's responsible event loop to run |
+ // these steps:" |
+ // The steps are implemented in WorkletPendingTasks::DecrementCounter(). |
+ // TODO(nhiroki): Queue a task instead of executing this here. |
+ pending_tasks_->DecrementCounter(); |
+ }; |
+ |
+ DEFINE_INLINE_VIRTUAL_TRACE() { |
+ visitor->Trace(pending_tasks_); |
+ ModuleTreeClient::Trace(visitor); |
+ } |
+ |
+ private: |
+ Member<WorkletPendingTasks> pending_tasks_; |
+}; |
+ |
MainThreadWorkletGlobalScope::MainThreadWorkletGlobalScope( |
LocalFrame* frame, |
const KURL& url, |
@@ -60,10 +108,16 @@ void MainThreadWorkletGlobalScope::FetchAndInvokeScript( |
// moduleURLRecord, moduleResponsesMap, credentialOptions, outsideSettings, |
// and insideSettings when it asynchronously completes." |
// TODO(nhiroki): Replace this with module script loading. |
- WorkletScriptLoader* script_loader = |
- WorkletScriptLoader::Create(GetFrame()->GetDocument()->Fetcher(), this); |
- loader_map_.Set(script_loader, pending_tasks); |
- script_loader->FetchScript(module_url_record); |
+ String nonce = ""; |
+ ParserDisposition parser_state = kNotParserInserted; |
+ WebURLRequest::FetchCredentialsMode credentials_mode = |
+ WebURLRequest::kFetchCredentialsModeOmit; |
+ Modulator* modulator = Modulator::From(ScriptController()->GetScriptState()); |
+ ModuleScriptFetchRequest module_request(module_url_record, nonce, |
+ parser_state, credentials_mode); |
+ |
+ WorkletModuleTreeClient* client = new WorkletModuleTreeClient(pending_tasks); |
+ modulator->FetchTree(module_request, client); |
} |
void MainThreadWorkletGlobalScope::EvaluateScript( |
@@ -73,49 +127,10 @@ void MainThreadWorkletGlobalScope::EvaluateScript( |
NOTREACHED(); |
} |
-// TODO(nhiroki): Add tests for termination. |
void MainThreadWorkletGlobalScope::TerminateWorkletGlobalScope() { |
- for (auto it = loader_map_.begin(); it != loader_map_.end();) { |
- WorkletScriptLoader* script_loader = it->key; |
- // Cancel() eventually calls NotifyWorkletScriptLoadingFinished() and |
- // removes |it| from |loader_map_|, so increment it in advance. |
- ++it; |
- script_loader->Cancel(); |
- } |
Dispose(); |
} |
-// Implementation of the second half of the "fetch and invoke a worklet script" |
-// algorithm: |
-// https://drafts.css-houdini.org/worklets/#fetch-and-invoke-a-worklet-script |
-void MainThreadWorkletGlobalScope::NotifyWorkletScriptLoadingFinished( |
- WorkletScriptLoader* script_loader, |
- const ScriptSourceCode& source_code) { |
- DCHECK(IsMainThread()); |
- auto it = loader_map_.find(script_loader); |
- DCHECK(it != loader_map_.end()); |
- WorkletPendingTasks* pending_tasks = it->value; |
- loader_map_.erase(it); |
- |
- if (!script_loader->WasScriptLoadSuccessful()) { |
- // Step 3: "If script is null, then queue a task on outsideSettings's |
- // responsible event loop to run these steps:" |
- // The steps are implemented in WorkletPendingTasks::Abort(). |
- // TODO(nhiroki): Queue a task instead of executing this here. |
- pending_tasks->Abort(); |
- return; |
- } |
- |
- // Step 4: "Run a module script given script." |
- ScriptController()->Evaluate(source_code); |
- |
- // Step 5: "Queue a task on outsideSettings's responsible event loop to run |
- // these steps:" |
- // The steps are implemented in WorkletPendingTasks::DecrementCounter(). |
- // TODO(nhiroki): Queue a task instead of executing this here. |
- pending_tasks->DecrementCounter(); |
-} |
- |
void MainThreadWorkletGlobalScope::AddConsoleMessage( |
ConsoleMessage* console_message) { |
GetFrame()->Console().AddMessage(console_message); |
@@ -130,7 +145,6 @@ CoreProbeSink* MainThreadWorkletGlobalScope::GetProbeSink() { |
} |
DEFINE_TRACE(MainThreadWorkletGlobalScope) { |
- visitor->Trace(loader_map_); |
WorkletGlobalScope::Trace(visitor); |
ContextClient::Trace(visitor); |
} |