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

Unified Diff: content/browser/mojo/mojo_shell_client_host.cc

Issue 1452823003: Bind Application in renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/mojo/mojo_shell_client_host.cc
diff --git a/content/browser/mojo/mojo_shell_client_host.cc b/content/browser/mojo/mojo_shell_client_host.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f58065b8520714c0b9095e78f8f3bb7272c685af
--- /dev/null
+++ b/content/browser/mojo/mojo_shell_client_host.cc
@@ -0,0 +1,72 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/thread_task_runner_handle.h"
+#include "content/browser/mojo/mojo_shell_client_host.h"
+#include "content/common/mojo/mojo_messages.h"
+#include "content/public/common/mojo_shell_connection.h"
+#include "ipc/ipc_sender.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"
+
+namespace content {
+namespace {
+void DidCreateChannel(mojo::embedder::ChannelInfo* info) {}
+
+base::PlatformFile PlatformFileFromScopedPlatformHandle(
+ mojo::embedder::ScopedPlatformHandle handle) {
+#if defined(OS_POSIX)
+ return handle.release().fd;
+#elif defined(OS_WIN)
+ return handle.release().handle;
+#endif
+}
+
+} // namespace
+
+void RegisterChildWithExternalShell(int child_process_id,
+ base::ProcessHandle process_handle,
+ IPC::Sender* sender) {
+ // 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));
+
+ // Send the other end to the child via Chrome IPC.
+ base::PlatformFile client_file = PlatformFileFromScopedPlatformHandle(
+ platform_channel_pair.PassClientHandle());
+ sender->Send(new MojoMsg_BindExternalMojoShellHandle(
+ IPC::GetFileHandleForProcess(client_file, process_handle, true)));
+}
+
+} // namespace content
« no previous file with comments | « content/browser/mojo/mojo_shell_client_host.h ('k') | content/browser/renderer_host/render_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698