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.h" | 15 #include "base/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_util.h" | 18 #include "base/process_util.h" |
19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
22 #include "base/strings/stringprintf.h" | 22 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/win/windows_version.h" | 24 #include "base/win/windows_version.h" |
25 #include "build/build_config.h" | 25 #include "build/build_config.h" |
26 #include "chrome/browser/extensions/extension_info_map.h" | 26 #include "chrome/browser/extensions/extension_info_map.h" |
27 #include "chrome/browser/nacl_host/nacl_browser.h" | 27 #include "chrome/browser/nacl_host/nacl_browser.h" |
28 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" | 28 #include "chrome/browser/nacl_host/nacl_host_message_filter.h" |
29 #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" |
30 #include "chrome/common/chrome_constants.h" | 30 #include "chrome/common/chrome_constants.h" |
31 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/chrome_process_type.h" | 32 #include "chrome/common/chrome_process_type.h" |
33 #include "chrome/common/chrome_switches.h" | 33 #include "chrome/common/chrome_switches.h" |
34 #include "chrome/common/chrome_version_info.h" | 34 #include "chrome/common/chrome_version_info.h" |
35 #include "chrome/common/logging_chrome.h" | 35 #include "chrome/common/logging_chrome.h" |
36 #include "chrome/common/nacl_cmd_line.h" | 36 #include "chrome/common/nacl_cmd_line.h" |
| 37 #include "chrome/common/nacl_host_messages.h" |
37 #include "chrome/common/nacl_messages.h" | 38 #include "chrome/common/nacl_messages.h" |
38 #include "chrome/common/render_messages.h" | 39 #include "chrome/common/render_messages.h" |
39 #include "content/public/browser/browser_child_process_host.h" | 40 #include "content/public/browser/browser_child_process_host.h" |
40 #include "content/public/browser/browser_ppapi_host.h" | 41 #include "content/public/browser/browser_ppapi_host.h" |
41 #include "content/public/browser/child_process_data.h" | 42 #include "content/public/browser/child_process_data.h" |
42 #include "content/public/common/child_process_host.h" | 43 #include "content/public/common/child_process_host.h" |
43 #include "content/public/common/process_type.h" | 44 #include "content/public/common/process_type.h" |
44 #include "extensions/common/constants.h" | 45 #include "extensions/common/constants.h" |
45 #include "ipc/ipc_channel.h" | 46 #include "ipc/ipc_channel.h" |
46 #include "ipc/ipc_switches.h" | 47 #include "ipc/ipc_switches.h" |
(...skipping 193 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 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
524 | 525 |
525 bool NaClProcessHost::ReplyToRenderer( | 526 bool NaClProcessHost::ReplyToRenderer( |
526 const IPC::ChannelHandle& channel_handle) { | 527 const IPC::ChannelHandle& channel_handle) { |
527 nacl::FileDescriptor handle_for_renderer; | 528 nacl::FileDescriptor handle_for_renderer; |
528 #if defined(OS_WIN) | 529 #if defined(OS_WIN) |
529 // Copy the handle into the renderer process. | 530 // Copy the handle into the renderer process. |
530 HANDLE handle_in_renderer; | 531 HANDLE handle_in_renderer; |
531 if (!DuplicateHandle(base::GetCurrentProcessHandle(), | 532 if (!DuplicateHandle(base::GetCurrentProcessHandle(), |
532 reinterpret_cast<HANDLE>( | 533 reinterpret_cast<HANDLE>( |
533 internal_->socket_for_renderer), | 534 internal_->socket_for_renderer), |
534 chrome_render_message_filter_->peer_handle(), | 535 nacl_host_message_filter_->peer_handle(), |
535 &handle_in_renderer, | 536 &handle_in_renderer, |
536 0, // Unused given DUPLICATE_SAME_ACCESS. | 537 0, // Unused given DUPLICATE_SAME_ACCESS. |
537 FALSE, | 538 FALSE, |
538 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { | 539 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { |
539 LOG(ERROR) << "DuplicateHandle() failed"; | 540 LOG(ERROR) << "DuplicateHandle() failed"; |
540 return false; | 541 return false; |
541 } | 542 } |
542 handle_for_renderer = reinterpret_cast<nacl::FileDescriptor>( | 543 handle_for_renderer = reinterpret_cast<nacl::FileDescriptor>( |
543 handle_in_renderer); | 544 handle_in_renderer); |
544 #else | 545 #else |
(...skipping 13 matching lines...) Expand all Loading... |
558 // BrokerDuplicateHandle(). | 559 // BrokerDuplicateHandle(). |
559 if (RunningOnWOW64()) { | 560 if (RunningOnWOW64()) { |
560 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { | 561 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { |
561 LOG(ERROR) << "Failed to add NaCl process PID"; | 562 LOG(ERROR) << "Failed to add NaCl process PID"; |
562 return false; | 563 return false; |
563 } | 564 } |
564 } | 565 } |
565 #endif | 566 #endif |
566 | 567 |
567 const ChildProcessData& data = process_->GetData(); | 568 const ChildProcessData& data = process_->GetData(); |
568 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( | 569 NaClHostMsg_LaunchNaCl::WriteReplyParams( |
569 reply_msg_, handle_for_renderer, | 570 reply_msg_, handle_for_renderer, |
570 channel_handle, base::GetProcId(data.handle), data.id); | 571 channel_handle, base::GetProcId(data.handle), data.id); |
571 chrome_render_message_filter_->Send(reply_msg_); | 572 nacl_host_message_filter_->Send(reply_msg_); |
572 chrome_render_message_filter_ = NULL; | 573 nacl_host_message_filter_ = NULL; |
573 reply_msg_ = NULL; | 574 reply_msg_ = NULL; |
574 internal_->socket_for_renderer = NACL_INVALID_HANDLE; | 575 internal_->socket_for_renderer = NACL_INVALID_HANDLE; |
575 return true; | 576 return true; |
576 } | 577 } |
577 | 578 |
578 // TCP port we chose for NaCl debug stub. It can be any other number. | 579 // TCP port we chose for NaCl debug stub. It can be any other number. |
579 static const int kDebugStubPort = 4014; | 580 static const int kDebugStubPort = 4014; |
580 | 581 |
581 #if defined(OS_POSIX) | 582 #if defined(OS_POSIX) |
582 SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() { | 583 SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
701 IPC::Channel::MODE_CLIENT, | 702 IPC::Channel::MODE_CLIENT, |
702 &ipc_plugin_listener_, | 703 &ipc_plugin_listener_, |
703 base::MessageLoopProxy::current().get())); | 704 base::MessageLoopProxy::current().get())); |
704 // Create the browser ppapi host and enable PPAPI message dispatching to the | 705 // Create the browser ppapi host and enable PPAPI message dispatching to the |
705 // browser process. | 706 // browser process. |
706 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( | 707 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( |
707 ipc_proxy_channel_.get(), // sender | 708 ipc_proxy_channel_.get(), // sender |
708 permissions_, | 709 permissions_, |
709 process_->GetData().handle, | 710 process_->GetData().handle, |
710 ipc_proxy_channel_.get(), | 711 ipc_proxy_channel_.get(), |
711 chrome_render_message_filter_->GetHostResolver(), | 712 nacl_host_message_filter_->GetHostResolver(), |
712 chrome_render_message_filter_->render_process_id(), | 713 nacl_host_message_filter_->render_process_id(), |
713 render_view_id_, | 714 render_view_id_, |
714 profile_directory_)); | 715 profile_directory_)); |
715 | 716 |
716 ppapi::PpapiNaClChannelArgs args; | 717 ppapi::PpapiNaClChannelArgs args; |
717 args.off_the_record = chrome_render_message_filter_->off_the_record(); | 718 args.off_the_record = nacl_host_message_filter_->off_the_record(); |
718 args.permissions = permissions_; | 719 args.permissions = permissions_; |
719 CommandLine* cmdline = CommandLine::ForCurrentProcess(); | 720 CommandLine* cmdline = CommandLine::ForCurrentProcess(); |
720 DCHECK(cmdline); | 721 DCHECK(cmdline); |
721 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; | 722 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; |
722 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { | 723 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { |
723 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); | 724 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); |
724 if (!value.empty()) { | 725 if (!value.empty()) { |
725 args.switch_names.push_back(flag_whitelist[i]); | 726 args.switch_names.push_back(flag_whitelist[i]); |
726 args.switch_values.push_back(value); | 727 args.switch_values.push_back(value); |
727 } | 728 } |
728 } | 729 } |
729 | 730 |
730 ppapi_host_->GetPpapiHost()->AddHostFactoryFilter( | 731 ppapi_host_->GetPpapiHost()->AddHostFactoryFilter( |
731 scoped_ptr<ppapi::host::HostFactory>( | 732 scoped_ptr<ppapi::host::HostFactory>( |
732 new chrome::ChromeBrowserPepperHostFactory(ppapi_host_.get()))); | 733 new chrome::ChromeBrowserPepperHostFactory(ppapi_host_.get()))); |
733 | 734 |
734 // Send a message to create the NaCl-Renderer channel. The handle is just | 735 // Send a message to create the NaCl-Renderer channel. The handle is just |
735 // a place holder. | 736 // a place holder. |
736 ipc_proxy_channel_->Send( | 737 ipc_proxy_channel_->Send( |
737 new PpapiMsg_CreateNaClChannel( | 738 new PpapiMsg_CreateNaClChannel( |
738 chrome_render_message_filter_->render_process_id(), | 739 nacl_host_message_filter_->render_process_id(), |
739 args, | 740 args, |
740 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, | 741 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, |
741 IPC::InvalidPlatformFileForTransit()))); | 742 IPC::InvalidPlatformFileForTransit()))); |
742 } else if (reply_msg_) { | 743 } else if (reply_msg_) { |
743 // Otherwise, this must be a renderer channel. | 744 // Otherwise, this must be a renderer channel. |
744 ReplyToRenderer(channel_handle); | 745 ReplyToRenderer(channel_handle); |
745 } else { | 746 } else { |
746 // Attempt to open more than 1 renderer channel is not supported. | 747 // Attempt to open more than 1 renderer channel is not supported. |
747 // Shut down the NaCl process. | 748 // Shut down the NaCl process. |
748 process_->GetHost()->ForceShutdown(); | 749 process_->GetHost()->ForceShutdown(); |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
929 } else { | 930 } else { |
930 NaClStartDebugExceptionHandlerThread( | 931 NaClStartDebugExceptionHandlerThread( |
931 process_handle.Take(), info, | 932 process_handle.Take(), info, |
932 base::MessageLoopProxy::current(), | 933 base::MessageLoopProxy::current(), |
933 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, | 934 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, |
934 weak_factory_.GetWeakPtr())); | 935 weak_factory_.GetWeakPtr())); |
935 return true; | 936 return true; |
936 } | 937 } |
937 } | 938 } |
938 #endif | 939 #endif |
OLD | NEW |