| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/common/sandbox_init_wrapper.h" | 5 #include "content/public/common/sandbox_init.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/common/sandbox_mac.h" | 10 #include "content/common/sandbox_mac.h" |
| 11 #include "content/public/common/content_switches.h" | 11 #include "content/public/common/content_switches.h" |
| 12 | 12 |
| 13 bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line, | 13 namespace content { |
| 14 const std::string& process_type) { | 14 |
| 15 bool InitializeSandbox() { |
| 15 using sandbox::Sandbox; | 16 using sandbox::Sandbox; |
| 16 | 17 |
| 18 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 17 if (command_line.HasSwitch(switches::kNoSandbox)) | 19 if (command_line.HasSwitch(switches::kNoSandbox)) |
| 18 return true; | 20 return true; |
| 19 | 21 |
| 20 Sandbox::SandboxProcessType sandbox_process_type; | 22 Sandbox::SandboxProcessType sandbox_process_type; |
| 21 FilePath allowed_dir; // Empty by default. | 23 FilePath allowed_dir; // Empty by default. |
| 22 | 24 |
| 25 std::string process_type = |
| 26 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 23 if (process_type.empty()) { | 27 if (process_type.empty()) { |
| 24 // Browser process isn't sandboxed. | 28 // Browser process isn't sandboxed. |
| 25 return true; | 29 return true; |
| 26 } else if (process_type == switches::kRendererProcess) { | 30 } else if (process_type == switches::kRendererProcess) { |
| 27 if (!command_line.HasSwitch(switches::kDisable3DAPIs) && | 31 if (!command_line.HasSwitch(switches::kDisable3DAPIs) && |
| 28 !command_line.HasSwitch(switches::kDisableExperimentalWebGL) && | 32 !command_line.HasSwitch(switches::kDisableExperimentalWebGL) && |
| 29 command_line.HasSwitch(switches::kInProcessWebGL)) { | 33 command_line.HasSwitch(switches::kInProcessWebGL)) { |
| 30 // TODO(kbr): this check seems to be necessary only on this | 34 // TODO(kbr): this check seems to be necessary only on this |
| 31 // platform because the sandbox is initialized later. Remove | 35 // platform because the sandbox is initialized later. Remove |
| 32 // this once this flag is removed. | 36 // this once this flag is removed. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 58 NOTREACHED() << "Unknown process type " << process_type; | 62 NOTREACHED() << "Unknown process type " << process_type; |
| 59 return true; | 63 return true; |
| 60 } | 64 } |
| 61 | 65 |
| 62 // Warm up APIs before turning on the sandbox. | 66 // Warm up APIs before turning on the sandbox. |
| 63 Sandbox::SandboxWarmup(sandbox_process_type); | 67 Sandbox::SandboxWarmup(sandbox_process_type); |
| 64 | 68 |
| 65 // Actually sandbox the process. | 69 // Actually sandbox the process. |
| 66 return Sandbox::EnableSandbox(sandbox_process_type, allowed_dir); | 70 return Sandbox::EnableSandbox(sandbox_process_type, allowed_dir); |
| 67 } | 71 } |
| 72 |
| 73 } // namespace content |
| OLD | NEW |