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/logging.h" | 8 #include "base/logging.h" |
| 9 #include "content/common/sandbox_policy.h" |
9 #include "content/public/common/content_switches.h" | 10 #include "content/public/common/content_switches.h" |
| 11 #include "sandbox/src/sandbox.h" |
| 12 #include "sandbox/src/sandbox_types.h" |
10 | 13 |
11 void SandboxInitWrapper::SetServices(sandbox::SandboxInterfaceInfo* info) { | 14 namespace content { |
12 if (!info) | 15 |
13 return; | 16 bool InitializeSandbox( |
14 if (info->legacy) { | 17 sandbox::SandboxInterfaceInfo* sandbox_info) { |
15 // Looks like we are in the case when the new chrome.dll is being launched | 18 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
16 // by the old chrome.exe, the old chrome exe has SandboxInterfaceInfo as a | 19 std::string process_type = |
17 // union, while now we have a struct. | 20 command_line.GetSwitchValueASCII(switches::kProcessType); |
18 // TODO(cpu): Remove this nasty hack after M10 release. | 21 if (process_type.empty() || process_type == switches::kNaClBrokerProcess) { |
19 broker_services_ = reinterpret_cast<sandbox::BrokerServices*>(info->legacy); | 22 // IMPORTANT: This piece of code needs to run as early as possible in the |
20 target_services_ = reinterpret_cast<sandbox::TargetServices*>(info->legacy); | 23 // process because it will initialize the sandbox broker, which requires the |
21 } else { | 24 // process to swap its window station. During this time all the UI will be |
22 // Normal case, both the exe and the dll are the same version. Both | 25 // broken. This has to run before threads and windows are created. |
23 // interface pointers cannot be non-zero. A process can either be a target | 26 sandbox::BrokerServices* broker_services = sandbox_info->broker_services; |
24 // or a broker but not both. | 27 if (broker_services) { |
25 broker_services_ = info->broker_services; | 28 sandbox::InitBrokerServices(broker_services); |
26 target_services_ = info->target_services; | 29 if (!command_line.HasSwitch(switches::kNoSandbox)) { |
27 DCHECK(!(target_services_ && broker_services_)); | 30 bool use_winsta = !command_line.HasSwitch( |
| 31 switches::kDisableAltWinstation); |
| 32 // Precreate the desktop and window station used by the renderers. |
| 33 sandbox::TargetPolicy* policy = broker_services->CreatePolicy(); |
| 34 sandbox::ResultCode result = policy->CreateAlternateDesktop(use_winsta); |
| 35 CHECK(sandbox::SBOX_ERROR_FAILED_TO_SWITCH_BACK_WINSTATION != result); |
| 36 policy->Release(); |
| 37 } |
| 38 } |
| 39 return true; |
28 } | 40 } |
29 } | |
30 | 41 |
31 bool SandboxInitWrapper::InitializeSandbox(const CommandLine& command_line, | |
32 const std::string& process_type) { | |
33 if (command_line.HasSwitch(switches::kNoSandbox)) | 42 if (command_line.HasSwitch(switches::kNoSandbox)) |
34 return true; | 43 return true; |
| 44 |
| 45 sandbox::TargetServices* target_services = sandbox_info->target_services; |
35 if ((process_type == switches::kRendererProcess) || | 46 if ((process_type == switches::kRendererProcess) || |
36 (process_type == switches::kWorkerProcess) || | 47 (process_type == switches::kWorkerProcess) || |
37 (process_type == switches::kNaClLoaderProcess) || | 48 (process_type == switches::kNaClLoaderProcess) || |
38 (process_type == switches::kUtilityProcess)) { | 49 (process_type == switches::kUtilityProcess)) { |
39 // The above five process types must be sandboxed unless --no-sandbox | 50 // The above five process types must be sandboxed unless --no-sandbox |
40 // is present in the command line. | 51 // is present in the command line. |
41 if (!target_services_) | 52 if (!target_services) |
42 return false; | 53 return false; |
43 } else { | 54 } else { |
44 // Other process types might or might not be sandboxed. | 55 // Other process types might or might not be sandboxed. |
45 // TODO(cpu): clean this mess. | 56 // TODO(cpu): clean this mess. |
46 if (!target_services_) | 57 if (!target_services) |
47 return true; | 58 return true; |
48 } | 59 } |
49 return (sandbox::SBOX_ALL_OK == target_services_->Init()); | 60 return (sandbox::SBOX_ALL_OK == target_services->Init()); |
50 } | 61 } |
| 62 |
| 63 } // namespace content |
OLD | NEW |