Commit 1822d34a authored by Fernando Serboncini's avatar Fernando Serboncini Committed by Commit Bot

Move requestAnimationFrame to DedicatedWorkerGlobalScope

This class was wrongfully attached to all WorkerGlobalScope.
This fixes it and aligns us to the spec.

Bug: 1003442
Change-Id: I829620997d0149da36d036eaba40c569f899991b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1807576Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Commit-Queue: Fernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699381}
parent 793ce820
......@@ -19,7 +19,7 @@
#include "third_party/blink/renderer/core/html/canvas/canvas_rendering_context_factory.h"
#include "third_party/blink/renderer/core/html/canvas/image_data.h"
#include "third_party/blink/renderer/core/imagebitmap/image_bitmap.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
#include "third_party/blink/renderer/core/workers/dedicated_worker_global_scope.h"
#include "third_party/blink/renderer/platform/graphics/canvas_resource_dispatcher.h"
#include "third_party/blink/renderer/platform/graphics/canvas_resource_provider.h"
#include "third_party/blink/renderer/platform/graphics/gpu/shared_gpu_context.h"
......@@ -77,9 +77,9 @@ void OffscreenCanvas::Dispose() {
}
if (HasPlaceholderCanvas() && GetTopExecutionContext() &&
GetTopExecutionContext()->IsWorkerGlobalScope()) {
GetTopExecutionContext()->IsDedicatedWorkerGlobalScope()) {
WorkerAnimationFrameProvider* animation_frame_provider =
To<WorkerGlobalScope>(GetTopExecutionContext())
To<DedicatedWorkerGlobalScope>(GetTopExecutionContext())
->GetAnimationFrameProvider();
if (animation_frame_provider)
animation_frame_provider->DeregisterOffscreenCanvas(this);
......@@ -89,9 +89,9 @@ void OffscreenCanvas::Dispose() {
void OffscreenCanvas::SetPlaceholderCanvasId(DOMNodeId canvas_id) {
placeholder_canvas_id_ = canvas_id;
if (GetTopExecutionContext() &&
GetTopExecutionContext()->IsWorkerGlobalScope()) {
GetTopExecutionContext()->IsDedicatedWorkerGlobalScope()) {
WorkerAnimationFrameProvider* animation_frame_provider =
To<WorkerGlobalScope>(GetTopExecutionContext())
To<DedicatedWorkerGlobalScope>(GetTopExecutionContext())
->GetAnimationFrameProvider();
if (animation_frame_provider)
animation_frame_provider->RegisterOffscreenCanvas(this);
......
......@@ -64,6 +64,8 @@ DedicatedWorkerGlobalScope* DedicatedWorkerGlobalScope::Create(
base::TimeTicks time_origin) {
std::unique_ptr<Vector<String>> outside_origin_trial_tokens =
std::move(creation_params->origin_trial_tokens);
BeginFrameProviderParams begin_frame_provider_params =
creation_params->begin_frame_provider_params;
// Off-the-main-thread worker script fetch:
// Initialize() is called after script fetch.
......@@ -71,7 +73,7 @@ DedicatedWorkerGlobalScope* DedicatedWorkerGlobalScope::Create(
OffMainThreadWorkerScriptFetchOption::kEnabled) {
return MakeGarbageCollected<DedicatedWorkerGlobalScope>(
std::move(creation_params), thread, time_origin,
std::move(outside_origin_trial_tokens));
std::move(outside_origin_trial_tokens), begin_frame_provider_params);
}
// Legacy on-the-main-thread worker script fetch (to be removed):
......@@ -82,7 +84,7 @@ DedicatedWorkerGlobalScope* DedicatedWorkerGlobalScope::Create(
*creation_params->response_address_space;
auto* global_scope = MakeGarbageCollected<DedicatedWorkerGlobalScope>(
std::move(creation_params), thread, time_origin,
std::move(outside_origin_trial_tokens));
std::move(outside_origin_trial_tokens), begin_frame_provider_params);
// Pass dummy CSP headers here as it is superseded by outside's CSP headers in
// Initialize().
// Pass dummy origin trial tokens here as it is already set to outside's
......@@ -100,8 +102,13 @@ DedicatedWorkerGlobalScope::DedicatedWorkerGlobalScope(
std::unique_ptr<GlobalScopeCreationParams> creation_params,
DedicatedWorkerThread* thread,
base::TimeTicks time_origin,
std::unique_ptr<Vector<String>> outside_origin_trial_tokens)
: WorkerGlobalScope(std::move(creation_params), thread, time_origin) {
std::unique_ptr<Vector<String>> outside_origin_trial_tokens,
const BeginFrameProviderParams& begin_frame_provider_params)
: WorkerGlobalScope(std::move(creation_params), thread, time_origin),
animation_frame_provider_(
MakeGarbageCollected<WorkerAnimationFrameProvider>(
this,
begin_frame_provider_params)) {
// Dedicated workers don't need to pause after script fetch.
ReadyToRunWorkerScript();
// Inherit the outside's origin trial tokens.
......@@ -304,12 +311,36 @@ void DedicatedWorkerGlobalScope::DidFetchClassicScript(
classic_script_loader->ReleaseCachedMetadata(), stack_id);
}
int DedicatedWorkerGlobalScope::requestAnimationFrame(
V8FrameRequestCallback* callback,
ExceptionState& exception_state) {
auto* frame_callback =
MakeGarbageCollected<FrameRequestCallbackCollection::V8FrameCallback>(
callback);
frame_callback->SetUseLegacyTimeBase(false);
int ret = animation_frame_provider_->RegisterCallback(frame_callback);
if (ret == WorkerAnimationFrameProvider::kInvalidCallbackId) {
exception_state.ThrowDOMException(
DOMExceptionCode::kNotSupportedError,
"requestAnimationFrame not supported in this Worker.");
}
return ret;
}
void DedicatedWorkerGlobalScope::cancelAnimationFrame(int id) {
animation_frame_provider_->CancelCallback(id);
}
DedicatedWorkerObjectProxy& DedicatedWorkerGlobalScope::WorkerObjectProxy()
const {
return static_cast<DedicatedWorkerThread*>(GetThread())->WorkerObjectProxy();
}
void DedicatedWorkerGlobalScope::Trace(blink::Visitor* visitor) {
visitor->Trace(animation_frame_provider_);
WorkerGlobalScope::Trace(visitor);
}
......
......@@ -32,6 +32,7 @@
#define THIRD_PARTY_BLINK_RENDERER_CORE_WORKERS_DEDICATED_WORKER_GLOBAL_SCOPE_H_
#include <memory>
#include "third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/messaging/message_port.h"
#include "third_party/blink/renderer/core/workers/worker_global_scope.h"
......@@ -64,7 +65,8 @@ class CORE_EXPORT DedicatedWorkerGlobalScope final : public WorkerGlobalScope {
std::unique_ptr<GlobalScopeCreationParams>,
DedicatedWorkerThread*,
base::TimeTicks time_origin,
std::unique_ptr<Vector<String>> outside_origin_trial_tokens);
std::unique_ptr<Vector<String>> outside_origin_trial_tokens,
const BeginFrameProviderParams& begin_frame_provider_params);
~DedicatedWorkerGlobalScope() override;
......@@ -75,6 +77,13 @@ class CORE_EXPORT DedicatedWorkerGlobalScope final : public WorkerGlobalScope {
// (via WorkerOrWorkletGlobalScope -> EventTargetWithInlineData).
const AtomicString& InterfaceName() const override;
// RequestAnimationFrame
int requestAnimationFrame(V8FrameRequestCallback* callback, ExceptionState&);
void cancelAnimationFrame(int id);
WorkerAnimationFrameProvider* GetAnimationFrameProvider() {
return animation_frame_provider_;
}
// Implements WorkerGlobalScope.
void Initialize(const KURL& response_url,
network::mojom::ReferrerPolicy response_referrer_policy,
......@@ -116,6 +125,8 @@ class CORE_EXPORT DedicatedWorkerGlobalScope final : public WorkerGlobalScope {
const v8_inspector::V8StackTraceId& stack_id);
DedicatedWorkerObjectProxy& WorkerObjectProxy() const;
Member<WorkerAnimationFrameProvider> animation_frame_provider_;
};
template <>
......
......@@ -41,6 +41,11 @@
void close();
// AnimationFrameProvider mixin
// https://html.spec.whatwg.org/C/#animation-frames
[RaisesException] long requestAnimationFrame(FrameRequestCallback callback);
void cancelAnimationFrame(long handle);
attribute EventHandler onmessage;
attribute EventHandler onmessageerror;
};
......@@ -489,10 +489,6 @@ WorkerGlobalScope::WorkerGlobalScope(
timers_(GetTaskRunner(TaskType::kJavascriptTimer)),
time_origin_(time_origin),
font_selector_(MakeGarbageCollected<OffscreenFontSelector>(this)),
animation_frame_provider_(
MakeGarbageCollected<WorkerAnimationFrameProvider>(
this,
creation_params->begin_frame_provider_params)),
script_eval_state_(ScriptEvalState::kPauseAfterFetch) {
InstanceCounters::IncrementCounter(
InstanceCounters::kWorkerGlobalScopeCounter);
......@@ -561,28 +557,6 @@ void WorkerGlobalScope::queueMicrotask(V8VoidFunction* callback) {
WrapPersistent(callback), nullptr));
}
int WorkerGlobalScope::requestAnimationFrame(V8FrameRequestCallback* callback,
ExceptionState& exception_state) {
auto* frame_callback =
MakeGarbageCollected<FrameRequestCallbackCollection::V8FrameCallback>(
callback);
frame_callback->SetUseLegacyTimeBase(false);
int ret = animation_frame_provider_->RegisterCallback(frame_callback);
if (ret == WorkerAnimationFrameProvider::kInvalidCallbackId) {
exception_state.ThrowDOMException(
DOMExceptionCode::kNotSupportedError,
"requestAnimationFrame not supported in this Worker.");
}
return ret;
}
void WorkerGlobalScope::cancelAnimationFrame(int id) {
animation_frame_provider_->CancelCallback(id);
}
void WorkerGlobalScope::SetWorkerSettings(
std::unique_ptr<WorkerSettings> worker_settings) {
worker_settings_ = std::move(worker_settings);
......@@ -605,7 +579,6 @@ void WorkerGlobalScope::Trace(blink::Visitor* visitor) {
visitor->Trace(timers_);
visitor->Trace(pending_error_events_);
visitor->Trace(font_selector_);
visitor->Trace(animation_frame_provider_);
visitor->Trace(trusted_types_);
visitor->Trace(worker_script_);
WorkerOrWorkletGlobalScope::Trace(visitor);
......
......@@ -35,7 +35,6 @@
#include "third_party/blink/public/common/browser_interface_broker_proxy.h"
#include "third_party/blink/public/mojom/script/script_type.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/active_script_wrappable.h"
#include "third_party/blink/renderer/core/animation_frame/worker_animation_frame_provider.h"
#include "third_party/blink/renderer/core/core_export.h"
#include "third_party/blink/renderer/core/dom/frame_request_callback_collection.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h"
......@@ -198,13 +197,6 @@ class CORE_EXPORT WorkerGlobalScope
// https://html.spec.whatwg.org/C/#windoworworkerglobalscope-mixin
void queueMicrotask(V8VoidFunction*);
int requestAnimationFrame(V8FrameRequestCallback* callback, ExceptionState&);
void cancelAnimationFrame(int id);
WorkerAnimationFrameProvider* GetAnimationFrameProvider() {
return animation_frame_provider_;
}
TrustedTypePolicyFactory* GetTrustedTypes() const override;
TrustedTypePolicyFactory* trustedTypesWorkers() const {
return GetTrustedTypes();
......@@ -266,7 +258,6 @@ class CORE_EXPORT WorkerGlobalScope
int last_pending_error_event_id_ = 0;
Member<OffscreenFontSelector> font_selector_;
Member<WorkerAnimationFrameProvider> animation_frame_provider_;
service_manager::InterfaceProvider interface_provider_;
......
......@@ -68,11 +68,6 @@
[Replaceable] readonly attribute DOMString origin;
void queueMicrotask(VoidFunction callback);
// AnimationFrameProvider mixin
// https://html.spec.whatwg.org/C/#animation-frames
[RaisesException] long requestAnimationFrame(FrameRequestCallback callback);
void cancelAnimationFrame(long handle);
// FontFaceSource
// https://drafts.csswg.org/css-font-loading-3/#font-face-source
// TODO(fserb): temporarly until we can enable the interface below.
......
This is a testharness.js-based test.
Found 673 tests; 647 PASS, 26 FAIL, 0 TIMEOUT, 0 NOTRUN.
Found 673 tests; 653 PASS, 20 FAIL, 0 TIMEOUT, 0 NOTRUN.
PASS idl_test setup
PASS Partial interface Document: original interface defined
PASS Partial interface mixin DocumentOrShadowRoot: original interface mixin defined
......@@ -517,8 +517,8 @@ PASS DedicatedWorkerGlobalScope interface: operation postMessage(any, PostMessag
PASS DedicatedWorkerGlobalScope interface: operation close()
PASS DedicatedWorkerGlobalScope interface: attribute onmessage
PASS DedicatedWorkerGlobalScope interface: attribute onmessageerror
FAIL DedicatedWorkerGlobalScope interface: operation requestAnimationFrame(FrameRequestCallback) assert_own_property: global object missing non-static operation expected property "requestAnimationFrame" missing
FAIL DedicatedWorkerGlobalScope interface: operation cancelAnimationFrame(unsigned long) assert_own_property: global object missing non-static operation expected property "cancelAnimationFrame" missing
PASS DedicatedWorkerGlobalScope interface: operation requestAnimationFrame(FrameRequestCallback)
PASS DedicatedWorkerGlobalScope interface: operation cancelAnimationFrame(unsigned long)
PASS DedicatedWorkerGlobalScope interface: internal [[SetPrototypeOf]] method of global platform object - setting to a new value via Object.setPrototypeOf should throw a TypeError
PASS DedicatedWorkerGlobalScope interface: internal [[SetPrototypeOf]] method of global platform object - setting to a new value via __proto__ should throw a TypeError
PASS DedicatedWorkerGlobalScope interface: internal [[SetPrototypeOf]] method of global platform object - setting to a new value via Reflect.setPrototypeOf should return false
......@@ -535,10 +535,10 @@ PASS DedicatedWorkerGlobalScope interface: calling postMessage(any, PostMessageO
PASS DedicatedWorkerGlobalScope interface: self must inherit property "close()" with the proper type
PASS DedicatedWorkerGlobalScope interface: self must inherit property "onmessage" with the proper type
PASS DedicatedWorkerGlobalScope interface: self must inherit property "onmessageerror" with the proper type
FAIL DedicatedWorkerGlobalScope interface: self must inherit property "requestAnimationFrame(FrameRequestCallback)" with the proper type assert_own_property: expected property "requestAnimationFrame" missing
FAIL DedicatedWorkerGlobalScope interface: calling requestAnimationFrame(FrameRequestCallback) on self with too few arguments must throw TypeError assert_own_property: expected property "requestAnimationFrame" missing
FAIL DedicatedWorkerGlobalScope interface: self must inherit property "cancelAnimationFrame(unsigned long)" with the proper type assert_own_property: expected property "cancelAnimationFrame" missing
FAIL DedicatedWorkerGlobalScope interface: calling cancelAnimationFrame(unsigned long) on self with too few arguments must throw TypeError assert_own_property: expected property "cancelAnimationFrame" missing
PASS DedicatedWorkerGlobalScope interface: self must inherit property "requestAnimationFrame(FrameRequestCallback)" with the proper type
PASS DedicatedWorkerGlobalScope interface: calling requestAnimationFrame(FrameRequestCallback) on self with too few arguments must throw TypeError
PASS DedicatedWorkerGlobalScope interface: self must inherit property "cancelAnimationFrame(unsigned long)" with the proper type
PASS DedicatedWorkerGlobalScope interface: calling cancelAnimationFrame(unsigned long) on self with too few arguments must throw TypeError
PASS WorkerGlobalScope interface: self must inherit property "self" with the proper type
PASS WorkerGlobalScope interface: self must inherit property "location" with the proper type
PASS WorkerGlobalScope interface: self must inherit property "navigator" with the proper type
......
......@@ -3679,7 +3679,6 @@ interface WorkerGlobalScope : EventTarget
getter self
method atob
method btoa
method cancelAnimationFrame
method clearInterval
method clearTimeout
method constructor
......@@ -3687,7 +3686,6 @@ interface WorkerGlobalScope : EventTarget
method fetch
method importScripts
method queueMicrotask
method requestAnimationFrame
method setInterval
method setTimeout
setter onerror
......
......@@ -2567,7 +2567,6 @@ interface WorkerGlobalScope : EventTarget
getter self
method atob
method btoa
method cancelAnimationFrame
method clearInterval
method clearTimeout
method constructor
......@@ -2575,7 +2574,6 @@ interface WorkerGlobalScope : EventTarget
method fetch
method importScripts
method queueMicrotask
method requestAnimationFrame
method setInterval
method setTimeout
setter onerror
......
......@@ -2591,7 +2591,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter self
[Worker] method atob
[Worker] method btoa
[Worker] method cancelAnimationFrame
[Worker] method clearInterval
[Worker] method clearTimeout
[Worker] method constructor
......@@ -2599,7 +2598,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method fetch
[Worker] method importScripts
[Worker] method queueMicrotask
[Worker] method requestAnimationFrame
[Worker] method setInterval
[Worker] method setTimeout
[Worker] setter onerror
......@@ -2715,9 +2713,11 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter name
[Worker] getter onmessage
[Worker] getter onmessageerror
[Worker] method cancelAnimationFrame
[Worker] method close
[Worker] method gc
[Worker] method postMessage
[Worker] method requestAnimationFrame
[Worker] method webkitRequestFileSystem
[Worker] method webkitRequestFileSystemSync
[Worker] method webkitResolveLocalFileSystemSyncURL
......
......@@ -2478,7 +2478,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter self
[Worker] method atob
[Worker] method btoa
[Worker] method cancelAnimationFrame
[Worker] method clearInterval
[Worker] method clearTimeout
[Worker] method constructor
......@@ -2486,7 +2485,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method fetch
[Worker] method importScripts
[Worker] method queueMicrotask
[Worker] method requestAnimationFrame
[Worker] method setInterval
[Worker] method setTimeout
[Worker] setter onerror
......
......@@ -3731,7 +3731,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter self
[Worker] method atob
[Worker] method btoa
[Worker] method cancelAnimationFrame
[Worker] method clearInterval
[Worker] method clearTimeout
[Worker] method constructor
......@@ -3739,7 +3738,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method fetch
[Worker] method importScripts
[Worker] method queueMicrotask
[Worker] method requestAnimationFrame
[Worker] method setInterval
[Worker] method setTimeout
[Worker] setter onerror
......@@ -3858,9 +3856,11 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter name
[Worker] getter onmessage
[Worker] getter onmessageerror
[Worker] method cancelAnimationFrame
[Worker] method close
[Worker] method gc
[Worker] method postMessage
[Worker] method requestAnimationFrame
[Worker] method webkitRequestFileSystem
[Worker] method webkitRequestFileSystemSync
[Worker] method webkitResolveLocalFileSystemSyncURL
......
......@@ -3580,7 +3580,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] getter self
[Worker] method atob
[Worker] method btoa
[Worker] method cancelAnimationFrame
[Worker] method clearInterval
[Worker] method clearTimeout
[Worker] method constructor
......@@ -3588,7 +3587,6 @@ Starting worker: resources/global-interface-listing-worker.js
[Worker] method fetch
[Worker] method importScripts
[Worker] method queueMicrotask
[Worker] method requestAnimationFrame
[Worker] method setInterval
[Worker] method setTimeout
[Worker] setter onerror
......
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