refactor: remove more dead code post render process reuse (#28983)

* Overrides for window.history.*
* Node environment cleanup / creation logic
* Options and switches that are now static values
This commit is contained in:
Samuel Attard 2021-05-04 11:30:29 -07:00 committed by GitHub
parent 38c877e9d3
commit e5e8ab4eea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 10 additions and 92 deletions

View file

@ -100,22 +100,6 @@ ipcMainUtils.handleSync(IPC_MESSAGES.BROWSER_SANDBOX_LOAD, async function (event
};
});
ipcMainInternal.on(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_BACK, function (event) {
event.sender.goBack();
});
ipcMainInternal.on(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_FORWARD, function (event) {
event.sender.goForward();
});
ipcMainInternal.on(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_TO_OFFSET, function (event, offset) {
event.sender.goToOffset(offset);
});
ipcMainInternal.on(IPC_MESSAGES.NAVIGATION_CONTROLLER_LENGTH, function (event) {
event.returnValue = event.sender.length();
});
ipcMainInternal.on(IPC_MESSAGES.BROWSER_PRELOAD_ERROR, function (event, preloadPath: string, error: Error) {
event.sender.emit('preload-error', event, preloadPath, error);
});

View file

@ -29,11 +29,6 @@ export const enum IPC_MESSAGES {
RENDERER_WEB_FRAME_METHOD = 'RENDERER_WEB_FRAME_METHOD',
NAVIGATION_CONTROLLER_GO_BACK = 'NAVIGATION_CONTROLLER_GO_BACK',
NAVIGATION_CONTROLLER_GO_FORWARD = 'NAVIGATION_CONTROLLER_GO_FORWARD',
NAVIGATION_CONTROLLER_GO_TO_OFFSET = 'NAVIGATION_CONTROLLER_GO_TO_OFFSET',
NAVIGATION_CONTROLLER_LENGTH = 'NAVIGATION_CONTROLLER_LENGTH',
INSPECTOR_CONFIRM = 'INSPECTOR_CONFIRM',
INSPECTOR_CONTEXT_MENU = 'INSPECTOR_CONTEXT_MENU',
INSPECTOR_SELECT_FILE = 'INSPECTOR_SELECT_FILE',

View file

@ -70,7 +70,6 @@ const nodeIntegration = mainFrame.getWebPreference('nodeIntegration');
const webviewTag = mainFrame.getWebPreference('webviewTag');
const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
const usesNativeWindowOpen = mainFrame.getWebPreference('nativeWindowOpen');
const rendererProcessReuseEnabled = mainFrame.getWebPreference('disableElectronSiteInstanceOverrides');
const preloadScript = mainFrame.getWebPreference('preload');
const preloadScripts = mainFrame.getWebPreference('preloadScripts');
const guestInstanceId = mainFrame.getWebPreference('guestInstanceId') || null;
@ -97,7 +96,7 @@ switch (window.location.protocol) {
default: {
// Override default web functions.
const { windowSetup } = require('@electron/internal/renderer/window-setup');
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled);
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen);
}
}

View file

@ -243,8 +243,7 @@ class BrowserWindowProxy {
}
export const windowSetup = (
guestInstanceId: number, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean, rendererProcessReuseEnabled: boolean
) => {
guestInstanceId: number, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean) => {
if (!process.sandboxed && guestInstanceId == null) {
// Override default window.close.
window.close = function () {
@ -319,30 +318,6 @@ export const windowSetup = (
});
}
if (!process.sandboxed && !rendererProcessReuseEnabled) {
window.history.back = function () {
ipcRendererInternal.send(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_BACK);
};
if (contextIsolationEnabled) internalContextBridge.overrideGlobalValueFromIsolatedWorld(['history', 'back'], window.history.back);
window.history.forward = function () {
ipcRendererInternal.send(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_FORWARD);
};
if (contextIsolationEnabled) internalContextBridge.overrideGlobalValueFromIsolatedWorld(['history', 'forward'], window.history.forward);
window.history.go = function (offset: number) {
ipcRendererInternal.send(IPC_MESSAGES.NAVIGATION_CONTROLLER_GO_TO_OFFSET, +offset);
};
if (contextIsolationEnabled) internalContextBridge.overrideGlobalValueFromIsolatedWorld(['history', 'go'], window.history.go);
const getHistoryLength = () => ipcRendererInternal.sendSync(IPC_MESSAGES.NAVIGATION_CONTROLLER_LENGTH);
Object.defineProperty(window.history, 'length', {
get: getHistoryLength,
set () {}
});
if (contextIsolationEnabled) internalContextBridge.overrideGlobalPropertyFromIsolatedWorld(['history', 'length'], getHistoryLength);
}
if (guestInstanceId != null) {
// Webview `document.visibilityState` tracks window visibility (and ignores
// the actual <webview> element visibility) for backwards compatibility.

View file

@ -124,7 +124,6 @@ if (hasSwitch('unsafely-expose-electron-internals-for-testing')) {
const contextIsolation = mainFrame.getWebPreference('contextIsolation');
const webviewTag = mainFrame.getWebPreference('webviewTag');
const isHiddenPage = mainFrame.getWebPreference('hiddenPage');
const rendererProcessReuseEnabled = mainFrame.getWebPreference('disableElectronSiteInstanceOverrides');
const usesNativeWindowOpen = true;
const guestInstanceId = mainFrame.getWebPreference('guestInstanceId') || null;
const openerId = mainFrame.getWebPreference('openerId') || null;
@ -144,7 +143,7 @@ switch (window.location.protocol) {
default: {
// Override default web functions.
const { windowSetup } = require('@electron/internal/renderer/window-setup');
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled);
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen);
}
}