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

Side by Side Diff: content/browser/mojo/mojo_shell_client_host.cc

Issue 1476643002: mustash: Enable connections to mus from the Chrome renderer [take 2] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Don't create a RenderWidgetWindowTreeeClientFactory in tests Created 5 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 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 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 "base/strings/stringprintf.h" 5 #include "base/strings/stringprintf.h"
6 #include "base/thread_task_runner_handle.h" 6 #include "base/thread_task_runner_handle.h"
7 #include "content/browser/mojo/mojo_shell_client_host.h" 7 #include "content/browser/mojo/mojo_shell_client_host.h"
8 #include "content/common/mojo/mojo_messages.h" 8 #include "content/common/mojo/mojo_messages.h"
9 #include "content/public/browser/render_process_host.h" 9 #include "content/public/browser/render_process_host.h"
10 #include "content/public/common/mojo_shell_connection.h" 10 #include "content/public/common/mojo_shell_connection.h"
11 #include "ipc/ipc_sender.h" 11 #include "ipc/ipc_sender.h"
12 #include "mojo/application/public/cpp/application_impl.h" 12 #include "mojo/application/public/cpp/application_impl.h"
13 #include "mojo/converters/network/network_type_converters.h" 13 #include "mojo/converters/network/network_type_converters.h"
14 #include "mojo/shell/application_manager.mojom.h" 14 #include "mojo/shell/application_manager.mojom.h"
15 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h" 15 #include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
16 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h" 16 #include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
17 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h" 17 #include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h"
18 18
19 namespace content { 19 namespace content {
20 namespace { 20 namespace {
21 21
22 const char kMojoShellInstanceURL[] = "mojo_shell_instance_url"; 22 const char kMojoShellInstanceURL[] = "mojo_shell_instance_url";
23 const char kMojoPlatformFile[] = "mojo_platform_file";
23 24
24 void DidCreateChannel(mojo::embedder::ChannelInfo* info) {} 25 void DidCreateChannel(mojo::embedder::ChannelInfo* info) {}
25 26
26 base::PlatformFile PlatformFileFromScopedPlatformHandle( 27 base::PlatformFile PlatformFileFromScopedPlatformHandle(
27 mojo::embedder::ScopedPlatformHandle handle) { 28 mojo::embedder::ScopedPlatformHandle handle) {
28 #if defined(OS_POSIX) 29 #if defined(OS_POSIX)
29 return handle.release().fd; 30 return handle.release().fd;
30 #elif defined(OS_WIN) 31 #elif defined(OS_WIN)
31 return handle.release().handle; 32 return handle.release().handle;
32 #endif 33 #endif
33 } 34 }
34 35
35 class InstanceURL : public base::SupportsUserData::Data { 36 class InstanceURL : public base::SupportsUserData::Data {
36 public: 37 public:
37 InstanceURL(const std::string& instance_url) : instance_url_(instance_url) {} 38 InstanceURL(const std::string& instance_url) : instance_url_(instance_url) {}
38 ~InstanceURL() override {} 39 ~InstanceURL() override {}
39 40
40 std::string get() const { return instance_url_; } 41 std::string get() const { return instance_url_; }
41 42
42 private: 43 private:
43 std::string instance_url_; 44 std::string instance_url_;
44 45
45 DISALLOW_COPY_AND_ASSIGN(InstanceURL); 46 DISALLOW_COPY_AND_ASSIGN(InstanceURL);
46 }; 47 };
47 48
49 class InstanceShellHandle : public base::SupportsUserData::Data {
50 public:
51 InstanceShellHandle(base::PlatformFile shell_handle)
52 : shell_handle_(shell_handle) {}
53 ~InstanceShellHandle() override {}
54
55 base::PlatformFile get() const { return shell_handle_; }
56
57 private:
58 base::PlatformFile shell_handle_;
59
60 DISALLOW_COPY_AND_ASSIGN(InstanceShellHandle);
61 };
62
48 void SetMojoApplicationInstanceURL(RenderProcessHost* render_process_host, 63 void SetMojoApplicationInstanceURL(RenderProcessHost* render_process_host,
49 const std::string& instance_url) { 64 const std::string& instance_url) {
50 render_process_host->SetUserData(kMojoShellInstanceURL, 65 render_process_host->SetUserData(kMojoShellInstanceURL,
51 new InstanceURL(instance_url)); 66 new InstanceURL(instance_url));
52 } 67 }
53 68
69 void SetMojoPlatformFile(RenderProcessHost* render_process_host,
70 base::PlatformFile platform_file) {
71 render_process_host->SetUserData(kMojoPlatformFile,
72 new InstanceShellHandle(platform_file));
73 }
74
54 } // namespace 75 } // namespace
55 76
56 void RegisterChildWithExternalShell(int child_process_id, 77 void RegisterChildWithExternalShell(int child_process_id,
57 base::ProcessHandle process_handle,
58 RenderProcessHost* render_process_host) { 78 RenderProcessHost* render_process_host) {
59 // Some process types get created before the main message loop. 79 // Some process types get created before the main message loop.
60 if (!MojoShellConnection::Get()) 80 if (!MojoShellConnection::Get())
61 return; 81 return;
62 82
63 // Create the channel to be shared with the target process. 83 // Create the channel to be shared with the target process.
64 mojo::embedder::HandlePassingInformation handle_passing_info; 84 mojo::embedder::HandlePassingInformation handle_passing_info;
65 mojo::embedder::PlatformChannelPair platform_channel_pair; 85 mojo::embedder::PlatformChannelPair platform_channel_pair;
66 86
67 // Give one end to the shell so that it can create an instance. 87 // Give one end to the shell so that it can create an instance.
(...skipping 13 matching lines...) Expand all
81 // chokepoint for all process types) and how to wire it through. 101 // chokepoint for all process types) and how to wire it through.
82 // http://crbug.com/555393 102 // http://crbug.com/555393
83 std::string url = 103 std::string url =
84 base::StringPrintf("exe:chrome_renderer%d", child_process_id); 104 base::StringPrintf("exe:chrome_renderer%d", child_process_id);
85 application_manager->CreateInstanceForHandle( 105 application_manager->CreateInstanceForHandle(
86 mojo::ScopedHandle(mojo::Handle(handle.release().value())), url); 106 mojo::ScopedHandle(mojo::Handle(handle.release().value())), url);
87 107
88 // Send the other end to the child via Chrome IPC. 108 // Send the other end to the child via Chrome IPC.
89 base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle( 109 base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle(
90 platform_channel_pair.PassClientHandle()); 110 platform_channel_pair.PassClientHandle());
91 render_process_host->Send(new MojoMsg_BindExternalMojoShellHandle( 111 SetMojoPlatformFile(render_process_host, client_file);
92 IPC::GetFileHandleForProcess(client_file, process_handle, true)));
93 112
94 // Store the URL on the RPH so client code can access it later via 113 // Store the URL on the RPH so client code can access it later via
95 // GetMojoApplicationInstanceURL(). 114 // GetMojoApplicationInstanceURL().
96 SetMojoApplicationInstanceURL(render_process_host, url); 115 SetMojoApplicationInstanceURL(render_process_host, url);
97 } 116 }
98 117
99 std::string GetMojoApplicationInstanceURL( 118 std::string GetMojoApplicationInstanceURL(
100 RenderProcessHost* render_process_host) { 119 RenderProcessHost* render_process_host) {
101 InstanceURL* instance_url = static_cast<InstanceURL*>( 120 InstanceURL* instance_url = static_cast<InstanceURL*>(
102 render_process_host->GetUserData(kMojoShellInstanceURL)); 121 render_process_host->GetUserData(kMojoShellInstanceURL));
103 return instance_url ? instance_url->get() : std::string(); 122 return instance_url ? instance_url->get() : std::string();
104 } 123 }
105 124
125 void SendExternalMojoShellHandleToChild(
126 base::ProcessHandle process_handle,
127 RenderProcessHost* render_process_host) {
128 InstanceShellHandle* client_file = static_cast<InstanceShellHandle*>(
129 render_process_host->GetUserData(kMojoPlatformFile));
130 if (!client_file)
131 return;
132 render_process_host->Send(new MojoMsg_BindExternalMojoShellHandle(
133 IPC::GetFileHandleForProcess(client_file->get(), process_handle, true)));
134 }
135
106 } // namespace content 136 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698