refactor: remove guestInstanceId from WebPreferences (#30280)
* refactor: remove guestInstanceId from WebPreferences * refactor: remove WebViewManager::GetEmbedder
This commit is contained in:
parent
c3abbdefdd
commit
c5ad7ed0cd
15 changed files with 53 additions and 71 deletions
|
@ -28,7 +28,7 @@ function sanitizeOptionsForGuest (options: Record<string, any>) {
|
|||
return ret;
|
||||
}
|
||||
|
||||
function makeWebPreferences (embedder: Electron.WebContents, params: Record<string, any>, guestInstanceId: number) {
|
||||
function makeWebPreferences (embedder: Electron.WebContents, params: Record<string, any>) {
|
||||
// parse the 'webpreferences' attribute string, if set
|
||||
// this uses the same parsing rules as window.open uses for its features
|
||||
const parsedWebPreferences =
|
||||
|
@ -37,7 +37,6 @@ function makeWebPreferences (embedder: Electron.WebContents, params: Record<stri
|
|||
: null;
|
||||
|
||||
const webPreferences: Electron.WebPreferences = {
|
||||
guestInstanceId,
|
||||
nodeIntegration: params.nodeintegration != null ? params.nodeintegration : false,
|
||||
nodeIntegrationInSubFrames: params.nodeintegrationinsubframes != null ? params.nodeintegrationinsubframes : false,
|
||||
plugins: params.plugins,
|
||||
|
@ -204,7 +203,7 @@ const attachGuest = function (event: Electron.IpcMainInvokeEvent,
|
|||
}
|
||||
}
|
||||
|
||||
const webPreferences = makeWebPreferences(embedder, params, guestInstanceId);
|
||||
const webPreferences = makeWebPreferences(embedder, params);
|
||||
|
||||
embedder.emit('will-attach-webview', event, webPreferences, params);
|
||||
if (event.defaultPrevented) {
|
||||
|
|
|
@ -74,7 +74,7 @@ const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
|
|||
const usesNativeWindowOpen = mainFrame.getWebPreference('nativeWindowOpen');
|
||||
const preloadScript = mainFrame.getWebPreference('preload');
|
||||
const preloadScripts = mainFrame.getWebPreference('preloadScripts');
|
||||
const guestInstanceId = mainFrame.getWebPreference('guestInstanceId');
|
||||
const isWebView = mainFrame.getWebPreference('isWebView');
|
||||
const openerId = mainFrame.getWebPreference('openerId');
|
||||
const appPath = hasSwitch('app-path') ? getSwitchValue('app-path') : null;
|
||||
|
||||
|
@ -98,14 +98,14 @@ switch (window.location.protocol) {
|
|||
default: {
|
||||
// Override default web functions.
|
||||
const { windowSetup } = require('@electron/internal/renderer/window-setup') as typeof windowSetupModule;
|
||||
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen);
|
||||
windowSetup(isWebView, openerId, isHiddenPage, usesNativeWindowOpen);
|
||||
}
|
||||
}
|
||||
|
||||
// Load webview tag implementation.
|
||||
if (process.isMainFrame) {
|
||||
const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init') as typeof webViewInitModule;
|
||||
webViewInit(contextIsolation, webviewTag, guestInstanceId);
|
||||
webViewInit(contextIsolation, webviewTag, isWebView);
|
||||
}
|
||||
|
||||
if (nodeIntegration) {
|
||||
|
|
|
@ -20,9 +20,9 @@ function handleFocusBlur () {
|
|||
});
|
||||
}
|
||||
|
||||
export function webViewInit (contextIsolation: boolean, webviewTag: boolean, guestInstanceId: number) {
|
||||
export function webViewInit (contextIsolation: boolean, webviewTag: boolean, isWebView: boolean) {
|
||||
// Don't allow recursive `<webview>`.
|
||||
if (webviewTag && !guestInstanceId) {
|
||||
if (webviewTag && !isWebView) {
|
||||
const guestViewInternal = require('@electron/internal/renderer/web-view/guest-view-internal') as typeof guestViewInternalModule;
|
||||
if (contextIsolation) {
|
||||
v8Util.setHiddenValue(window, 'guestViewInternal', guestViewInternal);
|
||||
|
@ -36,7 +36,7 @@ export function webViewInit (contextIsolation: boolean, webviewTag: boolean, gue
|
|||
}
|
||||
}
|
||||
|
||||
if (guestInstanceId) {
|
||||
if (isWebView) {
|
||||
// Report focus/blur events of webview to browser.
|
||||
handleFocusBlur();
|
||||
}
|
||||
|
|
|
@ -243,8 +243,8 @@ class BrowserWindowProxy {
|
|||
}
|
||||
|
||||
export const windowSetup = (
|
||||
guestInstanceId: number, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean) => {
|
||||
if (!process.sandboxed && !guestInstanceId) {
|
||||
isWebView: boolean, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean) => {
|
||||
if (!process.sandboxed && !isWebView) {
|
||||
// Override default window.close.
|
||||
window.close = function () {
|
||||
ipcRendererInternal.send(IPC_MESSAGES.BROWSER_WINDOW_CLOSE);
|
||||
|
@ -318,7 +318,7 @@ export const windowSetup = (
|
|||
});
|
||||
}
|
||||
|
||||
if (guestInstanceId) {
|
||||
if (isWebView) {
|
||||
// Webview `document.visibilityState` tracks window visibility (and ignores
|
||||
// the actual <webview> element visibility) for backwards compatibility.
|
||||
// See discussion in #9178.
|
||||
|
|
|
@ -127,7 +127,7 @@ const contextIsolation = mainFrame.getWebPreference('contextIsolation');
|
|||
const webviewTag = mainFrame.getWebPreference('webviewTag');
|
||||
const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
|
||||
const usesNativeWindowOpen = true;
|
||||
const guestInstanceId = mainFrame.getWebPreference('guestInstanceId');
|
||||
const isWebView = mainFrame.getWebPreference('isWebView');
|
||||
const openerId = mainFrame.getWebPreference('openerId');
|
||||
|
||||
switch (window.location.protocol) {
|
||||
|
@ -145,14 +145,14 @@ switch (window.location.protocol) {
|
|||
default: {
|
||||
// Override default web functions.
|
||||
const { windowSetup } = require('@electron/internal/renderer/window-setup') as typeof windowSetupModule;
|
||||
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen);
|
||||
windowSetup(isWebView, openerId, isHiddenPage, usesNativeWindowOpen);
|
||||
}
|
||||
}
|
||||
|
||||
// Load webview tag implementation.
|
||||
if (process.isMainFrame) {
|
||||
const { webViewInit } = require('@electron/internal/renderer/web-view/web-view-init') as typeof webViewInitModule;
|
||||
webViewInit(contextIsolation, webviewTag, guestInstanceId);
|
||||
webViewInit(contextIsolation, webviewTag, isWebView);
|
||||
}
|
||||
|
||||
// Wrap the script into a function executed in global scope. It won't have
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue