refactor: improve feature string parsing (#23130)
* test: add pre-change snapshot of new-window event * move to .ts file for easier diff * refactor: improve feature string parsing logic * test: update snapshots * update type names per review * update comma-separated parse test * use for loop instead of reduce per review * tighten up types * avoid variable guest contents id returnValue in test snapshot
This commit is contained in:
parent
b3909f5600
commit
aca2e4f968
10 changed files with 589 additions and 108 deletions
|
@ -3,7 +3,7 @@
|
|||
const { webContents } = require('electron');
|
||||
const { ipcMainInternal } = require('@electron/internal/browser/ipc-main-internal');
|
||||
const ipcMainUtils = require('@electron/internal/browser/ipc-main-internal-utils');
|
||||
const { parseFeaturesString } = require('@electron/internal/common/parse-features-string');
|
||||
const { parseWebViewWebPreferences } = require('@electron/internal/common/parse-features-string');
|
||||
const { syncMethods, asyncMethods, properties } = require('@electron/internal/common/web-view-methods');
|
||||
const { serialize } = require('@electron/internal/common/type-utils');
|
||||
|
||||
|
@ -184,6 +184,13 @@ const attachGuest = function (event, embedderFrameId, elementInstanceId, guestIn
|
|||
}
|
||||
}
|
||||
|
||||
// parse the 'webpreferences' attribute string, if set
|
||||
// this uses the same parsing rules as window.open uses for its features
|
||||
const parsedWebPreferences =
|
||||
typeof params.webpreferences === 'string'
|
||||
? parseWebViewWebPreferences(params.webpreferences)
|
||||
: null;
|
||||
|
||||
const webPreferences = {
|
||||
guestInstanceId: guestInstanceId,
|
||||
nodeIntegration: params.nodeintegration != null ? params.nodeintegration : false,
|
||||
|
@ -194,21 +201,10 @@ const attachGuest = function (event, embedderFrameId, elementInstanceId, guestIn
|
|||
disablePopups: !params.allowpopups,
|
||||
webSecurity: !params.disablewebsecurity,
|
||||
enableBlinkFeatures: params.blinkfeatures,
|
||||
disableBlinkFeatures: params.disableblinkfeatures
|
||||
disableBlinkFeatures: params.disableblinkfeatures,
|
||||
...parsedWebPreferences
|
||||
};
|
||||
|
||||
// parse the 'webpreferences' attribute string, if set
|
||||
// this uses the same parsing rules as window.open uses for its features
|
||||
if (typeof params.webpreferences === 'string') {
|
||||
parseFeaturesString(params.webpreferences, function (key, value) {
|
||||
if (value === undefined) {
|
||||
// no value was specified, default it to true
|
||||
value = true;
|
||||
}
|
||||
webPreferences[key] = value;
|
||||
});
|
||||
}
|
||||
|
||||
if (params.preload) {
|
||||
webPreferences.preloadURL = params.preload;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue