Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: third_party/WebKit/Source/core/workers/ThreadedWorklet.cpp

Issue 2911093002: Worklet: Move loader client impl from ThreadedWorklet to ThreadedWorkletMessagingProxy
Patch Set: rebase Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/workers/ThreadedWorklet.cpp
diff --git a/third_party/WebKit/Source/core/workers/ThreadedWorklet.cpp b/third_party/WebKit/Source/core/workers/ThreadedWorklet.cpp
index 06b37398f63d07fbc8f78dc885ec1d443a7a29f0..7a873ded155e8b95ad11f0ae5c508c9b85134706 100644
--- a/third_party/WebKit/Source/core/workers/ThreadedWorklet.cpp
+++ b/third_party/WebKit/Source/core/workers/ThreadedWorklet.cpp
@@ -9,16 +9,25 @@
#include "core/dom/DOMException.h"
#include "core/dom/Document.h"
#include "core/dom/ExceptionCode.h"
+#include "core/dom/TaskRunnerHelper.h"
#include "core/frame/LocalFrame.h"
#include "core/workers/WorkletGlobalScopeProxy.h"
+#include "core/workers/WorkletPendingTasks.h"
+#include "platform/WebTaskRunner.h"
#include "platform/wtf/WTF.h"
namespace blink {
ThreadedWorklet::ThreadedWorklet(LocalFrame* frame) : Worklet(frame) {}
+// Implementation of the second half of the "addModule(moduleURL, options)"
+// algorithm:
+// https://drafts.css-houdini.org/worklets/#dom-worklet-addmodule
+// TODO(nhiroki): MainThreadWorklet::FetchAndInvokeScript will be moved to the
+// parent class (i.e., Worklet) and this function will be replaced with it.
+// (https://crbug.com/727194)
void ThreadedWorklet::FetchAndInvokeScript(const KURL& module_url_record,
- const WorkletOptions&,
+ const WorkletOptions& options,
ScriptPromiseResolver* resolver) {
DCHECK(IsMainThread());
if (!GetExecutionContext())
@@ -27,39 +36,60 @@ void ThreadedWorklet::FetchAndInvokeScript(const KURL& module_url_record,
if (!IsInitialized())
Initialize();
- WorkletScriptLoader* script_loader = WorkletScriptLoader::Create(
- ToDocument(GetExecutionContext())->Fetcher(), this);
- loader_to_resolver_map_.Set(script_loader, resolver);
- script_loader->FetchScript(module_url_record);
-}
+ // Step 6: "Let credentialOptions be the credentials member of options."
+ // TODO(nhiroki): Add tests for credentialOptions (https://crbug.com/710837).
+ WebURLRequest::FetchCredentialsMode credentials_mode =
+ ParseCredentialsOption(options.credentials());
-void ThreadedWorklet::NotifyWorkletScriptLoadingFinished(
- WorkletScriptLoader* script_loader,
- const ScriptSourceCode& source_code) {
- DCHECK(IsMainThread());
- ScriptPromiseResolver* resolver = loader_to_resolver_map_.at(script_loader);
- loader_to_resolver_map_.erase(script_loader);
+ // Step 7: "Let outsideSettings be the relevant settings object of this."
+ // In the specification, outsideSettings is used for posting a task to the
+ // document's responsible event loop. In our implementation, we use the
+ // document's UnspecedLoading task runner as that is what we commonly use for
+ // module loading.
+ RefPtr<WebTaskRunner> outside_settings_task_runner =
+ TaskRunnerHelper::Get(TaskType::kUnspecedLoading, GetExecutionContext());
- if (!script_loader->WasScriptLoadSuccessful()) {
- resolver->Reject(DOMException::Create(kNetworkError));
- return;
- }
+ // Step 8: "Let moduleResponsesMap be worklet's module responses map."
+ // TODO(nhiroki): Implement moduleResponsesMap (https://crbug.com/627945).
+
+ // Step 9: "Let workletGlobalScopeType be worklet's worklet global scope
+ // type."
+ // workletGlobalScopeType is encoded into the class name (e.g., PaintWorklet).
+
+ // Step 10: "If the worklet's WorkletGlobalScopes is empty, run the following
+ // steps:"
+ // 10.1: "Create a WorkletGlobalScope given workletGlobalScopeType,
+ // moduleResponsesMap, and outsideSettings."
+ // 10.2: "Add the WorkletGlobalScope to worklet's WorkletGlobalScopes."
+ // "Depending on the type of worklet the user agent may create additional
+ // WorkletGlobalScopes at this time."
+ // TODO(nhiroki): These steps will be supported after MainThreadWorklet and
+ // ThreadedWorklet are merged into Worklet (https://crbug.com/727194)
+
+ // Step 11: "Let pendingTaskStruct be a new pending tasks struct with counter
+ // initialized to the length of worklet's WorkletGlobalScopes."
+ const int kNumberOfGlobalScopes = 1;
+ WorkletPendingTasks* pending_tasks =
+ new WorkletPendingTasks(kNumberOfGlobalScopes, resolver);
- GetWorkletGlobalScopeProxy()->EvaluateScript(source_code);
- resolver->Resolve();
+ // Step 12: "For each workletGlobalScope in the worklet's
+ // WorkletGlobalScopes, queue a task on the workletGlobalScope to fetch and
+ // invoke a worklet script given workletGlobalScope, moduleURLRecord,
+ // moduleResponsesMap, credentialOptions, outsideSettings, pendingTaskStruct,
+ // and promise."
+ // TODO(nhiroki): Queue a task instead of executing this here.
+ GetWorkletGlobalScopeProxy()->FetchAndInvokeScript(
+ module_url_record, credentials_mode,
+ std::move(outside_settings_task_runner), pending_tasks);
}
void ThreadedWorklet::ContextDestroyed(ExecutionContext* execution_context) {
DCHECK(IsMainThread());
- for (const auto& script_loader : loader_to_resolver_map_.Keys())
- script_loader->Cancel();
- loader_to_resolver_map_.clear();
if (IsInitialized())
GetWorkletGlobalScopeProxy()->TerminateWorkletGlobalScope();
}
DEFINE_TRACE(ThreadedWorklet) {
- visitor->Trace(loader_to_resolver_map_);
Worklet::Trace(visitor);
}

Powered by Google App Engine
This is Rietveld 408576698