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 b8462d19d3b61e5813a0248b8667af5bbace4716..3939abfd02fa8728d48e99b1ee1c00135f8220c5 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 { (network::mojom::AttributionSupport support), (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 6e61c80ad9779c3c703d20d0617529583cbf5973..5a756e2e5d3cef2f4ad0137dd59f22bb6b68ddb2 100644 --- a/content/browser/renderer_host/render_view_host_impl.cc +++ b/content/browser/renderer_host/render_view_host_impl.cc @@ -754,6 +754,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 5fb8a3dc69dc5fc5bfa08e01d8f03707a23c9274..41774b60b8cb7e0a22cedc597dc07ad15c96988c 100644 --- a/content/browser/renderer_host/render_view_host_impl.h +++ b/content/browser/renderer_host/render_view_host_impl.h @@ -135,6 +135,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 e2d7bfcc45c6450de38a1dd1a743ac3de61f3d35..09a67ee96d89df82f14c4b10e2cf856feece66eb 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 603798ae0d45836f1bf3e6608761ce1467303310..2d8caa06e418f123d7565b96d40c66fb51617a6d 100644 --- a/content/test/test_page_broadcast.h +++ b/content/test/test_page_broadcast.h @@ -50,6 +50,7 @@ class TestPageBroadcast : public blink::mojom::PageBroadcast { network::mojom::AttributionSupport support) override; void UpdateColorProviders( const blink::ColorProviderColorMaps& color_provider_colors) 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 c980f3f76a37a4207bb54f18fbcdb8d0950c8856..91a9dfe56fbbcd1cc873add438947dd29c7e6646 100644 --- a/third_party/blink/public/mojom/page/page.mojom +++ b/third_party/blink/public/mojom/page/page.mojom @@ -173,4 +173,7 @@ interface PageBroadcast { // 2. The ColorProvider associated with the WebContents changes as a result // of theme changes. UpdateColorProviders(ColorProviderColorMaps color_provider_colors); + + // 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 083af135d890c2837e72c314e170e81931bd2a20..5245ea88441ef84c15b8052a9011ce70b8e9b848 100644 --- a/third_party/blink/public/web/web_view.h +++ b/third_party/blink/public/web/web_view.h @@ -371,6 +371,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 7a5ad6c9f2b0598f2aab5fabcea09cf60101e890..bf141e3d121736ac38ae918cbe8400ee92325824 100644 --- a/third_party/blink/renderer/core/exported/web_view_impl.cc +++ b/third_party/blink/renderer/core/exported/web_view_impl.cc @@ -2468,6 +2468,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 && @@ -3996,10 +4000,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 1700e9ae4809eb34bfa9e477131c928afcc87814..16bb378b55eec58f5bb1d717c3f2dd1e5ab072e3 100644 --- a/third_party/blink/renderer/core/exported/web_view_impl.h +++ b/third_party/blink/renderer/core/exported/web_view_impl.h @@ -448,6 +448,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; @@ -938,6 +939,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;