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

Side by Side Diff: ppapi/proxy/plugin_main_nacl.cc

Issue 150713003: Create IPC channel to communicate with the renderer in NaClListener::OnStart(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
« no previous file with comments | « ppapi/proxy/nacl_message_scanner.cc ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <map> 5 #include <map>
6 #include <set> 6 #include <set>
7 7
8 #include "build/build_config.h" 8 #include "build/build_config.h"
9 // Need to include this before most other files because it defines 9 // Need to include this before most other files because it defines
10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define 10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define
11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the 11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the
12 // ViewMsgLog et al. functions. 12 // ViewMsgLog et al. functions.
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/message_loop/message_loop.h" 15 #include "base/message_loop/message_loop.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/synchronization/waitable_event.h" 17 #include "base/synchronization/waitable_event.h"
18 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
19 #include "components/tracing/child_trace_message_filter.h" 19 #include "components/tracing/child_trace_message_filter.h"
20 #include "ipc/ipc_channel_handle.h" 20 #include "ipc/ipc_channel_handle.h"
21 #include "ipc/ipc_logging.h" 21 #include "ipc/ipc_logging.h"
22 #include "ipc/ipc_message.h" 22 #include "ipc/ipc_message.h"
23 #include "native_client/src/public/chrome_main.h"
23 #include "native_client/src/shared/srpc/nacl_srpc.h" 24 #include "native_client/src/shared/srpc/nacl_srpc.h"
24 #include "native_client/src/untrusted/irt/irt_ppapi.h" 25 #include "native_client/src/untrusted/irt/irt_ppapi.h"
25 #include "ppapi/c/ppp.h" 26 #include "ppapi/c/ppp.h"
26 #include "ppapi/c/ppp_instance.h" 27 #include "ppapi/c/ppp_instance.h"
27 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" 28 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h"
28 #include "ppapi/proxy/plugin_dispatcher.h" 29 #include "ppapi/proxy/plugin_dispatcher.h"
29 #include "ppapi/proxy/plugin_globals.h" 30 #include "ppapi/proxy/plugin_globals.h"
30 #include "ppapi/proxy/plugin_message_filter.h" 31 #include "ppapi/proxy/plugin_message_filter.h"
31 #include "ppapi/proxy/plugin_proxy_delegate.h" 32 #include "ppapi/proxy/plugin_proxy_delegate.h"
32 #include "ppapi/proxy/resource_reply_thread_registrar.h" 33 #include "ppapi/proxy/resource_reply_thread_registrar.h"
33 #include "ppapi/shared_impl/ppapi_switches.h" 34 #include "ppapi/shared_impl/ppapi_switches.h"
34 #include "ppapi/shared_impl/ppb_audio_shared.h" 35 #include "ppapi/shared_impl/ppb_audio_shared.h"
35 36
36 #if defined(IPC_MESSAGE_LOG_ENABLED) 37 #if defined(IPC_MESSAGE_LOG_ENABLED)
37 #include "base/containers/hash_tables.h" 38 #include "base/containers/hash_tables.h"
38 39
39 LogFunctionMap g_log_function_mapping; 40 LogFunctionMap g_log_function_mapping;
40 41
41 #define IPC_MESSAGE_MACROS_LOG_ENABLED 42 #define IPC_MESSAGE_MACROS_LOG_ENABLED
42 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ 43 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \
43 g_log_function_mapping[msg_id] = logger 44 g_log_function_mapping[msg_id] = logger
44 45
45 #endif 46 #endif
46 #include "ppapi/proxy/ppapi_messages.h" 47 #include "ppapi/proxy/ppapi_messages.h"
47 48
48 // This must match up with NACL_CHROME_INITIAL_IPC_DESC,
49 // defined in sel_main_chrome.h
50 #define NACL_IPC_FD 6
51
52 using ppapi::proxy::PluginDispatcher; 49 using ppapi::proxy::PluginDispatcher;
53 using ppapi::proxy::PluginGlobals; 50 using ppapi::proxy::PluginGlobals;
54 using ppapi::proxy::PluginProxyDelegate; 51 using ppapi::proxy::PluginProxyDelegate;
55 using ppapi::proxy::ProxyChannel; 52 using ppapi::proxy::ProxyChannel;
56 using ppapi::proxy::SerializedHandle; 53 using ppapi::proxy::SerializedHandle;
57 54
58 namespace { 55 namespace {
59 56
60 // This class manages communication between the plugin and the browser, and 57 // This class manages communication between the plugin and the browser, and
61 // manages the PluginDispatcher instances for communication between the plugin 58 // manages the PluginDispatcher instances for communication between the plugin
(...skipping 23 matching lines...) Expand all
85 virtual PP_Resource CreateBrowserFont( 82 virtual PP_Resource CreateBrowserFont(
86 ppapi::proxy::Connection connection, 83 ppapi::proxy::Connection connection,
87 PP_Instance instance, 84 PP_Instance instance,
88 const PP_BrowserFont_Trusted_Description& desc, 85 const PP_BrowserFont_Trusted_Description& desc,
89 const ppapi::Preferences& prefs) OVERRIDE; 86 const ppapi::Preferences& prefs) OVERRIDE;
90 87
91 // IPC::Listener implementation. 88 // IPC::Listener implementation.
92 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 89 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
93 90
94 private: 91 private:
95 void OnMsgCreateNaClChannel(const ppapi::PpapiNaClChannelArgs& args, 92 void OnMsgInitializeNaClDispatcher(const ppapi::PpapiNaClPluginArgs& args);
96 SerializedHandle handle);
97 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); 93 void OnPluginDispatcherMessageReceived(const IPC::Message& msg);
98 94
99 void SetPpapiKeepAliveThrottleFromCommandLine(); 95 void SetPpapiKeepAliveThrottleFromCommandLine();
100 96
101 std::set<PP_Instance> instances_; 97 std::set<PP_Instance> instances_;
102 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; 98 std::map<uint32, PluginDispatcher*> plugin_dispatchers_;
103 uint32 next_plugin_dispatcher_id_; 99 uint32 next_plugin_dispatcher_id_;
104 scoped_refptr<base::MessageLoopProxy> message_loop_; 100 scoped_refptr<base::MessageLoopProxy> message_loop_;
105 base::WaitableEvent shutdown_event_; 101 base::WaitableEvent shutdown_event_;
106 }; 102 };
107 103
108 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) 104 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop)
109 : next_plugin_dispatcher_id_(0), 105 : next_plugin_dispatcher_id_(0),
110 message_loop_(io_loop), 106 message_loop_(io_loop),
111 shutdown_event_(true, false) { 107 shutdown_event_(true, false) {
108 // The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the
109 // browser.
112 IPC::ChannelHandle channel_handle( 110 IPC::ChannelHandle channel_handle(
113 "NaCl IPC", base::FileDescriptor(NACL_IPC_FD, false)); 111 "NaCl IPC", base::FileDescriptor(NACL_CHROME_DESC_BASE, false));
114 // We don't have/need a PID since handle sharing happens outside of the 112 // We don't have/need a PID since handle sharing happens outside of the
115 // NaCl sandbox. 113 // NaCl sandbox.
116 InitWithChannel(this, base::kNullProcessId, channel_handle, 114 InitWithChannel(this, base::kNullProcessId, channel_handle,
117 false); // Channel is server. 115 false); // Channel is server.
118 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter( 116 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter(
119 NULL, PluginGlobals::Get()->resource_reply_thread_registrar())); 117 NULL, PluginGlobals::Get()->resource_reply_thread_registrar()));
120 channel()->AddFilter( 118 channel()->AddFilter(
121 new tracing::ChildTraceMessageFilter(message_loop_.get())); 119 new tracing::ChildTraceMessageFilter(message_loop_.get()));
122 } 120 }
123 121
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ppapi::proxy::Connection connection, 180 ppapi::proxy::Connection connection,
183 PP_Instance instance, 181 PP_Instance instance,
184 const PP_BrowserFont_Trusted_Description& desc, 182 const PP_BrowserFont_Trusted_Description& desc,
185 const ppapi::Preferences& prefs) { 183 const ppapi::Preferences& prefs) {
186 NOTIMPLEMENTED(); 184 NOTIMPLEMENTED();
187 return 0; 185 return 0;
188 } 186 }
189 187
190 bool PpapiDispatcher::OnMessageReceived(const IPC::Message& msg) { 188 bool PpapiDispatcher::OnMessageReceived(const IPC::Message& msg) {
191 IPC_BEGIN_MESSAGE_MAP(PpapiDispatcher, msg) 189 IPC_BEGIN_MESSAGE_MAP(PpapiDispatcher, msg)
192 IPC_MESSAGE_HANDLER(PpapiMsg_CreateNaClChannel, OnMsgCreateNaClChannel) 190 IPC_MESSAGE_HANDLER(PpapiMsg_InitializeNaClDispatcher,
191 OnMsgInitializeNaClDispatcher)
193 // All other messages are simply forwarded to a PluginDispatcher. 192 // All other messages are simply forwarded to a PluginDispatcher.
194 IPC_MESSAGE_UNHANDLED(OnPluginDispatcherMessageReceived(msg)) 193 IPC_MESSAGE_UNHANDLED(OnPluginDispatcherMessageReceived(msg))
195 IPC_END_MESSAGE_MAP() 194 IPC_END_MESSAGE_MAP()
196 return true; 195 return true;
197 } 196 }
198 197
199 void PpapiDispatcher::OnMsgCreateNaClChannel( 198 void PpapiDispatcher::OnMsgInitializeNaClDispatcher(
200 const ppapi::PpapiNaClChannelArgs& args, 199 const ppapi::PpapiNaClPluginArgs& args) {
201 SerializedHandle handle) {
202 static bool command_line_and_logging_initialized = false; 200 static bool command_line_and_logging_initialized = false;
203 if (!command_line_and_logging_initialized) { 201 if (command_line_and_logging_initialized) {
204 CommandLine::Init(0, NULL); 202 LOG(FATAL) << "InitializeNaClDispatcher must be called once per plugin.";
205 for (size_t i = 0; i < args.switch_names.size(); ++i) { 203 return;
206 DCHECK(i < args.switch_values.size());
207 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
208 args.switch_names[i], args.switch_values[i]);
209 }
210 logging::LoggingSettings settings;
211 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
212 logging::InitLogging(settings);
213 SetPpapiKeepAliveThrottleFromCommandLine();
214 command_line_and_logging_initialized = true;
215 } 204 }
205
206 command_line_and_logging_initialized = true;
207 CommandLine::Init(0, NULL);
208 for (size_t i = 0; i < args.switch_names.size(); ++i) {
209 DCHECK(i < args.switch_values.size());
210 CommandLine::ForCurrentProcess()->AppendSwitchASCII(
211 args.switch_names[i], args.switch_values[i]);
212 }
213 logging::LoggingSettings settings;
214 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG;
215 logging::InitLogging(settings);
216 SetPpapiKeepAliveThrottleFromCommandLine();
217
216 // Tell the process-global GetInterface which interfaces it can return to the 218 // Tell the process-global GetInterface which interfaces it can return to the
217 // plugin. 219 // plugin.
218 ppapi::proxy::InterfaceList::SetProcessGlobalPermissions( 220 ppapi::proxy::InterfaceList::SetProcessGlobalPermissions(
219 args.permissions); 221 args.permissions);
220 222
221 int32_t error = ::PPP_InitializeModule( 223 int32_t error = ::PPP_InitializeModule(
222 0 /* module */, 224 0 /* module */,
223 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); 225 &ppapi::proxy::PluginDispatcher::GetBrowserInterface);
224 if (error) 226 if (error)
225 ::exit(error); 227 ::exit(error);
226 228
227 PluginDispatcher* dispatcher = 229 PluginDispatcher* dispatcher =
228 new PluginDispatcher(::PPP_GetInterface, args.permissions, 230 new PluginDispatcher(::PPP_GetInterface, args.permissions,
229 args.off_the_record); 231 args.off_the_record);
230 // The channel handle's true name is not revealed here. 232 // The channel handle's true name is not revealed here.
231 IPC::ChannelHandle channel_handle("nacl", handle.descriptor()); 233 // The second FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the
234 // renderer.
235 IPC::ChannelHandle channel_handle(
236 "nacl", base::FileDescriptor(NACL_CHROME_DESC_BASE + 1, false));
232 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId, 237 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId,
233 channel_handle, false)) { 238 channel_handle, false)) {
234 delete dispatcher; 239 delete dispatcher;
235 return; 240 return;
236 } 241 }
237 // From here, the dispatcher will manage its own lifetime according to the 242 // From here, the dispatcher will manage its own lifetime according to the
238 // lifetime of the attached channel. 243 // lifetime of the attached channel.
239 } 244 }
240 245
241 void PpapiDispatcher::OnPluginDispatcherMessageReceived( 246 void PpapiDispatcher::OnPluginDispatcherMessageReceived(
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 return 1; 299 return 1;
295 } 300 }
296 301
297 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); 302 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy());
298 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); 303 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher);
299 304
300 loop.Run(); 305 loop.Run();
301 306
302 return 0; 307 return 0;
303 } 308 }
OLDNEW
« no previous file with comments | « ppapi/proxy/nacl_message_scanner.cc ('k') | ppapi/proxy/ppapi_messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698