Commit 651f257e authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worklet: Merge (MainThread/Threaded)WorkletGlobalScope into WorkletGlobalScope

This is a cleanup CL to merge MainThreadWorkletGlobalScope and
ThreadedWorkletGlobalScope into WorkletGlobalScope for shallowing the class
hierarchy of WorkletGlobalScope and making it more extensible.

========== Details ==========

Before this CL, WorkletGlobalScope has the following class hierarchy.
MainThreadWorkletGlobalScope and ThreadedWorkletGlobalScope implement thread
specific things, for example, GetTaskRunner().

- WorkerOrWorkletGlobalScope
  - WorkletGlobalScope
    - MainThreadWorkletGlobalScope
      - PaintWorkletGlobalScope
      - LayoutWorkletGlobalScope
    - ThreadedWorkletGlobalScope
      - AudioWorkletGlobalScope
      - AnimationWorkletGlobalScope

This separation has been worked well until now because each subclass of
WorkletGlobalScope runs only on a specific thread (i.e., the main thread or a
worker thread). However, the situation has been changed. We started implementing
off-the-main-thread PaintWorklet (See https://crbug.com/829967) and noticed
this separation makes it so difficult to enable PaintWorklet to run on both the
main thread and a worker thread.

To mitigate the difficulty, this CL merges them into WorkletGlobalScope. After
this CL, the class hierarchy looks like this:

- WorkerOrWorkletGlobalScope
  - WorkletGlobalScope
    - PaintWorkletGlobalScope
    - LayoutWorkletGlobalScope
    - AudioWorkletGlobalScope
    - AnimationWorkletGlobalScope

In this new hierarchy, WorkletGlobalScope implements thread specific things, and
provides multiple constructors for its subclasses to specify thread affinity.

Bug: 893478
Change-Id: Iad817c7dd10ce5bd51a4c381fbd34aa1669454f7
Reviewed-on: https://chromium-review.googlesource.com/c/1272416Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarMakoto Shimazu <shimazu@chromium.org>
Reviewed-by: default avatarMatt Falkenhagen <falken@chromium.org>
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#598779}
parent 6b57f8cd
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
#include "third_party/blink/renderer/core/frame/settings.h" #include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/use_counter.h" #include "third_party/blink/renderer/core/frame/use_counter.h"
#include "third_party/blink/renderer/core/html/html_frame_element_base.h" #include "third_party/blink/renderer/core/html/html_frame_element_base.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_global_scope.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/wrapper_creation_security_check.h" #include "third_party/blink/renderer/platform/bindings/wrapper_creation_security_check.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h" #include "third_party/blink/renderer/platform/weborigin/security_origin.h"
......
...@@ -71,10 +71,10 @@ class CORE_EXPORT WorkerOrWorkletScriptController final ...@@ -71,10 +71,10 @@ class CORE_EXPORT WorkerOrWorkletScriptController final
// Used by WorkerThread. Returns true if the context is successfully // Used by WorkerThread. Returns true if the context is successfully
// initialized or already initialized. // initialized or already initialized.
// For WorkerGlobalScope and ThreadedWorkletGlobalScope, |url_for_debugger| is // For WorkerGlobalScope and threaded WorkletGlobalScope, |url_for_debugger|
// and should be used only for setting name/origin that appears in DevTools. // is and should be used only for setting name/origin that appears in
// For other global scopes, |human_readable_name| is used for setting // DevTools. For other global scopes, |human_readable_name| is used for
// DOMWrapperWorld's human readable name. // setting DOMWrapperWorld's human readable name.
bool InitializeContextIfNeeded(const String& human_readable_name, bool InitializeContextIfNeeded(const String& human_readable_name,
const KURL& url_for_debugger); const KURL& url_for_debugger);
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
#include "third_party/blink/renderer/core/loader/document_loader.h" #include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/page/page.h" #include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/timing/memory_info.h" #include "third_party/blink/renderer/core/timing/memory_info.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_global_scope.h" #include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/core/xml/xpath_evaluator.h" #include "third_party/blink/renderer/core/xml/xpath_evaluator.h"
#include "third_party/blink/renderer/core/xml/xpath_result.h" #include "third_party/blink/renderer/core/xml/xpath_result.h"
#include "third_party/blink/renderer/platform/bindings/dom_wrapper_world.h" #include "third_party/blink/renderer/platform/bindings/dom_wrapper_world.h"
...@@ -82,7 +82,7 @@ LocalFrame* ToFrame(ExecutionContext* context) { ...@@ -82,7 +82,7 @@ LocalFrame* ToFrame(ExecutionContext* context) {
if (auto* document = DynamicTo<Document>(context)) if (auto* document = DynamicTo<Document>(context))
return document->GetFrame(); return document->GetFrame();
if (context->IsMainThreadWorkletGlobalScope()) if (context->IsMainThreadWorkletGlobalScope())
return ToMainThreadWorkletGlobalScope(context)->GetFrame(); return ToWorkletGlobalScope(context)->GetFrame();
return nullptr; return nullptr;
} }
} }
...@@ -179,12 +179,11 @@ void MainThreadDebugger::ExceptionThrown(ExecutionContext* context, ...@@ -179,12 +179,11 @@ void MainThreadDebugger::ExceptionThrown(ExecutionContext* context,
script_state = script_state =
event->World() ? ToScriptState(frame, *event->World()) : nullptr; event->World() ? ToScriptState(frame, *event->World()) : nullptr;
} else if (context->IsMainThreadWorkletGlobalScope()) { } else if (context->IsMainThreadWorkletGlobalScope()) {
frame = ToMainThreadWorkletGlobalScope(context)->GetFrame(); frame = ToWorkletGlobalScope(context)->GetFrame();
if (!frame) if (!frame)
return; return;
script_state = ToMainThreadWorkletGlobalScope(context) script_state =
->ScriptController() ToWorkletGlobalScope(context)->ScriptController()->GetScriptState();
->GetScriptState();
} else { } else {
NOTREACHED(); NOTREACHED();
} }
......
...@@ -39,7 +39,6 @@ ...@@ -39,7 +39,6 @@
#include "third_party/blink/renderer/core/inspector/identifiers_factory.h" #include "third_party/blink/renderer/core/inspector/identifiers_factory.h"
#include "third_party/blink/renderer/core/inspector/v8_inspector_string.h" #include "third_party/blink/renderer/core/inspector/v8_inspector_string.h"
#include "third_party/blink/renderer/core/inspector/worker_inspector_controller.h" #include "third_party/blink/renderer/core/inspector/worker_inspector_controller.h"
#include "third_party/blink/renderer/core/workers/threaded_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h" #include "third_party/blink/renderer/core/workers/worker_thread.h"
......
...@@ -44,9 +44,7 @@ LayoutWorkletGlobalScope::LayoutWorkletGlobalScope( ...@@ -44,9 +44,7 @@ LayoutWorkletGlobalScope::LayoutWorkletGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params, std::unique_ptr<GlobalScopeCreationParams> creation_params,
WorkerReportingProxy& reporting_proxy, WorkerReportingProxy& reporting_proxy,
PendingLayoutRegistry* pending_layout_registry) PendingLayoutRegistry* pending_layout_registry)
: MainThreadWorkletGlobalScope(frame, : WorkletGlobalScope(std::move(creation_params), reporting_proxy, frame),
std::move(creation_params),
reporting_proxy),
pending_layout_registry_(pending_layout_registry) {} pending_layout_registry_(pending_layout_registry) {}
LayoutWorkletGlobalScope::~LayoutWorkletGlobalScope() = default; LayoutWorkletGlobalScope::~LayoutWorkletGlobalScope() = default;
...@@ -55,7 +53,7 @@ void LayoutWorkletGlobalScope::Dispose() { ...@@ -55,7 +53,7 @@ void LayoutWorkletGlobalScope::Dispose() {
MainThreadDebugger::Instance()->ContextWillBeDestroyed( MainThreadDebugger::Instance()->ContextWillBeDestroyed(
ScriptController()->GetScriptState()); ScriptController()->GetScriptState());
MainThreadWorkletGlobalScope::Dispose(); WorkletGlobalScope::Dispose();
} }
// https://drafts.css-houdini.org/css-layout-api/#dom-layoutworkletglobalscope-registerlayout // https://drafts.css-houdini.org/css-layout-api/#dom-layoutworkletglobalscope-registerlayout
...@@ -161,7 +159,7 @@ CSSLayoutDefinition* LayoutWorkletGlobalScope::FindDefinition( ...@@ -161,7 +159,7 @@ CSSLayoutDefinition* LayoutWorkletGlobalScope::FindDefinition(
void LayoutWorkletGlobalScope::Trace(blink::Visitor* visitor) { void LayoutWorkletGlobalScope::Trace(blink::Visitor* visitor) {
visitor->Trace(layout_definitions_); visitor->Trace(layout_definitions_);
visitor->Trace(pending_layout_registry_); visitor->Trace(pending_layout_registry_);
MainThreadWorkletGlobalScope::Trace(visitor); WorkletGlobalScope::Trace(visitor);
} }
} // namespace blink } // namespace blink
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "third_party/blink/renderer/core/core_export.h" #include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/layout/custom/pending_layout_registry.h" #include "third_party/blink/renderer/core/layout/custom/pending_layout_registry.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_global_scope.h" #include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
namespace blink { namespace blink {
...@@ -17,8 +17,7 @@ namespace blink { ...@@ -17,8 +17,7 @@ namespace blink {
class CSSLayoutDefinition; class CSSLayoutDefinition;
class WorkerReportingProxy; class WorkerReportingProxy;
class CORE_EXPORT LayoutWorkletGlobalScope final class CORE_EXPORT LayoutWorkletGlobalScope final : public WorkletGlobalScope {
: public MainThreadWorkletGlobalScope {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(LayoutWorkletGlobalScope); USING_GARBAGE_COLLECTED_MIXIN(LayoutWorkletGlobalScope);
......
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include "third_party/blink/renderer/core/loader/modulescript/module_script_loader_registry.h" #include "third_party/blink/renderer/core/loader/modulescript/module_script_loader_registry.h"
#include "third_party/blink/renderer/core/script/modulator.h" #include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/script/module_script.h" #include "third_party/blink/renderer/core/script/module_script.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_global_scope.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource.h" #include "third_party/blink/renderer/platform/loader/fetch/resource.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h" #include "third_party/blink/renderer/platform/loader/fetch/resource_loader_options.h"
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
#include "third_party/blink/renderer/core/testing/dummy_modulator.h" #include "third_party/blink/renderer/core/testing/dummy_modulator.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h" #include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/main_thread_worklet_reporting_proxy.h"
#include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worklet_module_responses_map.h" #include "third_party/blink/renderer/core/workers/worklet_module_responses_map.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
...@@ -157,7 +157,7 @@ class ModuleScriptLoaderTest : public PageTestBase { ...@@ -157,7 +157,7 @@ class ModuleScriptLoaderTest : public PageTestBase {
ScopedTestingPlatformSupport<FetchTestingPlatformSupport> platform_; ScopedTestingPlatformSupport<FetchTestingPlatformSupport> platform_;
std::unique_ptr<MainThreadWorkletReportingProxy> reporting_proxy_; std::unique_ptr<MainThreadWorkletReportingProxy> reporting_proxy_;
Persistent<ModuleScriptLoaderTestModulator> modulator_; Persistent<ModuleScriptLoaderTestModulator> modulator_;
Persistent<MainThreadWorkletGlobalScope> global_scope_; Persistent<WorkletGlobalScope> global_scope_;
}; };
void ModuleScriptLoaderTest::SetUp() { void ModuleScriptLoaderTest::SetUp() {
...@@ -191,8 +191,8 @@ void ModuleScriptLoaderTest::InitializeForWorklet() { ...@@ -191,8 +191,8 @@ void ModuleScriptLoaderTest::InitializeForWorklet() {
OriginTrialContext::GetTokens(&GetDocument()).get(), OriginTrialContext::GetTokens(&GetDocument()).get(),
base::UnguessableToken::Create(), nullptr /* worker_settings */, base::UnguessableToken::Create(), nullptr /* worker_settings */,
kV8CacheOptionsDefault, new WorkletModuleResponsesMap); kV8CacheOptionsDefault, new WorkletModuleResponsesMap);
global_scope_ = new MainThreadWorkletGlobalScope( global_scope_ = new WorkletGlobalScope(std::move(creation_params),
&GetFrame(), std::move(creation_params), *reporting_proxy_); *reporting_proxy_, &GetFrame());
global_scope_->ScriptController()->InitializeContextIfNeeded("Dummy Context", global_scope_->ScriptController()->InitializeContextIfNeeded("Dummy Context",
NullURL()); NullURL());
modulator_ = new ModuleScriptLoaderTestModulator( modulator_ = new ModuleScriptLoaderTestModulator(
......
...@@ -30,8 +30,6 @@ blink_core_sources("workers") { ...@@ -30,8 +30,6 @@ blink_core_sources("workers") {
"global_scope_creation_params.h", "global_scope_creation_params.h",
"installed_scripts_manager.cc", "installed_scripts_manager.cc",
"installed_scripts_manager.h", "installed_scripts_manager.h",
"main_thread_worklet_global_scope.cc",
"main_thread_worklet_global_scope.h",
"main_thread_worklet_reporting_proxy.cc", "main_thread_worklet_reporting_proxy.cc",
"main_thread_worklet_reporting_proxy.h", "main_thread_worklet_reporting_proxy.h",
"parent_execution_context_task_runners.cc", "parent_execution_context_task_runners.cc",
...@@ -51,8 +49,6 @@ blink_core_sources("workers") { ...@@ -51,8 +49,6 @@ blink_core_sources("workers") {
"threaded_messaging_proxy_base.h", "threaded_messaging_proxy_base.h",
"threaded_object_proxy_base.cc", "threaded_object_proxy_base.cc",
"threaded_object_proxy_base.h", "threaded_object_proxy_base.h",
"threaded_worklet_global_scope.cc",
"threaded_worklet_global_scope.h",
"threaded_worklet_messaging_proxy.cc", "threaded_worklet_messaging_proxy.cc",
"threaded_worklet_messaging_proxy.h", "threaded_worklet_messaging_proxy.h",
"threaded_worklet_object_proxy.cc", "threaded_worklet_object_proxy.cc",
......
...@@ -18,7 +18,7 @@ Classes in this directory are named with the following conventions, there're sti ...@@ -18,7 +18,7 @@ Classes in this directory are named with the following conventions, there're sti
- `WorkerOrWorklet` prefix: Classes commonly used for workers and worklets (e.g., `WorkerOrWorkletGlobalScope`). - `WorkerOrWorklet` prefix: Classes commonly used for workers and worklets (e.g., `WorkerOrWorkletGlobalScope`).
- `Worker` / `Worklet` prefix: Classes used for workers or worklets (e.g., `WorkerGlobalScope`). - `Worker` / `Worklet` prefix: Classes used for workers or worklets (e.g., `WorkerGlobalScope`).
- `Threaded` prefix: Classes used for workers and threaded worklets (e.g., `ThreadedMessagingProxyBase`). - `Threaded` prefix: Classes used for workers and threaded worklets (e.g., `ThreadedMessagingProxyBase`).
- `MainThreadWorklet` prefix: Classes used for main thread worklets (e.g., `MainThreadWorkletGlobalScope`). - `MainThreadWorklet` prefix: Classes used for main thread worklets (e.g., `MainThreadWorkletReportingProxy`).
Thread hopping between the main (parent) thread and a worker thread is handled by proxy classes. Thread hopping between the main (parent) thread and a worker thread is handled by proxy classes.
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/workers/main_thread_worklet_global_scope.h"
#include "third_party/blink/renderer/bindings/core/v8/v8_binding_for_core.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/frame/deprecation.h"
#include "third_party/blink/renderer/core/frame/frame_console.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/inspector/main_thread_debugger.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
namespace blink {
MainThreadWorkletGlobalScope::MainThreadWorkletGlobalScope(
LocalFrame* frame,
std::unique_ptr<GlobalScopeCreationParams> creation_params,
WorkerReportingProxy& reporting_proxy)
: WorkletGlobalScope(std::move(creation_params),
ToIsolate(frame),
reporting_proxy),
ContextClient(frame) {
BindContentSecurityPolicyToExecutionContext();
}
MainThreadWorkletGlobalScope::~MainThreadWorkletGlobalScope() = default;
WorkerThread* MainThreadWorkletGlobalScope::GetThread() const {
NOTREACHED();
return nullptr;
}
scoped_refptr<base::SingleThreadTaskRunner>
MainThreadWorkletGlobalScope::GetTaskRunner(TaskType type) {
DCHECK(IsContextThread());
// MainThreadWorkletGlobalScope lives on the main thread and its GetThread()
// doesn't return a valid worker thread. Instead, retrieve a task runner
// from the frame.
return GetFrame()->GetFrameScheduler()->GetTaskRunner(type);
}
void MainThreadWorkletGlobalScope::AddConsoleMessage(
ConsoleMessage* console_message) {
GetFrame()->Console().AddMessage(console_message);
}
void MainThreadWorkletGlobalScope::ExceptionThrown(ErrorEvent* event) {
MainThreadDebugger::Instance()->ExceptionThrown(this, event);
}
CoreProbeSink* MainThreadWorkletGlobalScope::GetProbeSink() {
return probe::ToCoreProbeSink(GetFrame());
}
void MainThreadWorkletGlobalScope::Trace(blink::Visitor* visitor) {
WorkletGlobalScope::Trace(visitor);
ContextClient::Trace(visitor);
}
} // namespace blink
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_MAIN_THREAD_WORKLET_GLOBAL_SCOPE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_MAIN_THREAD_WORKLET_GLOBAL_SCOPE_H_
#include "base/single_thread_task_runner.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/context_lifecycle_observer.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
namespace blink {
class ConsoleMessage;
class LocalFrame;
class WorkerReportingProxy;
class CORE_EXPORT MainThreadWorkletGlobalScope
: public WorkletGlobalScope,
public ContextClient {
USING_GARBAGE_COLLECTED_MIXIN(MainThreadWorkletGlobalScope);
public:
MainThreadWorkletGlobalScope(LocalFrame*,
std::unique_ptr<GlobalScopeCreationParams>,
WorkerReportingProxy&);
~MainThreadWorkletGlobalScope() override;
bool IsMainThreadWorkletGlobalScope() const final { return true; }
// WorkerOrWorkletGlobalScope
WorkerThread* GetThread() const final;
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(TaskType) override;
// ExecutionContext
void AddConsoleMessage(ConsoleMessage*) final;
void ExceptionThrown(ErrorEvent*) final;
CoreProbeSink* GetProbeSink() final;
void Trace(blink::Visitor*) override;
};
DEFINE_TYPE_CASTS(MainThreadWorkletGlobalScope,
ExecutionContext,
context,
context->IsMainThreadWorkletGlobalScope(),
context.IsMainThreadWorkletGlobalScope());
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_MAIN_THREAD_WORKLET_GLOBAL_SCOPE_H_
...@@ -11,8 +11,8 @@ ...@@ -11,8 +11,8 @@
#include "third_party/blink/renderer/core/script/script.h" #include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/testing/page_test_base.h" #include "third_party/blink/renderer/core/testing/page_test_base.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/main_thread_worklet_reporting_proxy.h"
#include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worklet_module_responses_map.h" #include "third_party/blink/renderer/core/workers/worklet_module_responses_map.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h" #include "third_party/blink/renderer/platform/weborigin/security_origin.h"
...@@ -72,15 +72,17 @@ class MainThreadWorkletTest : public PageTestBase { ...@@ -72,15 +72,17 @@ class MainThreadWorkletTest : public PageTestBase {
OriginTrialContext::GetTokens(document).get(), OriginTrialContext::GetTokens(document).get(),
base::UnguessableToken::Create(), nullptr /* worker_settings */, base::UnguessableToken::Create(), nullptr /* worker_settings */,
kV8CacheOptionsDefault, new WorkletModuleResponsesMap); kV8CacheOptionsDefault, new WorkletModuleResponsesMap);
global_scope_ = new MainThreadWorkletGlobalScope( global_scope_ = new WorkletGlobalScope(std::move(creation_params),
&GetFrame(), std::move(creation_params), *reporting_proxy_); *reporting_proxy_, &GetFrame());
EXPECT_TRUE(global_scope_->IsMainThreadWorkletGlobalScope());
EXPECT_FALSE(global_scope_->IsThreadedWorkletGlobalScope());
} }
void TearDown() override { global_scope_->Dispose(); } void TearDown() override { global_scope_->Dispose(); }
protected: protected:
std::unique_ptr<MainThreadWorkletReportingProxyForTest> reporting_proxy_; std::unique_ptr<MainThreadWorkletReportingProxyForTest> reporting_proxy_;
Persistent<MainThreadWorkletGlobalScope> global_scope_; Persistent<WorkletGlobalScope> global_scope_;
}; };
class MainThreadWorkletInvalidCSPTest : public MainThreadWorkletTest { class MainThreadWorkletInvalidCSPTest : public MainThreadWorkletTest {
...@@ -117,7 +119,7 @@ TEST_F(MainThreadWorkletTest, UseCounter) { ...@@ -117,7 +119,7 @@ TEST_F(MainThreadWorkletTest, UseCounter) {
// This feature is randomly selected. // This feature is randomly selected.
const WebFeature kFeature1 = WebFeature::kRequestFileSystem; const WebFeature kFeature1 = WebFeature::kRequestFileSystem;
// API use on the MainThreadWorkletGlobalScope should be recorded in // API use on WorkletGlobalScope for the main thread should be recorded in
// UseCounter on the Document. // UseCounter on the Document.
EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature1)); EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature1));
UseCounter::Count(global_scope_, kFeature1); UseCounter::Count(global_scope_, kFeature1);
...@@ -130,8 +132,8 @@ TEST_F(MainThreadWorkletTest, UseCounter) { ...@@ -130,8 +132,8 @@ TEST_F(MainThreadWorkletTest, UseCounter) {
// This feature is randomly selected from Deprecation::deprecationMessage(). // This feature is randomly selected from Deprecation::deprecationMessage().
const WebFeature kFeature2 = WebFeature::kPrefixedStorageInfo; const WebFeature kFeature2 = WebFeature::kPrefixedStorageInfo;
// Deprecated API use on the MainThreadWorkletGlobalScope should be recorded // Deprecated API use on WorkletGlobalScope for the main thread should be
// in UseCounter on the Document. // recorded in UseCounter on the Document.
EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature2)); EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature2));
Deprecation::CountDeprecation(global_scope_, kFeature2); Deprecation::CountDeprecation(global_scope_, kFeature2);
EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature2)); EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature2));
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/workers/threaded_worklet_global_scope.h"
#include "base/memory/scoped_refptr.h"
#include "third_party/blink/public/platform/platform.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/console_message_storage.h"
#include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/platform/weborigin/kurl.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/assertions.h"
namespace blink {
ThreadedWorkletGlobalScope::ThreadedWorkletGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params,
v8::Isolate* isolate,
WorkerThread* thread)
: WorkletGlobalScope(std::move(creation_params),
isolate,
thread->GetWorkerReportingProxy()),
thread_(thread) {
BindContentSecurityPolicyToExecutionContext();
}
ThreadedWorkletGlobalScope::~ThreadedWorkletGlobalScope() {
DCHECK(!thread_);
}
void ThreadedWorkletGlobalScope::Dispose() {
DCHECK(IsContextThread());
WorkletGlobalScope::Dispose();
thread_ = nullptr;
}
bool ThreadedWorkletGlobalScope::IsContextThread() const {
return GetThread()->IsCurrentThread();
}
void ThreadedWorkletGlobalScope::AddConsoleMessage(
ConsoleMessage* console_message) {
DCHECK(IsContextThread());
GetThread()->GetWorkerReportingProxy().ReportConsoleMessage(
console_message->Source(), console_message->Level(),
console_message->Message(), console_message->Location());
GetThread()->GetConsoleMessageStorage()->AddConsoleMessage(this,
console_message);
}
void ThreadedWorkletGlobalScope::ExceptionThrown(ErrorEvent* error_event) {
DCHECK(IsContextThread());
if (WorkerThreadDebugger* debugger =
WorkerThreadDebugger::From(GetThread()->GetIsolate()))
debugger->ExceptionThrown(thread_, error_event);
}
} // namespace blink
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_THREADED_WORKLET_GLOBAL_SCOPE_H_
#define THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_THREADED_WORKLET_GLOBAL_SCOPE_H_
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
namespace blink {
class WorkerThread;
struct GlobalScopeCreationParams;
class CORE_EXPORT ThreadedWorkletGlobalScope : public WorkletGlobalScope {
public:
~ThreadedWorkletGlobalScope() override;
void Dispose() override;
// ExecutionContext
bool IsThreadedWorkletGlobalScope() const final { return true; }
bool IsContextThread() const final;
void AddConsoleMessage(ConsoleMessage*) final;
void ExceptionThrown(ErrorEvent*) final;
WorkerThread* GetThread() const override { return thread_; }
protected:
ThreadedWorkletGlobalScope(std::unique_ptr<GlobalScopeCreationParams>,
v8::Isolate*,
WorkerThread*);
private:
friend class ThreadedWorkletThreadForTest;
WorkerThread* thread_;
};
DEFINE_TYPE_CASTS(ThreadedWorkletGlobalScope,
ExecutionContext,
context,
context->IsThreadedWorkletGlobalScope(),
context.IsThreadedWorkletGlobalScope());
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_THREADED_WORKLET_GLOBAL_SCOPE_H_
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#include <utility> #include <utility>
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "third_party/blink/renderer/core/workers/threaded_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/threaded_worklet_messaging_proxy.h" #include "third_party/blink/renderer/core/workers/threaded_worklet_messaging_proxy.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h" #include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h" #include "third_party/blink/renderer/platform/loader/fetch/fetch_client_settings_object_snapshot.h"
namespace blink { namespace blink {
...@@ -33,8 +33,8 @@ void ThreadedWorkletObjectProxy::FetchAndInvokeScript( ...@@ -33,8 +33,8 @@ void ThreadedWorkletObjectProxy::FetchAndInvokeScript(
scoped_refptr<base::SingleThreadTaskRunner> outside_settings_task_runner, scoped_refptr<base::SingleThreadTaskRunner> outside_settings_task_runner,
WorkletPendingTasks* pending_tasks, WorkletPendingTasks* pending_tasks,
WorkerThread* worker_thread) { WorkerThread* worker_thread) {
ThreadedWorkletGlobalScope* global_scope = WorkletGlobalScope* global_scope =
ToThreadedWorkletGlobalScope(worker_thread->GlobalScope()); ToWorkletGlobalScope(worker_thread->GlobalScope());
global_scope->FetchAndInvokeScript( global_scope->FetchAndInvokeScript(
module_url_record, credentials_mode, module_url_record, credentials_mode,
new FetchClientSettingsObjectSnapshot(std::move(outside_settings_object)), new FetchClientSettingsObjectSnapshot(std::move(outside_settings_object)),
......
...@@ -12,11 +12,11 @@ ...@@ -12,11 +12,11 @@
#include "third_party/blink/renderer/core/script/script.h" #include "third_party/blink/renderer/core/script/script.h"
#include "third_party/blink/renderer/core/testing/dummy_page_holder.h" #include "third_party/blink/renderer/core/testing/dummy_page_holder.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/threaded_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/threaded_worklet_messaging_proxy.h" #include "third_party/blink/renderer/core/workers/threaded_worklet_messaging_proxy.h"
#include "third_party/blink/renderer/core/workers/threaded_worklet_object_proxy.h" #include "third_party/blink/renderer/core/workers/threaded_worklet_object_proxy.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h" #include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/core/workers/worker_thread_test_helper.h" #include "third_party/blink/renderer/core/workers/worker_thread_test_helper.h"
#include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worklet_module_responses_map.h" #include "third_party/blink/renderer/core/workers/worklet_module_responses_map.h"
#include "third_party/blink/renderer/core/workers/worklet_thread_holder.h" #include "third_party/blink/renderer/core/workers/worklet_thread_holder.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h" #include "third_party/blink/renderer/platform/cross_thread_functional.h"
...@@ -133,7 +133,7 @@ class ThreadedWorkletThreadForTest : public WorkerThread { ...@@ -133,7 +133,7 @@ class ThreadedWorkletThreadForTest : public WorkerThread {
FROM_HERE, CrossThreadBind(&test::ExitRunLoop)); FROM_HERE, CrossThreadBind(&test::ExitRunLoop));
} }
// Emulates API use on ThreadedWorkletGlobalScope. // Emulates API use on threaded WorkletGlobalScope.
void CountFeature(WebFeature feature) { void CountFeature(WebFeature feature) {
EXPECT_TRUE(IsCurrentThread()); EXPECT_TRUE(IsCurrentThread());
GlobalScope()->CountFeature(feature); GlobalScope()->CountFeature(feature);
...@@ -142,7 +142,7 @@ class ThreadedWorkletThreadForTest : public WorkerThread { ...@@ -142,7 +142,7 @@ class ThreadedWorkletThreadForTest : public WorkerThread {
FROM_HERE, CrossThreadBind(&test::ExitRunLoop)); FROM_HERE, CrossThreadBind(&test::ExitRunLoop));
} }
// Emulates deprecated API use on ThreadedWorkletGlobalScope. // Emulates deprecated API use on threaded WorkletGlobalScope.
void CountDeprecation(WebFeature feature) { void CountDeprecation(WebFeature feature) {
EXPECT_TRUE(IsCurrentThread()); EXPECT_TRUE(IsCurrentThread());
GlobalScope()->CountDeprecation(feature); GlobalScope()->CountDeprecation(feature);
...@@ -170,8 +170,11 @@ class ThreadedWorkletThreadForTest : public WorkerThread { ...@@ -170,8 +170,11 @@ class ThreadedWorkletThreadForTest : public WorkerThread {
private: private:
WorkerOrWorkletGlobalScope* CreateWorkerGlobalScope( WorkerOrWorkletGlobalScope* CreateWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params) final { std::unique_ptr<GlobalScopeCreationParams> creation_params) final {
return new ThreadedWorkletGlobalScope(std::move(creation_params), auto* global_scope = new WorkletGlobalScope(
GetIsolate(), this); std::move(creation_params), GetWorkerReportingProxy(), this);
EXPECT_FALSE(global_scope->IsMainThreadWorkletGlobalScope());
EXPECT_TRUE(global_scope->IsThreadedWorkletGlobalScope());
return global_scope;
} }
bool IsOwningBackingThread() const final { return false; } bool IsOwningBackingThread() const final { return false; }
...@@ -306,7 +309,7 @@ TEST_F(ThreadedWorkletTest, UseCounter) { ...@@ -306,7 +309,7 @@ TEST_F(ThreadedWorkletTest, UseCounter) {
// This feature is randomly selected. // This feature is randomly selected.
const WebFeature kFeature1 = WebFeature::kRequestFileSystem; const WebFeature kFeature1 = WebFeature::kRequestFileSystem;
// API use on the ThreadedWorkletGlobalScope should be recorded in UseCounter // API use on the threaded WorkletGlobalScope should be recorded in UseCounter
// on the Document. // on the Document.
EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature1)); EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature1));
PostCrossThreadTask( PostCrossThreadTask(
...@@ -317,7 +320,7 @@ TEST_F(ThreadedWorkletTest, UseCounter) { ...@@ -317,7 +320,7 @@ TEST_F(ThreadedWorkletTest, UseCounter) {
EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature1)); EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature1));
// API use should be reported to the Document only one time. See comments in // API use should be reported to the Document only one time. See comments in
// ThreadedWorkletGlobalScopeForTest::CountFeature. // ThreadedWorkletObjectProxyForTest::CountFeature.
PostCrossThreadTask( PostCrossThreadTask(
*GetWorkerThread()->GetTaskRunner(TaskType::kInternalTest), FROM_HERE, *GetWorkerThread()->GetTaskRunner(TaskType::kInternalTest), FROM_HERE,
CrossThreadBind(&ThreadedWorkletThreadForTest::CountFeature, CrossThreadBind(&ThreadedWorkletThreadForTest::CountFeature,
...@@ -327,7 +330,7 @@ TEST_F(ThreadedWorkletTest, UseCounter) { ...@@ -327,7 +330,7 @@ TEST_F(ThreadedWorkletTest, UseCounter) {
// This feature is randomly selected from Deprecation::deprecationMessage(). // This feature is randomly selected from Deprecation::deprecationMessage().
const WebFeature kFeature2 = WebFeature::kPrefixedStorageInfo; const WebFeature kFeature2 = WebFeature::kPrefixedStorageInfo;
// Deprecated API use on the ThreadedWorkletGlobalScope should be recorded in // Deprecated API use on the threaded WorkletGlobalScope should be recorded in
// UseCounter on the Document. // UseCounter on the Document.
EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature2)); EXPECT_FALSE(UseCounter::IsCounted(GetDocument(), kFeature2));
PostCrossThreadTask( PostCrossThreadTask(
...@@ -338,7 +341,7 @@ TEST_F(ThreadedWorkletTest, UseCounter) { ...@@ -338,7 +341,7 @@ TEST_F(ThreadedWorkletTest, UseCounter) {
EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature2)); EXPECT_TRUE(UseCounter::IsCounted(GetDocument(), kFeature2));
// API use should be reported to the Document only one time. See comments in // API use should be reported to the Document only one time. See comments in
// ThreadedWorkletGlobalScopeForTest::CountDeprecation. // ThreadedWorkletObjectProxyForTest::CountDeprecation.
PostCrossThreadTask( PostCrossThreadTask(
*GetWorkerThread()->GetTaskRunner(TaskType::kInternalTest), FROM_HERE, *GetWorkerThread()->GetTaskRunner(TaskType::kInternalTest), FROM_HERE,
CrossThreadBind(&ThreadedWorkletThreadForTest::CountDeprecation, CrossThreadBind(&ThreadedWorkletThreadForTest::CountDeprecation,
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "third_party/blink/renderer/core/loader/modulescript/module_script_fetch_request.h" #include "third_party/blink/renderer/core/loader/modulescript/module_script_fetch_request.h"
#include "third_party/blink/renderer/core/loader/worker_fetch_context.h" #include "third_party/blink/renderer/core/loader/worker_fetch_context.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h" #include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/platform/cross_thread_functional.h" #include "third_party/blink/renderer/platform/cross_thread_functional.h"
......
...@@ -83,7 +83,7 @@ class CORE_EXPORT WorkerOrWorkletGlobalScope : public EventTargetWithInlineData, ...@@ -83,7 +83,7 @@ class CORE_EXPORT WorkerOrWorkletGlobalScope : public EventTargetWithInlineData,
void CountDeprecation(WebFeature); void CountDeprecation(WebFeature);
// May return nullptr if this global scope is not threaded (i.e., // May return nullptr if this global scope is not threaded (i.e.,
// MainThreadWorkletGlobalScope) or after dispose() is called. // WorkletGlobalScope for the main thread) or after Dispose() is called.
virtual WorkerThread* GetThread() const = 0; virtual WorkerThread* GetThread() const = 0;
ResourceFetcher* Fetcher() const override; ResourceFetcher* Fetcher() const override;
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h" #include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/threaded_worklet_global_scope.h"
#include "third_party/blink/renderer/core/workers/worker_backing_thread.h" #include "third_party/blink/renderer/core/workers/worker_backing_thread.h"
#include "third_party/blink/renderer/core/workers/worker_clients.h" #include "third_party/blink/renderer/core/workers/worker_clients.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h" #include "third_party/blink/renderer/core/workers/worker_global_scope.h"
......
...@@ -9,12 +9,18 @@ ...@@ -9,12 +9,18 @@
#include "third_party/blink/renderer/bindings/core/v8/script_source_code.h" #include "third_party/blink/renderer/bindings/core/v8/script_source_code.h"
#include "third_party/blink/renderer/bindings/core/v8/source_location.h" #include "third_party/blink/renderer/bindings/core/v8/source_location.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/frame/frame_console.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/inspector/console_message.h"
#include "third_party/blink/renderer/core/inspector/console_message_storage.h"
#include "third_party/blink/renderer/core/inspector/main_thread_debugger.h" #include "third_party/blink/renderer/core/inspector/main_thread_debugger.h"
#include "third_party/blink/renderer/core/inspector/worker_thread_debugger.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h" #include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/probe/core_probes.h" #include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/script/modulator.h" #include "third_party/blink/renderer/core/script/modulator.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h" #include "third_party/blink/renderer/core/workers/worker_reporting_proxy.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/core/workers/worklet_module_responses_map.h" #include "third_party/blink/renderer/core/workers/worklet_module_responses_map.h"
#include "third_party/blink/renderer/core/workers/worklet_module_tree_client.h" #include "third_party/blink/renderer/core/workers/worklet_module_tree_client.h"
#include "third_party/blink/renderer/core/workers/worklet_pending_tasks.h" #include "third_party/blink/renderer/core/workers/worklet_pending_tasks.h"
...@@ -23,13 +29,38 @@ ...@@ -23,13 +29,38 @@
namespace blink { namespace blink {
WorkletGlobalScope::WorkletGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params,
WorkerReportingProxy& reporting_proxy,
LocalFrame* frame)
: WorkletGlobalScope(std::move(creation_params),
reporting_proxy,
ToIsolate(frame),
ThreadType::kMainThread,
frame,
nullptr /* worker_thread */) {}
WorkletGlobalScope::WorkletGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params,
WorkerReportingProxy& reporting_proxy,
WorkerThread* worker_thread)
: WorkletGlobalScope(std::move(creation_params),
reporting_proxy,
worker_thread->GetIsolate(),
ThreadType::kOffMainThread,
nullptr /* frame */,
worker_thread) {}
// Partial implementation of the "set up a worklet environment settings object" // Partial implementation of the "set up a worklet environment settings object"
// algorithm: // algorithm:
// https://drafts.css-houdini.org/worklets/#script-settings-for-worklets // https://drafts.css-houdini.org/worklets/#script-settings-for-worklets
WorkletGlobalScope::WorkletGlobalScope( WorkletGlobalScope::WorkletGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params, std::unique_ptr<GlobalScopeCreationParams> creation_params,
WorkerReportingProxy& reporting_proxy,
v8::Isolate* isolate, v8::Isolate* isolate,
WorkerReportingProxy& reporting_proxy) ThreadType thread_type,
LocalFrame* frame,
WorkerThread* worker_thread)
: WorkerOrWorkletGlobalScope(isolate, : WorkerOrWorkletGlobalScope(isolate,
creation_params->worker_clients, creation_params->worker_clients,
reporting_proxy), reporting_proxy),
...@@ -42,7 +73,13 @@ WorkletGlobalScope::WorkletGlobalScope( ...@@ -42,7 +73,13 @@ WorkletGlobalScope::WorkletGlobalScope(
https_state_(creation_params->starter_https_state), https_state_(creation_params->starter_https_state),
agent_cluster_id_(creation_params->agent_cluster_id.is_empty() agent_cluster_id_(creation_params->agent_cluster_id.is_empty()
? base::UnguessableToken::Create() ? base::UnguessableToken::Create()
: creation_params->agent_cluster_id) { : creation_params->agent_cluster_id),
thread_type_(thread_type),
frame_(frame),
worker_thread_(worker_thread) {
DCHECK((thread_type_ == ThreadType::kMainThread && frame_) ||
(thread_type_ == ThreadType::kOffMainThread && worker_thread_));
// Step 2: "Let inheritedAPIBaseURL be outsideSettings's API base URL." // Step 2: "Let inheritedAPIBaseURL be outsideSettings's API base URL."
// |url_| is the inheritedAPIBaseURL passed from the parent Document. // |url_| is the inheritedAPIBaseURL passed from the parent Document.
...@@ -57,6 +94,7 @@ WorkletGlobalScope::WorkletGlobalScope( ...@@ -57,6 +94,7 @@ WorkletGlobalScope::WorkletGlobalScope(
// workletGlobalScope." // workletGlobalScope."
InitContentSecurityPolicyFromVector( InitContentSecurityPolicyFromVector(
creation_params->content_security_policy_parsed_headers); creation_params->content_security_policy_parsed_headers);
BindContentSecurityPolicyToExecutionContext();
OriginTrialContext::AddTokens(this, OriginTrialContext::AddTokens(this,
creation_params->origin_trial_tokens.get()); creation_params->origin_trial_tokens.get());
...@@ -64,6 +102,14 @@ WorkletGlobalScope::WorkletGlobalScope( ...@@ -64,6 +102,14 @@ WorkletGlobalScope::WorkletGlobalScope(
WorkletGlobalScope::~WorkletGlobalScope() = default; WorkletGlobalScope::~WorkletGlobalScope() = default;
bool WorkletGlobalScope::IsMainThreadWorkletGlobalScope() const {
return thread_type_ == ThreadType::kMainThread;
}
bool WorkletGlobalScope::IsThreadedWorkletGlobalScope() const {
return thread_type_ == ThreadType::kOffMainThread;
}
ExecutionContext* WorkletGlobalScope::GetExecutionContext() const { ExecutionContext* WorkletGlobalScope::GetExecutionContext() const {
return const_cast<WorkletGlobalScope*>(this); return const_cast<WorkletGlobalScope*>(this);
} }
...@@ -78,6 +124,64 @@ bool WorkletGlobalScope::IsSecureContext(String& error_message) const { ...@@ -78,6 +124,64 @@ bool WorkletGlobalScope::IsSecureContext(String& error_message) const {
return false; return false;
} }
bool WorkletGlobalScope::IsContextThread() const {
if (IsMainThreadWorkletGlobalScope())
return IsMainThread();
return worker_thread_->IsCurrentThread();
}
void WorkletGlobalScope::AddConsoleMessage(ConsoleMessage* console_message) {
if (IsMainThreadWorkletGlobalScope()) {
frame_->Console().AddMessage(console_message);
return;
}
worker_thread_->GetWorkerReportingProxy().ReportConsoleMessage(
console_message->Source(), console_message->Level(),
console_message->Message(), console_message->Location());
worker_thread_->GetConsoleMessageStorage()->AddConsoleMessage(
worker_thread_->GlobalScope(), console_message);
}
void WorkletGlobalScope::ExceptionThrown(ErrorEvent* error_event) {
if (IsMainThreadWorkletGlobalScope()) {
MainThreadDebugger::Instance()->ExceptionThrown(this, error_event);
return;
}
if (WorkerThreadDebugger* debugger =
WorkerThreadDebugger::From(GetThread()->GetIsolate())) {
debugger->ExceptionThrown(worker_thread_, error_event);
}
}
void WorkletGlobalScope::Dispose() {
frame_ = nullptr;
worker_thread_ = nullptr;
WorkerOrWorkletGlobalScope::Dispose();
}
WorkerThread* WorkletGlobalScope::GetThread() const {
DCHECK(!IsMainThreadWorkletGlobalScope());
return worker_thread_;
}
CoreProbeSink* WorkletGlobalScope::GetProbeSink() {
if (IsMainThreadWorkletGlobalScope())
return probe::ToCoreProbeSink(frame_);
return nullptr;
}
scoped_refptr<base::SingleThreadTaskRunner> WorkletGlobalScope::GetTaskRunner(
TaskType task_type) {
if (IsMainThreadWorkletGlobalScope())
return frame_->GetFrameScheduler()->GetTaskRunner(task_type);
return worker_thread_->GetTaskRunner(task_type);
}
LocalFrame* WorkletGlobalScope::GetFrame() const {
DCHECK(IsMainThreadWorkletGlobalScope());
return frame_;
}
// Implementation of the first half of the "fetch and invoke a worklet script" // Implementation of the first half of the "fetch and invoke a worklet script"
// algorithm: // algorithm:
// https://drafts.css-houdini.org/worklets/#fetch-and-invoke-a-worklet-script // https://drafts.css-houdini.org/worklets/#fetch-and-invoke-a-worklet-script
...@@ -135,6 +239,7 @@ void WorkletGlobalScope::BindContentSecurityPolicyToExecutionContext() { ...@@ -135,6 +239,7 @@ void WorkletGlobalScope::BindContentSecurityPolicyToExecutionContext() {
} }
void WorkletGlobalScope::Trace(blink::Visitor* visitor) { void WorkletGlobalScope::Trace(blink::Visitor* visitor) {
visitor->Trace(frame_);
WorkerOrWorkletGlobalScope::Trace(visitor); WorkerOrWorkletGlobalScope::Trace(visitor);
} }
......
...@@ -25,6 +25,13 @@ class WorkletPendingTasks; ...@@ -25,6 +25,13 @@ class WorkletPendingTasks;
class WorkerReportingProxy; class WorkerReportingProxy;
struct GlobalScopeCreationParams; struct GlobalScopeCreationParams;
// This is an implementation of the web-exposed WorkletGlobalScope interface
// defined in the Worklets spec:
// https://drafts.css-houdini.org/worklets/#workletglobalscope
//
// This instance lives either on the main thread (main thread worklet) or a
// worker thread (threaded worklet). It's determined by constructors. See
// comments on the constructors.
class CORE_EXPORT WorkletGlobalScope class CORE_EXPORT WorkletGlobalScope
: public WorkerOrWorkletGlobalScope, : public WorkerOrWorkletGlobalScope,
public ActiveScriptWrappable<WorkletGlobalScope> { public ActiveScriptWrappable<WorkletGlobalScope> {
...@@ -34,6 +41,8 @@ class CORE_EXPORT WorkletGlobalScope ...@@ -34,6 +41,8 @@ class CORE_EXPORT WorkletGlobalScope
public: public:
~WorkletGlobalScope() override; ~WorkletGlobalScope() override;
bool IsMainThreadWorkletGlobalScope() const final;
bool IsThreadedWorkletGlobalScope() const final;
bool IsWorkletGlobalScope() const final { return true; } bool IsWorkletGlobalScope() const final { return true; }
// Always returns false here as PaintWorkletGlobalScope and // Always returns false here as PaintWorkletGlobalScope and
...@@ -50,6 +59,18 @@ class CORE_EXPORT WorkletGlobalScope ...@@ -50,6 +59,18 @@ class CORE_EXPORT WorkletGlobalScope
String UserAgent() const final { return user_agent_; } String UserAgent() const final { return user_agent_; }
SecurityContext& GetSecurityContext() final { return *this; } SecurityContext& GetSecurityContext() final { return *this; }
bool IsSecureContext(String& error_message) const final; bool IsSecureContext(String& error_message) const final;
bool IsContextThread() const final;
void AddConsoleMessage(ConsoleMessage*) final;
void ExceptionThrown(ErrorEvent*) final;
CoreProbeSink* GetProbeSink() final;
scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner(TaskType) final;
// WorkerOrWorkletGlobalScope
void Dispose() override;
WorkerThread* GetThread() const final;
virtual LocalFrame* GetFrame() const;
const base::UnguessableToken& GetAgentClusterID() const final { const base::UnguessableToken& GetAgentClusterID() const final {
// Currently, worklet agents have no clearly defined owner. See // Currently, worklet agents have no clearly defined owner. See
// https://html.spec.whatwg.org/multipage/webappapis.html#integration-with-the-javascript-agent-cluster-formalism // https://html.spec.whatwg.org/multipage/webappapis.html#integration-with-the-javascript-agent-cluster-formalism
...@@ -101,19 +122,40 @@ class CORE_EXPORT WorkletGlobalScope ...@@ -101,19 +122,40 @@ class CORE_EXPORT WorkletGlobalScope
HttpsState GetHttpsState() const override { return https_state_; } HttpsState GetHttpsState() const override { return https_state_; }
protected: // Constructs an instance as a main thread worklet. Must be called on the main
// Partial implementation of the "set up a worklet environment settings // thread.
// object" algorithm: WorkletGlobalScope(std::unique_ptr<GlobalScopeCreationParams>,
WorkerReportingProxy&,
LocalFrame*);
// Constructs an instance as a threaded worklet. Must be called on a worker
// thread.
WorkletGlobalScope(std::unique_ptr<GlobalScopeCreationParams>,
WorkerReportingProxy&,
WorkerThread*);
private:
enum class ThreadType {
// Indicates this global scope lives on the main thread.
kMainThread,
// Indicates this global scope lives on a worker thread.
kOffMainThread
};
// The base constructor delegated from other public constructors. This
// partially implements the "set up a worklet environment settings object"
// algorithm defined in the Worklets spec:
// https://drafts.css-houdini.org/worklets/#script-settings-for-worklets // https://drafts.css-houdini.org/worklets/#script-settings-for-worklets
WorkletGlobalScope(std::unique_ptr<GlobalScopeCreationParams>, WorkletGlobalScope(std::unique_ptr<GlobalScopeCreationParams>,
WorkerReportingProxy&,
v8::Isolate*, v8::Isolate*,
WorkerReportingProxy&); ThreadType,
LocalFrame*,
WorkerThread*);
void BindContentSecurityPolicyToExecutionContext() override;
private:
EventTarget* ErrorEventTarget() final { return nullptr; } EventTarget* ErrorEventTarget() final { return nullptr; }
void BindContentSecurityPolicyToExecutionContext() override;
// The |url_| and |user_agent_| are inherited from the parent Document. // The |url_| and |user_agent_| are inherited from the parent Document.
const KURL url_; const KURL url_;
const String user_agent_; const String user_agent_;
...@@ -130,6 +172,12 @@ class CORE_EXPORT WorkletGlobalScope ...@@ -130,6 +172,12 @@ class CORE_EXPORT WorkletGlobalScope
const HttpsState https_state_; const HttpsState https_state_;
const base::UnguessableToken agent_cluster_id_; const base::UnguessableToken agent_cluster_id_;
const ThreadType thread_type_;
// |frame_| is available only when |thread_type_| is kMainThread.
Member<LocalFrame> frame_;
// |worker_thread_| is available only when |thread_type_| is kOffMainThread.
WorkerThread* worker_thread_;
}; };
DEFINE_TYPE_CASTS(WorkletGlobalScope, DEFINE_TYPE_CASTS(WorkletGlobalScope,
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "third_party/blink/renderer/bindings/core/v8/v8_object_parser.h" #include "third_party/blink/renderer/bindings/core/v8/v8_object_parser.h"
#include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h" #include "third_party/blink/renderer/bindings/core/v8/worker_or_worklet_script_controller.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/modules/animationworklet/animation_worklet_proxy_client.h" #include "third_party/blink/renderer/modules/animationworklet/animation_worklet_proxy_client.h"
#include "third_party/blink/renderer/modules/animationworklet/worklet_animation_options.h" #include "third_party/blink/renderer/modules/animationworklet/worklet_animation_options.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
...@@ -35,25 +36,23 @@ void UpdateAnimation(Animator* animator, ...@@ -35,25 +36,23 @@ void UpdateAnimation(Animator* animator,
AnimationWorkletGlobalScope* AnimationWorkletGlobalScope::Create( AnimationWorkletGlobalScope* AnimationWorkletGlobalScope::Create(
std::unique_ptr<GlobalScopeCreationParams> creation_params, std::unique_ptr<GlobalScopeCreationParams> creation_params,
v8::Isolate* isolate,
WorkerThread* thread) { WorkerThread* thread) {
return new AnimationWorkletGlobalScope(std::move(creation_params), isolate, return new AnimationWorkletGlobalScope(std::move(creation_params), thread);
thread);
} }
AnimationWorkletGlobalScope::AnimationWorkletGlobalScope( AnimationWorkletGlobalScope::AnimationWorkletGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params, std::unique_ptr<GlobalScopeCreationParams> creation_params,
v8::Isolate* isolate,
WorkerThread* thread) WorkerThread* thread)
: ThreadedWorkletGlobalScope(std::move(creation_params), isolate, thread) { : WorkletGlobalScope(std::move(creation_params),
} thread->GetWorkerReportingProxy(),
thread) {}
AnimationWorkletGlobalScope::~AnimationWorkletGlobalScope() = default; AnimationWorkletGlobalScope::~AnimationWorkletGlobalScope() = default;
void AnimationWorkletGlobalScope::Trace(blink::Visitor* visitor) { void AnimationWorkletGlobalScope::Trace(blink::Visitor* visitor) {
visitor->Trace(animator_definitions_); visitor->Trace(animator_definitions_);
visitor->Trace(animators_); visitor->Trace(animators_);
ThreadedWorkletGlobalScope::Trace(visitor); WorkletGlobalScope::Trace(visitor);
} }
void AnimationWorkletGlobalScope::Dispose() { void AnimationWorkletGlobalScope::Dispose() {
...@@ -61,7 +60,7 @@ void AnimationWorkletGlobalScope::Dispose() { ...@@ -61,7 +60,7 @@ void AnimationWorkletGlobalScope::Dispose() {
if (AnimationWorkletProxyClient* proxy_client = if (AnimationWorkletProxyClient* proxy_client =
AnimationWorkletProxyClient::From(Clients())) AnimationWorkletProxyClient::From(Clients()))
proxy_client->Dispose(); proxy_client->Dispose();
ThreadedWorkletGlobalScope::Dispose(); WorkletGlobalScope::Dispose();
} }
Animator* AnimationWorkletGlobalScope::CreateAnimatorFor( Animator* AnimationWorkletGlobalScope::CreateAnimatorFor(
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define THIRD_PARTY_BLINK_RENDERER_MODULES_ANIMATIONWORKLET_ANIMATION_WORKLET_GLOBAL_SCOPE_H_ #define THIRD_PARTY_BLINK_RENDERER_MODULES_ANIMATIONWORKLET_ANIMATION_WORKLET_GLOBAL_SCOPE_H_
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/workers/threaded_worklet_global_scope.h" #include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/modules/animationworklet/animator.h" #include "third_party/blink/renderer/modules/animationworklet/animator.h"
#include "third_party/blink/renderer/modules/animationworklet/animator_definition.h" #include "third_party/blink/renderer/modules/animationworklet/animator_definition.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
...@@ -27,14 +27,12 @@ class WorkletAnimationOptions; ...@@ -27,14 +27,12 @@ class WorkletAnimationOptions;
// The scope keeps a map of these animator definitions and can look them up // The scope keeps a map of these animator definitions and can look them up
// based on their name. The scope also owns a list of active animators that it // based on their name. The scope also owns a list of active animators that it
// animates. // animates.
class MODULES_EXPORT AnimationWorkletGlobalScope class MODULES_EXPORT AnimationWorkletGlobalScope : public WorkletGlobalScope {
: public ThreadedWorkletGlobalScope {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static AnimationWorkletGlobalScope* Create( static AnimationWorkletGlobalScope* Create(
std::unique_ptr<GlobalScopeCreationParams>, std::unique_ptr<GlobalScopeCreationParams>,
v8::Isolate*,
WorkerThread*); WorkerThread*);
~AnimationWorkletGlobalScope() override; ~AnimationWorkletGlobalScope() override;
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
...@@ -54,7 +52,6 @@ class MODULES_EXPORT AnimationWorkletGlobalScope ...@@ -54,7 +52,6 @@ class MODULES_EXPORT AnimationWorkletGlobalScope
private: private:
AnimationWorkletGlobalScope(std::unique_ptr<GlobalScopeCreationParams>, AnimationWorkletGlobalScope(std::unique_ptr<GlobalScopeCreationParams>,
v8::Isolate*,
WorkerThread*); WorkerThread*);
void RegisterWithProxyClientIfNeeded(); void RegisterWithProxyClientIfNeeded();
......
...@@ -66,8 +66,7 @@ WorkerOrWorkletGlobalScope* AnimationWorkletThread::CreateWorkerGlobalScope( ...@@ -66,8 +66,7 @@ WorkerOrWorkletGlobalScope* AnimationWorkletThread::CreateWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params) { std::unique_ptr<GlobalScopeCreationParams> creation_params) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("animation-worklet"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("animation-worklet"),
"AnimationWorkletThread::CreateWorkerGlobalScope"); "AnimationWorkletThread::CreateWorkerGlobalScope");
return AnimationWorkletGlobalScope::Create(std::move(creation_params), return AnimationWorkletGlobalScope::Create(std::move(creation_params), this);
GetIsolate(), this);
} }
} // namespace blink } // namespace blink
...@@ -111,9 +111,7 @@ PaintWorkletGlobalScope::PaintWorkletGlobalScope( ...@@ -111,9 +111,7 @@ PaintWorkletGlobalScope::PaintWorkletGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params, std::unique_ptr<GlobalScopeCreationParams> creation_params,
WorkerReportingProxy& reporting_proxy, WorkerReportingProxy& reporting_proxy,
PaintWorkletPendingGeneratorRegistry* pending_generator_registry) PaintWorkletPendingGeneratorRegistry* pending_generator_registry)
: MainThreadWorkletGlobalScope(frame, : WorkletGlobalScope(std::move(creation_params), reporting_proxy, frame),
std::move(creation_params),
reporting_proxy),
pending_generator_registry_(pending_generator_registry) {} pending_generator_registry_(pending_generator_registry) {}
PaintWorkletGlobalScope::~PaintWorkletGlobalScope() = default; PaintWorkletGlobalScope::~PaintWorkletGlobalScope() = default;
...@@ -121,9 +119,8 @@ PaintWorkletGlobalScope::~PaintWorkletGlobalScope() = default; ...@@ -121,9 +119,8 @@ PaintWorkletGlobalScope::~PaintWorkletGlobalScope() = default;
void PaintWorkletGlobalScope::Dispose() { void PaintWorkletGlobalScope::Dispose() {
MainThreadDebugger::Instance()->ContextWillBeDestroyed( MainThreadDebugger::Instance()->ContextWillBeDestroyed(
ScriptController()->GetScriptState()); ScriptController()->GetScriptState());
pending_generator_registry_ = nullptr; pending_generator_registry_ = nullptr;
MainThreadWorkletGlobalScope::Dispose(); WorkletGlobalScope::Dispose();
} }
void PaintWorkletGlobalScope::registerPaint( void PaintWorkletGlobalScope::registerPaint(
...@@ -230,7 +227,7 @@ double PaintWorkletGlobalScope::devicePixelRatio() const { ...@@ -230,7 +227,7 @@ double PaintWorkletGlobalScope::devicePixelRatio() const {
void PaintWorkletGlobalScope::Trace(blink::Visitor* visitor) { void PaintWorkletGlobalScope::Trace(blink::Visitor* visitor) {
visitor->Trace(paint_definitions_); visitor->Trace(paint_definitions_);
visitor->Trace(pending_generator_registry_); visitor->Trace(pending_generator_registry_);
MainThreadWorkletGlobalScope::Trace(visitor); WorkletGlobalScope::Trace(visitor);
} }
} // namespace blink } // namespace blink
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/workers/main_thread_worklet_global_scope.h" #include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/modules/csspaint/paint_worklet_pending_generator_registry.h" #include "third_party/blink/renderer/modules/csspaint/paint_worklet_pending_generator_registry.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/platform/bindings/script_wrappable.h" #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
...@@ -18,8 +18,7 @@ class CSSPaintDefinition; ...@@ -18,8 +18,7 @@ class CSSPaintDefinition;
class ExceptionState; class ExceptionState;
class WorkerReportingProxy; class WorkerReportingProxy;
class MODULES_EXPORT PaintWorkletGlobalScope final class MODULES_EXPORT PaintWorkletGlobalScope final : public WorkletGlobalScope {
: public MainThreadWorkletGlobalScope {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
USING_GARBAGE_COLLECTED_MIXIN(PaintWorkletGlobalScope); USING_GARBAGE_COLLECTED_MIXIN(PaintWorkletGlobalScope);
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "third_party/blink/renderer/core/messaging/message_port.h" #include "third_party/blink/renderer/core/messaging/message_port.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h" #include "third_party/blink/renderer/core/typed_arrays/dom_typed_array.h"
#include "third_party/blink/renderer/core/workers/global_scope_creation_params.h" #include "third_party/blink/renderer/core/workers/global_scope_creation_params.h"
#include "third_party/blink/renderer/core/workers/worker_thread.h"
#include "third_party/blink/renderer/modules/webaudio/audio_buffer.h" #include "third_party/blink/renderer/modules/webaudio/audio_buffer.h"
#include "third_party/blink/renderer/modules/webaudio/audio_param_descriptor.h" #include "third_party/blink/renderer/modules/webaudio/audio_param_descriptor.h"
#include "third_party/blink/renderer/modules/webaudio/audio_worklet_processor.h" #include "third_party/blink/renderer/modules/webaudio/audio_worklet_processor.h"
...@@ -36,24 +37,23 @@ namespace blink { ...@@ -36,24 +37,23 @@ namespace blink {
AudioWorkletGlobalScope* AudioWorkletGlobalScope::Create( AudioWorkletGlobalScope* AudioWorkletGlobalScope::Create(
std::unique_ptr<GlobalScopeCreationParams> creation_params, std::unique_ptr<GlobalScopeCreationParams> creation_params,
v8::Isolate* isolate,
WorkerThread* thread) { WorkerThread* thread) {
return new AudioWorkletGlobalScope(std::move(creation_params), isolate, return new AudioWorkletGlobalScope(std::move(creation_params), thread);
thread);
} }
AudioWorkletGlobalScope::AudioWorkletGlobalScope( AudioWorkletGlobalScope::AudioWorkletGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params, std::unique_ptr<GlobalScopeCreationParams> creation_params,
v8::Isolate* isolate,
WorkerThread* thread) WorkerThread* thread)
: ThreadedWorkletGlobalScope(std::move(creation_params), isolate, thread) {} : WorkletGlobalScope(std::move(creation_params),
thread->GetWorkerReportingProxy(),
thread) {}
AudioWorkletGlobalScope::~AudioWorkletGlobalScope() = default; AudioWorkletGlobalScope::~AudioWorkletGlobalScope() = default;
void AudioWorkletGlobalScope::Dispose() { void AudioWorkletGlobalScope::Dispose() {
DCHECK(IsContextThread()); DCHECK(IsContextThread());
is_closing_ = true; is_closing_ = true;
ThreadedWorkletGlobalScope::Dispose(); WorkletGlobalScope::Dispose();
} }
void AudioWorkletGlobalScope::registerProcessor( void AudioWorkletGlobalScope::registerProcessor(
...@@ -401,7 +401,7 @@ double AudioWorkletGlobalScope::currentTime() const { ...@@ -401,7 +401,7 @@ double AudioWorkletGlobalScope::currentTime() const {
void AudioWorkletGlobalScope::Trace(blink::Visitor* visitor) { void AudioWorkletGlobalScope::Trace(blink::Visitor* visitor) {
visitor->Trace(processor_definition_map_); visitor->Trace(processor_definition_map_);
visitor->Trace(processor_instances_); visitor->Trace(processor_instances_);
ThreadedWorkletGlobalScope::Trace(visitor); WorkletGlobalScope::Trace(visitor);
} }
} // namespace blink } // namespace blink
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "third_party/blink/renderer/bindings/core/v8/script_value.h" #include "third_party/blink/renderer/bindings/core/v8/script_value.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" #include "third_party/blink/renderer/core/execution_context/execution_context.h"
#include "third_party/blink/renderer/core/workers/threaded_worklet_global_scope.h" #include "third_party/blink/renderer/core/workers/worklet_global_scope.h"
#include "third_party/blink/renderer/modules/modules_export.h" #include "third_party/blink/renderer/modules/modules_export.h"
#include "third_party/blink/renderer/modules/webaudio/audio_param_descriptor.h" #include "third_party/blink/renderer/modules/webaudio/audio_param_descriptor.h"
#include "third_party/blink/renderer/platform/audio/audio_array.h" #include "third_party/blink/renderer/platform/audio/audio_array.h"
...@@ -46,14 +46,12 @@ class MODULES_EXPORT ProcessorCreationParams final { ...@@ -46,14 +46,12 @@ class MODULES_EXPORT ProcessorCreationParams final {
// This is constructed and destroyed on a worker thread, and all methods also // This is constructed and destroyed on a worker thread, and all methods also
// must be called on the worker thread. // must be called on the worker thread.
class MODULES_EXPORT AudioWorkletGlobalScope final class MODULES_EXPORT AudioWorkletGlobalScope final : public WorkletGlobalScope {
: public ThreadedWorkletGlobalScope {
DEFINE_WRAPPERTYPEINFO(); DEFINE_WRAPPERTYPEINFO();
public: public:
static AudioWorkletGlobalScope* Create( static AudioWorkletGlobalScope* Create(
std::unique_ptr<GlobalScopeCreationParams>, std::unique_ptr<GlobalScopeCreationParams>,
v8::Isolate*,
WorkerThread*); WorkerThread*);
~AudioWorkletGlobalScope() override; ~AudioWorkletGlobalScope() override;
bool IsAudioWorkletGlobalScope() const final { return true; } bool IsAudioWorkletGlobalScope() const final { return true; }
...@@ -106,7 +104,6 @@ class MODULES_EXPORT AudioWorkletGlobalScope final ...@@ -106,7 +104,6 @@ class MODULES_EXPORT AudioWorkletGlobalScope final
private: private:
AudioWorkletGlobalScope(std::unique_ptr<GlobalScopeCreationParams>, AudioWorkletGlobalScope(std::unique_ptr<GlobalScopeCreationParams>,
v8::Isolate*,
WorkerThread*); WorkerThread*);
bool is_closing_ = false; bool is_closing_ = false;
......
...@@ -68,8 +68,7 @@ WorkerOrWorkletGlobalScope* AudioWorkletThread::CreateWorkerGlobalScope( ...@@ -68,8 +68,7 @@ WorkerOrWorkletGlobalScope* AudioWorkletThread::CreateWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params) { std::unique_ptr<GlobalScopeCreationParams> creation_params) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("audio-worklet"), TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("audio-worklet"),
"AudioWorkletThread::createWorkerGlobalScope"); "AudioWorkletThread::createWorkerGlobalScope");
return AudioWorkletGlobalScope::Create(std::move(creation_params), return AudioWorkletGlobalScope::Create(std::move(creation_params), this);
GetIsolate(), this);
} }
} // namespace blink } // namespace blink
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment