Skip to content

Commit

Permalink
fix: handle a nil backgroundColor in win.getBackgroundColor() (#28186)
Browse files Browse the repository at this point in the history
* fix: handle a nil backgroundColor in win.getBackgroundColor()

* spec: add crash case

* fix: update to fix native_views transparent color

* chore: fix lint

Co-authored-by: Samuel Attard <sattard@slack-corp.com>
Co-authored-by: Samuel Attard <sam@electronjs.org>
  • Loading branch information
3 people authored Mar 15, 2021
1 parent 592430f commit b740cd2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions shell/browser/native_window_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1202,8 +1202,10 @@ void ViewDidMoveToSuperview(NSView* self, SEL _cmd) {
}

SkColor NativeWindowMac::GetBackgroundColor() {
return skia::CGColorRefToSkColor(
[[[window_ contentView] layer] backgroundColor]);
CGColorRef color = [[[window_ contentView] layer] backgroundColor];
if (!color)
return SK_ColorTRANSPARENT;
return skia::CGColorRefToSkColor(color);
}

void NativeWindowMac::SetHasShadow(bool has_shadow) {
Expand Down
5 changes: 4 additions & 1 deletion shell/browser/native_window_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,10 @@ bool NativeWindowViews::IsKiosk() {
}

SkColor NativeWindowViews::GetBackgroundColor() {
return root_view_->background()->get_color();
auto* background = root_view_->background();
if (!background)
return SK_ColorTRANSPARENT;
return background->get_color();
}

void NativeWindowViews::SetBackgroundColor(SkColor background_color) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const { app, BrowserWindow } = require('electron');

function createWindow () {
// Create the browser window.
const mainWindow = new BrowserWindow({
transparent: true
});
mainWindow.getBackgroundColor();
}

app.on('ready', () => {
createWindow();
setTimeout(() => app.quit());
});

0 comments on commit b740cd2

Please sign in to comment.