| Index: third_party/WebKit/Source/core/workers/ThreadedWorkletMessagingProxy.cpp
|
| diff --git a/third_party/WebKit/Source/core/workers/ThreadedWorkletMessagingProxy.cpp b/third_party/WebKit/Source/core/workers/ThreadedWorkletMessagingProxy.cpp
|
| index cf38c7bf066aa0296bf946b9d00c5807689826f9..8318d2f876c5bda4c9254f22ec3bf335f28e8375 100644
|
| --- a/third_party/WebKit/Source/core/workers/ThreadedWorkletMessagingProxy.cpp
|
| +++ b/third_party/WebKit/Source/core/workers/ThreadedWorkletMessagingProxy.cpp
|
| @@ -9,6 +9,7 @@
|
| #include "core/dom/SecurityContext.h"
|
| #include "core/dom/TaskRunnerHelper.h"
|
| #include "core/frame/csp/ContentSecurityPolicy.h"
|
| +#include "core/loader/WorkletScriptLoader.h"
|
| #include "core/origin_trials/OriginTrialContext.h"
|
| #include "core/workers/ThreadedWorkletObjectProxy.h"
|
| #include "core/workers/WorkerInspectorProxy.h"
|
| @@ -19,6 +20,41 @@
|
|
|
| namespace blink {
|
|
|
| +namespace {
|
| +
|
| +// TODO(nhiroki): This will be replaced with WorkletModuleTreeClient when module
|
| +// loading is ready for threaded worklets.
|
| +class LoaderClient final : public GarbageCollected<LoaderClient>,
|
| + public WorkletScriptLoader::Client {
|
| + USING_GARBAGE_COLLECTED_MIXIN(LoaderClient);
|
| +
|
| + public:
|
| + LoaderClient(WorkletPendingTasks* pending_tasks,
|
| + ThreadedWorkletMessagingProxy* proxy)
|
| + : pending_tasks_(pending_tasks), proxy_(proxy) {}
|
| +
|
| + // WorkletScriptLoader::Client
|
| + void NotifyWorkletScriptLoadingFinished(
|
| + WorkletScriptLoader* script_loader,
|
| + const ScriptSourceCode& source_code) final {
|
| + DCHECK(IsMainThread());
|
| + if (!script_loader->WasScriptLoadSuccessful()) {
|
| + pending_tasks_->Abort();
|
| + return;
|
| + }
|
| + proxy_->EvaluateScript(source_code);
|
| + pending_tasks_->DecrementCounter();
|
| + }
|
| +
|
| + DEFINE_INLINE_TRACE() { visitor->Trace(pending_tasks_); }
|
| +
|
| + private:
|
| + Member<WorkletPendingTasks> pending_tasks_;
|
| + ThreadedWorkletMessagingProxy* proxy_;
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| ThreadedWorkletMessagingProxy::ThreadedWorkletMessagingProxy(
|
| ExecutionContext* execution_context)
|
| : ThreadedMessagingProxyBase(execution_context), weak_ptr_factory_(this) {
|
| @@ -57,8 +93,20 @@ void ThreadedWorkletMessagingProxy::Initialize() {
|
| script_url);
|
| }
|
|
|
| +void ThreadedWorkletMessagingProxy::FetchAndInvokeScript(
|
| + const KURL& module_url_record,
|
| + WebURLRequest::FetchCredentialsMode credentials_mode,
|
| + WorkletPendingTasks* pending_tasks) {
|
| + DCHECK(IsMainThread());
|
| + LoaderClient* client = new LoaderClient(pending_tasks, this);
|
| + WorkletScriptLoader* script_loader = WorkletScriptLoader::Create(
|
| + ToDocument(GetExecutionContext())->Fetcher(), client);
|
| + script_loader->FetchScript(module_url_record);
|
| +}
|
| +
|
| void ThreadedWorkletMessagingProxy::EvaluateScript(
|
| const ScriptSourceCode& script_source_code) {
|
| + DCHECK(IsMainThread());
|
| TaskRunnerHelper::Get(TaskType::kMiscPlatformAPI, GetWorkerThread())
|
| ->PostTask(
|
| BLINK_FROM_HERE,
|
| @@ -69,6 +117,7 @@ void ThreadedWorkletMessagingProxy::EvaluateScript(
|
| }
|
|
|
| void ThreadedWorkletMessagingProxy::TerminateWorkletGlobalScope() {
|
| + DCHECK(IsMainThread());
|
| TerminateGlobalScope();
|
| }
|
|
|
|
|