Chromium Code Reviews| 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 "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 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/common/chrome_paths.h" | 27 #include "chrome/common/chrome_paths.h" |
| 28 #include "chrome/common/chrome_switches.h" | 28 #include "chrome/common/chrome_switches.h" |
| 29 #include "chrome/common/chrome_version_info.h" | 29 #include "chrome/common/chrome_version_info.h" |
| 30 #include "chrome/common/logging_chrome.h" | 30 #include "chrome/common/logging_chrome.h" |
| 31 #include "chrome/common/nacl_cmd_line.h" | 31 #include "chrome/common/nacl_cmd_line.h" |
| 32 #include "chrome/common/nacl_messages.h" | 32 #include "chrome/common/nacl_messages.h" |
| 33 #include "chrome/common/render_messages.h" | 33 #include "chrome/common/render_messages.h" |
| 34 #include "chrome/common/url_constants.h" | 34 #include "chrome/common/url_constants.h" |
| 35 #include "content/public/browser/browser_child_process_host.h" | 35 #include "content/public/browser/browser_child_process_host.h" |
| 36 #include "content/public/browser/child_process_data.h" | 36 #include "content/public/browser/child_process_data.h" |
| 37 #include "content/public/browser/pepper_helper.h" | |
| 38 #include "content/public/browser/render_process_host.h" | |
| 39 #include "content/public/browser/resource_context.h" | |
| 37 #include "content/public/common/child_process_host.h" | 40 #include "content/public/common/child_process_host.h" |
| 38 #include "ipc/ipc_channel.h" | 41 #include "ipc/ipc_channel.h" |
| 39 #include "ipc/ipc_switches.h" | 42 #include "ipc/ipc_switches.h" |
| 40 #include "native_client/src/shared/imc/nacl_imc.h" | 43 #include "native_client/src/shared/imc/nacl_imc.h" |
| 41 #include "net/base/net_util.h" | 44 #include "net/base/net_util.h" |
| 42 #include "ppapi/proxy/ppapi_messages.h" | 45 #include "ppapi/proxy/ppapi_messages.h" |
| 43 | 46 |
| 44 #if defined(OS_POSIX) | 47 #if defined(OS_POSIX) |
| 45 #include <fcntl.h> | 48 #include <fcntl.h> |
| 46 | 49 |
| 47 #include "ipc/ipc_channel_posix.h" | 50 #include "ipc/ipc_channel_posix.h" |
| 48 #elif defined(OS_WIN) | 51 #elif defined(OS_WIN) |
| 49 #include <windows.h> | 52 #include <windows.h> |
| 50 | 53 |
| 51 #include "base/threading/thread.h" | 54 #include "base/threading/thread.h" |
| 52 #include "base/process_util.h" | 55 #include "base/process_util.h" |
| 53 #include "base/win/scoped_handle.h" | 56 #include "base/win/scoped_handle.h" |
| 54 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" | 57 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" |
| 55 #include "chrome/common/nacl_debug_exception_handler_win.h" | 58 #include "chrome/common/nacl_debug_exception_handler_win.h" |
| 56 #include "content/public/common/sandbox_init.h" | 59 #include "content/public/common/sandbox_init.h" |
| 57 #endif | 60 #endif |
| 58 | 61 |
| 59 using content::BrowserThread; | 62 using content::BrowserThread; |
| 60 using content::ChildProcessData; | 63 using content::ChildProcessData; |
| 61 using content::ChildProcessHost; | 64 using content::ChildProcessHost; |
| 65 using content::RenderProcessHost; | |
| 66 using content::ResourceContext; | |
| 62 using ppapi::proxy::SerializedHandle; | 67 using ppapi::proxy::SerializedHandle; |
| 63 | 68 |
| 64 namespace { | 69 namespace { |
| 65 | 70 |
| 66 #if defined(OS_WIN) | 71 #if defined(OS_WIN) |
| 67 bool RunningOnWOW64() { | 72 bool RunningOnWOW64() { |
| 68 return (base::win::OSInfo::GetInstance()->wow64_status() == | 73 return (base::win::OSInfo::GetInstance()->wow64_status() == |
| 69 base::win::OSInfo::WOW64_ENABLED); | 74 base::win::OSInfo::WOW64_ENABLED); |
| 70 } | 75 } |
| 71 #endif | 76 #endif |
| (...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 705 DCHECK(enable_ipc_proxy_); | 710 DCHECK(enable_ipc_proxy_); |
| 706 // If the proxy channel is null, this must be the initial NaCl-Browser IPC | 711 // If the proxy channel is null, this must be the initial NaCl-Browser IPC |
| 707 // channel. | 712 // channel. |
| 708 if (!ipc_proxy_channel_.get()) { | 713 if (!ipc_proxy_channel_.get()) { |
| 709 ipc_proxy_channel_.reset( | 714 ipc_proxy_channel_.reset( |
| 710 new IPC::ChannelProxy(channel_handle, | 715 new IPC::ChannelProxy(channel_handle, |
| 711 IPC::Channel::MODE_CLIENT, | 716 IPC::Channel::MODE_CLIENT, |
| 712 &ipc_plugin_listener_, | 717 &ipc_plugin_listener_, |
| 713 base::MessageLoopProxy::current())); | 718 base::MessageLoopProxy::current())); |
| 714 // Send a message to create the NaCl-Renderer channel. The handle is just | 719 // Send a message to create the NaCl-Renderer channel. The handle is just |
| 715 // a place holder. | 720 // a place holder, filled in by NaCl process trusted code. |
| 716 ipc_proxy_channel_->Send( | 721 ipc_proxy_channel_->Send( |
| 717 new PpapiMsg_CreateNaClChannel( | 722 new PpapiMsg_CreateNaClChannel( |
| 718 chrome_render_message_filter_->render_process_id(), | 723 chrome_render_message_filter_->render_process_id(), |
| 719 chrome_render_message_filter_->off_the_record(), | 724 chrome_render_message_filter_->off_the_record(), |
| 720 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, | 725 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, |
| 721 IPC::InvalidPlatformFileForTransit()))); | 726 IPC::InvalidPlatformFileForTransit()))); |
| 727 // We will need a ResourceContext to enable the channel so messages get | |
| 728 // dispatched to the browser. This must be accessed on the UI thread. | |
| 729 BrowserThread::PostTask( | |
| 730 BrowserThread::UI, | |
| 731 FROM_HERE, | |
| 732 base::Bind(&NaClProcessHost::EnablePpapiChannelOnUIThread, | |
| 733 base::Unretained(this), | |
|
brettw
2012/09/06 23:38:09
You're using unretained here and below. What ensur
bbudge
2012/09/08 01:17:27
Moving this to PMF. Done.
| |
| 734 chrome_render_message_filter_->render_process_id())); | |
| 722 } else if (reply_msg_) { | 735 } else if (reply_msg_) { |
| 723 // Otherwise, this must be a renderer channel. | 736 // Otherwise, this must be a renderer channel. |
| 724 ReplyToRenderer(channel_handle); | 737 ReplyToRenderer(channel_handle); |
| 725 } else { | 738 } else { |
| 726 // Attempt to open more than 1 renderer channel is not supported. | 739 // Attempt to open more than 1 renderer channel is not supported. |
| 727 // Shut down the NaCl process. | 740 // Shut down the NaCl process. |
| 728 process_->GetHost()->ForceShutdown(); | 741 process_->GetHost()->ForceShutdown(); |
| 729 } | 742 } |
| 730 } | 743 } |
| 731 | 744 |
| 745 void NaClProcessHost::EnablePpapiChannelOnUIThread( | |
| 746 int render_process_id) { | |
| 747 content::RenderProcessHost* rph = | |
| 748 content::RenderProcessHost::FromID(render_process_id); | |
| 749 if (rph) { | |
| 750 // ResourceContext::GetHostResolver must be called on the IO thread. | |
| 751 BrowserThread::PostTask( | |
| 752 BrowserThread::IO, | |
| 753 FROM_HERE, | |
| 754 base::Bind(&NaClProcessHost::EnablePpapiChannelOnIOThread, | |
| 755 base::Unretained(this), | |
| 756 rph->GetBrowserContext()->GetResourceContext())); | |
| 757 } | |
| 758 } | |
| 759 | |
| 760 void NaClProcessHost::EnablePpapiChannelOnIOThread( | |
| 761 ResourceContext* resource_context) { | |
| 762 DCHECK(resource_context); | |
| 763 content::PepperHelper::EnablePepperSupportForChannel( | |
| 764 ipc_proxy_channel_.get(), resource_context->GetHostResolver()); | |
| 765 } | |
| 766 | |
| 732 bool NaClProcessHost::OnUntrustedMessageForwarded(const IPC::Message& msg) { | 767 bool NaClProcessHost::OnUntrustedMessageForwarded(const IPC::Message& msg) { |
| 733 // Handle messages that have been forwarded from our PluginListener. | 768 // Handle messages that have been forwarded from our PluginListener. |
| 734 // These messages come from untrusted code so should be handled with care. | 769 // These messages come from untrusted code so should be handled with care. |
| 735 bool handled = true; | 770 bool handled = true; |
| 736 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) | 771 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg) |
| 737 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, | 772 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated, |
| 738 OnPpapiChannelCreated) | 773 OnPpapiChannelCreated) |
| 739 IPC_MESSAGE_UNHANDLED(handled = false) | 774 IPC_MESSAGE_UNHANDLED(handled = false) |
| 740 IPC_END_MESSAGE_MAP() | 775 IPC_END_MESSAGE_MAP() |
| 741 return handled; | 776 return handled; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 838 } else { | 873 } else { |
| 839 NaClStartDebugExceptionHandlerThread( | 874 NaClStartDebugExceptionHandlerThread( |
| 840 process_handle.Take(), info, | 875 process_handle.Take(), info, |
| 841 base::MessageLoopProxy::current(), | 876 base::MessageLoopProxy::current(), |
| 842 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 877 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 843 weak_factory_.GetWeakPtr())); | 878 weak_factory_.GetWeakPtr())); |
| 844 return true; | 879 return true; |
| 845 } | 880 } |
| 846 } | 881 } |
| 847 #endif | 882 #endif |
| OLD | NEW |