From a49af26e39816d6c13456f4ccb0eebff26968c00 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Wed, 15 Mar 2017 18:51:21 +0900 Subject: [PATCH] Add nodeIntegrationInWorker option --- atom/browser/web_contents_preferences.cc | 4 ++++ atom/common/options_switches.cc | 6 ++++++ atom/common/options_switches.h | 2 ++ atom/renderer/atom_renderer_client.cc | 10 ++++++++-- 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/atom/browser/web_contents_preferences.cc b/atom/browser/web_contents_preferences.cc index c6527dd6f6d2..7bb8605039a1 100644 --- a/atom/browser/web_contents_preferences.cc +++ b/atom/browser/web_contents_preferences.cc @@ -97,6 +97,10 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches( command_line->AppendSwitchASCII(switches::kNodeIntegration, node_integration ? "true" : "false"); + // Whether to enable node integration in Worker. + if (web_preferences.GetBoolean(options::kNodeIntegrationInWorker, &b) && b) + command_line->AppendSwitch(switches::kNodeIntegrationInWorker); + // 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 // integration. diff --git a/atom/common/options_switches.cc b/atom/common/options_switches.cc index 6db479ceb75c..d040489b9f76 100644 --- a/atom/common/options_switches.cc +++ b/atom/common/options_switches.cc @@ -122,6 +122,9 @@ const char kBlinkFeatures[] = "blinkFeatures"; // Disable blink features. const char kDisableBlinkFeatures[] = "disableBlinkFeatures"; +// Enable the node integration in WebWorker. +const char kNodeIntegrationInWorker[] = "nodeIntegrationInWorker"; + } // namespace options namespace switches { @@ -164,6 +167,9 @@ const char kOpenerID[] = "opener-id"; const char kScrollBounce[] = "scroll-bounce"; const char kHiddenPage[] = "hidden-page"; +// Command switch passed to renderer process to control nodeIntegration. +const char kNodeIntegrationInWorker[] = "node-integration-in-worker"; + // Widevine options // Path to Widevine CDM binaries. const char kWidevineCdmPath[] = "widevine-cdm-path"; diff --git a/atom/common/options_switches.h b/atom/common/options_switches.h index abe3856cd870..dd2824c55c74 100644 --- a/atom/common/options_switches.h +++ b/atom/common/options_switches.h @@ -62,6 +62,7 @@ extern const char kOpenerID[]; extern const char kScrollBounce[]; extern const char kBlinkFeatures[]; extern const char kDisableBlinkFeatures[]; +extern const char kNodeIntegrationInWorker[]; } // namespace options @@ -89,6 +90,7 @@ extern const char kGuestInstanceID[]; extern const char kOpenerID[]; extern const char kScrollBounce[]; extern const char kHiddenPage[]; +extern const char kNodeIntegrationInWorker[]; extern const char kWidevineCdmPath[]; extern const char kWidevineCdmVersion[]; diff --git a/atom/renderer/atom_renderer_client.cc b/atom/renderer/atom_renderer_client.cc index c4f739c305ca..2a5c0218aab1 100644 --- a/atom/renderer/atom_renderer_client.cc +++ b/atom/renderer/atom_renderer_client.cc @@ -441,12 +441,18 @@ void AtomRendererClient::AddSupportedKeySystems( void AtomRendererClient::DidInitializeWorkerContextOnWorkerThread( v8::Local context) { - WebWorkerObserver::GetCurrent()->ContextCreated(context); + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kNodeIntegrationInWorker)) { + WebWorkerObserver::GetCurrent()->ContextCreated(context); + } } void AtomRendererClient::WillDestroyWorkerContextOnWorkerThread( v8::Local context) { - WebWorkerObserver::GetCurrent()->ContextWillDestroy(context); + if (base::CommandLine::ForCurrentProcess()->HasSwitch( + switches::kNodeIntegrationInWorker)) { + WebWorkerObserver::GetCurrent()->ContextWillDestroy(context); + } } v8::Local AtomRendererClient::GetContext(