fix: set WebContents background color ubiquitously (#27944)

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.

Co-authored-by: marekharanczyk <48673767+marekharanczyk@users.noreply.github.com>
This commit is contained in:
Shelley Vohr
2021-03-01 21:21:16 +00:00
committed by GitHub
parent 26c5cc2801
commit c50d0e49c1

View File

@@ -1091,6 +1091,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(
@@ -1715,21 +1728,6 @@ void WebContents::LoadURL(const GURL& url,
// It's not safe to assume that |this| points to valid memory at this point.
if (!weak_this)
return;
// 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) {