OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/shell/runner/host/child_process_host.h" | 5 #include "mojo/shell/runner/host/child_process_host.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
17 #include "base/process/kill.h" | 17 #include "base/process/kill.h" |
18 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
19 #include "base/task_runner.h" | 19 #include "base/task_runner.h" |
20 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
21 #include "mojo/edk/embedder/embedder.h" | 21 #include "mojo/edk/embedder/embedder.h" |
22 #include "mojo/public/cpp/bindings/interface_ptr_info.h" | 22 #include "mojo/public/cpp/bindings/interface_ptr_info.h" |
23 #include "mojo/public/cpp/system/core.h" | 23 #include "mojo/public/cpp/system/core.h" |
| 24 #include "mojo/shell/native_runner_delegate.h" |
24 #include "mojo/shell/runner/common/switches.h" | 25 #include "mojo/shell/runner/common/switches.h" |
25 #include "mojo/shell/runner/host/command_line_switch.h" | |
26 | 26 |
27 #if defined(OS_LINUX) && !defined(OS_ANDROID) | 27 #if defined(OS_LINUX) && !defined(OS_ANDROID) |
28 #include "sandbox/linux/services/namespace_sandbox.h" | 28 #include "sandbox/linux/services/namespace_sandbox.h" |
29 #endif | 29 #endif |
30 | 30 |
31 #if defined(OS_WIN) | 31 #if defined(OS_WIN) |
32 #include "base/win/windows_version.h" | 32 #include "base/win/windows_version.h" |
33 #endif | 33 #endif |
34 | 34 |
35 namespace mojo { | 35 namespace mojo { |
36 namespace shell { | 36 namespace shell { |
37 | 37 |
38 ChildProcessHost::ChildProcessHost( | 38 ChildProcessHost::ChildProcessHost(base::TaskRunner* launch_process_runner, |
39 base::TaskRunner* launch_process_runner, | 39 NativeRunnerDelegate* delegate, |
40 bool start_sandboxed, | 40 bool start_sandboxed, |
41 const base::FilePath& app_path, | 41 const Identity& target, |
42 const std::vector<CommandLineSwitch>& command_line_switches) | 42 const base::FilePath& app_path) |
43 : launch_process_runner_(launch_process_runner), | 43 : launch_process_runner_(launch_process_runner), |
| 44 delegate_(delegate), |
44 start_sandboxed_(start_sandboxed), | 45 start_sandboxed_(start_sandboxed), |
| 46 target_(target), |
45 app_path_(app_path), | 47 app_path_(app_path), |
46 start_child_process_event_(false, false), | 48 start_child_process_event_(false, false), |
47 command_line_switches_(command_line_switches), | |
48 weak_factory_(this) { | 49 weak_factory_(this) { |
49 node_channel_.reset(new edk::PlatformChannelPair); | 50 node_channel_.reset(new edk::PlatformChannelPair); |
50 primordial_pipe_token_ = edk::GenerateRandomToken(); | 51 primordial_pipe_token_ = edk::GenerateRandomToken(); |
51 controller_.Bind( | 52 controller_.Bind( |
52 InterfacePtrInfo<mojom::ChildController>( | 53 InterfacePtrInfo<mojom::ChildController>( |
53 edk::CreateParentMessagePipe(primordial_pipe_token_), 0u)); | 54 edk::CreateParentMessagePipe(primordial_pipe_token_), 0u)); |
54 } | 55 } |
55 | 56 |
56 ChildProcessHost::ChildProcessHost(ScopedHandle channel) | 57 ChildProcessHost::ChildProcessHost(ScopedHandle channel) |
57 : launch_process_runner_(nullptr), | 58 : launch_process_runner_(nullptr), |
| 59 delegate_(nullptr), |
58 start_sandboxed_(false), | 60 start_sandboxed_(false), |
59 start_child_process_event_(false, false), | 61 start_child_process_event_(false, false), |
60 weak_factory_(this) { | 62 weak_factory_(this) { |
61 CHECK(channel.is_valid()); | 63 CHECK(channel.is_valid()); |
62 ScopedMessagePipeHandle handle(MessagePipeHandle(channel.release().value())); | 64 ScopedMessagePipeHandle handle(MessagePipeHandle(channel.release().value())); |
63 controller_.Bind( | 65 controller_.Bind( |
64 InterfacePtrInfo<mojom::ChildController>(std::move(handle), 0u)); | 66 InterfacePtrInfo<mojom::ChildController>(std::move(handle), 0u)); |
65 } | 67 } |
66 | 68 |
67 ChildProcessHost::~ChildProcessHost() { | 69 ChildProcessHost::~ChildProcessHost() { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 child_command_line.AppendSwitch(switches::kEnableSandbox); | 144 child_command_line.AppendSwitch(switches::kEnableSandbox); |
143 | 145 |
144 if (node_channel_.get()) { | 146 if (node_channel_.get()) { |
145 node_channel_->PrepareToPassClientHandleToChildProcess( | 147 node_channel_->PrepareToPassClientHandleToChildProcess( |
146 &child_command_line, &handle_passing_info_); | 148 &child_command_line, &handle_passing_info_); |
147 } | 149 } |
148 | 150 |
149 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, | 151 child_command_line.AppendSwitchASCII(switches::kPrimordialPipeToken, |
150 primordial_pipe_token_); | 152 primordial_pipe_token_); |
151 | 153 |
152 for (const CommandLineSwitch& pair : command_line_switches_) | 154 if (delegate_) { |
153 child_command_line.AppendSwitchASCII(pair.key, pair.value); | 155 delegate_->AdjustCommandLineArgumentsForTarget(target_, |
| 156 &child_command_line); |
| 157 } |
154 | 158 |
155 base::LaunchOptions options; | 159 base::LaunchOptions options; |
156 #if defined(OS_WIN) | 160 #if defined(OS_WIN) |
157 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 161 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { |
158 options.handles_to_inherit = &handle_passing_info_; | 162 options.handles_to_inherit = &handle_passing_info_; |
159 } else { | 163 } else { |
160 #if defined(OFFICIAL_BUILD) | 164 #if defined(OFFICIAL_BUILD) |
161 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; | 165 CHECK(false) << "Launching mojo process with inherit_handles is insecure!"; |
162 #endif | 166 #endif |
163 options.inherit_handles = true; | 167 options.inherit_handles = true; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 void ChildProcessHost::AppCompleted(int32_t result) { | 225 void ChildProcessHost::AppCompleted(int32_t result) { |
222 if (!on_app_complete_.is_null()) { | 226 if (!on_app_complete_.is_null()) { |
223 auto on_app_complete = on_app_complete_; | 227 auto on_app_complete = on_app_complete_; |
224 on_app_complete_.reset(); | 228 on_app_complete_.reset(); |
225 on_app_complete.Run(result); | 229 on_app_complete.Run(result); |
226 } | 230 } |
227 } | 231 } |
228 | 232 |
229 } // namespace shell | 233 } // namespace shell |
230 } // namespace mojo | 234 } // namespace mojo |
OLD | NEW |