From 8d66340e3ed0c1d96e896cd98a827ec8bb3f8fe5 Mon Sep 17 00:00:00 2001 From: samuelmaddock Date: Tue, 31 Aug 2021 19:25:13 -0400 Subject: [PATCH] fix: BrowserWindow backgroundColor --- shell/browser/api/electron_api_browser_window.cc | 4 +--- shell/browser/api/electron_api_web_contents.cc | 10 +++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/shell/browser/api/electron_api_browser_window.cc b/shell/browser/api/electron_api_browser_window.cc index 68e772caf3af1..a61657f1d4ee9 100644 --- a/shell/browser/api/electron_api_browser_window.cc +++ b/shell/browser/api/electron_api_browser_window.cc @@ -360,9 +360,7 @@ void BrowserWindow::Blur() { void BrowserWindow::SetBackgroundColor(const std::string& color_name) { BaseWindow::SetBackgroundColor(color_name); - auto* view = web_contents()->GetRenderWidgetHostView(); - if (view) - view->SetBackgroundColor(ParseHexColor(color_name)); + web_contents()->SetPageBaseBackgroundColor(ParseHexColor(color_name)); // Also update the web preferences object otherwise the view will be reset on // the next load URL call if (api_web_contents_) { diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index b0952e34f5907..e5d6053cff4e6 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -1377,8 +1377,16 @@ void WebContents::HandleNewRenderFrame( std::string color_name; if (web_preferences->GetPreference(options::kBackgroundColor, &color_name)) { - rwhv->SetBackgroundColor(ParseHexColor(color_name)); + web_contents()->SetPageBaseBackgroundColor(ParseHexColor(color_name)); } else { + web_contents()->SetPageBaseBackgroundColor(absl::nullopt); + } + + // When a page base background color is set, transparency needs to be + // explicitly set by calling + // RenderWidgetHostOwnerDelegate::SetBackgroundOpaque(false). + // RenderWidgetHostViewBase::SetBackgroundColor() will do this for us. + if (web_preferences->IsEnabled(options::kTransparent)) { rwhv->SetBackgroundColor(SK_ColorTRANSPARENT); } }