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

Side by Side Diff: components/nacl/browser/nacl_process_host.cc

Issue 131413009: Prototype: Use Chromium IPC for plugin LOAD_MODULE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased, some FIXMEs cleaned up Created 6 years, 10 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
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 "components/nacl/browser/nacl_process_host.h" 5 #include "components/nacl/browser/nacl_process_host.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate, 566 IPC_MESSAGE_HANDLER(NaClProcessMsg_SetKnownToValidate,
567 OnSetKnownToValidate) 567 OnSetKnownToValidate)
568 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_ResolveFileToken, 568 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_ResolveFileToken,
569 OnResolveFileToken) 569 OnResolveFileToken)
570 #if defined(OS_WIN) 570 #if defined(OS_WIN)
571 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler, 571 IPC_MESSAGE_HANDLER_DELAY_REPLY(NaClProcessMsg_AttachDebugExceptionHandler,
572 OnAttachDebugExceptionHandler) 572 OnAttachDebugExceptionHandler)
573 #endif 573 #endif
574 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated, 574 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_PpapiChannelCreated,
575 OnPpapiBrowserChannelCreated) 575 OnPpapiBrowserChannelCreated)
576 IPC_MESSAGE_HANDLER(NaClProcessHostMsg_TrustedPluginChannelCreated,
577 OnTrustedPluginChannelCreated)
576 IPC_MESSAGE_UNHANDLED(handled = false) 578 IPC_MESSAGE_UNHANDLED(handled = false)
577 IPC_END_MESSAGE_MAP() 579 IPC_END_MESSAGE_MAP()
578 return handled; 580 return handled;
579 } 581 }
580 582
581 void NaClProcessHost::OnProcessLaunched() { 583 void NaClProcessHost::OnProcessLaunched() {
582 if (!StartWithLaunchedProcess()) 584 if (!StartWithLaunchedProcess())
583 delete this; 585 delete this;
584 } 586 }
585 587
586 // Called when the NaClBrowser singleton has been fully initialized. 588 // Called when the NaClBrowser singleton has been fully initialized.
587 void NaClProcessHost::OnResourcesReady() { 589 void NaClProcessHost::OnResourcesReady() {
588 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); 590 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
589 if (!nacl_browser->IsReady()) { 591 if (!nacl_browser->IsReady()) {
590 SendErrorToRenderer("could not acquire shared resources needed by NaCl"); 592 SendErrorToRenderer("could not acquire shared resources needed by NaCl");
591 delete this; 593 delete this;
592 } else if (!SendStart()) { 594 } else if (!SendStart()) {
593 delete this; 595 delete this;
594 } 596 }
595 } 597 }
596 598
597 bool NaClProcessHost::ReplyToRenderer( 599 bool NaClProcessHost::ReplyToRenderer() {
598 const IPC::ChannelHandle& channel_handle) { 600 fprintf(stderr, "NaClProcessHost::ReplyToRenderer\n");
599 #if defined(OS_WIN) 601 #if defined(OS_WIN)
600 // If we are on 64-bit Windows, the NaCl process's sandbox is 602 // If we are on 64-bit Windows, the NaCl process's sandbox is
601 // managed by a different process from the renderer's sandbox. We 603 // managed by a different process from the renderer's sandbox. We
602 // need to inform the renderer's sandbox about the NaCl process so 604 // need to inform the renderer's sandbox about the NaCl process so
603 // that the renderer can send handles to the NaCl process using 605 // that the renderer can send handles to the NaCl process using
604 // BrokerDuplicateHandle(). 606 // BrokerDuplicateHandle().
605 if (RunningOnWOW64()) { 607 if (RunningOnWOW64()) {
606 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { 608 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) {
607 SendErrorToRenderer("BrokerAddTargetPeer() failed"); 609 SendErrorToRenderer("BrokerAddTargetPeer() failed");
608 return false; 610 return false;
(...skipping 21 matching lines...) Expand all
630 #else 632 #else
631 // No need to dup the imc_handle - we don't pass it anywhere else so 633 // No need to dup the imc_handle - we don't pass it anywhere else so
632 // it cannot be closed. 634 // it cannot be closed.
633 FileDescriptor imc_handle; 635 FileDescriptor imc_handle;
634 imc_handle.fd = internal_->socket_for_renderer; 636 imc_handle.fd = internal_->socket_for_renderer;
635 imc_handle.auto_close = true; 637 imc_handle.auto_close = true;
636 handle_for_renderer = imc_handle; 638 handle_for_renderer = imc_handle;
637 #endif 639 #endif
638 640
639 const ChildProcessData& data = process_->GetData(); 641 const ChildProcessData& data = process_->GetData();
642 fprintf(stderr, "about to send message to renderer, "
643 "trusted plugin channel handle name: %s\n",
644 nacl_renderer_channel_handle_.name.c_str());
640 SendMessageToRenderer( 645 SendMessageToRenderer(
641 NaClLaunchResult(handle_for_renderer, 646 NaClLaunchResult(handle_for_renderer,
642 channel_handle, 647 ppapi_renderer_channel_handle_,
643 base::GetProcId(data.handle), 648 nacl_renderer_channel_handle_,
644 data.id), 649 base::GetProcId(data.handle),
650 data.id),
645 std::string() /* error_message */); 651 std::string() /* error_message */);
646 internal_->socket_for_renderer = NACL_INVALID_HANDLE; 652 internal_->socket_for_renderer = NACL_INVALID_HANDLE;
647 return true; 653 return true;
648 } 654 }
649 655
650 void NaClProcessHost::SendErrorToRenderer(const std::string& error_message) { 656 void NaClProcessHost::SendErrorToRenderer(const std::string& error_message) {
651 LOG(ERROR) << "NaCl process launch failed: " << error_message; 657 LOG(ERROR) << "NaCl process launch failed: " << error_message;
652 SendMessageToRenderer(NaClLaunchResult(), error_message); 658 SendMessageToRenderer(NaClLaunchResult(), error_message);
653 } 659 }
654 660
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 #endif 777 #endif
772 778
773 process_->Send(new NaClProcessMsg_Start(params)); 779 process_->Send(new NaClProcessMsg_Start(params));
774 780
775 internal_->socket_for_sel_ldr = NACL_INVALID_HANDLE; 781 internal_->socket_for_sel_ldr = NACL_INVALID_HANDLE;
776 return true; 782 return true;
777 } 783 }
778 784
779 bool NaClProcessHost::SendStart() { 785 bool NaClProcessHost::SendStart() {
780 if (!enable_ppapi_proxy()) { 786 if (!enable_ppapi_proxy()) {
781 if (!ReplyToRenderer(IPC::ChannelHandle())) 787 if (!ReplyToRenderer())
782 return false; 788 return false;
783 } 789 }
784 return StartNaClExecution(); 790 return StartNaClExecution();
785 } 791 }
786 792
787 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is 793 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is
788 // received. 794 // received.
789 void NaClProcessHost::OnPpapiBrowserChannelCreated( 795 void NaClProcessHost::OnPpapiBrowserChannelCreated(
790 const IPC::ChannelHandle& channel_handle) { 796 const IPC::ChannelHandle& channel_handle) {
791 // Only renderer processes should create a channel. 797 // Only renderer processes should create a channel.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 args, 847 args,
842 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, 848 SerializedHandle(SerializedHandle::CHANNEL_HANDLE,
843 IPC::InvalidPlatformFileForTransit()))); 849 IPC::InvalidPlatformFileForTransit())));
844 } else { 850 } else {
845 // Attempt to open more than 1 browser channel is not supported. 851 // Attempt to open more than 1 browser channel is not supported.
846 // Shut down the NaCl process. 852 // Shut down the NaCl process.
847 process_->GetHost()->ForceShutdown(); 853 process_->GetHost()->ForceShutdown();
848 } 854 }
849 } 855 }
850 856
857 void NaClProcessHost::OnTrustedPluginChannelCreated(
858 const IPC::ChannelHandle& channel_handle) {
859 fprintf(stderr, "NaClProcessHost::OnTrustedPluginChannelCreated\n");
860 fprintf(stderr, "handle name: %s\n", channel_handle.name.c_str());
861 nacl_renderer_channel_handle_ = channel_handle;
862 if (!ppapi_renderer_channel_handle_.name.empty()) {
863 if (reply_msg_) {
864 ReplyToRenderer();
dmichael (off chromium) 2014/02/06 18:18:47 This looks iffy... you do ReplyToRenderer wheneve
teravest1 2014/02/06 18:21:15 I do wait until both channels have been created be
dmichael (off chromium) 2014/02/06 18:24:22 D'oh, okay, I see that now. Sorry. I should either
865 } else {
866 // Attempt to open more than 1 NaCl renderer channel is not supported.
dmichael (off chromium) 2014/02/06 18:18:47 nit: "Attempt to open"->"Opening"?
867 // Shut down the NaCl process.
868 process_->GetHost()->ForceShutdown();
869 }
870 }
871 }
872
851 void NaClProcessHost::OnPpapiRendererChannelCreated( 873 void NaClProcessHost::OnPpapiRendererChannelCreated(
852 const IPC::ChannelHandle& channel_handle) { 874 const IPC::ChannelHandle& channel_handle) {
853 if (reply_msg_) { 875 fprintf(stderr, "NaClProcessHost::OnPpapiRendererChannelCreated\n");
854 ReplyToRenderer(channel_handle); 876 ppapi_renderer_channel_handle_ = channel_handle;
855 } else { 877 if (!nacl_renderer_channel_handle_.name.empty()) {
856 // Attempt to open more than 1 NaCl renderer channel is not supported. 878 if (reply_msg_) {
857 // Shut down the NaCl process. 879 ReplyToRenderer();
858 process_->GetHost()->ForceShutdown(); 880 } else {
881 // Attempt to open more than 1 NaCl renderer channel is not supported.
882 // Shut down the NaCl process.
883 process_->GetHost()->ForceShutdown();
884 }
859 } 885 }
860 } 886 }
861 887
862 bool NaClProcessHost::OnUntrustedMessageForwarded(const IPC::Message& msg) { 888 bool NaClProcessHost::OnUntrustedMessageForwarded(const IPC::Message& msg) {
863 // Handle messages that have been forwarded from our PluginListener. 889 // Handle messages that have been forwarded from our PluginListener.
864 // These messages come from untrusted code so should be handled with care. 890 // These messages come from untrusted code so should be handled with care.
865 bool handled = true; 891 bool handled = true;
866 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) 892 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg)
867 IPC_MESSAGE_HANDLER(PpapiHostMsg_NaClChannelCreated, 893 IPC_MESSAGE_HANDLER(PpapiHostMsg_NaClChannelCreated,
868 OnPpapiRendererChannelCreated) 894 OnPpapiRendererChannelCreated)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 process_handle.Take(), info, 1064 process_handle.Take(), info,
1039 base::MessageLoopProxy::current(), 1065 base::MessageLoopProxy::current(),
1040 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 1066 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
1041 weak_factory_.GetWeakPtr())); 1067 weak_factory_.GetWeakPtr()));
1042 return true; 1068 return true;
1043 } 1069 }
1044 } 1070 }
1045 #endif 1071 #endif
1046 1072
1047 } // namespace nacl 1073 } // namespace nacl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698