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

Unified Diff: content/browser/renderer_host/render_process_host_mojo_impl.cc

Issue 206923002: Adds plumbing to pass WebUI mojo::Handle from browser to renderer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add TODO and merge to trunk Created 6 years, 9 months 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/renderer_host/render_process_host_mojo_impl.cc
diff --git a/content/browser/renderer_host/render_process_host_mojo_impl.cc b/content/browser/renderer_host/render_process_host_mojo_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..16348a6d21c19851811ab3ff9f12badeef2d491e
--- /dev/null
+++ b/content/browser/renderer_host/render_process_host_mojo_impl.cc
@@ -0,0 +1,93 @@
+// Copyright 2014 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 "content/browser/renderer_host/render_process_host_mojo_impl.h"
+
+#include "base/platform_file.h"
+#include "content/common/mojo/mojo_channel_init.h"
+#include "content/common/mojo/mojo_messages.h"
+#include "content/public/browser/browser_thread.h"
+#include "content/public/browser/render_process_host.h"
+#include "mojo/embedder/platform_channel_pair.h"
+
+namespace content {
+
+namespace {
+
+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
+
+struct RenderProcessHostMojoImpl::PendingHandle {
+ PendingHandle() : view_routing_id(0) {}
+
+ int32 view_routing_id;
+ mojo::ScopedMessagePipeHandle handle;
+};
+
+RenderProcessHostMojoImpl::RenderProcessHostMojoImpl(RenderProcessHost* host)
+ : host_(host) {
+}
+
+RenderProcessHostMojoImpl::~RenderProcessHostMojoImpl() {
+}
+
+void RenderProcessHostMojoImpl::SetWebUIHandle(
+ int32 view_routing_id,
+ mojo::ScopedMessagePipeHandle handle) {
+ base::ProcessHandle process = host_->GetHandle();
+ if (process != base::kNullProcessHandle) {
+ CreateMojoChannel(process); // Does nothing if already connected.
+ if (!render_process_mojo_.is_null()) {
+ render_process_mojo_->SetWebUIHandle(view_routing_id, handle.Pass());
+ return;
+ }
+ }
+
+ // Remember the request, we'll attempt to reconnect once the child process is
+ // launched.
+ pending_handle_.reset(new PendingHandle);
+ pending_handle_->view_routing_id = view_routing_id;
+ pending_handle_->handle = handle.Pass();
+}
+
+void RenderProcessHostMojoImpl::OnProcessLaunched() {
+ if (pending_handle_) {
+ scoped_ptr<PendingHandle> handle(pending_handle_.Pass());
+ SetWebUIHandle(handle->view_routing_id, handle->handle.Pass());
+ }
+}
+
+
+void RenderProcessHostMojoImpl::CreateMojoChannel(
+ base::ProcessHandle process_handle) {
+ if (mojo_channel_init_.get())
+ return;
+
+ mojo::embedder::PlatformChannelPair channel_pair;
+ mojo_channel_init_.reset(new MojoChannelInit);
+ mojo_channel_init_->Init(
+ PlatformFileFromScopedPlatformHandle(channel_pair.PassServerHandle()),
+ BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO));
+ if (!mojo_channel_init_->is_handle_valid())
+ return;
+ base::PlatformFile client_file =
+ PlatformFileFromScopedPlatformHandle(channel_pair.PassClientHandle());
+ host_->Send(new MojoMsg_ChannelCreated(
+ IPC::GetFileHandleForProcess(client_file, process_handle,
+ true)));
+ ScopedRenderProcessMojoHandle render_process_handle(
+ RenderProcessMojoHandle(
+ mojo_channel_init_->bootstrap_message_pipe().release().value()));
+ render_process_mojo_.reset(render_process_handle.Pass(), this);
+}
+
+} // namespace content
« no previous file with comments | « content/browser/renderer_host/render_process_host_mojo_impl.h ('k') | content/browser/renderer_host/render_view_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698