Index: content/browser/render_process_connection_listener.cc |
diff --git a/content/browser/render_process_connection_listener.cc b/content/browser/render_process_connection_listener.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6d0344329cdf9e6cc7a51bab26087585a7fde6b6 |
--- /dev/null |
+++ b/content/browser/render_process_connection_listener.cc |
@@ -0,0 +1,89 @@ |
+// 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 "content/browser/render_process_connection_listener.h" |
+ |
+#include "base/logging.h" |
+#include "base/macros.h" |
+#include "components/mus/public/interfaces/window_tree.mojom.h" |
+#include "content/browser/mojo/mojo_shell_client_host.h" |
+#include "content/browser/renderer_host/render_view_host_impl.h" |
+#include "content/browser/renderer_host/render_widget_host_impl.h" |
+#include "content/browser/renderer_host/render_widget_host_view_mus.h" |
+#include "content/common/render_process_client.mojom.h" |
+#include "content/public/common/mojo_shell_connection.h" |
+#include "mojo/application/public/cpp/application_connection.h" |
+#include "mojo/application/public/cpp/interface_factory.h" |
+#include "mojo/public/cpp/bindings/strong_binding.h" |
+#include "url/gurl.h" |
+ |
+namespace content { |
+ |
+namespace { |
+ |
+class RenderProcessConnection : public mojom::RenderProcessClient { |
+ public: |
+ RenderProcessConnection( |
+ int render_process_id, |
+ mojo::InterfaceRequest<mojom::RenderProcessClient> request) |
+ : render_process_id_(render_process_id), binding_(this, request.Pass()) {} |
+ |
+ ~RenderProcessConnection() override {} |
+ |
+ private: |
+ // mojom::RenderProcessClient implementation. |
+ void OnRenderWidgetViewCreated( |
+ uint32_t routing_id, |
+ mus::mojom::WindowTreeClientPtr tree_client) override { |
+ RenderViewHostImpl* rvh = |
+ RenderViewHostImpl::FromID(render_process_id_, routing_id); |
+ RenderWidgetHostViewMus* rwhvmus = rvh->GetWidget()->GetView()->AsMusView(); |
+ if (rwhvmus) |
+ rwhvmus->Embed(tree_client.Pass()); |
+ } |
+ |
+ const int render_process_id_; |
+ mojo::StrongBinding<RenderProcessClient> binding_; |
+ DISALLOW_COPY_AND_ASSIGN(RenderProcessConnection); |
+}; |
+ |
+class RenderProcessConnectionListener |
+ : public MojoShellConnection::Listener, |
+ public mojo::InterfaceFactory<mojom::RenderProcessClient> { |
+ public: |
+ static void Create() { new RenderProcessConnectionListener; } |
+ |
+ private: |
+ RenderProcessConnectionListener() { |
+ DCHECK(MojoShellConnection::Get()); |
+ MojoShellConnection::Get()->AddListener(this); |
+ } |
+ |
+ ~RenderProcessConnectionListener() override {} |
+ |
+ // MojoShellConnection::Listener implementation: |
+ bool ConfigureIncomingConnection( |
+ mojo::ApplicationConnection* connection) override { |
+ connection->AddService<mojom::RenderProcessClient>(this); |
+ return true; |
+ } |
+ |
+ // mojo::InterfaceFactory<mojom::RenderProcessClient>: |
+ void Create( |
+ mojo::ApplicationConnection* connection, |
+ mojo::InterfaceRequest<mojom::RenderProcessClient> request) override { |
+ int render_process_id = GetRenderProcessIDFromConnection(connection); |
+ new RenderProcessConnection(render_process_id, request.Pass()); |
+ } |
+ |
+ DISALLOW_COPY_AND_ASSIGN(RenderProcessConnectionListener); |
+}; |
+ |
+} // namespace |
+ |
+void CreateRenderProcessConnectionListener() { |
+ RenderProcessConnectionListener::Create(); |
+} |
+ |
+} // namespace content |