Skip to content

Commit

Permalink
fix: correctly apply transparency settings to new webContents from we…
Browse files Browse the repository at this point in the history
…bPreferences
  • Loading branch information
VerteDinde committed Nov 2, 2021
1 parent 201d8bf commit 8a30f4b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
16 changes: 8 additions & 8 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1456,14 +1456,9 @@ void WebContents::HandleNewRenderFrame(
// Set the background color of RenderWidgetHostView.
auto* web_preferences = WebContentsPreferences::From(web_contents());
if (web_preferences) {
bool transparent = web_preferences->GetTransparency();
if (transparent) {
rwhv->SetBackgroundColor(SK_ColorTRANSPARENT);
} else {
absl::optional<SkColor> color = web_preferences->GetBackgroundColor();
web_contents()->SetPageBaseBackgroundColor(color);
rwhv->SetBackgroundColor(color.value_or(SK_ColorWHITE));
}
absl::optional<SkColor> color = web_preferences->GetBackgroundColor();
web_contents()->SetPageBaseBackgroundColor(color);
rwhv->SetBackgroundColor(color.value_or(SK_ColorWHITE));
}

if (!background_throttling_)
Expand Down Expand Up @@ -4063,6 +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 && color.has_value())
rwhv->SetBackgroundColor(color.value());
}
} else {
// Create one if not.
Expand Down
5 changes: 3 additions & 2 deletions shell/browser/web_contents_preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ void WebContentsPreferences::Clear() {
safe_dialogs_ = false;
safe_dialogs_message_ = absl::nullopt;
ignore_menu_shortcuts_ = false;
transparent_ = false;
background_color_ = absl::nullopt;
image_animation_policy_ =
blink::mojom::ImageAnimationPolicy::kImageAnimationPolicyAllowed;
Expand Down Expand Up @@ -226,9 +225,11 @@ 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)) {
transparent_ = true;
background_color_ = SK_ColorTRANSPARENT;
}
std::string background_color;
if (web_preferences.GetHidden(options::kBackgroundColor, &background_color))
Expand Down
3 changes: 0 additions & 3 deletions shell/browser/web_contents_preferences.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ class WebContentsPreferences
base::Value* last_preference() { return &last_web_preferences_; }

bool IsOffscreen() const { return offscreen_; }
bool GetTransparency() const { return transparent_; }
void SetTransparency(bool transparent) { transparent_ = transparent; }
absl::optional<SkColor> GetBackgroundColor() const {
return background_color_;
}
Expand Down Expand Up @@ -125,7 +123,6 @@ class WebContentsPreferences
bool safe_dialogs_;
absl::optional<std::string> safe_dialogs_message_;
bool ignore_menu_shortcuts_;
bool transparent_;
absl::optional<SkColor> background_color_;
blink::mojom::ImageAnimationPolicy image_animation_policy_;
absl::optional<base::FilePath> preload_path_;
Expand Down

0 comments on commit 8a30f4b

Please sign in to comment.