Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: content/common/sandbox_init_mac.cc

Issue 8589001: Load mac sandbox definitions from resources instead of the bundle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: different approach Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/public/common/sandbox_init.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 namespace content { 13 namespace content {
14 14
15 bool InitializeSandbox(int sandbox_type, const FilePath& allowed_dir) {
16 // Warm up APIs before turning on the sandbox.
17 sandbox::Sandbox::SandboxWarmup(sandbox_type);
18
19 // Actually sandbox the process.
20 return sandbox::Sandbox::EnableSandbox(sandbox_type, allowed_dir);
21 }
22
15 bool InitializeSandbox() { 23 bool InitializeSandbox() {
jeremy 2011/11/23 07:02:17 I think this would be a bit more readable if you s
jochen (gone - plz use gerrit) 2011/11/23 10:57:28 Done.
16 using sandbox::Sandbox;
17
18 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 24 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
19 if (command_line.HasSwitch(switches::kNoSandbox)) 25 if (command_line.HasSwitch(switches::kNoSandbox))
20 return true; 26 return true;
21 27
22 Sandbox::SandboxProcessType sandbox_process_type; 28 SandboxProcessType sandbox_process_type;
23 FilePath allowed_dir; // Empty by default. 29 FilePath allowed_dir; // Empty by default.
24 30
25 std::string process_type = 31 std::string process_type =
26 command_line.GetSwitchValueASCII(switches::kProcessType); 32 command_line.GetSwitchValueASCII(switches::kProcessType);
27 if (process_type.empty()) { 33 if (process_type.empty()) {
28 // Browser process isn't sandboxed. 34 // Browser process isn't sandboxed.
29 return true; 35 return true;
30 } else if (process_type == switches::kRendererProcess) { 36 } else if (process_type == switches::kRendererProcess) {
31 if (!command_line.HasSwitch(switches::kDisable3DAPIs) && 37 if (!command_line.HasSwitch(switches::kDisable3DAPIs) &&
32 !command_line.HasSwitch(switches::kDisableExperimentalWebGL) && 38 !command_line.HasSwitch(switches::kDisableExperimentalWebGL) &&
33 command_line.HasSwitch(switches::kInProcessWebGL)) { 39 command_line.HasSwitch(switches::kInProcessWebGL)) {
34 // TODO(kbr): this check seems to be necessary only on this 40 // TODO(kbr): this check seems to be necessary only on this
35 // platform because the sandbox is initialized later. Remove 41 // platform because the sandbox is initialized later. Remove
36 // this once this flag is removed. 42 // this once this flag is removed.
37 return true; 43 return true;
38 } else { 44 } else {
39 sandbox_process_type = Sandbox::SANDBOX_TYPE_RENDERER; 45 sandbox_process_type = SANDBOX_TYPE_RENDERER;
40 } 46 }
41 } else if (process_type == switches::kUtilityProcess) { 47 } else if (process_type == switches::kUtilityProcess) {
42 // Utility process sandbox. 48 // Utility process sandbox.
43 sandbox_process_type = Sandbox::SANDBOX_TYPE_UTILITY; 49 sandbox_process_type = SANDBOX_TYPE_UTILITY;
44 allowed_dir = 50 allowed_dir =
45 command_line.GetSwitchValuePath(switches::kUtilityProcessAllowedDir); 51 command_line.GetSwitchValuePath(switches::kUtilityProcessAllowedDir);
46 } else if (process_type == switches::kWorkerProcess) { 52 } else if (process_type == switches::kWorkerProcess) {
47 // Worker process sandbox. 53 // Worker process sandbox.
48 sandbox_process_type = Sandbox::SANDBOX_TYPE_WORKER; 54 sandbox_process_type = SANDBOX_TYPE_WORKER;
49 } else if (process_type == switches::kNaClLoaderProcess) {
50 // Native Client sel_ldr (user untrusted code) sandbox.
51 sandbox_process_type = Sandbox::SANDBOX_TYPE_NACL_LOADER;
52 } else if (process_type == switches::kGpuProcess) { 55 } else if (process_type == switches::kGpuProcess) {
53 sandbox_process_type = Sandbox::SANDBOX_TYPE_GPU; 56 sandbox_process_type = SANDBOX_TYPE_GPU;
54 } else if ((process_type == switches::kPluginProcess) || 57 } else if ((process_type == switches::kPluginProcess) ||
55 (process_type == switches::kServiceProcess) || 58 (process_type == switches::kServiceProcess) ||
56 (process_type == switches::kPpapiBrokerProcess)) { 59 (process_type == switches::kPpapiBrokerProcess)) {
57 return true; 60 return true;
58 } else if (process_type == switches::kPpapiPluginProcess) { 61 } else if (process_type == switches::kPpapiPluginProcess) {
59 sandbox_process_type = Sandbox::SANDBOX_TYPE_PPAPI; 62 sandbox_process_type = SANDBOX_TYPE_PPAPI;
60 } else { 63 } else {
61 // Failsafe: If you hit an unreached here, is your new process type in need 64 // Failsafe: If you hit an unreached here, is your new process type in need
62 // of sandboxing? 65 // of sandboxing?
63 NOTREACHED() << "Unknown process type " << process_type; 66 NOTREACHED() << "Unknown process type " << process_type;
64 return true; 67 return true;
65 } 68 }
66 69
67 // Warm up APIs before turning on the sandbox. 70 return InitializeSandbox(sandbox_process_type, allowed_dir);
68 Sandbox::SandboxWarmup(sandbox_process_type);
69
70 // Actually sandbox the process.
71 return Sandbox::EnableSandbox(sandbox_process_type, allowed_dir);
72 } 71 }
73 72
74 } // namespace content 73 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698