From 87064e5b5e19b9165beff5483a1953e07245d66b Mon Sep 17 00:00:00 2001 From: marekharanczyk <48673767+marekharanczyk@users.noreply.github.com> Date: Wed, 10 Feb 2021 21:03:48 +0100 Subject: [PATCH] fix: set WebContents background color ubiquitously #27592 (#27593) Move it from LoadURL to RenderViewCreated which is present in all window creation cases and is called early enough to be relevant from user prespective and after RenderWidgetHostView is already present. --- .../browser/api/electron_api_web_contents.cc | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index 8e0703bd9ca..711bfba4885 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -1361,6 +1361,19 @@ void WebContents::BeforeUnloadFired(bool proceed, void WebContents::RenderViewCreated(content::RenderViewHost* render_view_host) { if (!background_throttling_) render_view_host->SetSchedulerThrottling(false); + + // Set the background color of RenderWidgetHostView. + auto* const view = web_contents()->GetRenderWidgetHostView(); + auto* web_preferences = WebContentsPreferences::From(web_contents()); + if (view && web_preferences) { + std::string color_name; + if (web_preferences->GetPreference(options::kBackgroundColor, + &color_name)) { + view->SetBackgroundColor(ParseHexColor(color_name)); + } else { + view->SetBackgroundColor(SK_ColorTRANSPARENT); + } + } } void WebContents::RenderFrameCreated( @@ -1994,21 +2007,6 @@ void WebContents::LoadURL(const GURL& url, // Required to make beforeunload handler work. NotifyUserActivation(); - - // Set the background color of RenderWidgetHostView. - // We have to call it right after LoadURL because the RenderViewHost is only - // created after loading a page. - auto* const view = weak_this->web_contents()->GetRenderWidgetHostView(); - if (view) { - auto* web_preferences = WebContentsPreferences::From(web_contents()); - std::string color_name; - if (web_preferences->GetPreference(options::kBackgroundColor, - &color_name)) { - view->SetBackgroundColor(ParseHexColor(color_name)); - } else { - view->SetBackgroundColor(SK_ColorTRANSPARENT); - } - } } void WebContents::DownloadURL(const GURL& url) {