123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
- From: deepak1556 <[email protected]>
- 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/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc
- index 093bed2d057df4b12ae01b8edc11c7924233b0c5..43a24c45bc5adf1bb6a3eb00c3b3ad64e663522f 100644
- --- a/content/browser/renderer_host/render_view_host_impl.cc
- +++ b/content/browser/renderer_host/render_view_host_impl.cc
- @@ -716,6 +716,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 2d5431caee0b44828ae35a861cda8b15b587123f..5db98459e35767aee91c9b901c10f2f59ac1456b 100644
- --- a/content/browser/renderer_host/render_view_host_impl.h
- +++ b/content/browser/renderer_host/render_view_host_impl.h
- @@ -139,6 +139,7 @@ class CONTENT_EXPORT RenderViewHostImpl
- void EnablePreferredSizeMode() override;
- void WriteIntoTrace(perfetto::TracedProto<TraceProto> 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 2b7a01cd1e7637031bbd28ba32f332f9f97456f1..9840d0e1308bc6e4589f32f6eac5e27f353895dd 100644
- --- a/content/browser/renderer_host/render_widget_host_view_aura.cc
- +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc
- @@ -564,8 +564,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.
- - DCHECK(host_->is_hidden() || visibility_ == Visibility::VISIBLE);
- - OnShowWithPageVisibility(page_visibility);
- + if (host_->is_hidden() || visibility_ == Visibility::VISIBLE)
- + OnShowWithPageVisibility(page_visibility);
- }
-
- void RenderWidgetHostViewAura::NotifyHostAndDelegateOnWasShown(
- diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h
- index 9979c25ecd57e68331b628a518368635db5c2027..f65bfbbb663a5bb0511ffa389d3163e0fdeb4d1f 100644
- --- a/content/public/browser/render_view_host.h
- +++ b/content/public/browser/render_view_host.h
- @@ -76,6 +76,9 @@ class CONTENT_EXPORT RenderViewHost {
- virtual void WriteIntoTrace(
- perfetto::TracedProto<TraceProto> 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 b2204672b2dde14ce91a0c67e8a5b5ebede55aa9..0f9bed79ba572a5fffb4f39e2ffc6f58970ee7cb 100644
- --- a/content/test/test_page_broadcast.h
- +++ b/content/test/test_page_broadcast.h
- @@ -47,6 +47,7 @@ class TestPageBroadcast : public blink::mojom::PageBroadcast {
- browsing_context_group_info) override;
- void SetPageAttributionSupport(
- network::mojom::AttributionSupport support) override;
- + void SetSchedulerThrottling(bool allowed) override {}
-
- mojo::AssociatedReceiver<blink::mojom::PageBroadcast> receiver_;
- };
- diff --git a/third_party/blink/public/mojom/page/page.mojom b/third_party/blink/public/mojom/page/page.mojom
- index 1270218d71d365b3b33188ba803026e9a24f51dc..78fe7a385eb8781787c5288a9eb790df05afa088 100644
- --- a/third_party/blink/public/mojom/page/page.mojom
- +++ b/third_party/blink/public/mojom/page/page.mojom
- @@ -162,4 +162,7 @@ interface PageBroadcast {
- // supported/unsupported or when attribution is enabled/disabled for
- // Android WebView.
- SetPageAttributionSupport(network.mojom.AttributionSupport support);
- +
- + // 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 e89d7153d66d15e6e9a2a6980aaec5c671dfd0f3..c77228f8aa6ada81bcafc2622d784bb3f85cca30 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 9f211819ae0b54718c89ecb777fbf469fa4ebe4d..d9b1a87fb6c7dca120c1a7d25eeda1135f4a3831 100644
- --- a/third_party/blink/renderer/core/exported/web_view_impl.cc
- +++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
- @@ -2395,6 +2395,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 &&
- @@ -3885,10 +3889,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 90359a1f1aafadc7bb4e8776c9b609a7485072f6..b66744a6557152b69a3c769f8dfb5b0221d67a01 100644
- --- a/third_party/blink/renderer/core/exported/web_view_impl.h
- +++ b/third_party/blink/renderer/core/exported/web_view_impl.h
- @@ -447,6 +447,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;
- @@ -914,6 +915,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;
|