Index: chrome/browser/nacl_host/nacl_process_host.cc |
=================================================================== |
--- chrome/browser/nacl_host/nacl_process_host.cc (revision 137169) |
+++ chrome/browser/nacl_host/nacl_process_host.cc (working copy) |
@@ -110,6 +110,7 @@ |
struct NaClProcessHost::NaClInternal { |
std::vector<nacl::Handle> sockets_for_renderer; |
std::vector<nacl::Handle> sockets_for_sel_ldr; |
+ std::vector<nacl::FileDescriptor> handles_for_renderer; |
}; |
// ----------------------------------------------------------------------------- |
@@ -522,6 +523,8 @@ |
IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, |
OnAttachDebugExceptionHandler) |
#endif |
+ IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated, |
+ OnPpapiChannelCreated) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
return handled; |
@@ -547,8 +550,7 @@ |
} |
} |
-bool NaClProcessHost::ReplyToRenderer() { |
- std::vector<nacl::FileDescriptor> handles_for_renderer; |
+bool NaClProcessHost::SendStart() { |
for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) { |
#if defined(OS_WIN) |
// Copy the handle into the renderer process. |
@@ -564,7 +566,7 @@ |
DLOG(ERROR) << "DuplicateHandle() failed"; |
return false; |
} |
- handles_for_renderer.push_back( |
+ internal_->handles_for_renderer.push_back( |
reinterpret_cast<nacl::FileDescriptor>(handle_in_renderer)); |
#else |
// No need to dup the imc_handle - we don't pass it anywhere else so |
@@ -572,10 +574,11 @@ |
nacl::FileDescriptor imc_handle; |
imc_handle.fd = internal_->sockets_for_renderer[i]; |
imc_handle.auto_close = true; |
- handles_for_renderer.push_back(imc_handle); |
+ internal_->handles_for_renderer.push_back(imc_handle); |
#endif |
} |
+ const ChildProcessData& data = process_->GetData(); |
#if defined(OS_WIN) |
// If we are on 64-bit Windows, the NaCl process's sandbox is |
// managed by a different process from the renderer's sandbox. We |
@@ -583,23 +586,13 @@ |
// that the renderer can send handles to the NaCl process using |
// BrokerDuplicateHandle(). |
if (RunningOnWOW64()) { |
- if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { |
+ if (!content::BrokerAddTargetPeer(data.handle)) { |
DLOG(ERROR) << "Failed to add NaCl process PID"; |
return false; |
} |
} |
#endif |
- ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( |
- reply_msg_, handles_for_renderer); |
- chrome_render_message_filter_->Send(reply_msg_); |
- chrome_render_message_filter_ = NULL; |
- reply_msg_ = NULL; |
- internal_->sockets_for_renderer.clear(); |
- return true; |
-} |
- |
-bool NaClProcessHost::StartNaClExecution() { |
NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
nacl::NaClStartParams params; |
@@ -611,7 +604,6 @@ |
base::PlatformFile irt_file = nacl_browser->IrtFile(); |
CHECK_NE(irt_file, base::kInvalidPlatformFileValue); |
- const ChildProcessData& data = process_->GetData(); |
for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) { |
if (!ShareHandleToSelLdr(data.handle, |
internal_->sockets_for_sel_ldr[i], true, |
@@ -647,14 +639,36 @@ |
params.handles.push_back(memory_fd); |
#endif |
+ // The start message should only be sent once we are sure we won't delete |
+ // ourselves. |
process_->Send(new NaClProcessMsg_Start(params)); |
internal_->sockets_for_sel_ldr.clear(); |
+ |
+ // If we aren't creating the IPC channel, send the reply message without |
+ // waiting for the NaCl process to signal that it's ready. |
+ if (!CommandLine::ForCurrentProcess()->HasSwitch( |
+ switches::kEnableNaClIPCProxy)) { |
+ OnPpapiChannelCreated(IPC::ChannelHandle()); |
+ } |
+ |
return true; |
} |
-bool NaClProcessHost::SendStart() { |
- return ReplyToRenderer() && StartNaClExecution(); |
+void NaClProcessHost::OnPpapiChannelCreated( |
+ const IPC::ChannelHandle& channel_handle) { |
+ // Now that the server end of the channel has been created, send the reply to |
+ // the renderer. |
+ base::ProcessId nacl_process_id = base::GetProcId(process_->GetData().handle); |
+ ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( |
+ reply_msg_, internal_->handles_for_renderer, channel_handle, |
+ nacl_process_id); |
+ chrome_render_message_filter_->Send(reply_msg_); |
+ chrome_render_message_filter_ = NULL; |
+ reply_msg_ = NULL; |
+ |
+ internal_->sockets_for_renderer.clear(); |
+ internal_->handles_for_renderer.clear(); |
} |
bool NaClProcessHost::StartWithLaunchedProcess() { |