summaryrefslogtreecommitdiffstats
path: root/content/browser/child_process_launcher.cc
diff options
context:
space:
mode:
Diffstat (limited to 'content/browser/child_process_launcher.cc')
-rw-r--r--content/browser/child_process_launcher.cc59
1 files changed, 59 insertions, 0 deletions
diff --git a/content/browser/child_process_launcher.cc b/content/browser/child_process_launcher.cc
index e54cada..830d5b9 100644
--- a/content/browser/child_process_launcher.cc
+++ b/content/browser/child_process_launcher.cc
@@ -48,6 +48,17 @@
#include "gin/v8_initializer.h"
#endif
+#if defined(MOJO_SHELL_CLIENT)
+#include "base/thread_task_runner_handle.h"
+#include "content/public/common/mojo_shell_connection.h"
+#include "mojo/application/public/cpp/application_impl.h"
+#include "mojo/converters/network/network_type_converters.h"
+#include "mojo/shell/application_manager.mojom.h"
+#include "third_party/mojo/src/mojo/edk/embedder/embedder.h"
+#include "third_party/mojo/src/mojo/edk/embedder/platform_channel_pair.h"
+#include "third_party/mojo/src/mojo/edk/embedder/scoped_platform_handle.h"
+#endif
+
namespace content {
namespace {
@@ -322,6 +333,10 @@ void SetProcessBackgroundedOnLauncherThread(base::Process process,
#endif
}
+#if defined(MOJO_SHELL_CLIENT)
+void DidCreateChannel(mojo::embedder::ChannelInfo* info) {}
+#endif
+
} // namespace
ChildProcessLauncher::ChildProcessLauncher(
@@ -365,6 +380,10 @@ void ChildProcessLauncher::Launch(
int child_process_id) {
DCHECK(CalledOnValidThread());
+#if defined(MOJO_SHELL_CLIENT)
+ CreateMojoShellChannel(cmd_line, child_process_id);
+#endif
+
#if defined(OS_ANDROID)
// Android only supports renderer, sandboxed utility and gpu.
std::string process_type =
@@ -504,6 +523,46 @@ void ChildProcessLauncher::Notify(
}
}
+#if defined(MOJO_SHELL_CLIENT)
+void ChildProcessLauncher::CreateMojoShellChannel(
+ base::CommandLine* command_line,
+ int child_process_id) {
+ // Some process types get created before the main message loop.
+ if (!MojoShellConnection::Get())
+ return;
+
+ // Create the channel to be shared with the target process.
+ mojo::embedder::HandlePassingInformation handle_passing_info;
+ mojo::embedder::PlatformChannelPair platform_channel_pair;
+
+ // Give one end to the shell so that it can create an instance.
+ mojo::embedder::ScopedPlatformHandle platform_channel =
+ platform_channel_pair.PassServerHandle();
+ mojo::ScopedMessagePipeHandle handle(mojo::embedder::CreateChannel(
+ platform_channel.Pass(), base::Bind(&DidCreateChannel),
+ base::ThreadTaskRunnerHandle::Get()));
+ mojo::shell::mojom::ApplicationManagerPtr application_manager;
+ MojoShellConnection::Get()->GetApplication()->ConnectToService(
+ mojo::URLRequest::From(std::string("mojo:shell")),
+ &application_manager);
+ // The content of the URL/qualifier we pass is actually meaningless, it's only
+ // important that they're unique per process.
+ // TODO(beng): We need to specify a restrictive CapabilityFilter here that
+ // matches the needs of the target process. Figure out where that
+ // specification is best determined (not here, this is a common
+ // chokepoint for all process types) and how to wire it through.
+ // http://crbug.com/555393
+ application_manager->CreateInstanceForHandle(
+ mojo::ScopedHandle(mojo::Handle(handle.release().value())),
+ "exe:chrome_renderer", // See above about how this string is meaningless.
+ base::IntToString(child_process_id));
+
+ // Put the other end on the command line used to launch the target.
+ platform_channel_pair.PrepareToPassClientHandleToChildProcess(
+ command_line, &handle_passing_info);
+}
+#endif // defined(MOJO_SHELL_CLIENT)
+
bool ChildProcessLauncher::IsStarting() {
// TODO(crbug.com/469248): This fails in some tests.
// DCHECK(CalledOnValidThread());