Commit a3acb2d5 authored by Hiroki Nakagawa's avatar Hiroki Nakagawa Committed by Commit Bot

Worklet: Remove dependency on LocalFrame from Worklet

This is a clean-up and doesn't change behavior. Worklets care about the lifetime
of Document not LocalFrame. To make it clearer, this CL removes dependency on
LocalFrame from Worklet.

Bug: 792307, 792108
Change-Id: I24268c2f59efa70f26a0024bb02ee8a35d01ba7f
Reviewed-on: https://chromium-review.googlesource.com/810405
Commit-Queue: Hiroki Nakagawa <nhiroki@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522033}
parent edaf7f06
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "bindings/core/v8/ScriptPromiseResolver.h" #include "bindings/core/v8/ScriptPromiseResolver.h"
#include "core/dom/DOMException.h" #include "core/dom/DOMException.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "core/workers/WorkletPendingTasks.h" #include "core/workers/WorkletPendingTasks.h"
#include "platform/WebTaskRunner.h" #include "platform/WebTaskRunner.h"
#include "platform/wtf/WTF.h" #include "platform/wtf/WTF.h"
...@@ -32,10 +31,10 @@ network::mojom::FetchCredentialsMode ParseCredentialsOption( ...@@ -32,10 +31,10 @@ network::mojom::FetchCredentialsMode ParseCredentialsOption(
} // namespace } // namespace
Worklet::Worklet(LocalFrame* frame) Worklet::Worklet(Document* document)
: ContextLifecycleObserver(frame->GetDocument()), : ContextLifecycleObserver(document),
module_responses_map_( module_responses_map_(
new WorkletModuleResponsesMap(frame->GetDocument()->Fetcher())) { new WorkletModuleResponsesMap(document->Fetcher())) {
DCHECK(IsMainThread()); DCHECK(IsMainThread());
} }
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
namespace blink { namespace blink {
class LocalFrame; class Document;
class ScriptPromiseResolver; class ScriptPromiseResolver;
// This is the base implementation of Worklet interface defined in the spec: // This is the base implementation of Worklet interface defined in the spec:
...@@ -47,8 +47,7 @@ class CORE_EXPORT Worklet : public ScriptWrappable, ...@@ -47,8 +47,7 @@ class CORE_EXPORT Worklet : public ScriptWrappable,
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
protected: protected:
// The Worklet inherits the url and userAgent from the frame->document(). explicit Worklet(Document*);
explicit Worklet(LocalFrame*);
// Returns one of available global scopes. // Returns one of available global scopes.
WorkletGlobalScopeProxy* FindAvailableGlobalScope(); WorkletGlobalScopeProxy* FindAvailableGlobalScope();
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
#include "bindings/core/v8/V8BindingForCore.h" #include "bindings/core/v8/V8BindingForCore.h"
#include "core/dom/AnimationWorkletProxyClient.h" #include "core/dom/AnimationWorkletProxyClient.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/frame/LocalFrame.h"
#include "core/page/ChromeClient.h" #include "core/page/ChromeClient.h"
#include "core/workers/WorkerClients.h" #include "core/workers/WorkerClients.h"
#include "modules/animationworklet/AnimationWorkletMessagingProxy.h" #include "modules/animationworklet/AnimationWorkletMessagingProxy.h"
...@@ -16,14 +15,9 @@ ...@@ -16,14 +15,9 @@
namespace blink { namespace blink {
// static AnimationWorklet::AnimationWorklet(Document* document) : Worklet(document) {}
AnimationWorklet* AnimationWorklet::Create(LocalFrame* frame) {
return new AnimationWorklet(frame);
}
AnimationWorklet::AnimationWorklet(LocalFrame* frame) : Worklet(frame) {}
AnimationWorklet::~AnimationWorklet() {} AnimationWorklet::~AnimationWorklet() = default;
bool AnimationWorklet::NeedsToCreateGlobalScope() { bool AnimationWorklet::NeedsToCreateGlobalScope() {
// For now, create only one global scope per document. // For now, create only one global scope per document.
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
namespace blink { namespace blink {
class LocalFrame; class Document;
// Represents the animation worklet on the main thread. All the logic for // Represents the animation worklet on the main thread. All the logic for
// loading a new source module is implemented in its parent class |Worklet|. The // loading a new source module is implemented in its parent class |Worklet|. The
...@@ -22,13 +22,12 @@ class MODULES_EXPORT AnimationWorklet final : public Worklet { ...@@ -22,13 +22,12 @@ class MODULES_EXPORT AnimationWorklet final : public Worklet {
WTF_MAKE_NONCOPYABLE(AnimationWorklet); WTF_MAKE_NONCOPYABLE(AnimationWorklet);
public: public:
static AnimationWorklet* Create(LocalFrame*); explicit AnimationWorklet(Document*);
~AnimationWorklet() override; ~AnimationWorklet() override;
void Trace(blink::Visitor*) override; void Trace(blink::Visitor*) override;
private: private:
explicit AnimationWorklet(LocalFrame*);
// Implements Worklet. // Implements Worklet.
bool NeedsToCreateGlobalScope() final; bool NeedsToCreateGlobalScope() final;
......
...@@ -42,15 +42,15 @@ WindowAnimationWorklet& WindowAnimationWorklet::From(LocalDOMWindow& window) { ...@@ -42,15 +42,15 @@ WindowAnimationWorklet& WindowAnimationWorklet::From(LocalDOMWindow& window) {
WindowAnimationWorklet* supplement = static_cast<WindowAnimationWorklet*>( WindowAnimationWorklet* supplement = static_cast<WindowAnimationWorklet*>(
Supplement<LocalDOMWindow>::From(window, SupplementName())); Supplement<LocalDOMWindow>::From(window, SupplementName()));
if (!supplement) { if (!supplement) {
supplement = new WindowAnimationWorklet(window); supplement = new WindowAnimationWorklet(window.GetFrame()->GetDocument());
ProvideTo(window, SupplementName(), supplement); ProvideTo(window, SupplementName(), supplement);
} }
return *supplement; return *supplement;
} }
WindowAnimationWorklet::WindowAnimationWorklet(LocalDOMWindow& window) WindowAnimationWorklet::WindowAnimationWorklet(Document* document)
: ContextLifecycleObserver(window.GetFrame()->GetDocument()), : ContextLifecycleObserver(document),
animation_worklet_(AnimationWorklet::Create(window.GetFrame())) { animation_worklet_(new AnimationWorklet(document)) {
DCHECK(GetExecutionContext()); DCHECK(GetExecutionContext());
} }
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
namespace blink { namespace blink {
class Document;
class LocalDOMWindow; class LocalDOMWindow;
class MODULES_EXPORT WindowAnimationWorklet final class MODULES_EXPORT WindowAnimationWorklet final
...@@ -31,7 +32,7 @@ class MODULES_EXPORT WindowAnimationWorklet final ...@@ -31,7 +32,7 @@ class MODULES_EXPORT WindowAnimationWorklet final
private: private:
static WindowAnimationWorklet& From(LocalDOMWindow&); static WindowAnimationWorklet& From(LocalDOMWindow&);
explicit WindowAnimationWorklet(LocalDOMWindow&); explicit WindowAnimationWorklet(Document*);
static const char* SupplementName(); static const char* SupplementName();
Member<AnimationWorklet> animation_worklet_; Member<AnimationWorklet> animation_worklet_;
......
...@@ -36,7 +36,7 @@ PaintWorklet* PaintWorklet::Create(LocalFrame* frame) { ...@@ -36,7 +36,7 @@ PaintWorklet* PaintWorklet::Create(LocalFrame* frame) {
} }
PaintWorklet::PaintWorklet(LocalFrame* frame) PaintWorklet::PaintWorklet(LocalFrame* frame)
: Worklet(frame), : Worklet(frame->GetDocument()),
Supplement<LocalDOMWindow>(*frame->DomWindow()), Supplement<LocalDOMWindow>(*frame->DomWindow()),
pending_generator_registry_(new PaintWorkletPendingGeneratorRegistry) {} pending_generator_registry_(new PaintWorkletPendingGeneratorRegistry) {}
......
...@@ -6,8 +6,6 @@ ...@@ -6,8 +6,6 @@
#include "bindings/core/v8/V8BindingForCore.h" #include "bindings/core/v8/V8BindingForCore.h"
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/UseCounter.h" #include "core/frame/UseCounter.h"
#include "core/workers/WorkerClients.h" #include "core/workers/WorkerClients.h"
#include "modules/webaudio/AudioWorkletMessagingProxy.h" #include "modules/webaudio/AudioWorkletMessagingProxy.h"
...@@ -23,8 +21,7 @@ AudioWorklet* AudioWorklet::Create(BaseAudioContext* context) { ...@@ -23,8 +21,7 @@ AudioWorklet* AudioWorklet::Create(BaseAudioContext* context) {
} }
AudioWorklet::AudioWorklet(BaseAudioContext* context) AudioWorklet::AudioWorklet(BaseAudioContext* context)
: Worklet(context->GetExecutionContext()->ExecutingWindow()->GetFrame()), : Worklet(ToDocument(context->GetExecutionContext())), context_(context) {}
context_(context) {}
void AudioWorklet::CreateProcessor(AudioWorkletHandler* handler, void AudioWorklet::CreateProcessor(AudioWorkletHandler* handler,
MessagePortChannel message_port_channel) { MessagePortChannel message_port_channel) {
...@@ -71,7 +68,7 @@ bool AudioWorklet::IsReady() { ...@@ -71,7 +68,7 @@ bool AudioWorklet::IsReady() {
bool AudioWorklet::NeedsToCreateGlobalScope() { bool AudioWorklet::NeedsToCreateGlobalScope() {
// This is a callback from |Worklet::FetchAndInvokeScript| call, which only // This is a callback from |Worklet::FetchAndInvokeScript| call, which only
// can be triggered by Worklet.addModule() call. // can be triggered by Worklet.addModule() call.
UseCounter::Count(GetFrame(), WebFeature::kAudioWorkletAddModule); UseCounter::Count(GetExecutionContext(), WebFeature::kAudioWorkletAddModule);
return GetNumberOfGlobalScopes() == 0; return GetNumberOfGlobalScopes() == 0;
} }
......
...@@ -151,11 +151,7 @@ void BaseAudioContext::Initialize() { ...@@ -151,11 +151,7 @@ void BaseAudioContext::Initialize() {
if (OriginTrials::audioWorkletEnabled(GetExecutionContext()) || if (OriginTrials::audioWorkletEnabled(GetExecutionContext()) ||
RuntimeEnabledFeatures::AudioWorkletEnabled()) { RuntimeEnabledFeatures::AudioWorkletEnabled()) {
// Worklet requires a valid Frame object, but GetFrame() from the window audio_worklet_ = AudioWorklet::Create(this);
// can be nullptr. Block out such case. See: crbug.com/792108
if (GetExecutionContext()->ExecutingWindow()->GetFrame()) {
audio_worklet_ = AudioWorklet::Create(this);
}
} }
if (destination_node_) { if (destination_node_) {
......
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