mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: backgroundThrottling rwh assignment (#21358)
* fix: backgroundThrottling rwh assignment * fix: disable DOM timer throttling * chore: fix typo
This commit is contained in:
@@ -87,3 +87,4 @@ chore_use_electron_resources_not_chrome_for_spellchecker.patch
|
||||
fix_add_missing_include_algorithm_as_needed.patch
|
||||
add_trustedauthclient_to_urlloaderfactory.patch
|
||||
fix_focusowningwebcontents_to_handle_renderwidgethosts_for_oopifs.patch
|
||||
feat_allow_disbaling_blink_scheduler_throttling_per_renderview.patch
|
||||
|
||||
@@ -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 47ef3deb0e645c4d173902051ed7bb2d5b7dcf3e..8b322d50a7873113110b32b8d21707ae36458a4c 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 ef396103f614a16dc1137061db939ea8f8f1ee42..ebd616daee663c1e54de209fcbaa0791ed6e7abe 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 e31eca37ea538c1c26fe6be636d2b0372792653b..5e35cfc73a785bb2021eefa3c5b3bd4550bdcbad 100644
|
||||
--- a/content/renderer/render_view_impl.cc
|
||||
+++ b/content/renderer/render_view_impl.cc
|
||||
@@ -1256,6 +1256,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)
|
||||
@@ -1857,6 +1859,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 367c9d35d41511c344b9f52cbaa506188b3b5490..a1bb786b58eff06915d8a1af2c2e852dcc3b19cc 100644
|
||||
--- a/third_party/blink/renderer/core/exported/web_view_impl.cc
|
||||
+++ b/third_party/blink/renderer/core/exported/web_view_impl.cc
|
||||
@@ -3370,10 +3370,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 a4a5046c8c7e0c50d4a0e6a19ad1ae6d5e098d06..a04587c8c8405024483a377e07fb3f4ede45ff8a 100644
|
||||
--- a/third_party/blink/renderer/core/exported/web_view_impl.h
|
||||
+++ b/third_party/blink/renderer/core/exported/web_view_impl.h
|
||||
@@ -309,6 +309,7 @@ class CORE_EXPORT WebViewImpl final : public WebView,
|
||||
LocalDOMWindow* PagePopupWindow() const;
|
||||
|
||||
PageScheduler* Scheduler() const override;
|
||||
+ void SetSchedulerThrottling(bool allowed) override;
|
||||
void SetIsHidden(bool hidden, bool is_initial_state) override;
|
||||
bool IsHidden() override;
|
||||
|
||||
@@ -683,6 +684,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_;
|
||||
@@ -867,10 +867,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,
|
||||
@@ -1290,31 +1300,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -422,7 +422,8 @@ class WebContents : public mate::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;
|
||||
|
||||
Reference in New Issue
Block a user