feat: add app.enableSandbox() (#14999)
This commit is contained in:
parent
cc0c6ad14a
commit
5bd6de52e0
5 changed files with 99 additions and 22 deletions
|
@ -1184,6 +1184,33 @@ v8::Local<v8::Promise> App::GetGPUInfo(v8::Isolate* isolate,
|
|||
return promise->GetHandle();
|
||||
}
|
||||
|
||||
static void RemoveNoSandboxSwitch(base::CommandLine* command_line) {
|
||||
if (command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
|
||||
const base::CommandLine::CharType* noSandboxArg =
|
||||
FILE_PATH_LITERAL("--no-sandbox");
|
||||
base::CommandLine::StringVector modified_command_line;
|
||||
for (auto& arg : command_line->argv()) {
|
||||
if (arg.compare(noSandboxArg) != 0) {
|
||||
modified_command_line.push_back(arg);
|
||||
}
|
||||
}
|
||||
command_line->InitFromArgv(modified_command_line);
|
||||
}
|
||||
}
|
||||
|
||||
void App::EnableSandbox(mate::Arguments* args) {
|
||||
if (Browser::Get()->is_ready()) {
|
||||
args->ThrowError(
|
||||
"app.enableSandbox() can only be called "
|
||||
"before app is ready");
|
||||
return;
|
||||
}
|
||||
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
RemoveNoSandboxSwitch(command_line);
|
||||
command_line->AppendSwitch(switches::kEnableSandbox);
|
||||
}
|
||||
|
||||
void App::EnableMixedSandbox(mate::Arguments* args) {
|
||||
if (Browser::Get()->is_ready()) {
|
||||
args->ThrowError(
|
||||
|
@ -1193,22 +1220,7 @@ void App::EnableMixedSandbox(mate::Arguments* args) {
|
|||
}
|
||||
|
||||
auto* command_line = base::CommandLine::ForCurrentProcess();
|
||||
if (command_line->HasSwitch(service_manager::switches::kNoSandbox)) {
|
||||
#if defined(OS_WIN)
|
||||
const base::CommandLine::CharType* noSandboxArg = L"--no-sandbox";
|
||||
#else
|
||||
const base::CommandLine::CharType* noSandboxArg = "--no-sandbox";
|
||||
#endif
|
||||
|
||||
// Remove the --no-sandbox switch
|
||||
base::CommandLine::StringVector modified_command_line;
|
||||
for (auto& arg : command_line->argv()) {
|
||||
if (arg.compare(noSandboxArg) != 0) {
|
||||
modified_command_line.push_back(arg);
|
||||
}
|
||||
}
|
||||
command_line->InitFromArgv(modified_command_line);
|
||||
}
|
||||
RemoveNoSandboxSwitch(command_line);
|
||||
command_line->AppendSwitch(switches::kEnableMixedSandbox);
|
||||
}
|
||||
|
||||
|
@ -1316,6 +1328,7 @@ void App::BuildPrototype(v8::Isolate* isolate,
|
|||
.SetMethod("startAccessingSecurityScopedResource",
|
||||
&App::StartAccessingSecurityScopedResource)
|
||||
#endif
|
||||
.SetMethod("enableSandbox", &App::EnableSandbox)
|
||||
.SetMethod("enableMixedSandbox", &App::EnableMixedSandbox);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue