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

Side by Side Diff: chrome/browser/nacl_host/nacl_process_host.cc

Issue 10214007: Add an IPC channel between the NaCl loader process and the renderer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/nacl_host/nacl_process_host.h ('k') | chrome/common/nacl_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/nacl_host/nacl_process_host.h" 5 #include "chrome/browser/nacl_host/nacl_process_host.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // for this use case. 138 // for this use case.
139 process_->SetName(net::FormatUrl(manifest_url_, std::string())); 139 process_->SetName(net::FormatUrl(manifest_url_, std::string()));
140 140
141 // We allow untrusted hardware exception handling to be enabled via 141 // We allow untrusted hardware exception handling to be enabled via
142 // an env var for consistency with the standalone build of NaCl. 142 // an env var for consistency with the standalone build of NaCl.
143 if (CommandLine::ForCurrentProcess()->HasSwitch( 143 if (CommandLine::ForCurrentProcess()->HasSwitch(
144 switches::kEnableNaClExceptionHandling) || 144 switches::kEnableNaClExceptionHandling) ||
145 getenv("NACL_UNTRUSTED_EXCEPTION_HANDLING") != NULL) { 145 getenv("NACL_UNTRUSTED_EXCEPTION_HANDLING") != NULL) {
146 enable_exception_handling_ = true; 146 enable_exception_handling_ = true;
147 } 147 }
148
149 enable_ipc_proxy_ = CommandLine::ForCurrentProcess()->HasSwitch(
150 switches::kEnableNaClIPCProxy);
148 } 151 }
149 152
150 NaClProcessHost::~NaClProcessHost() { 153 NaClProcessHost::~NaClProcessHost() {
151 int exit_code; 154 int exit_code;
152 process_->GetTerminationStatus(&exit_code); 155 process_->GetTerminationStatus(&exit_code);
153 std::string message = 156 std::string message =
154 base::StringPrintf("NaCl process exited with status %i (0x%x)", 157 base::StringPrintf("NaCl process exited with status %i (0x%x)",
155 exit_code, exit_code); 158 exit_code, exit_code);
156 if (exit_code == 0) { 159 if (exit_code == 0) {
157 LOG(INFO) << message; 160 LOG(INFO) << message;
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 bool handled = true; 533 bool handled = true;
531 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) 534 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg)
532 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate, 535 IPC_MESSAGE_HANDLER(NaClProcessMsg_QueryKnownToValidate,
533 OnQueryKnownToValidate) 536 OnQueryKnownToValidate)
534 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, 537 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate,
535 OnSetKnownToValidate) 538 OnSetKnownToValidate)
536 #if defined(OS_WIN) 539 #if defined(OS_WIN)
537 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, 540 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler,
538 OnAttachDebugExceptionHandler) 541 OnAttachDebugExceptionHandler)
539 #endif 542 #endif
543 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated,
544 OnPpapiChannelCreated)
540 IPC_MESSAGE_UNHANDLED(handled = false) 545 IPC_MESSAGE_UNHANDLED(handled = false)
541 IPC_END_MESSAGE_MAP() 546 IPC_END_MESSAGE_MAP()
542 return handled; 547 return handled;
543 } 548 }
544 549
545 void NaClProcessHost::OnProcessLaunched() { 550 void NaClProcessHost::OnProcessLaunched() {
546 if (!StartWithLaunchedProcess()) 551 if (!StartWithLaunchedProcess())
547 delete this; 552 delete this;
548 } 553 }
549 554
550 // Called when the NaClBrowser singleton has been fully initialized. 555 // Called when the NaClBrowser singleton has been fully initialized.
551 void NaClProcessHost::OnResourcesReady() { 556 void NaClProcessHost::OnResourcesReady() {
552 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); 557 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
553 if (!nacl_browser->IsReady() || !SendStart()) { 558 if (!nacl_browser->IsReady() || !SendStart()) {
554 DLOG(ERROR) << "Cannot launch NaCl process"; 559 DLOG(ERROR) << "Cannot launch NaCl process";
555 delete this; 560 delete this;
556 } 561 }
557 } 562 }
558 563
559 bool NaClProcessHost::ReplyToRenderer() { 564 bool NaClProcessHost::ReplyToRenderer(
565 const IPC::ChannelHandle& channel_handle) {
560 std::vector<nacl::FileDescriptor> handles_for_renderer; 566 std::vector<nacl::FileDescriptor> handles_for_renderer;
561 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) { 567 for (size_t i = 0; i < internal_->sockets_for_renderer.size(); i++) {
562 #if defined(OS_WIN) 568 #if defined(OS_WIN)
563 // Copy the handle into the renderer process. 569 // Copy the handle into the renderer process.
564 HANDLE handle_in_renderer; 570 HANDLE handle_in_renderer;
565 if (!DuplicateHandle(base::GetCurrentProcessHandle(), 571 if (!DuplicateHandle(base::GetCurrentProcessHandle(),
566 reinterpret_cast<HANDLE>( 572 reinterpret_cast<HANDLE>(
567 internal_->sockets_for_renderer[i]), 573 internal_->sockets_for_renderer[i]),
568 chrome_render_message_filter_->peer_handle(), 574 chrome_render_message_filter_->peer_handle(),
569 &handle_in_renderer, 575 &handle_in_renderer,
(...skipping 23 matching lines...) Expand all
593 // BrokerDuplicateHandle(). 599 // BrokerDuplicateHandle().
594 if (RunningOnWOW64()) { 600 if (RunningOnWOW64()) {
595 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { 601 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) {
596 DLOG(ERROR) << "Failed to add NaCl process PID"; 602 DLOG(ERROR) << "Failed to add NaCl process PID";
597 return false; 603 return false;
598 } 604 }
599 } 605 }
600 #endif 606 #endif
601 607
602 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( 608 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams(
603 reply_msg_, handles_for_renderer); 609 reply_msg_, handles_for_renderer, channel_handle);
604 chrome_render_message_filter_->Send(reply_msg_); 610 chrome_render_message_filter_->Send(reply_msg_);
605 chrome_render_message_filter_ = NULL; 611 chrome_render_message_filter_ = NULL;
606 reply_msg_ = NULL; 612 reply_msg_ = NULL;
607 internal_->sockets_for_renderer.clear(); 613 internal_->sockets_for_renderer.clear();
608 return true; 614 return true;
609 } 615 }
610 616
611 bool NaClProcessHost::StartNaClExecution() { 617 bool NaClProcessHost::StartNaClExecution() {
612 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); 618 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
613 619
614 nacl::NaClStartParams params; 620 nacl::NaClStartParams params;
615 params.validation_cache_enabled = nacl_browser->ValidationCacheIsEnabled(); 621 params.validation_cache_enabled = nacl_browser->ValidationCacheIsEnabled();
616 params.validation_cache_key = nacl_browser->GetValidationCacheKey(); 622 params.validation_cache_key = nacl_browser->GetValidationCacheKey();
617 params.version = chrome::VersionInfo().CreateVersionString(); 623 params.version = chrome::VersionInfo().CreateVersionString();
618 params.enable_exception_handling = enable_exception_handling_; 624 params.enable_exception_handling = enable_exception_handling_;
619 params.enable_debug_stub = 625 params.enable_debug_stub =
620 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaClDebug); 626 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableNaClDebug);
627 params.enable_ipc_proxy = enable_ipc_proxy_;
621 628
622 base::PlatformFile irt_file = nacl_browser->IrtFile(); 629 base::PlatformFile irt_file = nacl_browser->IrtFile();
623 CHECK_NE(irt_file, base::kInvalidPlatformFileValue); 630 CHECK_NE(irt_file, base::kInvalidPlatformFileValue);
624 631
625 const ChildProcessData& data = process_->GetData(); 632 const ChildProcessData& data = process_->GetData();
626 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) { 633 for (size_t i = 0; i < internal_->sockets_for_sel_ldr.size(); i++) {
627 if (!ShareHandleToSelLdr(data.handle, 634 if (!ShareHandleToSelLdr(data.handle,
628 internal_->sockets_for_sel_ldr[i], true, 635 internal_->sockets_for_sel_ldr[i], true,
629 &params.handles)) { 636 &params.handles)) {
630 return false; 637 return false;
(...skipping 27 matching lines...) Expand all
658 params.handles.push_back(memory_fd); 665 params.handles.push_back(memory_fd);
659 #endif 666 #endif
660 667
661 process_->Send(new NaClProcessMsg_Start(params)); 668 process_->Send(new NaClProcessMsg_Start(params));
662 669
663 internal_->sockets_for_sel_ldr.clear(); 670 internal_->sockets_for_sel_ldr.clear();
664 return true; 671 return true;
665 } 672 }
666 673
667 bool NaClProcessHost::SendStart() { 674 bool NaClProcessHost::SendStart() {
668 return ReplyToRenderer() && StartNaClExecution(); 675 if (!enable_ipc_proxy_) {
676 if (!ReplyToRenderer(IPC::ChannelHandle()))
677 return false;
678 }
679 return StartNaClExecution();
680 }
681
682 void NaClProcessHost::OnPpapiChannelCreated(
683 const IPC::ChannelHandle& channel_handle) {
684 DCHECK(enable_ipc_proxy_);
685 ReplyToRenderer(channel_handle);
669 } 686 }
670 687
671 bool NaClProcessHost::StartWithLaunchedProcess() { 688 bool NaClProcessHost::StartWithLaunchedProcess() {
672 #if defined(OS_LINUX) 689 #if defined(OS_LINUX)
673 if (wait_for_nacl_gdb_) { 690 if (wait_for_nacl_gdb_) {
674 if (LaunchNaClGdb(base::GetProcId(process_->GetData().handle))) { 691 if (LaunchNaClGdb(base::GetProcId(process_->GetData().handle))) {
675 // We will be called with wait_for_nacl_gdb_ = false once debugger is 692 // We will be called with wait_for_nacl_gdb_ = false once debugger is
676 // attached to the program. 693 // attached to the program.
677 return true; 694 return true;
678 } 695 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 } else { 782 } else {
766 NaClStartDebugExceptionHandlerThread( 783 NaClStartDebugExceptionHandlerThread(
767 process_handle.Take(), info, 784 process_handle.Take(), info,
768 base::MessageLoopProxy::current(), 785 base::MessageLoopProxy::current(),
769 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 786 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
770 weak_factory_.GetWeakPtr())); 787 weak_factory_.GetWeakPtr()));
771 return true; 788 return true;
772 } 789 }
773 } 790 }
774 #endif 791 #endif
OLDNEW
« no previous file with comments | « chrome/browser/nacl_host/nacl_process_host.h ('k') | chrome/common/nacl_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698