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
Conversation
67ccba5
to
8a30f4b
Compare
@VerteDinde this PR does not fix #31686. |
Milan and I took a look at this PR - I'm going to merge this to fix an open issue with child windows and "-will-add-new-contents", I think we'll have to take a slightly different code path for the webview issue. Changing the rwhv call to |
Release Notes Persisted
|
I have automatically backported this PR to "16-x-y", please check out #31700 |
…31685) * fix: add transparency to web_contents_preferences * fix: correctly apply transparency settings to new webContents from webPreferences
Description of Change
In #30193, we refactored WebContentsPreferences to store its values directly and centralize logic for default values. As part of that refactor, the
transparency
setting was removed, and any transparent values were instead stored in thebackground_color_
property (e.g.,background_color_ = SK_ColorTRANSPARENT
.We handle for cases like this explicitly for browser windows here:
electron/shell/browser/api/electron_api_browser_window.cc
Lines 40 to 50 in a2d993c
However, this transparency handling only applies to browser windows, and does not take into account events where the WebContents or WebContentsPreferences are created independently from the browser window, such as "-will-add-new-contents" events.
This PR adds a transparency check to web_contents_preferences, where any passed-in transparency values are checked and set the background_color_ to
SK_ColorTRANSPARENT
.It also slightly amends a check in
WebContents::CreateFromWebPreferences
to only set a color to the RenderWidgetHostView if a color value exists. Because we're creating a window from web preferences, which don't recognize transparency, this can override transparent web contents with a white background on the window itself.This PR has been tested on a series of gists to make sure no regressions were caused:
Background Color (gist)
Transparent Main Window (gist)
Transparent Child Window (gist)
Checklist
npm test
passesRelease Notes
Notes: Fixes an issue where transparency was not always set correctly on webContents.