OLD | NEW |
| (Empty) |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/thread_task_runner_handle.h" | |
6 #include "content/browser/mojo/mojo_shell_client_host.h" | |
7 #include "content/common/mojo/mojo_messages.h" | |
8 #include "content/public/common/mojo_shell_connection.h" | |
9 #include "ipc/ipc_sender.h" | |
10 #include "mojo/application/public/cpp/application_impl.h" | |
11 #include "mojo/converters/network/network_type_converters.h" | |
12 #include "mojo/shell/application_manager.mojom.h" | |
13 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" | |
14 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" | |
15 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h" | |
16 | |
17 namespace content { | |
18 namespace { | |
19 void DidCreateChannel(mojo::embedder::ChannelInfo* info) {} | |
20 | |
21 base::PlatformFile PlatformFileFromScopedPlatformHandle( | |
22 mojo::embedder::ScopedPlatformHandle handle) { | |
23 #if defined(OS_POSIX) | |
24 return handle.release().fd; | |
25 #elif defined(OS_WIN) | |
26 return handle.release().handle; | |
27 #endif | |
28 } | |
29 | |
30 } // namespace | |
31 | |
32 void RegisterChildWithExternalShell(int child_process_id, | |
33 base::ProcessHandle process_handle, | |
34 IPC::Sender* sender) { | |
35 // Some process types get created before the main message loop. | |
36 if (!MojoShellConnection::Get()) | |
37 return; | |
38 | |
39 // Create the channel to be shared with the target process. | |
40 mojo::embedder::HandlePassingInformation handle_passing_info; | |
41 mojo::embedder::PlatformChannelPair platform_channel_pair; | |
42 | |
43 // Give one end to the shell so that it can create an instance. | |
44 mojo::embedder::ScopedPlatformHandle platform_channel = | |
45 platform_channel_pair.PassServerHandle(); | |
46 mojo::ScopedMessagePipeHandle handle(mojo::embedder::CreateChannel( | |
47 platform_channel.Pass(), base::Bind(&DidCreateChannel), | |
48 base::ThreadTaskRunnerHandle::Get())); | |
49 mojo::shell::mojom::ApplicationManagerPtr application_manager; | |
50 MojoShellConnection::Get()->GetApplication()->ConnectToService( | |
51 mojo::URLRequest::From(std::string("mojo:shell")), | |
52 &application_manager); | |
53 // The content of the URL/qualifier we pass is actually meaningless, it's only | |
54 // important that they're unique per process. | |
55 // TODO(beng): We need to specify a restrictive CapabilityFilter here that | |
56 // matches the needs of the target process. Figure out where that | |
57 // specification is best determined (not here, this is a common | |
58 // chokepoint for all process types) and how to wire it through. | |
59 // http://crbug.com/555393 | |
60 application_manager->CreateInstanceForHandle( | |
61 mojo::ScopedHandle(mojo::Handle(handle.release().value())), | |
62 "exe:chrome_renderer", // See above about how this string is meaningless. | |
63 base::IntToString(child_process_id)); | |
64 | |
65 // Send the other end to the child via Chrome IPC. | |
66 base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle( | |
67 platform_channel_pair.PassClientHandle()); | |
68 sender->Send(new MojoMsg_BindControllerHandle( | |
69 IPC::GetFileHandleForProcess(client_file, process_handle, true))); | |
70 } | |
71 | |
72 } // namespace content | |
OLD | NEW |