| OLD | NEW |
| 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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 565 OnQueryKnownToValidate) | 565 OnQueryKnownToValidate) |
| 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 OnPpapiChannelCreated) | 575 OnPpapiBrowserChannelCreated) |
| 576 IPC_MESSAGE_UNHANDLED(handled = false) | 576 IPC_MESSAGE_UNHANDLED(handled = false) |
| 577 IPC_END_MESSAGE_MAP() | 577 IPC_END_MESSAGE_MAP() |
| 578 return handled; | 578 return handled; |
| 579 } | 579 } |
| 580 | 580 |
| 581 void NaClProcessHost::OnProcessLaunched() { | 581 void NaClProcessHost::OnProcessLaunched() { |
| 582 if (!StartWithLaunchedProcess()) | 582 if (!StartWithLaunchedProcess()) |
| 583 delete this; | 583 delete this; |
| 584 } | 584 } |
| 585 | 585 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 | 769 |
| 770 bool NaClProcessHost::SendStart() { | 770 bool NaClProcessHost::SendStart() { |
| 771 if (!enable_ppapi_proxy()) { | 771 if (!enable_ppapi_proxy()) { |
| 772 if (!ReplyToRenderer(IPC::ChannelHandle())) | 772 if (!ReplyToRenderer(IPC::ChannelHandle())) |
| 773 return false; | 773 return false; |
| 774 } | 774 } |
| 775 return StartNaClExecution(); | 775 return StartNaClExecution(); |
| 776 } | 776 } |
| 777 | 777 |
| 778 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is | 778 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is |
| 779 // received or PpapiHostMsg_ChannelCreated is forwarded by our plugin | 779 // received. |
| 780 // listener. | 780 void NaClProcessHost::OnPpapiBrowserChannelCreated( |
| 781 void NaClProcessHost::OnPpapiChannelCreated( | |
| 782 const IPC::ChannelHandle& channel_handle) { | 781 const IPC::ChannelHandle& channel_handle) { |
| 783 // Only renderer processes should create a channel. | 782 // Only renderer processes should create a channel. |
| 784 DCHECK(enable_ppapi_proxy()); | 783 DCHECK(enable_ppapi_proxy()); |
| 785 // If the proxy channel is null, this must be the initial NaCl-Browser IPC | |
| 786 // channel. | |
| 787 if (!ipc_proxy_channel_.get()) { | 784 if (!ipc_proxy_channel_.get()) { |
| 788 DCHECK_EQ(PROCESS_TYPE_NACL_LOADER, process_->GetData().process_type); | 785 DCHECK_EQ(PROCESS_TYPE_NACL_LOADER, process_->GetData().process_type); |
| 789 | 786 |
| 790 ipc_proxy_channel_.reset( | 787 ipc_proxy_channel_.reset( |
| 791 new IPC::ChannelProxy(channel_handle, | 788 new IPC::ChannelProxy(channel_handle, |
| 792 IPC::Channel::MODE_CLIENT, | 789 IPC::Channel::MODE_CLIENT, |
| 793 &ipc_plugin_listener_, | 790 &ipc_plugin_listener_, |
| 794 base::MessageLoopProxy::current().get())); | 791 base::MessageLoopProxy::current().get())); |
| 795 // Create the browser ppapi host and enable PPAPI message dispatching to the | 792 // Create the browser ppapi host and enable PPAPI message dispatching to the |
| 796 // browser process. | 793 // browser process. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 825 ppapi_host_.get()))); | 822 ppapi_host_.get()))); |
| 826 | 823 |
| 827 // Send a message to create the NaCl-Renderer channel. The handle is just | 824 // Send a message to create the NaCl-Renderer channel. The handle is just |
| 828 // a place holder. | 825 // a place holder. |
| 829 ipc_proxy_channel_->Send( | 826 ipc_proxy_channel_->Send( |
| 830 new PpapiMsg_CreateNaClChannel( | 827 new PpapiMsg_CreateNaClChannel( |
| 831 nacl_host_message_filter_->render_process_id(), | 828 nacl_host_message_filter_->render_process_id(), |
| 832 args, | 829 args, |
| 833 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, | 830 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, |
| 834 IPC::InvalidPlatformFileForTransit()))); | 831 IPC::InvalidPlatformFileForTransit()))); |
| 835 } else if (reply_msg_) { | |
| 836 // Otherwise, this must be a renderer channel. | |
| 837 ReplyToRenderer(channel_handle); | |
| 838 } else { | 832 } else { |
| 839 // Attempt to open more than 1 renderer channel is not supported. | 833 // Attempt to open more than 1 browser channel is not supported. |
| 840 // Shut down the NaCl process. | 834 // Shut down the NaCl process. |
| 841 process_->GetHost()->ForceShutdown(); | 835 process_->GetHost()->ForceShutdown(); |
| 842 } | 836 } |
| 837 } |
| 838 |
| 839 void NaClProcessHost::OnPpapiRendererChannelCreated( |
| 840 const IPC::ChannelHandle& channel_handle) { |
| 841 if (reply_msg_) { |
| 842 ReplyToRenderer(channel_handle); |
| 843 } else { |
| 844 // Attempt to open more than 1 NaCl renderer channel is not supported. |
| 845 // Shut down the NaCl process. |
| 846 process_->GetHost()->ForceShutdown(); |
| 847 } |
| 843 } | 848 } |
| 844 | 849 |
| 845 bool NaClProcessHost::OnUntrustedMessageForwarded(const IPC::Message& msg) { | 850 bool NaClProcessHost::OnUntrustedMessageForwarded(const IPC::Message& msg) { |
| 846 // Handle messages that have been forwarded from our PluginListener. | 851 // Handle messages that have been forwarded from our PluginListener. |
| 847 // These messages come from untrusted code so should be handled with care. | 852 // These messages come from untrusted code so should be handled with care. |
| 848 bool handled = true; | 853 bool handled = true; |
| 849 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) | 854 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) |
| 850 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, | 855 IPC_MESSAGE_HANDLER(PpapiHostMsg_NaClChannelCreated, |
| 851 OnPpapiChannelCreated) | 856 OnPpapiRendererChannelCreated) |
| 852 IPC_MESSAGE_UNHANDLED(handled = false) | 857 IPC_MESSAGE_UNHANDLED(handled = false) |
| 853 IPC_END_MESSAGE_MAP() | 858 IPC_END_MESSAGE_MAP() |
| 854 return handled; | 859 return handled; |
| 855 } | 860 } |
| 856 | 861 |
| 857 bool NaClProcessHost::StartWithLaunchedProcess() { | 862 bool NaClProcessHost::StartWithLaunchedProcess() { |
| 858 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | 863 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
| 859 | 864 |
| 860 if (nacl_browser->IsReady()) { | 865 if (nacl_browser->IsReady()) { |
| 861 return SendStart(); | 866 return SendStart(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 process_handle.Take(), info, | 1026 process_handle.Take(), info, |
| 1022 base::MessageLoopProxy::current(), | 1027 base::MessageLoopProxy::current(), |
| 1023 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1028 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 1024 weak_factory_.GetWeakPtr())); | 1029 weak_factory_.GetWeakPtr())); |
| 1025 return true; | 1030 return true; |
| 1026 } | 1031 } |
| 1027 } | 1032 } |
| 1028 #endif | 1033 #endif |
| 1029 | 1034 |
| 1030 } // namespace nacl | 1035 } // namespace nacl |
| OLD | NEW |