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

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

Issue 10912011: Change NaCl IPC PPAPI proxy startup to support a NaCl-Browser process (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 3 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 | Annotate | Revision Log
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 <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/message_loop.h" 12 #include "base/message_loop.h"
13 #include "base/path_service.h" 13 #include "base/path_service.h"
14 #include "base/string_number_conversions.h" 14 #include "base/string_number_conversions.h"
15 #include "base/string_split.h" 15 #include "base/string_split.h"
16 #include "base/string_util.h" 16 #include "base/string_util.h"
17 #include "base/stringprintf.h" 17 #include "base/stringprintf.h"
18 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
19 #include "base/win/windows_version.h" 19 #include "base/win/windows_version.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "chrome/browser/browser_process.h"
21 #include "chrome/browser/extensions/extension_info_map.h" 22 #include "chrome/browser/extensions/extension_info_map.h"
23 #include "chrome/browser/io_thread.h"
22 #include "chrome/browser/nacl_host/nacl_browser.h" 24 #include "chrome/browser/nacl_host/nacl_browser.h"
23 #include "chrome/browser/renderer_host/chrome_render_message_filter.h" 25 #include "chrome/browser/renderer_host/chrome_render_message_filter.h"
24 #include "chrome/common/chrome_constants.h" 26 #include "chrome/common/chrome_constants.h"
25 #include "chrome/common/chrome_paths.h" 27 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/chrome_switches.h" 28 #include "chrome/common/chrome_switches.h"
27 #include "chrome/common/chrome_version_info.h" 29 #include "chrome/common/chrome_version_info.h"
28 #include "chrome/common/logging_chrome.h" 30 #include "chrome/common/logging_chrome.h"
29 #include "chrome/common/nacl_cmd_line.h" 31 #include "chrome/common/nacl_cmd_line.h"
30 #include "chrome/common/nacl_messages.h" 32 #include "chrome/common/nacl_messages.h"
31 #include "chrome/common/render_messages.h" 33 #include "chrome/common/render_messages.h"
32 #include "chrome/common/url_constants.h" 34 #include "chrome/common/url_constants.h"
33 #include "content/public/browser/browser_child_process_host.h" 35 #include "content/public/browser/browser_child_process_host.h"
34 #include "content/public/browser/child_process_data.h" 36 #include "content/public/browser/child_process_data.h"
35 #include "content/public/common/child_process_host.h" 37 #include "content/public/common/child_process_host.h"
38 #include "ipc/ipc_channel.h"
36 #include "ipc/ipc_switches.h" 39 #include "ipc/ipc_switches.h"
37 #include "native_client/src/shared/imc/nacl_imc.h" 40 #include "native_client/src/shared/imc/nacl_imc.h"
38 #include "net/base/net_util.h" 41 #include "net/base/net_util.h"
42 #include "ppapi/proxy/ppapi_messages.h"
39 43
40 #if defined(OS_POSIX) 44 #if defined(OS_POSIX)
41 #include <fcntl.h> 45 #include <fcntl.h>
42 46
43 #include "ipc/ipc_channel_posix.h" 47 #include "ipc/ipc_channel_posix.h"
44 #elif defined(OS_WIN) 48 #elif defined(OS_WIN)
45 #include <windows.h> 49 #include <windows.h>
46 50
47 #include "base/threading/thread.h" 51 #include "base/threading/thread.h"
48 #include "base/process_util.h" 52 #include "base/process_util.h"
49 #include "base/win/scoped_handle.h" 53 #include "base/win/scoped_handle.h"
50 #include "chrome/browser/nacl_host/nacl_broker_service_win.h" 54 #include "chrome/browser/nacl_host/nacl_broker_service_win.h"
51 #include "chrome/common/nacl_debug_exception_handler_win.h" 55 #include "chrome/common/nacl_debug_exception_handler_win.h"
52 #include "content/public/common/sandbox_init.h" 56 #include "content/public/common/sandbox_init.h"
53 #endif 57 #endif
54 58
55 using content::BrowserThread; 59 using content::BrowserThread;
56 using content::ChildProcessData; 60 using content::ChildProcessData;
57 using content::ChildProcessHost; 61 using content::ChildProcessHost;
62 using ppapi::proxy::SerializedHandle;
58 63
59 namespace { 64 namespace {
60 65
61 #if defined(OS_WIN) 66 #if defined(OS_WIN)
62 bool RunningOnWOW64() { 67 bool RunningOnWOW64() {
63 return (base::win::OSInfo::GetInstance()->wow64_status() == 68 return (base::win::OSInfo::GetInstance()->wow64_status() ==
64 base::win::OSInfo::WOW64_ENABLED); 69 base::win::OSInfo::WOW64_ENABLED);
65 } 70 }
66 #endif 71 #endif
67 72
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 112
108 } // namespace 113 } // namespace
109 114
110 struct NaClProcessHost::NaClInternal { 115 struct NaClProcessHost::NaClInternal {
111 std::vector<nacl::Handle> sockets_for_renderer; 116 std::vector<nacl::Handle> sockets_for_renderer;
112 std::vector<nacl::Handle> sockets_for_sel_ldr; 117 std::vector<nacl::Handle> sockets_for_sel_ldr;
113 }; 118 };
114 119
115 // ----------------------------------------------------------------------------- 120 // -----------------------------------------------------------------------------
116 121
122 NaClProcessHost::PluginListener::PluginListener(NaClProcessHost* host)
123 : host_(host) {
124 }
125
126 bool NaClProcessHost::PluginListener::OnMessageReceived(
127 const IPC::Message& msg) {
128 return host_->OnUntrustedMessageForwarded(msg);
129 }
130
117 NaClProcessHost::NaClProcessHost(const GURL& manifest_url, bool off_the_record) 131 NaClProcessHost::NaClProcessHost(const GURL& manifest_url, bool off_the_record)
118 : manifest_url_(manifest_url), 132 : manifest_url_(manifest_url),
119 #if defined(OS_WIN) 133 #if defined(OS_WIN)
120 process_launched_by_broker_(false), 134 process_launched_by_broker_(false),
121 #elif defined(OS_LINUX) 135 #elif defined(OS_LINUX)
122 wait_for_nacl_gdb_(false), 136 wait_for_nacl_gdb_(false),
123 #endif 137 #endif
124 reply_msg_(NULL), 138 reply_msg_(NULL),
125 #if defined(OS_WIN) 139 #if defined(OS_WIN)
126 debug_exception_handler_requested_(false), 140 debug_exception_handler_requested_(false),
127 #endif 141 #endif
128 internal_(new NaClInternal()), 142 internal_(new NaClInternal()),
129 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), 143 ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)),
130 enable_exception_handling_(false), 144 enable_exception_handling_(false),
131 enable_debug_stub_(false), 145 enable_debug_stub_(false),
132 off_the_record_(off_the_record) { 146 off_the_record_(off_the_record),
147 enable_ipc_proxy_(false),
148 ALLOW_THIS_IN_INITIALIZER_LIST(ipc_plugin_listener_(this)) {
133 process_.reset(content::BrowserChildProcessHost::Create( 149 process_.reset(content::BrowserChildProcessHost::Create(
134 content::PROCESS_TYPE_NACL_LOADER, this)); 150 content::PROCESS_TYPE_NACL_LOADER, this));
135 151
136 // Set the display name so the user knows what plugin the process is running. 152 // Set the display name so the user knows what plugin the process is running.
137 // We aren't on the UI thread so getting the pref locale for language 153 // We aren't on the UI thread so getting the pref locale for language
138 // formatting isn't possible, so IDN will be lost, but this is probably OK 154 // formatting isn't possible, so IDN will be lost, but this is probably OK
139 // for this use case. 155 // for this use case.
140 process_->SetName(net::FormatUrl(manifest_url_, std::string())); 156 process_->SetName(net::FormatUrl(manifest_url_, std::string()));
141 157
142 // We allow untrusted hardware exception handling to be enabled via 158 // We allow untrusted hardware exception handling to be enabled via
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 } 690 }
675 691
676 bool NaClProcessHost::SendStart() { 692 bool NaClProcessHost::SendStart() {
677 if (!enable_ipc_proxy_) { 693 if (!enable_ipc_proxy_) {
678 if (!ReplyToRenderer(IPC::ChannelHandle())) 694 if (!ReplyToRenderer(IPC::ChannelHandle()))
679 return false; 695 return false;
680 } 696 }
681 return StartNaClExecution(); 697 return StartNaClExecution();
682 } 698 }
683 699
700 // This method is called when NaClProcessHostMsg_PpapiChannelCreated is
701 // received or PpapiHostMsg_ChannelCreated is forwarded by our plugin
702 // listener.
684 void NaClProcessHost::OnPpapiChannelCreated( 703 void NaClProcessHost::OnPpapiChannelCreated(
685 const IPC::ChannelHandle& channel_handle) { 704 const IPC::ChannelHandle& channel_handle) {
686 DCHECK(enable_ipc_proxy_); 705 DCHECK(enable_ipc_proxy_);
687 ReplyToRenderer(channel_handle); 706 // If the proxy channel is null, this must be the initial NaCl-Browser IPC
707 // channel.
708 if (!ipc_proxy_channel_.get()) {
709 ipc_proxy_channel_.reset(
710 new IPC::ChannelProxy(channel_handle,
711 IPC::Channel::MODE_CLIENT,
712 &ipc_plugin_listener_,
713 base::MessageLoopProxy::current()));
714 // Send a message to create the NaCl-Renderer channel. The handle is just
715 // a place holder.
716 ipc_proxy_channel_->Send(
717 new PpapiMsg_CreateNaClChannel(
718 chrome_render_message_filter_->render_process_id(),
719 chrome_render_message_filter_->off_the_record(),
720 SerializedHandle(SerializedHandle::CHANNEL_HANDLE,
721 IPC::InvalidPlatformFileForTransit())));
722 } else if (reply_msg_) {
723 // Otherwise, this must be a renderer channel.
724 ReplyToRenderer(channel_handle);
725 } else {
726 // Attempt to open more than 1 renderer channel is not supported.
727 // Shut down the NaCl process.
728 process_->GetHost()->ForceShutdown();
729 }
730 }
731
732 bool NaClProcessHost::OnUntrustedMessageForwarded(const IPC::Message& msg) {
733 // Handle messages that have been forwarded from our PluginListener.
734 // These messages come from untrusted code so should be handled with care.
735 bool handled = true;
736 IPC_BEGIN_MESSAGE_MAP(NaClProcessHost, msg)
737 IPC_MESSAGE_HANDLER(PpapiHostMsg_ChannelCreated,
738 OnPpapiChannelCreated)
739 IPC_MESSAGE_UNHANDLED(handled = false)
740 IPC_END_MESSAGE_MAP()
741 return handled;
688 } 742 }
689 743
690 bool NaClProcessHost::StartWithLaunchedProcess() { 744 bool NaClProcessHost::StartWithLaunchedProcess() {
691 #if defined(OS_LINUX) 745 #if defined(OS_LINUX)
692 if (wait_for_nacl_gdb_) { 746 if (wait_for_nacl_gdb_) {
693 if (LaunchNaClGdb(base::GetProcId(process_->GetData().handle))) { 747 if (LaunchNaClGdb(base::GetProcId(process_->GetData().handle))) {
694 // We will be called with wait_for_nacl_gdb_ = false once debugger is 748 // We will be called with wait_for_nacl_gdb_ = false once debugger is
695 // attached to the program. 749 // attached to the program.
696 return true; 750 return true;
697 } 751 }
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 } else { 838 } else {
785 NaClStartDebugExceptionHandlerThread( 839 NaClStartDebugExceptionHandlerThread(
786 process_handle.Take(), info, 840 process_handle.Take(), info,
787 base::MessageLoopProxy::current(), 841 base::MessageLoopProxy::current(),
788 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker, 842 base::Bind(&NaClProcessHost::OnDebugExceptionHandlerLaunchedByBroker,
789 weak_factory_.GetWeakPtr())); 843 weak_factory_.GetWeakPtr()));
790 return true; 844 return true;
791 } 845 }
792 } 846 }
793 #endif 847 #endif
OLDNEW
« no previous file with comments | « chrome/browser/nacl_host/nacl_process_host.h ('k') | chrome/browser/renderer_host/chrome_render_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698