chore: simplify main world setup of contextIsolation (#16046)

This commit is contained in:
Cheng Zhao 2018-12-14 06:25:12 +09:00 committed by John Kleinschmidt
parent d6d245d0c3
commit 897c6e93cb
7 changed files with 34 additions and 49 deletions

View file

@ -33,6 +33,7 @@ require('@electron/internal/renderer/web-frame-init')()
// Process command line arguments.
let nodeIntegration = false
let webviewTag = false
let contextIsolation = false
let preloadScript = null
let preloadScripts = []
let isBackgroundPage = false
@ -56,6 +57,8 @@ for (const arg of process.argv) {
appPath = arg.substr(arg.indexOf('=') + 1)
} else if (arg.indexOf('--webview-tag=') === 0) {
webviewTag = arg.substr(arg.indexOf('=') + 1) === 'true'
} else if (arg === '--context-isolation') {
contextIsolation = true
} else if (arg.indexOf('--preload-scripts') === 0) {
preloadScripts = arg.substr(arg.indexOf('=') + 1).split(path.delimiter)
}
@ -69,6 +72,12 @@ if (preloadScript) {
preloadScripts.push(preloadScript)
}
// Pass the arguments to isolatedWorld.
if (contextIsolation) {
const isolatedWorldArgs = { ipcRenderer, guestInstanceId, hiddenPage, openerId, usesNativeWindowOpen }
v8Util.setHiddenValue(global, 'isolated-world-args', isolatedWorldArgs)
}
if (window.location.protocol === 'chrome-devtools:') {
// Override some inspector APIs.
require('@electron/internal/renderer/inspector')