mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: falsy transparent shouldn't affect webContents background (#38159)
This commit is contained in:
@@ -524,17 +524,10 @@ WebContents.prototype._callWindowOpenHandler = function (event: Electron.Event,
|
||||
event.preventDefault();
|
||||
return defaultResponse;
|
||||
} else if (response.action === 'allow') {
|
||||
if (typeof response.overrideBrowserWindowOptions === 'object' && response.overrideBrowserWindowOptions !== null) {
|
||||
return {
|
||||
browserWindowConstructorOptions: response.overrideBrowserWindowOptions,
|
||||
outlivesOpener: typeof response.outlivesOpener === 'boolean' ? response.outlivesOpener : false
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
browserWindowConstructorOptions: {},
|
||||
outlivesOpener: typeof response.outlivesOpener === 'boolean' ? response.outlivesOpener : false
|
||||
};
|
||||
}
|
||||
return {
|
||||
browserWindowConstructorOptions: typeof response.overrideBrowserWindowOptions === 'object' ? response.overrideBrowserWindowOptions : null,
|
||||
outlivesOpener: typeof response.outlivesOpener === 'boolean' ? response.outlivesOpener : false
|
||||
};
|
||||
} else {
|
||||
event.preventDefault();
|
||||
console.error('The window open handler response must be an object with an \'action\' property of \'allow\' or \'deny\'.');
|
||||
|
||||
@@ -226,7 +226,7 @@ void WebContentsPreferences::SetFromDictionary(
|
||||
// preferences don't save a transparency option,
|
||||
// apply any existing transparency setting to background_color_
|
||||
bool transparent;
|
||||
if (web_preferences.Get(options::kTransparent, &transparent)) {
|
||||
if (web_preferences.Get(options::kTransparent, &transparent) && transparent) {
|
||||
background_color_ = SK_ColorTRANSPARENT;
|
||||
}
|
||||
std::string background_color;
|
||||
|
||||
@@ -5596,7 +5596,7 @@ describe('BrowserWindow module', () => {
|
||||
});
|
||||
|
||||
// Linux and arm64 platforms (WOA and macOS) do not return any capture sources
|
||||
ifit(process.platform === 'darwin' && process.arch !== 'x64')('should not display a visible background', async () => {
|
||||
ifit(process.platform === 'darwin' && process.arch === 'x64')('should not display a visible background', async () => {
|
||||
const display = screen.getPrimaryDisplay();
|
||||
|
||||
const backgroundWindow = new BrowserWindow({
|
||||
@@ -5669,6 +5669,32 @@ describe('BrowserWindow module', () => {
|
||||
|
||||
expect(areColorsSimilar(centerColor, HexColors.PURPLE)).to.be.true();
|
||||
});
|
||||
|
||||
// Linux and arm64 platforms (WOA and macOS) do not return any capture sources
|
||||
ifit(process.platform === 'darwin' && process.arch === 'x64')('should not make background transparent if falsy', async () => {
|
||||
const display = screen.getPrimaryDisplay();
|
||||
|
||||
for (const transparent of [false, undefined]) {
|
||||
const window = new BrowserWindow({
|
||||
...display.bounds,
|
||||
transparent
|
||||
});
|
||||
|
||||
await emittedOnce(window, 'show');
|
||||
await window.webContents.loadURL('data:text/html,<head><meta name="color-scheme" content="dark"></head>');
|
||||
|
||||
await delay(500);
|
||||
const screenCapture = await captureScreen();
|
||||
const centerColor = getPixelColor(screenCapture, {
|
||||
x: display.size.width / 2,
|
||||
y: display.size.height / 2
|
||||
});
|
||||
window.close();
|
||||
|
||||
// color-scheme is set to dark so background should not be white
|
||||
expect(areColorsSimilar(centerColor, HexColors.WHITE)).to.be.false();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('"backgroundColor" option', () => {
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { BrowserWindow } from 'electron';
|
||||
import { BrowserWindow, screen } from 'electron';
|
||||
import { expect, assert } from 'chai';
|
||||
import { emittedOnce } from './events-helpers';
|
||||
import { areColorsSimilar, captureScreen, HexColors, getPixelColor } from './screen-helpers';
|
||||
import { ifit, delay } from './spec-helpers';
|
||||
import { closeAllWindows } from './window-helpers';
|
||||
const { emittedOnce } = require('./events-helpers');
|
||||
|
||||
describe('webContents.setWindowOpenHandler', () => {
|
||||
let browserWindow: BrowserWindow;
|
||||
@@ -194,4 +196,31 @@ describe('webContents.setWindowOpenHandler', () => {
|
||||
browserWindow.webContents.executeJavaScript("window.open('https://127.0.0.1')");
|
||||
expect(await browserWindow.webContents.executeJavaScript('42')).to.equal(42);
|
||||
});
|
||||
|
||||
// Linux and arm64 platforms (WOA and macOS) do not return any capture sources
|
||||
ifit(process.platform === 'darwin' && process.arch === 'x64')('should not make child window background transparent', (done) => {
|
||||
browserWindow.webContents.setWindowOpenHandler(() => ({ action: 'allow' }));
|
||||
|
||||
browserWindow.webContents.once('did-create-window', async (childWindow) => {
|
||||
const display = screen.getPrimaryDisplay();
|
||||
childWindow.setBounds(display.bounds);
|
||||
await childWindow.webContents.executeJavaScript("const meta = document.createElement('meta'); meta.name = 'color-scheme'; meta.content = 'dark'; document.head.appendChild(meta); true;");
|
||||
await delay(1000);
|
||||
const screenCapture = await captureScreen();
|
||||
const centerColor = getPixelColor(screenCapture, {
|
||||
x: display.size.width / 2,
|
||||
y: display.size.height / 2
|
||||
});
|
||||
|
||||
try {
|
||||
// color-scheme is set to dark so background should not be white
|
||||
expect(areColorsSimilar(centerColor, HexColors.WHITE)).to.be.false();
|
||||
done();
|
||||
} catch (err) {
|
||||
done(err);
|
||||
}
|
||||
});
|
||||
|
||||
browserWindow.webContents.executeJavaScript("window.open('about:blank') && true");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,8 @@ export enum HexColors {
|
||||
GREEN = '#00b140',
|
||||
PURPLE = '#6a0dad',
|
||||
RED = '#ff0000',
|
||||
BLUE = '#0000ff'
|
||||
BLUE = '#0000ff',
|
||||
WHITE = '#ffffff'
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user