| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/base_switches.h" | 11 #include "base/base_switches.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/file_util.h" | 14 #include "base/file_util.h" |
| 15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/process/launch.h" | 18 #include "base/process/launch.h" |
| 19 #include "base/process/process_iterator.h" | 19 #include "base/process/process_iterator.h" |
| 20 #include "base/rand_util.h" | 20 #include "base/rand_util.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
| 23 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
| 24 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 25 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "base/win/windows_version.h" | 26 #include "base/win/windows_version.h" |
| 27 #include "build/build_config.h" | 27 #include "build/build_config.h" |
| 28 #include "chrome/browser/extensions/extension_service.h" |
| 29 #include "chrome/browser/extensions/extension_system.h" |
| 28 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" | 30 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" |
| 31 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
| 30 #include "components/nacl/browser/nacl_browser.h" | 33 #include "components/nacl/browser/nacl_browser.h" |
| 31 #include "components/nacl/common/nacl_cmd_line.h" | 34 #include "components/nacl/common/nacl_cmd_line.h" |
| 32 #include "components/nacl/common/nacl_host_messages.h" | 35 #include "components/nacl/common/nacl_host_messages.h" |
| 33 #include "components/nacl/common/nacl_messages.h" | 36 #include "components/nacl/common/nacl_messages.h" |
| 34 #include "components/nacl/common/nacl_process_type.h" | 37 #include "components/nacl/common/nacl_process_type.h" |
| 35 #include "components/nacl/common/nacl_switches.h" | 38 #include "components/nacl/common/nacl_switches.h" |
| 36 #include "content/public/browser/browser_child_process_host.h" | 39 #include "content/public/browser/browser_child_process_host.h" |
| 37 #include "content/public/browser/browser_ppapi_host.h" | 40 #include "content/public/browser/browser_ppapi_host.h" |
| 38 #include "content/public/browser/child_process_data.h" | 41 #include "content/public/browser/child_process_data.h" |
| 42 #include "content/public/browser/render_view_host.h" |
| 43 #include "content/public/browser/site_instance.h" |
| 39 #include "content/public/common/child_process_host.h" | 44 #include "content/public/common/child_process_host.h" |
| 40 #include "content/public/common/content_switches.h" | 45 #include "content/public/common/content_switches.h" |
| 41 #include "content/public/common/process_type.h" | 46 #include "content/public/common/process_type.h" |
| 42 #include "ipc/ipc_channel.h" | 47 #include "ipc/ipc_channel.h" |
| 43 #include "ipc/ipc_switches.h" | 48 #include "ipc/ipc_switches.h" |
| 44 #include "native_client/src/shared/imc/nacl_imc_c.h" | 49 #include "native_client/src/shared/imc/nacl_imc_c.h" |
| 45 #include "net/base/net_util.h" | 50 #include "net/base/net_util.h" |
| 46 #include "net/socket/tcp_listen_socket.h" | 51 #include "net/socket/tcp_listen_socket.h" |
| 47 #include "ppapi/host/host_factory.h" | 52 #include "ppapi/host/host_factory.h" |
| 48 #include "ppapi/host/ppapi_host.h" | 53 #include "ppapi/host/ppapi_host.h" |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 } | 767 } |
| 763 | 768 |
| 764 bool NaClProcessHost::SendStart() { | 769 bool NaClProcessHost::SendStart() { |
| 765 if (!enable_ppapi_proxy()) { | 770 if (!enable_ppapi_proxy()) { |
| 766 if (!ReplyToRenderer(IPC::ChannelHandle())) | 771 if (!ReplyToRenderer(IPC::ChannelHandle())) |
| 767 return false; | 772 return false; |
| 768 } | 773 } |
| 769 return StartNaClExecution(); | 774 return StartNaClExecution(); |
| 770 } | 775 } |
| 771 | 776 |
| 777 class BrowserPpapiHostDelegate : public content::BrowserPpapiHost::Delegate { |
| 778 virtual void OnIdleState(bool idle, |
| 779 const base::FilePath& profile_data_directory, |
| 780 const content::RenderViewHost* render_view_host, |
| 781 const GURL& document_url) OVERRIDE { |
| 782 DCHECK(render_view_host); |
| 783 if (!render_view_host) |
| 784 return; |
| 785 |
| 786 content::SiteInstance* site_instance = render_view_host->GetSiteInstance(); |
| 787 DCHECK(site_instance); |
| 788 if (!site_instance) |
| 789 return; |
| 790 |
| 791 extensions::ExtensionSystem* extension_system = |
| 792 extensions::ExtensionSystem::GetForBrowserContext( |
| 793 site_instance->GetBrowserContext()); |
| 794 DCHECK(extension_system); |
| 795 if (!extension_system) |
| 796 return; |
| 797 |
| 798 const ExtensionService* extension_service = |
| 799 extension_system->extension_service(); |
| 800 DCHECK(extension_service); |
| 801 if (!extension_service) |
| 802 return; |
| 803 |
| 804 const extensions::Extension* extension = |
| 805 extension_service->GetExtensionById(document_url.host(), false); |
| 806 DCHECK(extension); |
| 807 if (!extension) |
| 808 return; |
| 809 |
| 810 ExtensionProcessManager* pm = extension_system->process_manager(); |
| 811 DCHECK(pm); |
| 812 if (!pm) |
| 813 return; |
| 814 |
| 815 if (idle) { |
| 816 fprintf(stderr, "%s:%s:%d DecrementLazyKeepaliveCount\n", |
| 817 __FILE__, __FUNCTION__, __LINE__); |
| 818 pm->DecrementLazyKeepaliveCount(extension); |
| 819 } else { |
| 820 fprintf(stderr, "%s:%s:%d IncrementLazyKeepaliveCount\n", |
| 821 __FILE__, __FUNCTION__, __LINE__); |
| 822 pm->IncrementLazyKeepaliveCount(extension); |
| 823 } |
| 824 } |
| 825 }; |
| 826 |
| 772 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is | 827 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is |
| 773 // received or PpapiHostMsg_ChannelCreated is forwarded by our plugin | 828 // received or PpapiHostMsg_ChannelCreated is forwarded by our plugin |
| 774 // listener. | 829 // listener. |
| 775 void NaClProcessHost::OnPpapiChannelCreated( | 830 void NaClProcessHost::OnPpapiChannelCreated( |
| 776 const IPC::ChannelHandle& channel_handle) { | 831 const IPC::ChannelHandle& channel_handle) { |
| 777 // Only renderer processes should create a channel. | 832 // Only renderer processes should create a channel. |
| 778 DCHECK(enable_ppapi_proxy()); | 833 DCHECK(enable_ppapi_proxy()); |
| 779 // If the proxy channel is null, this must be the initial NaCl-Browser IPC | 834 // If the proxy channel is null, this must be the initial NaCl-Browser IPC |
| 780 // channel. | 835 // channel. |
| 781 if (!ipc_proxy_channel_.get()) { | 836 if (!ipc_proxy_channel_.get()) { |
| 782 DCHECK_EQ(PROCESS_TYPE_NACL_LOADER, process_->GetData().process_type); | 837 DCHECK_EQ(PROCESS_TYPE_NACL_LOADER, process_->GetData().process_type); |
| 783 | 838 |
| 784 ipc_proxy_channel_.reset( | 839 ipc_proxy_channel_.reset( |
| 785 new IPC::ChannelProxy(channel_handle, | 840 new IPC::ChannelProxy(channel_handle, |
| 786 IPC::Channel::MODE_CLIENT, | 841 IPC::Channel::MODE_CLIENT, |
| 787 &ipc_plugin_listener_, | 842 &ipc_plugin_listener_, |
| 788 base::MessageLoopProxy::current().get())); | 843 base::MessageLoopProxy::current().get())); |
| 789 // Create the browser ppapi host and enable PPAPI message dispatching to the | 844 // Create the browser ppapi host and enable PPAPI message dispatching to the |
| 790 // browser process. | 845 // browser process. |
| 791 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( | 846 ppapi_host_ = content::BrowserPpapiHost::CreateExternalPluginProcess( |
| 847 new BrowserPpapiHostDelegate(), |
| 792 ipc_proxy_channel_.get(), // sender | 848 ipc_proxy_channel_.get(), // sender |
| 793 permissions_, | 849 permissions_, |
| 794 process_->GetData().handle, | 850 process_->GetData().handle, |
| 795 ipc_proxy_channel_.get(), | 851 ipc_proxy_channel_.get(), |
| 796 nacl_host_message_filter_->render_process_id(), | 852 nacl_host_message_filter_->render_process_id(), |
| 797 render_view_id_, | 853 render_view_id_, |
| 798 profile_directory_)); | 854 profile_directory_); |
| 799 | 855 |
| 800 ppapi::PpapiNaClChannelArgs args; | 856 ppapi::PpapiNaClChannelArgs args; |
| 801 args.off_the_record = nacl_host_message_filter_->off_the_record(); | 857 args.off_the_record = nacl_host_message_filter_->off_the_record(); |
| 802 args.permissions = permissions_; | 858 args.permissions = permissions_; |
| 803 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 859 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 804 DCHECK(cmdline); | 860 DCHECK(cmdline); |
| 805 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; | 861 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; |
| 806 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { | 862 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { |
| 807 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); | 863 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); |
| 808 if (!value.empty()) { | 864 if (!value.empty()) { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1014 } else { | 1070 } else { |
| 1015 NaClStartDebugExceptionHandlerThread( | 1071 NaClStartDebugExceptionHandlerThread( |
| 1016 process_handle.Take(), info, | 1072 process_handle.Take(), info, |
| 1017 base::MessageLoopProxy::current(), | 1073 base::MessageLoopProxy::current(), |
| 1018 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1074 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 1019 weak_factory_.GetWeakPtr())); | 1075 weak_factory_.GetWeakPtr())); |
| 1020 return true; | 1076 return true; |
| 1021 } | 1077 } |
| 1022 } | 1078 } |
| 1023 #endif | 1079 #endif |
| OLD | NEW |