refactor: use helpers for command-line parsing in renderer/init.js (#16239)

This commit is contained in:
Milan Burda 2019-01-03 17:22:34 +01:00 committed by John Kleinschmidt
parent baaeb7cece
commit 3f1d22759a
9 changed files with 63 additions and 52 deletions

View file

@ -228,19 +228,16 @@ 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))
command_line->AppendSwitch(switches::kNodeIntegrationInWorker);
// 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

View file

@ -0,0 +1,34 @@
// Copyright (c) 2019 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/common/native_mate_converters/string16_converter.h"
#include "base/command_line.h"
#include "native_mate/converter.h"
#include "native_mate/dictionary.h"
#include "atom/common/node_includes.h"
namespace {
bool HasSwitch(const std::string& name) {
return base::CommandLine::ForCurrentProcess()->HasSwitch(name.c_str());
}
base::CommandLine::StringType GetSwitchValue(const std::string& name) {
return base::CommandLine::ForCurrentProcess()->GetSwitchValueNative(
name.c_str());
}
void Initialize(v8::Local<v8::Object> exports,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
void* priv) {
mate::Dictionary dict(context->GetIsolate(), exports);
dict.SetMethod("hasSwitch", &HasSwitch);
dict.SetMethod("getSwitchValue", &GetSwitchValue);
}
} // namespace
NODE_BUILTIN_MODULE_CONTEXT_AWARE(atom_common_command_line, Initialize)

View file

@ -58,6 +58,7 @@
V(atom_browser_window) \
V(atom_common_asar) \
V(atom_common_clipboard) \
V(atom_common_command_line) \
V(atom_common_crash_reporter) \
V(atom_common_features) \
V(atom_common_native_image) \

View file

@ -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;