Index: content/browser/renderer_host/render_process_host_impl.cc |
diff --git a/content/browser/renderer_host/render_process_host_impl.cc b/content/browser/renderer_host/render_process_host_impl.cc |
index 7b5f9ff57367f8073f1ad0d206db307da2d413b8..1befcec16fedbdf51df06ead6c915b0717935fa2 100644 |
--- a/content/browser/renderer_host/render_process_host_impl.cc |
+++ b/content/browser/renderer_host/render_process_host_impl.cc |
@@ -126,6 +126,8 @@ |
#include "content/common/frame_messages.h" |
#include "content/common/gpu_host_messages.h" |
#include "content/common/in_process_child_thread_params.h" |
+#include "content/common/mojo/channel_init.h" |
+#include "content/common/mojo/mojo_messages.h" |
#include "content/common/mojo/mojo_shell_connection_impl.h" |
#include "content/common/render_process_messages.h" |
#include "content/common/resource_messages.h" |
@@ -730,6 +732,9 @@ |
content::BrowserThread::IO)); |
#endif |
+ // Setup the Mojo channel. |
+ mojo_application_host_->Init(); |
+ |
// Call the embedder first so that their IPC filters have priority. |
GetContentClient()->browser()->RenderProcessWillLaunch(this); |
@@ -749,7 +754,7 @@ |
channel_id, |
BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO) |
->task_runner(), |
- mojo_channel_token_, mojo_application_host_->GetToken()))); |
+ in_process_renderer_handle_.release()))); |
base::Thread::Options options; |
#if defined(OS_WIN) && !defined(OS_MACOSX) |
@@ -808,9 +813,16 @@ |
BrowserThread::GetMessageLoopProxyForThread(BrowserThread::IO); |
if (ShouldUseMojoChannel()) { |
VLOG(1) << "Mojo Channel is enabled on host"; |
- mojo_channel_token_ = mojo::edk::GenerateRandomToken(); |
- mojo::ScopedMessagePipeHandle handle = |
- mojo::edk::CreateParentMessagePipe(mojo_channel_token_); |
+ mojo::ScopedMessagePipeHandle handle; |
+ |
+ if (run_renderer_in_process()) { |
+ mojo::MessagePipe pipe; |
+ handle = std::move(pipe.handle0); |
+ in_process_renderer_handle_ = std::move(pipe.handle1); |
+ } else { |
+ mojo_channel_token_ = mojo::edk::GenerateRandomToken(); |
+ handle = mojo::edk::CreateParentMessagePipe(mojo_channel_token_); |
+ } |
// Do NOT expand ifdef or run time condition checks here! Synchronous |
// IPCs from browser process are banned. It is only narrowly allowed |
@@ -1369,8 +1381,6 @@ |
command_line->AppendSwitchASCII(switches::kMojoChannelToken, |
mojo_channel_token_); |
} |
- command_line->AppendSwitchASCII(switches::kMojoApplicationChannelToken, |
- mojo_application_host_->GetToken()); |
} |
void RenderProcessHostImpl::PropagateBrowserCommandLineToRenderer( |
@@ -2608,6 +2618,11 @@ |
Source<RenderProcessHost>(this), |
NotificationService::NoDetails()); |
+ // Allow Mojo to be setup before the renderer sees any Chrome IPC messages. |
+ // This way, Mojo can be safely used from the renderer in response to any |
+ // Chrome IPC message. |
+ mojo_application_host_->Activate(this, GetHandle()); |
+ |
while (!queued_messages_.empty()) { |
Send(queued_messages_.front()); |
queued_messages_.pop(); |