OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/logging.h" | 8 #include "base/logging.h" |
9 #include "content/common/sandbox_policy.h" | 9 #include "content/common/sandbox_policy.h" |
10 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
11 #include "sandbox/src/sandbox.h" | 11 #include "sandbox/src/sandbox.h" |
12 #include "sandbox/src/sandbox_types.h" | 12 #include "sandbox/src/sandbox_types.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 bool InitializeSandbox( | 16 bool InitializeSandbox( |
17 sandbox::SandboxInterfaceInfo* sandbox_info) { | 17 sandbox::SandboxInterfaceInfo* sandbox_info) { |
18 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 18 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
19 std::string process_type = | 19 std::string process_type = |
20 command_line.GetSwitchValueASCII(switches::kProcessType); | 20 command_line.GetSwitchValueASCII(switches::kProcessType); |
21 sandbox::BrokerServices* broker_services = sandbox_info->broker_services; | |
Albert Bodenhamer
2012/07/03 00:20:54
I'm not sure it's correct to InitBrokerServices in
jschuh
2012/07/03 03:22:35
Albert is right. The correct thing to do is branch
Vitaly Buka (NO REVIEWS)
2012/07/03 05:01:09
Done.
Vitaly Buka (NO REVIEWS)
2012/07/03 05:01:09
Done.
| |
22 // IMPORTANT: This piece of code needs to run as early as possible in the | |
23 // process because it will initialize the sandbox broker, which requires the | |
24 // process to swap its window station. During this time all the UI will be | |
Vitaly Buka (NO REVIEWS)
2012/07/03 05:01:09
I moved this to separate if because Winstation is
| |
25 // broken. This has to run before threads and windows are created. | |
26 if (broker_services) { | |
27 if (!sandbox::InitBrokerServices(broker_services)) | |
28 return false; | |
29 } | |
30 | |
21 if (process_type.empty() || process_type == switches::kNaClBrokerProcess) { | 31 if (process_type.empty() || process_type == switches::kNaClBrokerProcess) { |
22 // IMPORTANT: This piece of code needs to run as early as possible in the | 32 if (broker_services && !command_line.HasSwitch(switches::kNoSandbox)) { |
23 // process because it will initialize the sandbox broker, which requires the | 33 bool use_winsta = !command_line.HasSwitch( |
24 // process to swap its window station. During this time all the UI will be | 34 switches::kDisableAltWinstation); |
25 // broken. This has to run before threads and windows are created. | 35 // Precreate the desktop and window station used by the renderers. |
26 sandbox::BrokerServices* broker_services = sandbox_info->broker_services; | 36 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); |
27 if (broker_services) { | 37 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); |
28 if (!sandbox::InitBrokerServices(broker_services)) | 38 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); |
29 return false; | 39 policy->Release(); |
30 if (!command_line.HasSwitch(switches::kNoSandbox)) { | |
31 bool use_winsta = !command_line.HasSwitch( | |
32 switches::kDisableAltWinstation); | |
33 // Precreate the desktop and window station used by the renderers. | |
34 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); | |
35 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); | |
36 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); | |
37 policy->Release(); | |
38 } | |
39 } | 40 } |
40 return true; | 41 return true; |
41 } | 42 } |
42 | 43 |
43 if (command_line.HasSwitch(switches::kNoSandbox)) | 44 if (command_line.HasSwitch(switches::kNoSandbox)) |
44 return true; | 45 return true; |
45 | 46 |
46 sandbox::TargetServices* target_services = sandbox_info->target_services; | 47 sandbox::TargetServices* target_services = sandbox_info->target_services; |
47 if ((process_type == switches::kRendererProcess) || | 48 if ((process_type == switches::kRendererProcess) || |
48 (process_type == switches::kWorkerProcess) || | 49 (process_type == switches::kWorkerProcess) || |
49 (process_type == switches::kNaClLoaderProcess) || | 50 (process_type == switches::kNaClLoaderProcess) || |
50 (process_type == switches::kUtilityProcess)) { | 51 (process_type == switches::kUtilityProcess)) { |
51 // The above five process types must be sandboxed unless --no-sandbox | 52 // The above five process types must be sandboxed unless --no-sandbox |
52 // is present in the command line. | 53 // is present in the command line. |
53 if (!target_services) | 54 if (!target_services) |
54 return false; | 55 return false; |
55 } else { | 56 } else { |
56 // Other process types might or might not be sandboxed. | 57 // Other process types might or might not be sandboxed. |
57 // TODO(cpu): clean this mess. | 58 // TODO(cpu): clean this mess. |
58 if (!target_services) | 59 if (!target_services) |
59 return true; | 60 return true; |
60 } | 61 } |
61 return sandbox::InitTargetServices(target_services); | 62 return sandbox::InitTargetServices(target_services); |
62 } | 63 } |
63 | 64 |
64 } // namespace content | 65 } // namespace content |
OLD | NEW |