| OLD | NEW |
| 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 "content/browser/mojo/mojo_shell_client_host.h" | 5 #include "content/browser/mojo/mojo_shell_client_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 14 #include "content/public/browser/browser_thread.h" | 14 #include "content/public/browser/browser_thread.h" |
| 15 #include "content/public/browser/render_process_host.h" | 15 #include "content/public/browser/render_process_host.h" |
| 16 #include "content/public/browser/render_process_host_observer.h" | 16 #include "content/public/browser/render_process_host_observer.h" |
| 17 #include "content/public/common/mojo_shell_connection.h" | 17 #include "content/public/common/mojo_shell_connection.h" |
| 18 #include "ipc/ipc_sender.h" | 18 #include "ipc/ipc_sender.h" |
| 19 #include "mojo/converters/network/network_type_converters.h" | 19 #include "mojo/converters/network/network_type_converters.h" |
| 20 #include "mojo/edk/embedder/embedder.h" | 20 #include "mojo/edk/embedder/embedder.h" |
| 21 #include "mojo/public/cpp/system/message_pipe.h" | 21 #include "mojo/public/cpp/system/message_pipe.h" |
| 22 #include "mojo/shell/public/cpp/connector.h" | 22 #include "mojo/shell/public/cpp/connector.h" |
| 23 #include "mojo/shell/public/interfaces/application_manager.mojom.h" | 23 #include "mojo/shell/public/interfaces/shell.mojom.h" |
| 24 | 24 |
| 25 namespace content { | 25 namespace content { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 const char kMojoShellInstanceURL[] = "mojo_shell_instance_url"; | 28 const char kMojoShellInstanceURL[] = "mojo_shell_instance_url"; |
| 29 | 29 |
| 30 class InstanceURL : public base::SupportsUserData::Data { | 30 class InstanceURL : public base::SupportsUserData::Data { |
| 31 public: | 31 public: |
| 32 explicit InstanceURL(const std::string& instance_url) | 32 explicit InstanceURL(const std::string& instance_url) |
| 33 : instance_url_(instance_url) {} | 33 : instance_url_(instance_url) {} |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 std::string pipe_token = mojo::edk::GenerateRandomToken(); | 92 std::string pipe_token = mojo::edk::GenerateRandomToken(); |
| 93 mojo::ScopedMessagePipeHandle request_pipe = | 93 mojo::ScopedMessagePipeHandle request_pipe = |
| 94 mojo::edk::CreateParentMessagePipe(pipe_token); | 94 mojo::edk::CreateParentMessagePipe(pipe_token); |
| 95 | 95 |
| 96 // Some process types get created before the main message loop. In this case | 96 // Some process types get created before the main message loop. In this case |
| 97 // the shell request pipe will simply be closed, and the child can detect | 97 // the shell request pipe will simply be closed, and the child can detect |
| 98 // this. | 98 // this. |
| 99 if (!MojoShellConnection::Get()) | 99 if (!MojoShellConnection::Get()) |
| 100 return pipe_token; | 100 return pipe_token; |
| 101 | 101 |
| 102 mojo::shell::mojom::ApplicationManagerPtr application_manager; | 102 mojo::shell::mojom::ShellPtr shell; |
| 103 MojoShellConnection::Get()->GetConnector()->ConnectToInterface( | 103 MojoShellConnection::Get()->GetConnector()->ConnectToInterface( |
| 104 "mojo:shell", &application_manager); | 104 "mojo:shell", &shell); |
| 105 | 105 |
| 106 // The content of the URL/qualifier we pass is actually meaningless, it's only | 106 // The content of the URL/qualifier we pass is actually meaningless, it's only |
| 107 // important that they're unique per process. | 107 // important that they're unique per process. |
| 108 // TODO(beng): We need to specify a restrictive CapabilityFilter here that | 108 // TODO(beng): We need to specify a restrictive CapabilityFilter here that |
| 109 // matches the needs of the target process. Figure out where that | 109 // matches the needs of the target process. Figure out where that |
| 110 // specification is best determined (not here, this is a common | 110 // specification is best determined (not here, this is a common |
| 111 // chokepoint for all process types) and how to wire it through. | 111 // chokepoint for all process types) and how to wire it through. |
| 112 // http://crbug.com/555393 | 112 // http://crbug.com/555393 |
| 113 std::string url = base::StringPrintf( | 113 std::string url = base::StringPrintf( |
| 114 "exe:chrome_renderer%d_%d", child_process_id, instance_id); | 114 "exe:chrome_renderer%d_%d", child_process_id, instance_id); |
| 115 | 115 |
| 116 mojo::shell::mojom::PIDReceiverPtr pid_receiver; | 116 mojo::shell::mojom::PIDReceiverPtr pid_receiver; |
| 117 mojo::InterfaceRequest<mojo::shell::mojom::PIDReceiver> request = | 117 mojo::InterfaceRequest<mojo::shell::mojom::PIDReceiver> request = |
| 118 GetProxy(&pid_receiver); | 118 GetProxy(&pid_receiver); |
| 119 new PIDSender(render_process_host, std::move(pid_receiver)); | 119 new PIDSender(render_process_host, std::move(pid_receiver)); |
| 120 | 120 |
| 121 mojo::shell::mojom::ShellClientFactoryPtr factory; | 121 mojo::shell::mojom::ShellClientFactoryPtr factory; |
| 122 factory.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClientFactory>( | 122 factory.Bind(mojo::InterfacePtrInfo<mojo::shell::mojom::ShellClientFactory>( |
| 123 std::move(request_pipe), 0u)); | 123 std::move(request_pipe), 0u)); |
| 124 | 124 |
| 125 application_manager->CreateInstanceForFactory( | 125 shell->CreateInstanceForFactory(std::move(factory), url, |
| 126 std::move(factory), url, mojo::shell::mojom::Connector::kUserInherit, | 126 mojo::shell::mojom::Connector::kUserInherit, |
| 127 CreateCapabilityFilterForRenderer(), std::move(request)); | 127 CreateCapabilityFilterForRenderer(), |
| 128 std::move(request)); |
| 128 | 129 |
| 129 // Store the URL on the RPH so client code can access it later via | 130 // Store the URL on the RPH so client code can access it later via |
| 130 // GetMojoApplicationInstanceURL(). | 131 // GetMojoApplicationInstanceURL(). |
| 131 SetMojoApplicationInstanceURL(render_process_host, url); | 132 SetMojoApplicationInstanceURL(render_process_host, url); |
| 132 | 133 |
| 133 return pipe_token; | 134 return pipe_token; |
| 134 } | 135 } |
| 135 | 136 |
| 136 std::string GetMojoApplicationInstanceURL( | 137 std::string GetMojoApplicationInstanceURL( |
| 137 RenderProcessHost* render_process_host) { | 138 RenderProcessHost* render_process_host) { |
| 138 InstanceURL* instance_url = static_cast<InstanceURL*>( | 139 InstanceURL* instance_url = static_cast<InstanceURL*>( |
| 139 render_process_host->GetUserData(kMojoShellInstanceURL)); | 140 render_process_host->GetUserData(kMojoShellInstanceURL)); |
| 140 return instance_url ? instance_url->get() : std::string(); | 141 return instance_url ? instance_url->get() : std::string(); |
| 141 } | 142 } |
| 142 | 143 |
| 143 } // namespace content | 144 } // namespace content |
| OLD | NEW |