From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 18 May 2020 11:12:26 -0700 Subject: allow disabling blink scheduler throttling per RenderView This allows us to disable throttling for hidden windows. diff --git a/content/browser/renderer_host/navigation_controller_impl_unittest.cc b/content/browser/renderer_host/navigation_controller_impl_unittest.cc index 1d002528ba2b90d9c361c77ab00aeb1ccd000177..77f3b011f9c3710ac93ad20a92eafea0d35bb9a7 100644 --- a/content/browser/renderer_host/navigation_controller_impl_unittest.cc +++ b/content/browser/renderer_host/navigation_controller_impl_unittest.cc @@ -168,6 +168,12 @@ class MockPageBroadcast : public blink::mojom::PageBroadcast { (const std::optional canvas_noise_token), (override)); + MOCK_METHOD( + void, + SetSchedulerThrottling, + (bool allowed), + (override)); + mojo::PendingAssociatedRemote GetRemote() { return receiver_.BindNewEndpointAndPassDedicatedRemote(); } diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc index ac7638da0c0b360d21b88e4e458d3687949884fa..45d2fe002330cb4aa7c81defaa5004d5e62e369a 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -786,6 +786,11 @@ void RenderViewHostImpl::SetBackgroundOpaque(bool opaque) { GetWidget()->GetAssociatedFrameWidget()->SetBackgroundOpaque(opaque); } +void RenderViewHostImpl::SetSchedulerThrottling(bool allowed) { + if (auto& broadcast = GetAssociatedPageBroadcast()) + broadcast->SetSchedulerThrottling(allowed); +} + bool RenderViewHostImpl::IsMainFrameActive() { return is_active(); } diff --git a/content/browser/renderer_host/render_view_host_impl.h b/content/browser/renderer_host/render_view_host_impl.h index 7944fe64e0da112fc670358b75506bb199bb5e4a..0e3c16c6af2a078943e9f39808134ab20c115e99 100644 --- a/content/browser/renderer_host/render_view_host_impl.h +++ b/content/browser/renderer_host/render_view_host_impl.h @@ -136,6 +136,7 @@ class CONTENT_EXPORT RenderViewHostImpl void EnablePreferredSizeMode() override; void WriteIntoTrace(perfetto::TracedProto context) const override; + void SetSchedulerThrottling(bool allowed) override; void SendWebPreferencesToRenderer(); void SendRendererPreferencesToRenderer( const blink::RendererPreferences& preferences); diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index e98d74fecf4275ef8e7c6d23e5ea5ec3af80b926..0927d69b56d064327f0659d8ffe6ceff98064947 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -579,8 +579,8 @@ void RenderWidgetHostViewAura::ShowImpl(PageVisibilityState page_visibility) { // OnShowWithPageVisibility will not call NotifyHostAndDelegateOnWasShown, // which updates `visibility_`, unless the host is hidden. Make sure no update // is needed. - CHECK(host_->is_hidden() || visibility_ == Visibility::VISIBLE); - OnShowWithPageVisibility(page_visibility); + if (host_->is_hidden() || visibility_ == Visibility::VISIBLE) + OnShowWithPageVisibility(page_visibility); } void RenderWidgetHostViewAura::EnsurePlatformVisibility( diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h index 20ca763ff7f55e8176b77349b41917b11e051ae6..a50c122064b5f0092f57e3d508fb19389b72203b 100644 --- a/content/public/browser/render_view_host.h +++ b/content/public/browser/render_view_host.h @@ -75,6 +75,9 @@ class CONTENT_EXPORT RenderViewHost { virtual void WriteIntoTrace( perfetto::TracedProto context) const = 0; + // Disable/Enable scheduler throttling. + virtual void SetSchedulerThrottling(bool allowed) {} + private: // This interface should only be implemented inside content. friend class RenderViewHostImpl; diff --git a/content/test/test_page_broadcast.h b/content/test/test_page_broadcast.h index 0dc1cd52dec74ede2117eb244e423d7f3ad322ea..352c64b3aec50546451a0033114e3a35dcf32136 100644 --- a/content/test/test_page_broadcast.h +++ b/content/test/test_page_broadcast.h @@ -53,6 +53,7 @@ class TestPageBroadcast : public blink::mojom::PageBroadcast { const blink::ColorProviderColorMaps& color_provider_colors) override; void UpdateCanvasNoiseToken( std::optional canvas_noise_token) override; + void SetSchedulerThrottling(bool allowed) override {} mojo::AssociatedReceiver receiver_; }; diff --git a/third_party/blink/public/mojom/page/page.mojom b/third_party/blink/public/mojom/page/page.mojom index bcf8559d759e73e4f3f00710d263fe24cc801828..556f990868b862452156cec2354a90ae75352251 100644 --- a/third_party/blink/public/mojom/page/page.mojom +++ b/third_party/blink/public/mojom/page/page.mojom @@ -180,4 +180,7 @@ interface PageBroadcast { // the noise token at ReadyToCommit time and update blink::WebViews that // were made at request time. UpdateCanvasNoiseToken(uint64? canvas_noise_token); + + // Whether to enable the Renderer scheduler background throttling. + SetSchedulerThrottling(bool allowed); }; diff --git a/third_party/blink/public/web/web_view.h b/third_party/blink/public/web/web_view.h index b3553c0783a7b00e055f82ef0b72bd866284473d..c91e49807ec0b56d867504831118269116024626 100644 --- a/third_party/blink/public/web/web_view.h +++ b/third_party/blink/public/web/web_view.h @@ -365,6 +365,7 @@ class BLINK_EXPORT WebView { // Scheduling ----------------------------------------------------------- virtual PageScheduler* Scheduler() const = 0; + virtual void SetSchedulerThrottling(bool allowed) {} // Visibility ----------------------------------------------------------- diff --git a/third_party/blink/renderer/core/exported/web_view_impl.cc b/third_party/blink/renderer/core/exported/web_view_impl.cc index 714b713cd466ac289b3d172ac484ddfd2b46190b..be43ac07eb6563dcb72374dfc4f3bd34913e98c3 100644 --- a/third_party/blink/renderer/core/exported/web_view_impl.cc +++ b/third_party/blink/renderer/core/exported/web_view_impl.cc @@ -2500,6 +2500,10 @@ void WebViewImpl::SetPageLifecycleStateInternal( TRACE_EVENT2("navigation", "WebViewImpl::SetPageLifecycleStateInternal", "old_state", old_state, "new_state", new_state); + // If backgroundThrottling is disabled, the page is always visible. + if (!scheduler_throttling_allowed_) + new_state->visibility = mojom::blink::PageVisibilityState::kVisible; + bool storing_in_bfcache = new_state->is_in_back_forward_cache && !old_state->is_in_back_forward_cache; bool restoring_from_bfcache = !new_state->is_in_back_forward_cache && @@ -4009,10 +4013,23 @@ PageScheduler* WebViewImpl::Scheduler() const { return GetPage()->GetPageScheduler(); } +void WebViewImpl::SetSchedulerThrottling(bool allowed) { + DCHECK(GetPage()); + scheduler_throttling_allowed_ = allowed; + GetPage()->GetPageScheduler()->SetPageVisible(!allowed || GetVisibilityState() == mojom::blink::PageVisibilityState::kVisible); +} + void WebViewImpl::SetVisibilityState( mojom::blink::PageVisibilityState visibility_state, bool is_initial_state) { DCHECK(GetPage()); + + if (!scheduler_throttling_allowed_) { + GetPage()->SetVisibilityState(mojom::blink::PageVisibilityState::kVisible, is_initial_state); + GetPage()->GetPageScheduler()->SetPageVisible(true); + return; + } + GetPage()->SetVisibilityState(visibility_state, is_initial_state); // Do not throttle if the page should be painting. bool is_visible = diff --git a/third_party/blink/renderer/core/exported/web_view_impl.h b/third_party/blink/renderer/core/exported/web_view_impl.h index 883269126ff93c26765ab62013035c6193f8adbb..f821da879a6b6b04d33ef60037a053f3a5c0851d 100644 --- a/third_party/blink/renderer/core/exported/web_view_impl.h +++ b/third_party/blink/renderer/core/exported/web_view_impl.h @@ -450,6 +450,7 @@ class CORE_EXPORT WebViewImpl final : public WebView, LocalDOMWindow* PagePopupWindow() const; PageScheduler* Scheduler() const override; + void SetSchedulerThrottling(bool allowed) override; void SetVisibilityState(mojom::blink::PageVisibilityState visibility_state, bool is_initial_state) override; mojom::blink::PageVisibilityState GetVisibilityState() override; @@ -943,6 +944,8 @@ class CORE_EXPORT WebViewImpl final : public WebView, // If true, we send IPC messages when |preferred_size_| changes. bool send_preferred_size_changes_ = false; + bool scheduler_throttling_allowed_ = true; + // Whether the preferred size may have changed and |UpdatePreferredSize| needs // to be called. bool needs_preferred_size_update_ = true;