fix: backgroundThrottling rwh assignment (#21037)

* fix: backgroundThrottling rwh assignment

* fix: disable DOM timer throttling

* chore: fix typo
This commit is contained in:
Shelley Vohr 2019-12-02 10:29:03 -08:00 committed by Robo
parent f2f52c23b5
commit c7cbc2e6b1
4 changed files with 183 additions and 23 deletions

View file

@ -88,3 +88,4 @@ build_win_fix_msstl_compatibility_for_pdf.patch
fix_missing_algorithm_include.patch
add_trustedauthclient_to_urlloaderfactory.patch
fix_focusowningwebcontents_to_handle_renderwidgethosts_for_oopifs.patch
feat_allow_disbaling_blink_scheduler_throttling_per_renderview.patch

View file

@ -0,0 +1,155 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: deepak1556 <hop2deep@gmail.com>
Date: Fri, 29 Nov 2019 16:08:14 -0800
Subject: feat: allow disabling blink scheduler throttling per RenderView
diff --git a/content/browser/renderer_host/render_view_host_impl.cc b/content/browser/renderer_host/render_view_host_impl.cc
index f95ac8630d499c2e4dd1f874873b7264e219dfe4..cfa2a325cdcce4d6ee8e833603cccf241be0f7fc 100644
--- a/content/browser/renderer_host/render_view_host_impl.cc
+++ b/content/browser/renderer_host/render_view_host_impl.cc
@@ -431,6 +431,10 @@ void RenderViewHostImpl::SetBackgroundOpaque(bool opaque) {
Send(new ViewMsg_SetBackgroundOpaque(GetRoutingID(), opaque));
}
+void RenderViewHostImpl::SetSchedulerThrottling(bool allowed) {
+ Send(new ViewMsg_SetSchedulerThrottling(GetRoutingID(), 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 5d18be58585804db41eee98f65b527ed89bbfee2..62e6fe1d025b17fb8924b8a01905b50925a148b2 100644
--- a/content/browser/renderer_host/render_view_host_impl.h
+++ b/content/browser/renderer_host/render_view_host_impl.h
@@ -104,6 +104,7 @@ class CONTENT_EXPORT RenderViewHostImpl
void NotifyMoveOrResizeStarted() override;
void SetWebUIProperty(const std::string& name,
const std::string& value) override;
+ void SetSchedulerThrottling(bool allowed) override;
WebPreferences GetWebkitPreferences() override;
void UpdateWebkitPreferences(const WebPreferences& prefs) override;
void OnWebkitPreferencesChanged() override;
diff --git a/content/common/view_messages.h b/content/common/view_messages.h
index ac32a53c5cd55e93342d705cc3021c4cb964c9c5..d2d1325c07658c6ffd48df8db8a5bcfbf6a0f670 100644
--- a/content/common/view_messages.h
+++ b/content/common/view_messages.h
@@ -115,6 +115,9 @@ IPC_STRUCT_TRAITS_END()
// Make the RenderWidget background transparent or opaque.
IPC_MESSAGE_ROUTED1(ViewMsg_SetBackgroundOpaque, bool /* opaque */)
+// Whether to enable the Renderer scheduler background throttling.
+IPC_MESSAGE_ROUTED1(ViewMsg_SetSchedulerThrottling, bool /* allowed */)
+
// This passes a set of webkit preferences down to the renderer.
IPC_MESSAGE_ROUTED1(ViewMsg_UpdateWebPreferences,
content::WebPreferences)
diff --git a/content/public/browser/render_view_host.h b/content/public/browser/render_view_host.h
index a0c210b5df52598ce9bcc810d776b86cffac837c..0edc8e6f48c39c4dcc2bb3ce64363c722910a286 100644
--- a/content/public/browser/render_view_host.h
+++ b/content/public/browser/render_view_host.h
@@ -104,6 +104,9 @@ class CONTENT_EXPORT RenderViewHost : public IPC::Sender {
virtual void SetWebUIProperty(const std::string& name,
const std::string& value) = 0;
+ // Disable/Enable scheduler throttling.
+ virtual void SetSchedulerThrottling(bool allowed) = 0;
+
// TODO(mustaq): Replace "Webkit" from the following three method names.
//
// Returns the current WebKit preferences. Note: WebPreferences is cached, so
diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc
index 08ef43b9dcd13ee48598dd50b893347635ab6b06..2929528c73e3bad0c5b784c56ff45a97b3e3e375 100644
--- a/content/renderer/render_view_impl.cc
+++ b/content/renderer/render_view_impl.cc
@@ -1257,6 +1257,8 @@ bool RenderViewImpl::OnMessageReceived(const IPC::Message& message) {
IPC_BEGIN_MESSAGE_MAP(RenderViewImpl, message)
IPC_MESSAGE_HANDLER(ViewMsg_SetPageScale, OnSetPageScale)
IPC_MESSAGE_HANDLER(ViewMsg_SetInitialFocus, OnSetInitialFocus)
+ IPC_MESSAGE_HANDLER(ViewMsg_SetSchedulerThrottling,
+ OnSetSchedulerThrottling)
IPC_MESSAGE_HANDLER(ViewMsg_UpdateTargetURL_ACK, OnUpdateTargetURLAck)
IPC_MESSAGE_HANDLER(ViewMsg_UpdateWebPreferences, OnUpdateWebPreferences)
IPC_MESSAGE_HANDLER(ViewMsg_ClosePage, OnClosePage)
@@ -1862,6 +1864,12 @@ void RenderViewImpl::OnSetPageScale(float page_scale_factor) {
webview()->SetPageScaleFactor(page_scale_factor);
}
+void RenderViewImpl::OnSetSchedulerThrottling(bool allowed) {
+ if (!webview())
+ return;
+ webview()->SetSchedulerThrottling(allowed);
+}
+
void RenderViewImpl::ApplyPageHidden(bool hidden, bool initial_setting) {
webview()->SetIsHidden(hidden, initial_setting);
// Note: RenderWidget visibility is separately set from the IPC handlers, and
diff --git a/content/renderer/render_view_impl.h b/content/renderer/render_view_impl.h
index 0907c4cdc11b3c775e8856672c397388fa12d91f..bcab94fdd5079e459dcf4e906b22acdbac003dd9 100644
--- a/content/renderer/render_view_impl.h
+++ b/content/renderer/render_view_impl.h
@@ -451,6 +451,7 @@ class CONTENT_EXPORT RenderViewImpl : public blink::WebViewClient,
void OnSetRendererPrefs(
const blink::mojom::RendererPreferences& renderer_prefs);
void OnSetWebUIProperty(const std::string& name, const std::string& value);
+ void OnSetSchedulerThrottling(bool allowed);
void OnSuppressDialogsUntilSwapOut();
void OnUpdateTargetURLAck();
void OnUpdateWebPreferences(const WebPreferences& prefs);
diff --git a/third_party/blink/public/web/web_view.h b/third_party/blink/public/web/web_view.h
index bd279e31c8bbaa1d9e0f97155f912ac9501fee6c..30b1634775e6f8c9ae4e771a7d8394de06b68a61 100644
--- a/third_party/blink/public/web/web_view.h
+++ b/third_party/blink/public/web/web_view.h
@@ -402,6 +402,7 @@ class WebView {
// Scheduling -----------------------------------------------------------
virtual PageScheduler* Scheduler() const = 0;
+ virtual void SetSchedulerThrottling(bool allowed) = 0;
// 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 a395c00732349a5ee65a69afac10f61ef5ccf236..8efbe8bc04e675cdb4c43fb22e310256156b94cc 100644
--- a/third_party/blink/renderer/core/exported/web_view_impl.cc
+++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
@@ -3415,10 +3415,17 @@ PageScheduler* WebViewImpl::Scheduler() const {
return GetPage()->GetPageScheduler();
}
+void WebViewImpl::SetSchedulerThrottling(bool allowed) {
+ DCHECK(GetPage());
+ scheduler_throttling_allowed_ = allowed;
+ GetPage()->GetPageScheduler()->SetPageVisible(allowed ? !IsHidden() : true);
+}
+
void WebViewImpl::SetIsHidden(bool hidden, bool is_initial_state) {
DCHECK(GetPage());
GetPage()->SetIsHidden(hidden, is_initial_state);
- GetPage()->GetPageScheduler()->SetPageVisible(!hidden);
+ GetPage()->GetPageScheduler()->SetPageVisible(
+ scheduler_throttling_allowed_ ? !hidden : true);
}
bool WebViewImpl::IsHidden() {
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 e3f37ec7c3d31188503bbea2f0d8d4de5f062ecf..c9a866f74dcde800d4aadf65cef7559c55eb69d3 100644
--- a/third_party/blink/renderer/core/exported/web_view_impl.h
+++ b/third_party/blink/renderer/core/exported/web_view_impl.h
@@ -313,6 +313,7 @@ class CORE_EXPORT WebViewImpl final : public WebView,
PaintLayerCompositor* Compositor() const;
PageScheduler* Scheduler() const override;
+ void SetSchedulerThrottling(bool allowed) override;
void SetIsHidden(bool hidden, bool is_initial_state) override;
bool IsHidden() override;
@@ -690,6 +691,8 @@ class CORE_EXPORT WebViewImpl final : public WebView,
// WebViewImpl::Close while handling an input event.
bool debug_inside_input_handling_ = false;
+ bool scheduler_throttling_allowed_ = true;
+
FloatSize elastic_overscroll_;
Persistent<EventListener> popup_mouse_wheel_event_listener_;

View file

@ -863,10 +863,20 @@ void WebContents::BeforeUnloadFired(bool proceed,
}
void WebContents::RenderViewCreated(content::RenderViewHost* render_view_host) {
auto* impl = static_cast<content::RenderWidgetHostImpl*>(
render_view_host->GetWidget());
if (impl)
impl->disable_hidden_ = !background_throttling_;
if (!background_throttling_)
render_view_host->SetSchedulerThrottling(false);
}
void WebContents::RenderFrameCreated(
content::RenderFrameHost* render_frame_host) {
auto* rwhv = render_frame_host->GetView();
if (!rwhv)
return;
auto* rwh_impl =
static_cast<content::RenderWidgetHostImpl*>(rwhv->GetRenderWidgetHost());
if (rwh_impl)
rwh_impl->disable_hidden_ = !background_throttling_;
}
void WebContents::RenderViewHostChanged(content::RenderViewHost* old_host,
@ -1286,31 +1296,24 @@ void WebContents::NavigationEntryCommitted(
void WebContents::SetBackgroundThrottling(bool allowed) {
background_throttling_ = allowed;
auto* contents = web_contents();
if (!contents) {
auto* rfh = web_contents()->GetMainFrame();
if (!rfh)
return;
}
auto* render_view_host = contents->GetRenderViewHost();
if (!render_view_host) {
auto* rwhv = rfh->GetView();
if (!rwhv)
return;
}
auto* render_process_host = render_view_host->GetProcess();
if (!render_process_host) {
auto* rwh_impl =
static_cast<content::RenderWidgetHostImpl*>(rwhv->GetRenderWidgetHost());
if (!rwh_impl)
return;
}
auto* render_widget_host_impl = content::RenderWidgetHostImpl::FromID(
render_process_host->GetID(), render_view_host->GetRoutingID());
if (!render_widget_host_impl) {
return;
}
rwh_impl->disable_hidden_ = !background_throttling_;
web_contents()->GetRenderViewHost()->SetSchedulerThrottling(allowed);
render_widget_host_impl->disable_hidden_ = !background_throttling_;
if (render_widget_host_impl->is_hidden()) {
render_widget_host_impl->WasShown(base::nullopt);
if (rwh_impl->is_hidden()) {
rwh_impl->WasShown(base::nullopt);
}
}

View file

@ -422,7 +422,8 @@ class WebContents : public gin_helper::TrackableObject<WebContents>,
// content::WebContentsObserver:
void BeforeUnloadFired(bool proceed,
const base::TimeTicks& proceed_time) override;
void RenderViewCreated(content::RenderViewHost*) override;
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
void RenderFrameCreated(content::RenderFrameHost* render_frame_host) override;
void RenderViewHostChanged(content::RenderViewHost* old_host,
content::RenderViewHost* new_host) override;
void RenderViewDeleted(content::RenderViewHost*) override;