From e918fe6030d1934eb0ee4b957379489161801ac6 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Wed, 3 Nov 2021 12:50:57 -0700 Subject: [PATCH] fix: apply transparency settings to WebContentsPreferences (#31700) * fix: add transparency to web_contents_preferences * fix: correctly apply transparency settings to new webContents from webPreferences Co-authored-by: VerteDinde --- shell/browser/api/electron_api_web_contents.cc | 6 ++++-- shell/browser/web_contents_preferences.cc | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/shell/browser/api/electron_api_web_contents.cc b/shell/browser/api/electron_api_web_contents.cc index cc5e9fceb9bdc..dae8e8dd01f89 100644 --- a/shell/browser/api/electron_api_web_contents.cc +++ b/shell/browser/api/electron_api_web_contents.cc @@ -4028,9 +4028,11 @@ gin::Handle WebContents::CreateFromWebPreferences( absl::optional color = existing_preferences->GetBackgroundColor(); web_contents->web_contents()->SetPageBaseBackgroundColor(color); + // Because web preferences don't recognize transparency, + // only set rwhv background color if a color exists auto* rwhv = web_contents->web_contents()->GetRenderWidgetHostView(); - if (rwhv) - rwhv->SetBackgroundColor(color.value_or(SK_ColorWHITE)); + if (rwhv && color.has_value()) + rwhv->SetBackgroundColor(color.value()); } } else { // Create one if not. diff --git a/shell/browser/web_contents_preferences.cc b/shell/browser/web_contents_preferences.cc index 6927be5b9b6ab..efa0aa9fdae4e 100644 --- a/shell/browser/web_contents_preferences.cc +++ b/shell/browser/web_contents_preferences.cc @@ -225,6 +225,12 @@ void WebContentsPreferences::SetFromDictionary( web_preferences.Get("disablePopups", &disable_popups_); web_preferences.Get("disableDialogs", &disable_dialogs_); web_preferences.Get("safeDialogs", &safe_dialogs_); + // preferences don't save a transparency option, + // apply any existing transparency setting to background_color_ + bool transparent; + if (web_preferences.Get(options::kTransparent, &transparent)) { + background_color_ = SK_ColorTRANSPARENT; + } std::string background_color; if (web_preferences.GetHidden(options::kBackgroundColor, &background_color)) background_color_ = ParseHexColor(background_color);