| 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/base_switches.h" | 10 #include "base/base_switches.h" |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/process_util.h" | 17 #include "base/process_util.h" |
| 18 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/stringprintf.h" | 19 #include "base/stringprintf.h" |
| 20 #include "base/strings/string_number_conversions.h" | 20 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_split.h" | 21 #include "base/strings/string_split.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/win/windows_version.h" | 23 #include "base/win/windows_version.h" |
| 24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
| 25 #include "chrome/browser/extensions/extension_info_map.h" | 25 #include "chrome/browser/extensions/extension_info_map.h" |
| 26 #include "chrome/browser/nacl_host/nacl_browser.h" | 26 #include "chrome/browser/nacl_host/nacl_browser.h" |
| 27 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 27 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" |
| 28 #include "chrome/browser/nacl_host/nacl_host_messages.h" |
| 28 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory
.h" | 29 #include "chrome/browser/renderer_host/pepper/chrome_browser_pepper_host_factory
.h" |
| 29 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
| 30 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
| 31 #include "chrome/common/chrome_process_type.h" | 32 #include "chrome/common/chrome_process_type.h" |
| 32 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
| 33 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
| 34 #include "chrome/common/logging_chrome.h" | 35 #include "chrome/common/logging_chrome.h" |
| 35 #include "chrome/common/nacl_cmd_line.h" | 36 #include "chrome/common/nacl_cmd_line.h" |
| 36 #include "chrome/common/nacl_messages.h" | 37 #include "chrome/common/nacl_messages.h" |
| 37 #include "chrome/common/render_messages.h" | 38 #include "chrome/common/render_messages.h" |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 if (internal_->socket_for_sel_ldr != NACL_INVALID_HANDLE) { | 241 if (internal_->socket_for_sel_ldr != NACL_INVALID_HANDLE) { |
| 241 if (NaClClose(internal_->socket_for_sel_ldr) != 0) { | 242 if (NaClClose(internal_->socket_for_sel_ldr) != 0) { |
| 242 NOTREACHED() << "NaClClose() failed"; | 243 NOTREACHED() << "NaClClose() failed"; |
| 243 } | 244 } |
| 244 } | 245 } |
| 245 | 246 |
| 246 if (reply_msg_) { | 247 if (reply_msg_) { |
| 247 // The process failed to launch for some reason. | 248 // The process failed to launch for some reason. |
| 248 // Don't keep the renderer hanging. | 249 // Don't keep the renderer hanging. |
| 249 reply_msg_->set_reply_error(); | 250 reply_msg_->set_reply_error(); |
| 250 chrome_render_message_filter_->Send(reply_msg_); | 251 nacl_host_message_filter_->Send(reply_msg_); |
| 251 } | 252 } |
| 252 #if defined(OS_WIN) | 253 #if defined(OS_WIN) |
| 253 if (process_launched_by_broker_) { | 254 if (process_launched_by_broker_) { |
| 254 NaClBrokerService::GetInstance()->OnLoaderDied(); | 255 NaClBrokerService::GetInstance()->OnLoaderDied(); |
| 255 } | 256 } |
| 256 #endif | 257 #endif |
| 257 } | 258 } |
| 258 | 259 |
| 259 // This is called at browser startup. | 260 // This is called at browser startup. |
| 260 // static | 261 // static |
| (...skipping 11 matching lines...) Expand all Loading... |
| 272 "NaCl.nacl-gdb-script", | 273 "NaCl.nacl-gdb-script", |
| 273 !cmd->GetSwitchValuePath(switches::kNaClGdbScript).empty()); | 274 !cmd->GetSwitchValuePath(switches::kNaClGdbScript).empty()); |
| 274 UMA_HISTOGRAM_BOOLEAN( | 275 UMA_HISTOGRAM_BOOLEAN( |
| 275 "NaCl.enable-nacl-debug", | 276 "NaCl.enable-nacl-debug", |
| 276 cmd->HasSwitch(switches::kEnableNaClDebug)); | 277 cmd->HasSwitch(switches::kEnableNaClDebug)); |
| 277 NaClBrowser::GetInstance()->SetDebugPatterns( | 278 NaClBrowser::GetInstance()->SetDebugPatterns( |
| 278 cmd->GetSwitchValueASCII(switches::kNaClDebugMask)); | 279 cmd->GetSwitchValueASCII(switches::kNaClDebugMask)); |
| 279 } | 280 } |
| 280 | 281 |
| 281 void NaClProcessHost::Launch( | 282 void NaClProcessHost::Launch( |
| 282 ChromeRenderMessageFilter* chrome_render_message_filter, | 283 NaClHostMessageFilter* nacl_host_message_filter, |
| 283 IPC::Message* reply_msg, | 284 IPC::Message* reply_msg, |
| 284 scoped_refptr<ExtensionInfoMap> extension_info_map) { | 285 scoped_refptr<ExtensionInfoMap> extension_info_map) { |
| 285 chrome_render_message_filter_ = chrome_render_message_filter; | 286 nacl_host_message_filter_ = nacl_host_message_filter; |
| 286 reply_msg_ = reply_msg; | 287 reply_msg_ = reply_msg; |
| 287 extension_info_map_ = extension_info_map; | 288 extension_info_map_ = extension_info_map; |
| 288 | 289 |
| 289 // Start getting the IRT open asynchronously while we launch the NaCl process. | 290 // Start getting the IRT open asynchronously while we launch the NaCl process. |
| 290 // We'll make sure this actually finished in StartWithLaunchedProcess, below. | 291 // We'll make sure this actually finished in StartWithLaunchedProcess, below. |
| 291 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); | 292 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); |
| 292 nacl_browser->EnsureAllResourcesAvailable(); | 293 nacl_browser->EnsureAllResourcesAvailable(); |
| 293 if (!nacl_browser->IsOk()) { | 294 if (!nacl_browser->IsOk()) { |
| 294 LOG(ERROR) << "NaCl process launch failed: could not find all the " | 295 LOG(ERROR) << "NaCl process launch failed: could not find all the " |
| 295 "resources needed to launch the process"; | 296 "resources needed to launch the process"; |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 651 | 652 |
| 652 bool NaClProcessHost::ReplyToRenderer( | 653 bool NaClProcessHost::ReplyToRenderer( |
| 653 const IPC::ChannelHandle& channel_handle) { | 654 const IPC::ChannelHandle& channel_handle) { |
| 654 nacl::FileDescriptor handle_for_renderer; | 655 nacl::FileDescriptor handle_for_renderer; |
| 655 #if defined(OS_WIN) | 656 #if defined(OS_WIN) |
| 656 // Copy the handle into the renderer process. | 657 // Copy the handle into the renderer process. |
| 657 HANDLE handle_in_renderer; | 658 HANDLE handle_in_renderer; |
| 658 if (!DuplicateHandle(base::GetCurrentProcessHandle(), | 659 if (!DuplicateHandle(base::GetCurrentProcessHandle(), |
| 659 reinterpret_cast<HANDLE>( | 660 reinterpret_cast<HANDLE>( |
| 660 internal_->socket_for_renderer), | 661 internal_->socket_for_renderer), |
| 661 chrome_render_message_filter_->peer_handle(), | 662 nacl_host_message_filter_->peer_handle(), |
| 662 &handle_in_renderer, | 663 &handle_in_renderer, |
| 663 0, // Unused given DUPLICATE_SAME_ACCESS. | 664 0, // Unused given DUPLICATE_SAME_ACCESS. |
| 664 FALSE, | 665 FALSE, |
| 665 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | 666 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
| 666 LOG(ERROR) << "DuplicateHandle() failed"; | 667 LOG(ERROR) << "DuplicateHandle() failed"; |
| 667 return false; | 668 return false; |
| 668 } | 669 } |
| 669 handle_for_renderer = reinterpret_cast<nacl::FileDescriptor>( | 670 handle_for_renderer = reinterpret_cast<nacl::FileDescriptor>( |
| 670 handle_in_renderer); | 671 handle_in_renderer); |
| 671 #else | 672 #else |
| (...skipping 13 matching lines...) Expand all Loading... |
| 685 // BrokerDuplicateHandle(). | 686 // BrokerDuplicateHandle(). |
| 686 if (RunningOnWOW64()) { | 687 if (RunningOnWOW64()) { |
| 687 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { | 688 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { |
| 688 LOG(ERROR) << "Failed to add NaCl process PID"; | 689 LOG(ERROR) << "Failed to add NaCl process PID"; |
| 689 return false; | 690 return false; |
| 690 } | 691 } |
| 691 } | 692 } |
| 692 #endif | 693 #endif |
| 693 | 694 |
| 694 const ChildProcessData& data = process_->GetData(); | 695 const ChildProcessData& data = process_->GetData(); |
| 695 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( | 696 NaClHostMsg_LaunchNaCl::WriteReplyParams( |
| 696 reply_msg_, handle_for_renderer, | 697 reply_msg_, handle_for_renderer, |
| 697 channel_handle, base::GetProcId(data.handle), data.id); | 698 channel_handle, base::GetProcId(data.handle), data.id); |
| 698 chrome_render_message_filter_->Send(reply_msg_); | 699 nacl_host_message_filter_->Send(reply_msg_); |
| 699 chrome_render_message_filter_ = NULL; | 700 nacl_host_message_filter_ = NULL; |
| 700 reply_msg_ = NULL; | 701 reply_msg_ = NULL; |
| 701 internal_->socket_for_renderer = NACL_INVALID_HANDLE; | 702 internal_->socket_for_renderer = NACL_INVALID_HANDLE; |
| 702 return true; | 703 return true; |
| 703 } | 704 } |
| 704 | 705 |
| 705 // TCP port we chose for NaCl debug stub. It can be any other number. | 706 // TCP port we chose for NaCl debug stub. It can be any other number. |
| 706 static const int kDebugStubPort = 4014; | 707 static const int kDebugStubPort = 4014; |
| 707 | 708 |
| 708 #if defined(OS_POSIX) | 709 #if defined(OS_POSIX) |
| 709 SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() { | 710 SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 828 IPC::Channel::MODE_CLIENT, | 829 IPC::Channel::MODE_CLIENT, |
| 829 &ipc_plugin_listener_, | 830 &ipc_plugin_listener_, |
| 830 base::MessageLoopProxy::current())); | 831 base::MessageLoopProxy::current())); |
| 831 // Create the browser ppapi host and enable PPAPI message dispatching to the | 832 // Create the browser ppapi host and enable PPAPI message dispatching to the |
| 832 // browser process. | 833 // browser process. |
| 833 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( | 834 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( |
| 834 ipc_proxy_channel_.get(), // sender | 835 ipc_proxy_channel_.get(), // sender |
| 835 permissions_, | 836 permissions_, |
| 836 process_->GetData().handle, | 837 process_->GetData().handle, |
| 837 ipc_proxy_channel_.get(), | 838 ipc_proxy_channel_.get(), |
| 838 chrome_render_message_filter_->GetHostResolver(), | 839 nacl_host_message_filter_->GetHostResolver(), |
| 839 chrome_render_message_filter_->render_process_id(), | 840 nacl_host_message_filter_->render_process_id(), |
| 840 render_view_id_, | 841 render_view_id_, |
| 841 profile_directory_)); | 842 profile_directory_)); |
| 842 | 843 |
| 843 ppapi::PpapiNaClChannelArgs args; | 844 ppapi::PpapiNaClChannelArgs args; |
| 844 args.off_the_record = chrome_render_message_filter_->off_the_record(); | 845 args.off_the_record = nacl_host_message_filter_->off_the_record(); |
| 845 args.permissions = permissions_; | 846 args.permissions = permissions_; |
| 846 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 847 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
| 847 DCHECK(cmdline); | 848 DCHECK(cmdline); |
| 848 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; | 849 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; |
| 849 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { | 850 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { |
| 850 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); | 851 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); |
| 851 if (!value.empty()) { | 852 if (!value.empty()) { |
| 852 args.switch_names.push_back(flag_whitelist[i]); | 853 args.switch_names.push_back(flag_whitelist[i]); |
| 853 args.switch_values.push_back(value); | 854 args.switch_values.push_back(value); |
| 854 } | 855 } |
| 855 } | 856 } |
| 856 | 857 |
| 857 ppapi_host_->GetPpapiHost()->AddHostFactoryFilter( | 858 ppapi_host_->GetPpapiHost()->AddHostFactoryFilter( |
| 858 scoped_ptr<ppapi::host::HostFactory>( | 859 scoped_ptr<ppapi::host::HostFactory>( |
| 859 new chrome::ChromeBrowserPepperHostFactory(ppapi_host_.get()))); | 860 new chrome::ChromeBrowserPepperHostFactory(ppapi_host_.get()))); |
| 860 | 861 |
| 861 // Send a message to create the NaCl-Renderer channel. The handle is just | 862 // Send a message to create the NaCl-Renderer channel. The handle is just |
| 862 // a place holder. | 863 // a place holder. |
| 863 ipc_proxy_channel_->Send( | 864 ipc_proxy_channel_->Send( |
| 864 new PpapiMsg_CreateNaClChannel( | 865 new PpapiMsg_CreateNaClChannel( |
| 865 chrome_render_message_filter_->render_process_id(), | 866 nacl_host_message_filter_->render_process_id(), |
| 866 args, | 867 args, |
| 867 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, | 868 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, |
| 868 IPC::InvalidPlatformFileForTransit()))); | 869 IPC::InvalidPlatformFileForTransit()))); |
| 869 } else if (reply_msg_) { | 870 } else if (reply_msg_) { |
| 870 // Otherwise, this must be a renderer channel. | 871 // Otherwise, this must be a renderer channel. |
| 871 ReplyToRenderer(channel_handle); | 872 ReplyToRenderer(channel_handle); |
| 872 } else { | 873 } else { |
| 873 // Attempt to open more than 1 renderer channel is not supported. | 874 // Attempt to open more than 1 renderer channel is not supported. |
| 874 // Shut down the NaCl process. | 875 // Shut down the NaCl process. |
| 875 process_->GetHost()->ForceShutdown(); | 876 process_->GetHost()->ForceShutdown(); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 } else { | 1069 } else { |
| 1069 NaClStartDebugExceptionHandlerThread( | 1070 NaClStartDebugExceptionHandlerThread( |
| 1070 process_handle.Take(), info, | 1071 process_handle.Take(), info, |
| 1071 base::MessageLoopProxy::current(), | 1072 base::MessageLoopProxy::current(), |
| 1072 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 1073 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
| 1073 weak_factory_.GetWeakPtr())); | 1074 weak_factory_.GetWeakPtr())); |
| 1074 return true; | 1075 return true; |
| 1075 } | 1076 } |
| 1076 } | 1077 } |
| 1077 #endif | 1078 #endif |
| OLD | NEW |