Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(281)

Side by Side Diff: chrome/browser/nacl_host/nacl_process_host.cc

Issue 15906013: Separate NaCl messages from the rest of chrome messages and create a new message filter. This is pa… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 if (internal_->socket_for_sel_ldr != NACL_INVALID_HANDLE) { 240 if (internal_->socket_for_sel_ldr != NACL_INVALID_HANDLE) {
240 if (NaClClose(internal_->socket_for_sel_ldr) != 0) { 241 if (NaClClose(internal_->socket_for_sel_ldr) != 0) {
241 NOTREACHED() << "NaClClose() failed"; 242 NOTREACHED() << "NaClClose() failed";
242 } 243 }
243 } 244 }
244 245
245 if (reply_msg_) { 246 if (reply_msg_) {
246 // The process failed to launch for some reason. 247 // The process failed to launch for some reason.
247 // Don't keep the renderer hanging. 248 // Don't keep the renderer hanging.
248 reply_msg_->set_reply_error(); 249 reply_msg_->set_reply_error();
249 chrome_render_message_filter_->Send(reply_msg_); 250 nacl_host_message_filter_->Send(reply_msg_);
250 } 251 }
251 #if defined(OS_WIN) 252 #if defined(OS_WIN)
252 if (process_launched_by_broker_) { 253 if (process_launched_by_broker_) {
253 NaClBrokerService::GetInstance()->OnLoaderDied(); 254 NaClBrokerService::GetInstance()->OnLoaderDied();
254 } 255 }
255 #endif 256 #endif
256 } 257 }
257 258
258 // This is called at browser startup. 259 // This is called at browser startup.
259 // static 260 // static
(...skipping 11 matching lines...) Expand all
271 "NaCl.nacl-gdb-script", 272 "NaCl.nacl-gdb-script",
272 !cmd->GetSwitchValuePath(switches::kNaClGdbScript).empty()); 273 !cmd->GetSwitchValuePath(switches::kNaClGdbScript).empty());
273 UMA_HISTOGRAM_BOOLEAN( 274 UMA_HISTOGRAM_BOOLEAN(
274 "NaCl.enable-nacl-debug", 275 "NaCl.enable-nacl-debug",
275 cmd->HasSwitch(switches::kEnableNaClDebug)); 276 cmd->HasSwitch(switches::kEnableNaClDebug));
276 NaClBrowser::GetInstance()->SetDebugPatterns( 277 NaClBrowser::GetInstance()->SetDebugPatterns(
277 cmd->GetSwitchValueASCII(switches::kNaClDebugMask)); 278 cmd->GetSwitchValueASCII(switches::kNaClDebugMask));
278 } 279 }
279 280
280 void NaClProcessHost::Launch( 281 void NaClProcessHost::Launch(
281 ChromeRenderMessageFilter* chrome_render_message_filter, 282 NaClHostMessageFilter* nacl_host_message_filter,
282 IPC::Message* reply_msg, 283 IPC::Message* reply_msg,
283 scoped_refptr<ExtensionInfoMap> extension_info_map) { 284 scoped_refptr<ExtensionInfoMap> extension_info_map) {
284 chrome_render_message_filter_ = chrome_render_message_filter; 285 nacl_host_message_filter_ = nacl_host_message_filter;
285 reply_msg_ = reply_msg; 286 reply_msg_ = reply_msg;
286 extension_info_map_ = extension_info_map; 287 extension_info_map_ = extension_info_map;
287 288
288 // Start getting the IRT open asynchronously while we launch the NaCl process. 289 // Start getting the IRT open asynchronously while we launch the NaCl process.
289 // We'll make sure this actually finished in StartWithLaunchedProcess, below. 290 // We'll make sure this actually finished in StartWithLaunchedProcess, below.
290 NaClBrowser* nacl_browser = NaClBrowser::GetInstance(); 291 NaClBrowser* nacl_browser = NaClBrowser::GetInstance();
291 nacl_browser->EnsureAllResourcesAvailable(); 292 nacl_browser->EnsureAllResourcesAvailable();
292 if (!nacl_browser->IsOk()) { 293 if (!nacl_browser->IsOk()) {
293 LOG(ERROR) << "NaCl process launch failed: could not find all the " 294 LOG(ERROR) << "NaCl process launch failed: could not find all the "
294 "resources needed to launch the process"; 295 "resources needed to launch the process";
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 524
524 bool NaClProcessHost::ReplyToRenderer( 525 bool NaClProcessHost::ReplyToRenderer(
525 const IPC::ChannelHandle& channel_handle) { 526 const IPC::ChannelHandle& channel_handle) {
526 nacl::FileDescriptor handle_for_renderer; 527 nacl::FileDescriptor handle_for_renderer;
527 #if defined(OS_WIN) 528 #if defined(OS_WIN)
528 // Copy the handle into the renderer process. 529 // Copy the handle into the renderer process.
529 HANDLE handle_in_renderer; 530 HANDLE handle_in_renderer;
530 if (!DuplicateHandle(base::GetCurrentProcessHandle(), 531 if (!DuplicateHandle(base::GetCurrentProcessHandle(),
531 reinterpret_cast<HANDLE>( 532 reinterpret_cast<HANDLE>(
532 internal_->socket_for_renderer), 533 internal_->socket_for_renderer),
533 chrome_render_message_filter_->peer_handle(), 534 nacl_host_message_filter_->peer_handle(),
534 &handle_in_renderer, 535 &handle_in_renderer,
535 0, // Unused given DUPLICATE_SAME_ACCESS. 536 0, // Unused given DUPLICATE_SAME_ACCESS.
536 FALSE, 537 FALSE,
537 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) { 538 DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) {
538 LOG(ERROR) << "DuplicateHandle() failed"; 539 LOG(ERROR) << "DuplicateHandle() failed";
539 return false; 540 return false;
540 } 541 }
541 handle_for_renderer = reinterpret_cast<nacl::FileDescriptor>( 542 handle_for_renderer = reinterpret_cast<nacl::FileDescriptor>(
542 handle_in_renderer); 543 handle_in_renderer);
543 #else 544 #else
(...skipping 13 matching lines...) Expand all
557 // BrokerDuplicateHandle(). 558 // BrokerDuplicateHandle().
558 if (RunningOnWOW64()) { 559 if (RunningOnWOW64()) {
559 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) { 560 if (!content::BrokerAddTargetPeer(process_->GetData().handle)) {
560 LOG(ERROR) << "Failed to add NaCl process PID"; 561 LOG(ERROR) << "Failed to add NaCl process PID";
561 return false; 562 return false;
562 } 563 }
563 } 564 }
564 #endif 565 #endif
565 566
566 const ChildProcessData& data = process_->GetData(); 567 const ChildProcessData& data = process_->GetData();
567 ChromeViewHostMsg_LaunchNaCl::WriteReplyParams( 568 NaClHostMsg_LaunchNaCl::WriteReplyParams(
568 reply_msg_, handle_for_renderer, 569 reply_msg_, handle_for_renderer,
569 channel_handle, base::GetProcId(data.handle), data.id); 570 channel_handle, base::GetProcId(data.handle), data.id);
570 chrome_render_message_filter_->Send(reply_msg_); 571 nacl_host_message_filter_->Send(reply_msg_);
571 chrome_render_message_filter_ = NULL; 572 nacl_host_message_filter_ = NULL;
572 reply_msg_ = NULL; 573 reply_msg_ = NULL;
573 internal_->socket_for_renderer = NACL_INVALID_HANDLE; 574 internal_->socket_for_renderer = NACL_INVALID_HANDLE;
574 return true; 575 return true;
575 } 576 }
576 577
577 // TCP port we chose for NaCl debug stub. It can be any other number. 578 // TCP port we chose for NaCl debug stub. It can be any other number.
578 static const int kDebugStubPort = 4014; 579 static const int kDebugStubPort = 4014;
579 580
580 #if defined(OS_POSIX) 581 #if defined(OS_POSIX)
581 SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() { 582 SocketDescriptor NaClProcessHost::GetDebugStubSocketHandle() {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
700 IPC::Channel::MODE_CLIENT, 701 IPC::Channel::MODE_CLIENT,
701 &ipc_plugin_listener_, 702 &ipc_plugin_listener_,
702 base::MessageLoopProxy::current().get())); 703 base::MessageLoopProxy::current().get()));
703 // Create the browser ppapi host and enable PPAPI message dispatching to the 704 // Create the browser ppapi host and enable PPAPI message dispatching to the
704 // browser process. 705 // browser process.
705 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess( 706 ppapi_host_.reset(content::BrowserPpapiHost::CreateExternalPluginProcess(
706 ipc_proxy_channel_.get(), // sender 707 ipc_proxy_channel_.get(), // sender
707 permissions_, 708 permissions_,
708 process_->GetData().handle, 709 process_->GetData().handle,
709 ipc_proxy_channel_.get(), 710 ipc_proxy_channel_.get(),
710 chrome_render_message_filter_->GetHostResolver(), 711 nacl_host_message_filter_->GetHostResolver(),
711 chrome_render_message_filter_->render_process_id(), 712 nacl_host_message_filter_->render_process_id(),
712 render_view_id_, 713 render_view_id_,
713 profile_directory_)); 714 profile_directory_));
714 715
715 ppapi::PpapiNaClChannelArgs args; 716 ppapi::PpapiNaClChannelArgs args;
716 args.off_the_record = chrome_render_message_filter_->off_the_record(); 717 args.off_the_record = nacl_host_message_filter_->off_the_record();
717 args.permissions = permissions_; 718 args.permissions = permissions_;
718 CommandLine* cmdline = CommandLine::ForCurrentProcess(); 719 CommandLine* cmdline = CommandLine::ForCurrentProcess();
719 DCHECK(cmdline); 720 DCHECK(cmdline);
720 std::string flag_whitelist[] = {switches::kV, switches::kVModule}; 721 std::string flag_whitelist[] = {switches::kV, switches::kVModule};
721 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) { 722 for (size_t i = 0; i < arraysize(flag_whitelist); ++i) {
722 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]); 723 std::string value = cmdline->GetSwitchValueASCII(flag_whitelist[i]);
723 if (!value.empty()) { 724 if (!value.empty()) {
724 args.switch_names.push_back(flag_whitelist[i]); 725 args.switch_names.push_back(flag_whitelist[i]);
725 args.switch_values.push_back(value); 726 args.switch_values.push_back(value);
726 } 727 }
727 } 728 }
728 729
729 ppapi_host_->GetPpapiHost()->AddHostFactoryFilter( 730 ppapi_host_->GetPpapiHost()->AddHostFactoryFilter(
730 scoped_ptr<ppapi::host::HostFactory>( 731 scoped_ptr<ppapi::host::HostFactory>(
731 new chrome::ChromeBrowserPepperHostFactory(ppapi_host_.get()))); 732 new chrome::ChromeBrowserPepperHostFactory(ppapi_host_.get())));
732 733
733 // Send a message to create the NaCl-Renderer channel. The handle is just 734 // Send a message to create the NaCl-Renderer channel. The handle is just
734 // a place holder. 735 // a place holder.
735 ipc_proxy_channel_->Send( 736 ipc_proxy_channel_->Send(
736 new PpapiMsg_CreateNaClChannel( 737 new PpapiMsg_CreateNaClChannel(
737 chrome_render_message_filter_->render_process_id(), 738 nacl_host_message_filter_->render_process_id(),
738 args, 739 args,
739 SerializedHandle(SerializedHandle::CHANNEL_HANDLE, 740 SerializedHandle(SerializedHandle::CHANNEL_HANDLE,
740 IPC::InvalidPlatformFileForTransit()))); 741 IPC::InvalidPlatformFileForTransit())));
741 } else if (reply_msg_) { 742 } else if (reply_msg_) {
742 // Otherwise, this must be a renderer channel. 743 // Otherwise, this must be a renderer channel.
743 ReplyToRenderer(channel_handle); 744 ReplyToRenderer(channel_handle);
744 } else { 745 } else {
745 // Attempt to open more than 1 renderer channel is not supported. 746 // Attempt to open more than 1 renderer channel is not supported.
746 // Shut down the NaCl process. 747 // Shut down the NaCl process.
747 process_->GetHost()->ForceShutdown(); 748 process_->GetHost()->ForceShutdown();
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
928 } else { 929 } else {
929 NaClStartDebugExceptionHandlerThread( 930 NaClStartDebugExceptionHandlerThread(
930 process_handle.Take(), info, 931 process_handle.Take(), info,
931 base::MessageLoopProxy::current(), 932 base::MessageLoopProxy::current(),
932 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 933 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
933 weak_factory_.GetWeakPtr())); 934 weak_factory_.GetWeakPtr()));
934 return true; 935 return true;
935 } 936 }
936 } 937 }
937 #endif 938 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698