Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
|
Mark Mentovai
2010/11/04 16:19:30
CL description: “clean up” as a verb is two words.
| |
| 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 "chrome/common/sandbox_init_wrapper.h" | 5 #include "chrome/common/sandbox_init_wrapper.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 "chrome/common/chrome_switches.h" | 10 #include "chrome/common/chrome_switches.h" |
| 11 #include "chrome/common/sandbox_mac.h" | 11 #include "chrome/common/sandbox_mac.h" |
| 12 | 12 |
| 13 bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line, | 13 bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line, |
| 14 const std::string& process_type) { | 14 const std::string& process_type) { |
| 15 using sandbox::Sandbox; | |
| 16 | |
| 15 if (command_line.HasSwitch(switches::kNoSandbox)) | 17 if (command_line.HasSwitch(switches::kNoSandbox)) |
| 16 return true; | 18 return true; |
| 17 | 19 |
| 18 sandbox::SandboxProcessType sandbox_process_type; | 20 Sandbox::SandboxProcessType sandbox_process_type; |
| 19 FilePath allowed_dir; // Empty by default. | 21 FilePath allowed_dir; // Empty by default. |
| 20 | 22 |
| 21 if (process_type.empty()) { | 23 if (process_type.empty()) { |
| 22 // Browser process isn't sandboxed. | 24 // Browser process isn't sandboxed. |
| 23 return true; | 25 return true; |
| 24 } else if (process_type == switches::kRendererProcess) { | 26 } else if (process_type == switches::kRendererProcess) { |
| 25 if (!command_line.HasSwitch(switches::kDisableExperimentalWebGL) && | 27 if (!command_line.HasSwitch(switches::kDisableExperimentalWebGL) && |
| 26 command_line.HasSwitch(switches::kInProcessWebGL)) { | 28 command_line.HasSwitch(switches::kInProcessWebGL)) { |
| 27 // TODO(kbr): this check seems to be necessary only on this | 29 // TODO(kbr): this check seems to be necessary only on this |
| 28 // platform because the sandbox is initialized later. Remove | 30 // platform because the sandbox is initialized later. Remove |
| 29 // this once this flag is removed. | 31 // this once this flag is removed. |
| 30 return true; | 32 return true; |
| 31 } else { | 33 } else { |
| 32 sandbox_process_type = sandbox::SANDBOX_TYPE_RENDERER; | 34 sandbox_process_type = Sandbox::SANDBOX_TYPE_RENDERER; |
| 33 } | 35 } |
| 34 } else if (process_type == switches::kExtensionProcess) { | 36 } else if (process_type == switches::kExtensionProcess) { |
| 35 // Extension processes are just renderers [they use RenderMain()] with a | 37 // Extension processes are just renderers [they use RenderMain()] with a |
| 36 // different set of command line flags. | 38 // different set of command line flags. |
| 37 // If we ever get here it means something has changed in regards | 39 // If we ever get here it means something has changed in regards |
| 38 // to the extension process mechanics and we should probably reexamine | 40 // to the extension process mechanics and we should probably reexamine |
| 39 // how we sandbox extension processes since they are no longer identical | 41 // how we sandbox extension processes since they are no longer identical |
| 40 // to renderers. | 42 // to renderers. |
| 41 NOTREACHED(); | 43 NOTREACHED(); |
| 42 return true; | 44 return true; |
| 43 } else if (process_type == switches::kUtilityProcess) { | 45 } else if (process_type == switches::kUtilityProcess) { |
| 44 // Utility process sandbox. | 46 // Utility process sandbox. |
| 45 sandbox_process_type = sandbox::SANDBOX_TYPE_UTILITY; | 47 sandbox_process_type = Sandbox::SANDBOX_TYPE_UTILITY; |
| 46 allowed_dir = | 48 allowed_dir = |
| 47 command_line.GetSwitchValuePath(switches::kUtilityProcessAllowedDir); | 49 command_line.GetSwitchValuePath(switches::kUtilityProcessAllowedDir); |
| 48 } else if (process_type == switches::kWorkerProcess) { | 50 } else if (process_type == switches::kWorkerProcess) { |
| 49 // Worker process sandbox. | 51 // Worker process sandbox. |
| 50 sandbox_process_type = sandbox::SANDBOX_TYPE_WORKER; | 52 sandbox_process_type = Sandbox::SANDBOX_TYPE_WORKER; |
| 51 } else if (process_type == switches::kNaClLoaderProcess) { | 53 } else if (process_type == switches::kNaClLoaderProcess) { |
| 52 // Native Client sel_ldr (user untrusted code) sandbox. | 54 // Native Client sel_ldr (user untrusted code) sandbox. |
| 53 sandbox_process_type = sandbox::SANDBOX_TYPE_NACL_LOADER; | 55 sandbox_process_type = Sandbox::SANDBOX_TYPE_NACL_LOADER; |
| 54 } else if ((process_type == switches::kPluginProcess) || | 56 } else if ((process_type == switches::kPluginProcess) || |
| 55 (process_type == switches::kProfileImportProcess) || | 57 (process_type == switches::kProfileImportProcess) || |
| 56 (process_type == switches::kGpuProcess) || | 58 (process_type == switches::kGpuProcess) || |
| 57 (process_type == switches::kServiceProcess)) { | 59 (process_type == switches::kServiceProcess)) { |
| 58 return true; | 60 return true; |
| 59 } else { | 61 } else { |
| 60 // Failsafe: If you hit an unreached here, is your new process type in need | 62 // Failsafe: If you hit an unreached here, is your new process type in need |
| 61 // of sandboxing? | 63 // of sandboxing? |
| 62 NOTREACHED(); | 64 NOTREACHED(); |
| 63 return true; | 65 return true; |
| 64 } | 66 } |
| 65 | 67 |
| 66 // Warm up APIs before turning on the sandbox. | 68 // Warm up APIs before turning on the sandbox. |
| 67 sandbox::SandboxWarmup(); | 69 Sandbox::SandboxWarmup(); |
| 68 | 70 |
| 69 // Actually sandbox the process. | 71 // Actually sandbox the process. |
| 70 return sandbox::EnableSandbox(sandbox_process_type, allowed_dir); | 72 return Sandbox::EnableSandbox(sandbox_process_type, allowed_dir); |
| 71 } | 73 } |
| OLD | NEW |