Compare commits

...

2 Commits

Author SHA1 Message Date
electron-patch-conflict-fixer[bot]
1d936143e3 Merged in branch 'main' to fix mergability 2023-02-08 14:25:50 +00:00
Milan Burda
7b2f78965a feat: pass parsed features to setWindowOpenHandler() callback 2022-06-23 22:39:36 +02:00
3 changed files with 12 additions and 3 deletions

View File

@@ -1168,6 +1168,7 @@ Ignore application menu shortcuts while this web contents is focused.
* `url` string - The _resolved_ version of the URL passed to `window.open()`. e.g. opening a window with `window.open('foo')` will yield something like `https://the-origin/the/current/path/foo`. * `url` string - The _resolved_ version of the URL passed to `window.open()`. e.g. opening a window with `window.open('foo')` will yield something like `https://the-origin/the/current/path/foo`.
* `frameName` string - Name of the window provided in `window.open()` * `frameName` string - Name of the window provided in `window.open()`
* `features` string - Comma separated list of window features provided to `window.open()`. * `features` string - Comma separated list of window features provided to `window.open()`.
* `parsedFeatures` Record<string, any> - Parsed version of the features.
* `disposition` string - Can be `default`, `foreground-tab`, `background-tab`, * `disposition` string - Can be `default`, `foreground-tab`, `background-tab`,
`new-window`, `save-to-disk` or `other`. `new-window`, `save-to-disk` or `other`.
* `referrer` [Referrer](structures/referrer.md) - The referrer that will be * `referrer` [Referrer](structures/referrer.md) - The referrer that will be

View File

@@ -4,7 +4,7 @@ import type { BrowserWindowConstructorOptions, LoadURLOptions } from 'electron/m
import * as url from 'url'; import * as url from 'url';
import * as path from 'path'; import * as path from 'path';
import { openGuestWindow, makeWebPreferences, parseContentTypeFormat } from '@electron/internal/browser/guest-window-manager'; import { openGuestWindow, makeWebPreferences, parseContentTypeFormat } from '@electron/internal/browser/guest-window-manager';
import { parseFeatures } from '@electron/internal/browser/parse-features-string'; import { parseFeatures, parseCommaSeparatedKeyValue } from '@electron/internal/browser/parse-features-string';
import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal'; import { ipcMainInternal } from '@electron/internal/browser/ipc-main-internal';
import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils'; import * as ipcMainUtils from '@electron/internal/browser/ipc-main-internal-utils';
import { MessagePortMain } from '@electron/internal/browser/message-port-main'; import { MessagePortMain } from '@electron/internal/browser/message-port-main';
@@ -662,6 +662,7 @@ WebContents.prototype._init = function () {
url, url,
frameName, frameName,
features: rawFeatures, features: rawFeatures,
parsedFeatures: parseCommaSeparatedKeyValue(rawFeatures),
referrer, referrer,
postBody, postBody,
disposition disposition
@@ -700,6 +701,7 @@ WebContents.prototype._init = function () {
url, url,
frameName, frameName,
features: rawFeatures, features: rawFeatures,
parsedFeatures: parseCommaSeparatedKeyValue(rawFeatures),
disposition, disposition,
referrer, referrer,
postBody postBody

View File

@@ -113,7 +113,7 @@ describe('webContents.setWindowOpenHandler', () => {
it('fires handler with correct params', async () => { it('fires handler with correct params', async () => {
const testFrameName = 'test-frame-name'; const testFrameName = 'test-frame-name';
const testFeatures = 'top=10&left=10&something-unknown&show=no'; const testFeatures = 'top=10,left=10,something-unknown,show=no';
const testUrl = 'app://does-not-exist/'; const testUrl = 'app://does-not-exist/';
const details = await new Promise<Electron.HandlerDetails>(resolve => { const details = await new Promise<Electron.HandlerDetails>(resolve => {
browserWindow.webContents.setWindowOpenHandler((details) => { browserWindow.webContents.setWindowOpenHandler((details) => {
@@ -123,10 +123,16 @@ describe('webContents.setWindowOpenHandler', () => {
browserWindow.webContents.executeJavaScript(`window.open('${testUrl}', '${testFrameName}', '${testFeatures}') && true`); browserWindow.webContents.executeJavaScript(`window.open('${testUrl}', '${testFrameName}', '${testFeatures}') && true`);
}); });
const { url, frameName, features, disposition, referrer } = details; const { url, frameName, features, parsedFeatures, disposition, referrer } = details;
expect(url).to.equal(testUrl); expect(url).to.equal(testUrl);
expect(frameName).to.equal(testFrameName); expect(frameName).to.equal(testFrameName);
expect(features).to.equal(testFeatures); expect(features).to.equal(testFeatures);
expect(parsedFeatures).to.deep.equal({
left: 10,
top: 10,
'something-unknown': true,
show: false
});
expect(disposition).to.equal('new-window'); expect(disposition).to.equal('new-window');
expect(referrer).to.deep.equal({ expect(referrer).to.deep.equal({
policy: 'strict-origin-when-cross-origin', policy: 'strict-origin-when-cross-origin',