fix: apply transparency settings to WebContentsPreferences #31685
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
transparencysetting 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::CreateFromWebPreferencesto 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 testpassesRelease Notes
Notes: Fixes an issue where transparency was not always set correctly on webContents.