diff --git a/filenames.gni b/filenames.gni index b01a65746b..128480e6b3 100644 --- a/filenames.gni +++ b/filenames.gni @@ -70,7 +70,6 @@ filenames = { "lib/renderer/inspector.js", "lib/renderer/ipc-renderer-internal.js", "lib/renderer/remote.js", - "lib/renderer/override.js", "lib/renderer/security-warnings.js", "lib/renderer/web-frame-init.js", "lib/renderer/window-setup.js", diff --git a/lib/browser/rpc-server.js b/lib/browser/rpc-server.js index db2afa4227..e0249cff76 100644 --- a/lib/browser/rpc-server.js +++ b/lib/browser/rpc-server.js @@ -138,7 +138,7 @@ const plainObjectToMeta = function (obj) { } // Convert Error into meta data. -const exceptionToMeta = function (sender, contextId, error) { +const exceptionToMeta = function (error) { return { type: 'exception', value: errorUtils.serialize(error) @@ -275,7 +275,7 @@ const handleRemoteCommand = function (channel, handler) { try { returnValue = handler(event, contextId, ...args) } catch (error) { - returnValue = exceptionToMeta(event.sender, contextId, error) + returnValue = exceptionToMeta(error) } if (returnValue !== undefined) { diff --git a/lib/renderer/api/remote.js b/lib/renderer/api/remote.js index 036ebd8c36..98fc55ca7a 100644 --- a/lib/renderer/api/remote.js +++ b/lib/renderer/api/remote.js @@ -311,7 +311,9 @@ exports.getCurrentWindow = () => { // Get current WebContents object. exports.getCurrentWebContents = () => { - return metaToValue(ipcRenderer.sendSync('ELECTRON_BROWSER_CURRENT_WEB_CONTENTS', contextId)) + const command = 'ELECTRON_BROWSER_CURRENT_WEB_CONTENTS' + const meta = ipcRenderer.sendSync(command, contextId) + return metaToValue(meta) } // Get a global object in browser. diff --git a/lib/renderer/init.js b/lib/renderer/init.js index c65c6066b7..11dc73a9e8 100644 --- a/lib/renderer/init.js +++ b/lib/renderer/init.js @@ -37,13 +37,15 @@ let preloadScript = null let preloadScripts = [] let isBackgroundPage = false let appPath = null +let guestInstanceId = null +let openerId = null for (const arg of process.argv) { if (arg.indexOf('--guest-instance-id=') === 0) { // This is a guest web view. - process.guestInstanceId = parseInt(arg.substr(arg.indexOf('=') + 1)) + guestInstanceId = parseInt(arg.substr(arg.indexOf('=') + 1)) } else if (arg.indexOf('--opener-id=') === 0) { // This is a guest BrowserWindow. - process.openerId = parseInt(arg.substr(arg.indexOf('=') + 1)) + openerId = parseInt(arg.substr(arg.indexOf('=') + 1)) } else if (arg.indexOf('--node-integration=') === 0) { nodeIntegration = arg.substr(arg.indexOf('=') + 1) === 'true' } else if (arg.indexOf('--preload=') === 0) { @@ -59,6 +61,9 @@ for (const arg of process.argv) { } } +const hiddenPage = process.argv.includes('--hidden-page') +const usesNativeWindowOpen = process.argv.includes('--native-window-open') + // The webContents preload script is loaded after the session preload scripts. if (preloadScript) { preloadScripts.push(preloadScript) @@ -77,13 +82,13 @@ if (window.location.protocol === 'chrome-devtools:') { nodeIntegration = false } else { // Override default web functions. - require('@electron/internal/renderer/override') + require('@electron/internal/renderer/window-setup')(ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNativeWindowOpen) // Inject content scripts. require('@electron/internal/renderer/content-scripts-injector') // Load webview tag implementation. - if (webviewTag && process.guestInstanceId == null) { + if (webviewTag && guestInstanceId == null) { require('@electron/internal/renderer/web-view/web-view') require('@electron/internal/renderer/web-view/web-view-attributes') } @@ -162,11 +167,11 @@ require('@electron/internal/renderer/security-warnings')(nodeIntegration) // Report focus/blur events of webview to browser. // Note that while Chromium content APIs have observer for focus/blur, they // unfortunately do not work for webview. -if (process.guestInstanceId) { +if (guestInstanceId) { window.addEventListener('focus', () => { - ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', true, process.guestInstanceId) + ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', true, guestInstanceId) }) window.addEventListener('blur', () => { - ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', false, process.guestInstanceId) + ipcRenderer.send('ELECTRON_GUEST_VIEW_MANAGER_FOCUS_CHANGE', false, guestInstanceId) }) } diff --git a/lib/renderer/override.js b/lib/renderer/override.js index 413b8b8204..e69de29bb2 100644 --- a/lib/renderer/override.js +++ b/lib/renderer/override.js @@ -1,9 +0,0 @@ -'use strict' - -const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal') - -const { guestInstanceId, openerId } = process -const hiddenPage = process.argv.includes('--hidden-page') -const usesNativeWindowOpen = process.argv.includes('--native-window-open') - -require('@electron/internal/renderer/window-setup')(ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNativeWindowOpen)