mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: apply zoomFactor from setWindowOpenHandler to window.open() windows (#49911)
fix: apply zoomFactor from setWindowOpenHandler to window.open() windows Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
@@ -4742,6 +4742,19 @@ gin_helper::Handle<WebContents> WebContents::CreateFromWebPreferences(
|
||||
existing_preferences->SetFromDictionary(web_preferences_dict);
|
||||
web_contents->SetBackgroundColor(
|
||||
existing_preferences->GetBackgroundColor());
|
||||
|
||||
double zoom_factor;
|
||||
if (web_preferences.Get(options::kZoomFactor, &zoom_factor)) {
|
||||
auto* zoom_controller = WebContentsZoomController::FromWebContents(
|
||||
web_contents->web_contents());
|
||||
if (zoom_controller) {
|
||||
zoom_controller->SetDefaultZoomFactor(zoom_factor);
|
||||
// Also set the current zoom level immediately, since the page
|
||||
// has already navigated by the time we wrap the webContents.
|
||||
zoom_controller->SetZoomLevel(
|
||||
blink::ZoomFactorToZoomLevel(zoom_factor));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Create one if not.
|
||||
|
||||
@@ -3977,6 +3977,28 @@ describe('BrowserWindow module', () => {
|
||||
expect(webPreferences!.contextIsolation).to.equal(false);
|
||||
});
|
||||
|
||||
it('should apply zoomFactor from setWindowOpenHandler overrideBrowserWindowOptions', async () => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
webPreferences: {
|
||||
sandbox: true
|
||||
}
|
||||
});
|
||||
|
||||
w.webContents.setWindowOpenHandler(() => ({
|
||||
action: 'allow',
|
||||
overrideBrowserWindowOptions: {
|
||||
webPreferences: {
|
||||
zoomFactor: 2.0
|
||||
}
|
||||
}
|
||||
}));
|
||||
w.loadFile(path.join(fixtures, 'api', 'new-window.html'));
|
||||
const [childWindow] = await once(w.webContents, 'did-create-window') as [BrowserWindow, any];
|
||||
await once(childWindow.webContents, 'did-finish-load');
|
||||
expect(childWindow.webContents.getZoomFactor()).to.be.closeTo(2.0, 0.1);
|
||||
});
|
||||
|
||||
it('should set ipc event sender correctly', async () => {
|
||||
const w = new BrowserWindow({
|
||||
show: false,
|
||||
|
||||
Reference in New Issue
Block a user