Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: apply transparency settings to WebContentsPreferences #31685

Merged
merged 2 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4058,9 +4058,11 @@ gin::Handle<WebContents> WebContents::CreateFromWebPreferences(
absl::optional<SkColor> 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.
Expand Down
6 changes: 6 additions & 0 deletions shell/browser/web_contents_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down