chore: do not override history methods when rendererprocessreuse is enabled (#22335)

This commit is contained in:
Samuel Attard 2020-02-24 12:14:11 -08:00 committed by GitHub
parent fd46bc653f
commit 360c1cad1b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 10 deletions

View file

@ -24,9 +24,9 @@ Object.setPrototypeOf(process, EventEmitter.prototype)
const isolatedWorldArgs = v8Util.getHiddenValue(isolatedWorld, 'isolated-world-args') const isolatedWorldArgs = v8Util.getHiddenValue(isolatedWorld, 'isolated-world-args')
if (isolatedWorldArgs) { if (isolatedWorldArgs) {
const { guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen } = isolatedWorldArgs const { guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen, rendererProcessReuseEnabled } = isolatedWorldArgs
const { windowSetup } = require('@electron/internal/renderer/window-setup') const { windowSetup } = require('@electron/internal/renderer/window-setup')
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen) windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled)
} }
const extensionId = v8Util.getHiddenValue(isolatedWorld, `extension-${worldId}`) const extensionId = v8Util.getHiddenValue(isolatedWorld, `extension-${worldId}`)

View file

@ -21,7 +21,7 @@ if (webViewImpl) {
const isolatedWorldArgs = v8Util.getHiddenValue(isolatedWorld, 'isolated-world-args') const isolatedWorldArgs = v8Util.getHiddenValue(isolatedWorld, 'isolated-world-args')
if (isolatedWorldArgs) { if (isolatedWorldArgs) {
const { guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen } = isolatedWorldArgs const { guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen, rendererProcessReuseEnabled } = isolatedWorldArgs
const { windowSetup } = require('@electron/internal/renderer/window-setup') const { windowSetup } = require('@electron/internal/renderer/window-setup')
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen) windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled)
} }

View file

@ -77,6 +77,7 @@ const nodeIntegration = hasSwitch('node-integration')
const webviewTag = hasSwitch('webview-tag') const webviewTag = hasSwitch('webview-tag')
const isHiddenPage = hasSwitch('hidden-page') const isHiddenPage = hasSwitch('hidden-page')
const usesNativeWindowOpen = hasSwitch('native-window-open') const usesNativeWindowOpen = hasSwitch('native-window-open')
const rendererProcessReuseEnabled = hasSwitch('disable-electron-site-instance-overrides')
const preloadScript = parseOption('preload', null) const preloadScript = parseOption('preload', null)
const preloadScripts = parseOption('preload-scripts', [], value => value.split(path.delimiter)) as string[] const preloadScripts = parseOption('preload-scripts', [], value => value.split(path.delimiter)) as string[]
@ -85,7 +86,7 @@ const guestInstanceId = parseOption('guest-instance-id', null, value => parseInt
const openerId = parseOption('opener-id', null, value => parseInt(value)) const openerId = parseOption('opener-id', null, value => parseInt(value))
// The arguments to be passed to isolated world. // The arguments to be passed to isolated world.
const isolatedWorldArgs = { ipcRendererInternal, guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen } const isolatedWorldArgs = { ipcRendererInternal, guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen, rendererProcessReuseEnabled }
// The webContents preload script is loaded after the session preload scripts. // The webContents preload script is loaded after the session preload scripts.
if (preloadScript) { if (preloadScript) {
@ -110,7 +111,7 @@ switch (window.location.protocol) {
default: { default: {
// Override default web functions. // Override default web functions.
const { windowSetup } = require('@electron/internal/renderer/window-setup') const { windowSetup } = require('@electron/internal/renderer/window-setup')
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen) windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled)
// Inject content scripts. // Inject content scripts.
if (!process.electronBinding('features').isExtensionsEnabled()) { if (!process.electronBinding('features').isExtensionsEnabled()) {

View file

@ -175,7 +175,7 @@ class BrowserWindowProxy {
} }
export const windowSetup = ( export const windowSetup = (
guestInstanceId: number, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean guestInstanceId: number, openerId: number, isHiddenPage: boolean, usesNativeWindowOpen: boolean, rendererProcessReuseEnabled: boolean
) => { ) => {
if (!process.sandboxed && guestInstanceId == null) { if (!process.sandboxed && guestInstanceId == null) {
// Override default window.close. // Override default window.close.
@ -229,7 +229,7 @@ export const windowSetup = (
}) })
} }
if (!process.sandboxed) { if (!process.sandboxed && !rendererProcessReuseEnabled) {
window.history.back = function () { window.history.back = function () {
ipcRendererInternal.send('ELECTRON_NAVIGATION_CONTROLLER_GO_BACK') ipcRendererInternal.send('ELECTRON_NAVIGATION_CONTROLLER_GO_BACK')
} }

View file

@ -116,10 +116,11 @@ const { hasSwitch } = process.electronBinding('command_line')
const contextIsolation = hasSwitch('context-isolation') const contextIsolation = hasSwitch('context-isolation')
const isHiddenPage = hasSwitch('hidden-page') const isHiddenPage = hasSwitch('hidden-page')
const rendererProcessReuseEnabled = hasSwitch('disable-electron-site-instance-overrides')
const usesNativeWindowOpen = true const usesNativeWindowOpen = true
// The arguments to be passed to isolated world. // The arguments to be passed to isolated world.
const isolatedWorldArgs = { ipcRendererInternal, guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen } const isolatedWorldArgs = { ipcRendererInternal, guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen, rendererProcessReuseEnabled }
switch (window.location.protocol) { switch (window.location.protocol) {
case 'devtools:': { case 'devtools:': {
@ -140,7 +141,7 @@ switch (window.location.protocol) {
default: { default: {
// Override default web functions. // Override default web functions.
const { windowSetup } = require('@electron/internal/renderer/window-setup') const { windowSetup } = require('@electron/internal/renderer/window-setup')
windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen) windowSetup(guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen, rendererProcessReuseEnabled)
// Inject content scripts. // Inject content scripts.
if (!process.electronBinding('features').isExtensionsEnabled()) { if (!process.electronBinding('features').isExtensionsEnabled()) {