refactor: use boolean for nodeIntegration / webviewTag (#15005)
This commit is contained in:
parent
918488a2f0
commit
9177dbb584
1 changed files with 10 additions and 10 deletions
|
@ -31,8 +31,8 @@ const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
|
||||||
require('@electron/internal/renderer/web-frame-init')()
|
require('@electron/internal/renderer/web-frame-init')()
|
||||||
|
|
||||||
// Process command line arguments.
|
// Process command line arguments.
|
||||||
let nodeIntegration = 'false'
|
let nodeIntegration = false
|
||||||
let webviewTag = 'false'
|
let webviewTag = false
|
||||||
let preloadScript = null
|
let preloadScript = null
|
||||||
let preloadScripts = []
|
let preloadScripts = []
|
||||||
let isBackgroundPage = false
|
let isBackgroundPage = false
|
||||||
|
@ -45,7 +45,7 @@ for (const arg of process.argv) {
|
||||||
// This is a guest BrowserWindow.
|
// This is a guest BrowserWindow.
|
||||||
process.openerId = parseInt(arg.substr(arg.indexOf('=') + 1))
|
process.openerId = parseInt(arg.substr(arg.indexOf('=') + 1))
|
||||||
} else if (arg.indexOf('--node-integration=') === 0) {
|
} else if (arg.indexOf('--node-integration=') === 0) {
|
||||||
nodeIntegration = arg.substr(arg.indexOf('=') + 1)
|
nodeIntegration = arg.substr(arg.indexOf('=') + 1) === 'true'
|
||||||
} else if (arg.indexOf('--preload=') === 0) {
|
} else if (arg.indexOf('--preload=') === 0) {
|
||||||
preloadScript = arg.substr(arg.indexOf('=') + 1)
|
preloadScript = arg.substr(arg.indexOf('=') + 1)
|
||||||
} else if (arg === '--background-page') {
|
} else if (arg === '--background-page') {
|
||||||
|
@ -53,7 +53,7 @@ for (const arg of process.argv) {
|
||||||
} else if (arg.indexOf('--app-path=') === 0) {
|
} else if (arg.indexOf('--app-path=') === 0) {
|
||||||
appPath = arg.substr(arg.indexOf('=') + 1)
|
appPath = arg.substr(arg.indexOf('=') + 1)
|
||||||
} else if (arg.indexOf('--webview-tag=') === 0) {
|
} else if (arg.indexOf('--webview-tag=') === 0) {
|
||||||
webviewTag = arg.substr(arg.indexOf('=') + 1)
|
webviewTag = arg.substr(arg.indexOf('=') + 1) === 'true'
|
||||||
} else if (arg.indexOf('--preload-scripts') === 0) {
|
} else if (arg.indexOf('--preload-scripts') === 0) {
|
||||||
preloadScripts = arg.substr(arg.indexOf('=') + 1).split(path.delimiter)
|
preloadScripts = arg.substr(arg.indexOf('=') + 1).split(path.delimiter)
|
||||||
}
|
}
|
||||||
|
@ -67,14 +67,14 @@ if (preloadScript) {
|
||||||
if (window.location.protocol === 'chrome-devtools:') {
|
if (window.location.protocol === 'chrome-devtools:') {
|
||||||
// Override some inspector APIs.
|
// Override some inspector APIs.
|
||||||
require('@electron/internal/renderer/inspector')
|
require('@electron/internal/renderer/inspector')
|
||||||
nodeIntegration = 'false'
|
nodeIntegration = false
|
||||||
} else if (window.location.protocol === 'chrome-extension:') {
|
} else if (window.location.protocol === 'chrome-extension:') {
|
||||||
// Add implementations of chrome API.
|
// Add implementations of chrome API.
|
||||||
require('@electron/internal/renderer/chrome-api').injectTo(window.location.hostname, isBackgroundPage, window)
|
require('@electron/internal/renderer/chrome-api').injectTo(window.location.hostname, isBackgroundPage, window)
|
||||||
nodeIntegration = 'false'
|
nodeIntegration = false
|
||||||
} else if (window.location.protocol === 'chrome:') {
|
} else if (window.location.protocol === 'chrome:') {
|
||||||
// Disable node integration for chrome UI scheme.
|
// Disable node integration for chrome UI scheme.
|
||||||
nodeIntegration = 'false'
|
nodeIntegration = false
|
||||||
} else {
|
} else {
|
||||||
// Override default web functions.
|
// Override default web functions.
|
||||||
require('@electron/internal/renderer/override')
|
require('@electron/internal/renderer/override')
|
||||||
|
@ -83,13 +83,13 @@ if (window.location.protocol === 'chrome-devtools:') {
|
||||||
require('@electron/internal/renderer/content-scripts-injector')
|
require('@electron/internal/renderer/content-scripts-injector')
|
||||||
|
|
||||||
// Load webview tag implementation.
|
// Load webview tag implementation.
|
||||||
if (webviewTag === 'true' && process.guestInstanceId == null) {
|
if (webviewTag && process.guestInstanceId == null) {
|
||||||
require('@electron/internal/renderer/web-view/web-view')
|
require('@electron/internal/renderer/web-view/web-view')
|
||||||
require('@electron/internal/renderer/web-view/web-view-attributes')
|
require('@electron/internal/renderer/web-view/web-view-attributes')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nodeIntegration === 'true') {
|
if (nodeIntegration) {
|
||||||
// Export node bindings to global.
|
// Export node bindings to global.
|
||||||
global.require = require
|
global.require = require
|
||||||
global.module = module
|
global.module = module
|
||||||
|
@ -157,7 +157,7 @@ for (const preloadScript of preloadScripts) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Warn about security issues
|
// Warn about security issues
|
||||||
require('@electron/internal/renderer/security-warnings')(nodeIntegration === 'true')
|
require('@electron/internal/renderer/security-warnings')(nodeIntegration)
|
||||||
|
|
||||||
// Report focus/blur events of webview to browser.
|
// Report focus/blur events of webview to browser.
|
||||||
// Note that while Chromium content APIs have observer for focus/blur, they
|
// Note that while Chromium content APIs have observer for focus/blur, they
|
||||||
|
|
Loading…
Reference in a new issue