From 74196b96a1ebf0a0b4341e48e9a9b7d0167850ef Mon Sep 17 00:00:00 2001 From: Hari Krishna Reddy Juturu Date: Mon, 26 Jun 2017 14:13:41 -0700 Subject: [PATCH] Adding enableMixedSandbox api --- atom/browser/api/atom_api_app.cc | 27 ++++++++++++++++++++++++++- atom/browser/api/atom_api_app.h | 1 + docs/api/app.md | 6 ++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/atom_api_app.cc b/atom/browser/api/atom_api_app.cc index 8f2d08277aea..9db24ba54906 100644 --- a/atom/browser/api/atom_api_app.cc +++ b/atom/browser/api/atom_api_app.cc @@ -1028,6 +1028,30 @@ v8::Local App::GetGPUFeatureStatus(v8::Isolate* isolate) { status ? *status : base::DictionaryValue()); } +void App::EnableMixedSandbox(mate::Arguments* args) { + if (Browser::Get()->is_ready()) { + args->ThrowError("app.enableMixedSandbox() can only be called " + "before app is ready"); + return; + } + auto command_line = base::CommandLine::ForCurrentProcess(); + if (command_line->HasSwitch(::switches::kNoSandbox)) { + // Remove the --no-sandbox switch + using StringType = base::CommandLine::StringType; + using StringVector = base::CommandLine::StringVector; + using CharType = base::CommandLine::CharType; + auto argv = command_line->argv(); + StringVector modified_command_line; + const CharType* kNoSandboxArg = L"--no-sandbox"; + for (const StringType& arg : argv) { + if (arg.compare(kNoSandboxArg) != 0) + modified_command_line.push_back(arg); + } + command_line->InitFromArgv(modified_command_line); + } + command_line->AppendSwitch(switches::kEnableMixedSandbox); +} + // static mate::Handle App::Create(v8::Isolate* isolate) { return mate::CreateHandle(isolate, new App(isolate)); @@ -1103,7 +1127,8 @@ void App::BuildPrototype( .SetMethod("getAppMetrics", &App::GetAppMetrics) .SetMethod("getGPUFeatureStatus", &App::GetGPUFeatureStatus) // TODO(juturu): Remove in 2.0, deprecate before then with warnings - .SetMethod("getAppMemoryInfo", &App::GetAppMetrics); + .SetMethod("getAppMemoryInfo", &App::GetAppMetrics) + .SetMethod("enableMixedSandbox", &App::EnableMixedSandbox); } } // namespace api diff --git a/atom/browser/api/atom_api_app.h b/atom/browser/api/atom_api_app.h index f97265943509..3787d383a6dd 100644 --- a/atom/browser/api/atom_api_app.h +++ b/atom/browser/api/atom_api_app.h @@ -178,6 +178,7 @@ class App : public AtomBrowserClient::Delegate, std::vector GetAppMetrics(v8::Isolate* isolate); v8::Local GetGPUFeatureStatus(v8::Isolate* isolate); + void EnableMixedSandbox(mate::Arguments* args); #if defined(OS_WIN) // Get the current Jump List settings. diff --git a/docs/api/app.md b/docs/api/app.md index 784b20a47301..9e736f0872ad 100644 --- a/docs/api/app.md +++ b/docs/api/app.md @@ -903,6 +903,12 @@ correctly. **Note:** This will not affect `process.argv`. +### `app.enableMixedSandbox()` + +Enables mixed sandbox mode on the app. + +This method can only be called before app is ready. + ### `app.dock.bounce([type])` _macOS_ * `type` String (optional) - Can be `critical` or `informational`. The default is