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

Unified Diff: content/renderer/render_thread_impl.cc

Issue 285333003: Support exposing Mojo services between render frames, render threads, and their respective hosts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 6 years, 6 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/renderer/render_thread_impl.cc
diff --git a/content/renderer/render_thread_impl.cc b/content/renderer/render_thread_impl.cc
index e66bd926caa120ba4bdba4ce5d523db9f365493e..ba379174c084dea27eee5631149a842f882d6e29 100644
--- a/content/renderer/render_thread_impl.cc
+++ b/content/renderer/render_thread_impl.cc
@@ -51,7 +51,7 @@
#include "content/common/gpu/client/gpu_memory_buffer_impl.h"
#include "content/common/gpu/gpu_messages.h"
#include "content/common/gpu/gpu_process_launch_causes.h"
-#include "content/common/mojo/mojo_service_names.h"
+#include "content/common/render_frame_setup.mojom.h"
#include "content/common/resource_messages.h"
#include "content/common/view_messages.h"
#include "content/common/worker_messages.h"
@@ -92,7 +92,6 @@
#include "content/renderer/service_worker/embedded_worker_context_message_filter.h"
#include "content/renderer/service_worker/embedded_worker_dispatcher.h"
#include "content/renderer/shared_worker/embedded_shared_worker_stub.h"
-#include "content/renderer/web_ui_setup_impl.h"
#include "grit/content_resources.h"
#include "ipc/ipc_channel_handle.h"
#include "ipc/ipc_forwarding_message_filter.h"
@@ -265,6 +264,28 @@ void NotifyTimezoneChangeOnThisThread() {
v8::Date::DateTimeConfigurationChangeNotification(isolate);
}
+class RenderFrameSetupImpl : public mojo::InterfaceImpl<RenderFrameSetup> {
+ public:
+ virtual void GetServiceProvider(
+ int32_t frame_routing_id,
+ mojo::InterfaceRequest<mojo::IInterfaceProvider> request) OVERRIDE {
+ RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_routing_id);
+ if (!frame) {
darin (slow to review) 2014/06/21 04:33:35 Under what conditions is there no frame yet for th
Sam McNally 2014/06/24 04:00:29 There's a race between the IPC that causes the Ren
+ RenderThreadImpl::current()->RegisterPendingRenderFrameConnect(
+ frame_routing_id, request.PassMessagePipe());
+ return;
+ }
+
+ frame->BindServiceRegistry(request.PassMessagePipe());
+ }
+
+ virtual void OnConnectionError() OVERRIDE { delete this; }
+};
+
+void CreateRenderFrameSetup(mojo::InterfaceRequest<RenderFrameSetup> request) {
+ mojo::BindToRequest(new RenderFrameSetupImpl(), &request);
+}
+
} // namespace
RenderThreadImpl::HistogramCustomizer::HistogramCustomizer() {
@@ -507,10 +528,19 @@ void RenderThreadImpl::Init() {
}
}
+ service_registry()->AddService<RenderFrameSetup>(
+ base::Bind(CreateRenderFrameSetup));
+
TRACE_EVENT_END_ETW("RenderThreadImpl::Init", 0, "");
}
RenderThreadImpl::~RenderThreadImpl() {
+ for (std::map<int, mojo::MessagePipeHandle>::iterator it =
+ pending_render_frame_connects_.begin();
+ it != pending_render_frame_connects_.end();
+ ++it) {
+ mojo::ScopedMessagePipeHandle handle(it->second);
darin (slow to review) 2014/06/21 04:33:35 nit: again, CloseRaw() might be clearer.
Sam McNally 2014/06/24 04:00:29 Done.
+ }
}
void RenderThreadImpl::Shutdown() {
@@ -679,6 +709,18 @@ scoped_refptr<base::MessageLoopProxy>
void RenderThreadImpl::AddRoute(int32 routing_id, IPC::Listener* listener) {
ChildThread::GetRouter()->AddRoute(routing_id, listener);
+ std::map<int, mojo::MessagePipeHandle>::iterator it =
+ pending_render_frame_connects_.find(routing_id);
+ if (it == pending_render_frame_connects_.end())
+ return;
+
+ RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(routing_id);
+ if (!frame)
+ return;
+
+ mojo::ScopedMessagePipeHandle handle(it->second);
+ pending_render_frame_connects_.erase(it);
+ frame->BindServiceRegistry(handle.Pass());
}
void RenderThreadImpl::RemoveRoute(int32 routing_id) {
@@ -702,6 +744,15 @@ void RenderThreadImpl::RemoveEmbeddedWorkerRoute(int32 routing_id) {
}
}
+void RenderThreadImpl::RegisterPendingRenderFrameConnect(
+ int routing_id,
+ mojo::ScopedMessagePipeHandle handle) {
+ std::pair<std::map<int, mojo::MessagePipeHandle>::iterator, bool> result =
+ pending_render_frame_connects_.insert(
+ std::make_pair(routing_id, handle.release()));
+ CHECK(result.second) << "Inserting a duplicate item.";
+}
+
int RenderThreadImpl::GenerateRoutingID() {
int routing_id = MSG_ROUTING_NONE;
Send(new ViewHostMsg_GenerateRoutingID(&routing_id));
@@ -1094,6 +1145,10 @@ void RenderThreadImpl::ReleaseCachedFonts() {
#endif // OS_WIN
+ServiceRegistry* RenderThreadImpl::GetServiceRegistry() {
+ return service_registry();
+}
+
bool RenderThreadImpl::IsMainThread() {
return !!current();
}
@@ -1174,19 +1229,6 @@ scoped_ptr<gfx::GpuMemoryBuffer> RenderThreadImpl::AllocateGpuMemoryBuffer(
.PassAs<gfx::GpuMemoryBuffer>();
}
-void RenderThreadImpl::ConnectToService(
- const mojo::String& service_url,
- const mojo::String& service_name,
- mojo::ScopedMessagePipeHandle message_pipe,
- const mojo::String& requestor_url) {
- // TODO(darin): Invent some kind of registration system to use here.
- if (service_url.To<base::StringPiece>() == kRendererService_WebUISetup) {
- WebUISetupImpl::Bind(message_pipe.Pass());
- } else {
- NOTREACHED() << "Unknown service name";
- }
-}
-
void RenderThreadImpl::DoNotSuspendWebKitSharedTimer() {
suspend_webkit_shared_timer_ = false;
}

Powered by Google App Engine
This is Rietveld 408576698