Add nodeIntegrationInWorker option

This commit is contained in:
Cheng Zhao 2017-03-15 18:51:21 +09:00
parent e496e18f6e
commit a49af26e39
4 changed files with 20 additions and 2 deletions

View file

@ -97,6 +97,10 @@ void WebContentsPreferences::AppendExtraCommandLineSwitches(
command_line->AppendSwitchASCII(switches::kNodeIntegration, command_line->AppendSwitchASCII(switches::kNodeIntegration,
node_integration ? "true" : "false"); 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, // 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 // pass `--enable-sandbox` to the renderer so it won't have any node.js
// integration. // integration.

View file

@ -122,6 +122,9 @@ const char kBlinkFeatures[] = "blinkFeatures";
// Disable blink features. // Disable blink features.
const char kDisableBlinkFeatures[] = "disableBlinkFeatures"; const char kDisableBlinkFeatures[] = "disableBlinkFeatures";
// Enable the node integration in WebWorker.
const char kNodeIntegrationInWorker[] = "nodeIntegrationInWorker";
} // namespace options } // namespace options
namespace switches { namespace switches {
@ -164,6 +167,9 @@ const char kOpenerID[] = "opener-id";
const char kScrollBounce[] = "scroll-bounce"; const char kScrollBounce[] = "scroll-bounce";
const char kHiddenPage[] = "hidden-page"; const char kHiddenPage[] = "hidden-page";
// Command switch passed to renderer process to control nodeIntegration.
const char kNodeIntegrationInWorker[] = "node-integration-in-worker";
// Widevine options // Widevine options
// Path to Widevine CDM binaries. // Path to Widevine CDM binaries.
const char kWidevineCdmPath[] = "widevine-cdm-path"; const char kWidevineCdmPath[] = "widevine-cdm-path";

View file

@ -62,6 +62,7 @@ extern const char kOpenerID[];
extern const char kScrollBounce[]; extern const char kScrollBounce[];
extern const char kBlinkFeatures[]; extern const char kBlinkFeatures[];
extern const char kDisableBlinkFeatures[]; extern const char kDisableBlinkFeatures[];
extern const char kNodeIntegrationInWorker[];
} // namespace options } // namespace options
@ -89,6 +90,7 @@ extern const char kGuestInstanceID[];
extern const char kOpenerID[]; extern const char kOpenerID[];
extern const char kScrollBounce[]; extern const char kScrollBounce[];
extern const char kHiddenPage[]; extern const char kHiddenPage[];
extern const char kNodeIntegrationInWorker[];
extern const char kWidevineCdmPath[]; extern const char kWidevineCdmPath[];
extern const char kWidevineCdmVersion[]; extern const char kWidevineCdmVersion[];

View file

@ -441,12 +441,18 @@ void AtomRendererClient::AddSupportedKeySystems(
void AtomRendererClient::DidInitializeWorkerContextOnWorkerThread( void AtomRendererClient::DidInitializeWorkerContextOnWorkerThread(
v8::Local<v8::Context> context) { v8::Local<v8::Context> context) {
WebWorkerObserver::GetCurrent()->ContextCreated(context); if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kNodeIntegrationInWorker)) {
WebWorkerObserver::GetCurrent()->ContextCreated(context);
}
} }
void AtomRendererClient::WillDestroyWorkerContextOnWorkerThread( void AtomRendererClient::WillDestroyWorkerContextOnWorkerThread(
v8::Local<v8::Context> context) { v8::Local<v8::Context> context) {
WebWorkerObserver::GetCurrent()->ContextWillDestroy(context); if (base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kNodeIntegrationInWorker)) {
WebWorkerObserver::GetCurrent()->ContextWillDestroy(context);
}
} }
v8::Local<v8::Context> AtomRendererClient::GetContext( v8::Local<v8::Context> AtomRendererClient::GetContext(