Commit cc367865 authored by Fernando Serboncini's avatar Fernando Serboncini Committed by Commit Bot

Prevents RAF crash with invalid Workers

If BeginFrameProvider is invalid, we should not pass RAF calls.

Bug: 860102
Cq-Include-Trybots: luci.chromium.try:linux_layout_tests_slimming_paint_v2;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I4bf971316bf93c19d4613f38c413575a0c2be17a
Reviewed-on: https://chromium-review.googlesource.com/1147429Reviewed-by: default avatarJustin Novosad <junov@chromium.org>
Commit-Queue: Fernando Serboncini <fserb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579046}
parent 9b3eab8e
...@@ -22,6 +22,10 @@ WorkerAnimationFrameProvider::WorkerAnimationFrameProvider( ...@@ -22,6 +22,10 @@ WorkerAnimationFrameProvider::WorkerAnimationFrameProvider(
int WorkerAnimationFrameProvider::RegisterCallback( int WorkerAnimationFrameProvider::RegisterCallback(
FrameRequestCallbackCollection::FrameCallback* callback) { FrameRequestCallbackCollection::FrameCallback* callback) {
if (!begin_frame_provider_->IsValidFrameProvider()) {
return WorkerAnimationFrameProvider::kInvalidCallbackId;
}
FrameRequestCallbackCollection::CallbackId id = FrameRequestCallbackCollection::CallbackId id =
callback_collection_.RegisterCallback(callback); callback_collection_.RegisterCallback(callback);
begin_frame_provider_->RequestBeginFrame(); begin_frame_provider_->RequestBeginFrame();
......
...@@ -48,6 +48,8 @@ class CORE_EXPORT WorkerAnimationFrameProvider ...@@ -48,6 +48,8 @@ class CORE_EXPORT WorkerAnimationFrameProvider
void RegisterOffscreenCanvas(OffscreenCanvas*); void RegisterOffscreenCanvas(OffscreenCanvas*);
void DeregisterOffscreenCanvas(OffscreenCanvas*); void DeregisterOffscreenCanvas(OffscreenCanvas*);
static const int kInvalidCallbackId = -1;
protected: protected:
WorkerAnimationFrameProvider( WorkerAnimationFrameProvider(
ExecutionContext* context, ExecutionContext* context,
......
...@@ -405,12 +405,21 @@ void WorkerGlobalScope::RemoveURLFromMemoryCache(const KURL& url) { ...@@ -405,12 +405,21 @@ void WorkerGlobalScope::RemoveURLFromMemoryCache(const KURL& url) {
CrossThreadBind(&RemoveURLFromMemoryCacheInternal, url)); CrossThreadBind(&RemoveURLFromMemoryCacheInternal, url));
} }
int WorkerGlobalScope::requestAnimationFrame(V8FrameRequestCallback* callback) { int WorkerGlobalScope::requestAnimationFrame(V8FrameRequestCallback* callback,
ExceptionState& exception_state) {
FrameRequestCallbackCollection::V8FrameCallback* frame_callback = FrameRequestCallbackCollection::V8FrameCallback* frame_callback =
FrameRequestCallbackCollection::V8FrameCallback::Create(callback); FrameRequestCallbackCollection::V8FrameCallback::Create(callback);
frame_callback->SetUseLegacyTimeBase(true); frame_callback->SetUseLegacyTimeBase(true);
return animation_frame_provider_->RegisterCallback(frame_callback); 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) { void WorkerGlobalScope::cancelAnimationFrame(int id) {
......
...@@ -150,7 +150,7 @@ class CORE_EXPORT WorkerGlobalScope ...@@ -150,7 +150,7 @@ class CORE_EXPORT WorkerGlobalScope
// FontFaceSource on the IDL. // FontFaceSource on the IDL.
FontFaceSet* fonts(); FontFaceSet* fonts();
int requestAnimationFrame(V8FrameRequestCallback* callback); int requestAnimationFrame(V8FrameRequestCallback* callback, ExceptionState&);
void cancelAnimationFrame(int id); void cancelAnimationFrame(int id);
WorkerAnimationFrameProvider* GetAnimationFrameProvider() { WorkerAnimationFrameProvider* GetAnimationFrameProvider() {
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
// TODO(fserb): temporarly until we can enable the interface below. // TODO(fserb): temporarly until we can enable the interface below.
[RuntimeEnabled=OffscreenCanvasText] readonly attribute FontFaceSet fonts; [RuntimeEnabled=OffscreenCanvasText] readonly attribute FontFaceSet fonts;
[RuntimeEnabled=OffscreenCanvas] long requestAnimationFrame(FrameRequestCallback callback); [RuntimeEnabled=OffscreenCanvas, RaisesException] long requestAnimationFrame(FrameRequestCallback callback);
[RuntimeEnabled=OffscreenCanvas] void cancelAnimationFrame(long handle); [RuntimeEnabled=OffscreenCanvas] void cancelAnimationFrame(long handle);
}; };
......
...@@ -42,6 +42,14 @@ void BeginFrameProvider::OnMojoConnectionError(uint32_t custom_reason, ...@@ -42,6 +42,14 @@ void BeginFrameProvider::OnMojoConnectionError(uint32_t custom_reason,
ResetCompositorFrameSink(); ResetCompositorFrameSink();
} }
bool BeginFrameProvider::IsValidFrameProvider() {
if (!parent_frame_sink_id_.is_valid() || !frame_sink_id_.is_valid()) {
return false;
}
return true;
}
void BeginFrameProvider::CreateCompositorFrameSinkIfNeeded() { void BeginFrameProvider::CreateCompositorFrameSinkIfNeeded() {
if (!parent_frame_sink_id_.is_valid() || !frame_sink_id_.is_valid()) { if (!parent_frame_sink_id_.is_valid() || !frame_sink_id_.is_valid()) {
return; return;
......
...@@ -60,6 +60,8 @@ class PLATFORM_EXPORT BeginFrameProvider ...@@ -60,6 +60,8 @@ class PLATFORM_EXPORT BeginFrameProvider
void ResetCompositorFrameSink(); void ResetCompositorFrameSink();
bool IsValidFrameProvider();
~BeginFrameProvider() override = default; ~BeginFrameProvider() override = default;
private: private:
......
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