diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index 93dd2be03eac7..79493be4d7c87 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -228,9 +228,8 @@ void WebContentsPreferences::AppendCommandLineSwitches( ::switches::kEnableExperimentalWebPlatformFeatures); // Check if we have node integration specified. - bool enable_node_integration = IsEnabled(options::kNodeIntegration, true); - command_line->AppendSwitchASCII(switches::kNodeIntegration, - enable_node_integration ? "true" : "false"); + if (IsEnabled(options::kNodeIntegration)) + command_line->AppendSwitch(switches::kNodeIntegration); // Whether to enable node integration in Worker. if (IsEnabled(options::kNodeIntegrationInWorker)) @@ -238,9 +237,8 @@ void WebContentsPreferences::AppendCommandLineSwitches( // Check if webview tag creation is enabled, default to nodeIntegration value. // TODO(kevinsawicki): Default to false in 2.0 - bool webview_tag = IsEnabled(options::kWebviewTag, enable_node_integration); - command_line->AppendSwitchASCII(switches::kWebviewTag, - webview_tag ? "true" : "false"); + if (IsEnabled(options::kWebviewTag)) + command_line->AppendSwitch(switches::kWebviewTag); // If the `sandbox` option was passed to the BrowserWindow's webPreferences, // pass `--enable-sandbox` to the renderer so it won't have any node.js diff --git a/atom/renderer/atom_renderer_client.h b/atom/renderer/atom_renderer_client.h index 12a64e3c07cc0..9e9e89d503349 100644 --- a/atom/renderer/atom_renderer_client.h +++ b/atom/renderer/atom_renderer_client.h @@ -35,13 +35,6 @@ class AtomRendererClient : public RendererClientBase { content::RenderFrame* render_frame) override; private: - enum NodeIntegration { - ALL, - EXCEPT_IFRAME, - MANUAL_ENABLE_IFRAME, - DISABLE, - }; - // content::ContentRendererClient: void RenderThreadStarted() override; void RenderFrameCreated(content::RenderFrame*) override; diff --git a/filenames.gni b/filenames.gni index 128480e6b386e..5524452b89d64 100644 --- a/filenames.gni +++ b/filenames.gni @@ -65,6 +65,7 @@ filenames = { "lib/common/web-view-methods.js", "lib/renderer/callbacks-registry.js", "lib/renderer/chrome-api.js", + "lib/renderer/command-line.js", "lib/renderer/content-scripts-injector.js", "lib/renderer/init.js", "lib/renderer/inspector.js", diff --git a/lib/renderer/command-line.js b/lib/renderer/command-line.js new file mode 100644 index 0000000000000..9b4d3f314d8e3 --- /dev/null +++ b/lib/renderer/command-line.js @@ -0,0 +1,14 @@ +'use strict' + +exports.hasSwitch = function (name) { + return process.argv.includes(`--${name}`) +} + +exports.getSwitchValue = function (name, defaultValue, converter = value => value) { + for (const arg of process.argv) { + if (arg.indexOf(`--${name}=`) === 0) { + return converter(arg.substr(arg.indexOf('=') + 1)) + } + } + return defaultValue +} diff --git a/lib/renderer/init.js b/lib/renderer/init.js index af114785d13b4..80620406811dc 100644 --- a/lib/renderer/init.js +++ b/lib/renderer/init.js @@ -31,41 +31,20 @@ const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal') 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 -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. - guestInstanceId = parseInt(arg.substr(arg.indexOf('=') + 1)) - } else if (arg.indexOf('--opener-id=') === 0) { - // This is a guest BrowserWindow. - 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) { - preloadScript = arg.substr(arg.indexOf('=') + 1) - } else if (arg === '--background-page') { - isBackgroundPage = true - } else if (arg.indexOf('--app-path=') === 0) { - 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) - } -} +const { hasSwitch, getSwitchValue } = require('@electron/internal/renderer/command-line') + +const contextIsolation = hasSwitch('context-isolation') +let nodeIntegration = hasSwitch('node-integration') +const webviewTag = hasSwitch('webview-tag') +const isHiddenPage = hasSwitch('hidden-page') +const isBackgroundPage = hasSwitch('background-page') +const usesNativeWindowOpen = hasSwitch('native-window-open') -const hiddenPage = process.argv.includes('--hidden-page') -const usesNativeWindowOpen = process.argv.includes('--native-window-open') +const preloadScript = getSwitchValue('preload', null) +const preloadScripts = getSwitchValue('preload-scripts', [], value => value.split(path.delimiter)) +const appPath = getSwitchValue('app-path', null) +const guestInstanceId = getSwitchValue('guest-instance-id', null, value => parseInt(value)) +const openerId = getSwitchValue('opener-id', null, value => parseInt(value)) // The webContents preload script is loaded after the session preload scripts. if (preloadScript) { @@ -74,7 +53,7 @@ if (preloadScript) { // Pass the arguments to isolatedWorld. if (contextIsolation) { - const isolatedWorldArgs = { ipcRenderer, guestInstanceId, hiddenPage, openerId, usesNativeWindowOpen } + const isolatedWorldArgs = { ipcRenderer, guestInstanceId, isHiddenPage, openerId, usesNativeWindowOpen } v8Util.setHiddenValue(global, 'isolated-world-args', isolatedWorldArgs) } @@ -91,7 +70,7 @@ if (window.location.protocol === 'chrome-devtools:') { nodeIntegration = false } else { // Override default web functions. - require('@electron/internal/renderer/window-setup')(ipcRenderer, guestInstanceId, openerId, hiddenPage, usesNativeWindowOpen) + require('@electron/internal/renderer/window-setup')(ipcRenderer, guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen) // Inject content scripts. require('@electron/internal/renderer/content-scripts-injector')