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_mac.h" | 5 #include "content/common/sandbox_init_mac.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/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 #include "content/public/common/sandbox_init.h" | 12 #include "content/public/common/sandbox_init.h" |
| 13 #include "sandbox/mac/seatbelt.h" |
13 | 14 |
14 namespace content { | 15 namespace content { |
15 | 16 |
16 bool InitializeSandbox(int sandbox_type, const base::FilePath& allowed_dir) { | 17 bool InitializeSandbox(int sandbox_type, const base::FilePath& allowed_dir) { |
17 // Warm up APIs before turning on the sandbox. | 18 // Warm up APIs before turning on the sandbox. |
18 Sandbox::SandboxWarmup(sandbox_type); | 19 Sandbox::SandboxWarmup(sandbox_type); |
19 | 20 |
20 // Actually sandbox the process. | 21 // Actually sandbox the process. |
21 return Sandbox::EnableSandbox(sandbox_type, allowed_dir); | 22 return Sandbox::EnableSandbox(sandbox_type, allowed_dir); |
22 } | 23 } |
23 | 24 |
24 // Fill in |sandbox_type| and |allowed_dir| based on the command line, returns | 25 // Fill in |sandbox_type| and |allowed_dir| based on the command line, returns |
25 // false if the current process type doesn't need to be sandboxed or if the | 26 // false if the current process type doesn't need to be sandboxed or if the |
26 // sandbox was disabled from the command line. | 27 // sandbox was disabled from the command line. |
27 bool GetSandboxTypeFromCommandLine(int* sandbox_type, | 28 bool GetSandboxTypeFromCommandLine(int* sandbox_type, |
28 base::FilePath* allowed_dir) { | 29 base::FilePath* allowed_dir) { |
29 DCHECK(sandbox_type); | 30 DCHECK(sandbox_type); |
30 DCHECK(allowed_dir); | 31 DCHECK(allowed_dir); |
31 | 32 |
32 *sandbox_type = -1; | 33 *sandbox_type = -1; |
33 *allowed_dir = base::FilePath(); // Empty by default. | 34 *allowed_dir = base::FilePath(); // Empty by default. |
34 | 35 |
35 const base::CommandLine& command_line = | 36 const base::CommandLine& command_line = |
36 *base::CommandLine::ForCurrentProcess(); | 37 *base::CommandLine::ForCurrentProcess(); |
37 if (command_line.HasSwitch(switches::kNoSandbox)) | 38 if (command_line.HasSwitch(switches::kNoSandbox)) |
38 return false; | 39 return false; |
| 40 if (command_line.HasSwitch(switches::kV2SandboxedEnabled)) |
| 41 CHECK(sandbox::Seatbelt::IsSandboxed()); |
39 | 42 |
40 std::string process_type = | 43 std::string process_type = |
41 command_line.GetSwitchValueASCII(switches::kProcessType); | 44 command_line.GetSwitchValueASCII(switches::kProcessType); |
42 if (process_type.empty()) { | 45 if (process_type.empty()) { |
43 // Browser process isn't sandboxed. | 46 // Browser process isn't sandboxed. |
44 return false; | 47 return false; |
45 } else if (process_type == switches::kRendererProcess) { | 48 } else if (process_type == switches::kRendererProcess) { |
46 *sandbox_type = SANDBOX_TYPE_RENDERER; | 49 *sandbox_type = SANDBOX_TYPE_RENDERER; |
47 } else if (process_type == switches::kUtilityProcess) { | 50 } else if (process_type == switches::kUtilityProcess) { |
48 // Utility process sandbox. | 51 // Utility process sandbox. |
(...skipping 19 matching lines...) Expand all Loading... |
68 | 71 |
69 bool InitializeSandbox() { | 72 bool InitializeSandbox() { |
70 int sandbox_type = 0; | 73 int sandbox_type = 0; |
71 base::FilePath allowed_dir; | 74 base::FilePath allowed_dir; |
72 if (!GetSandboxTypeFromCommandLine(&sandbox_type, &allowed_dir)) | 75 if (!GetSandboxTypeFromCommandLine(&sandbox_type, &allowed_dir)) |
73 return true; | 76 return true; |
74 return InitializeSandbox(sandbox_type, allowed_dir); | 77 return InitializeSandbox(sandbox_type, allowed_dir); |
75 } | 78 } |
76 | 79 |
77 } // namespace content | 80 } // namespace content |
OLD | NEW |