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 "ppapi/proxy/plugin_main_irt.h" | |
6 | |
5 #include <map> | 7 #include <map> |
6 #include <set> | 8 #include <set> |
7 | 9 |
8 #include "build/build_config.h" | 10 #include "build/build_config.h" |
9 // Need to include this before most other files because it defines | 11 // Need to include this before most other files because it defines |
10 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define | 12 // IPC_MESSAGE_LOG_ENABLED. We need to use it to define |
11 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the | 13 // IPC_MESSAGE_MACROS_LOG_ENABLED so ppapi_messages.h will generate the |
12 // ViewMsgLog et al. functions. | 14 // ViewMsgLog et al. functions. |
13 | 15 |
16 #ifndef __native_client__ | |
17 # if OS_LINUX | |
18 # define NACL_LINUX 1 | |
Mark Seaborn
2014/02/15 03:00:52
This is rather hacky... Which headers do you find
hidehiko
2014/02/19 13:05:02
nacl_compiler_annotations.h, which is indirectly i
| |
19 # else | |
20 # error "non-SFI mode is currently supported only on Linux." | |
21 # endif | |
22 #endif | |
23 | |
24 #include "base/at_exit.h" | |
14 #include "base/command_line.h" | 25 #include "base/command_line.h" |
15 #include "base/message_loop/message_loop.h" | 26 #include "base/message_loop/message_loop.h" |
16 #include "base/strings/string_number_conversions.h" | 27 #include "base/strings/string_number_conversions.h" |
17 #include "base/synchronization/waitable_event.h" | 28 #include "base/synchronization/waitable_event.h" |
18 #include "base/threading/thread.h" | 29 #include "base/threading/thread.h" |
19 #include "components/tracing/child_trace_message_filter.h" | 30 #include "components/tracing/child_trace_message_filter.h" |
20 #include "ipc/ipc_channel_handle.h" | 31 #include "ipc/ipc_channel_handle.h" |
21 #include "ipc/ipc_logging.h" | 32 #include "ipc/ipc_logging.h" |
22 #include "ipc/ipc_message.h" | 33 #include "ipc/ipc_message.h" |
23 #include "native_client/src/public/chrome_main.h" | 34 #include "native_client/src/public/chrome_main.h" |
24 #include "native_client/src/shared/srpc/nacl_srpc.h" | |
25 #include "ppapi/c/ppp.h" | 35 #include "ppapi/c/ppp.h" |
26 #include "ppapi/c/ppp_instance.h" | 36 #include "ppapi/c/ppp_instance.h" |
27 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" | 37 #include "ppapi/native_client/src/shared/ppapi_proxy/ppruntime.h" |
Mark Seaborn
2014/02/15 03:00:52
You can remove this now that you #include "ppapi/p
hidehiko
2014/02/19 13:05:02
Done.
| |
28 #include "ppapi/proxy/plugin_dispatcher.h" | 38 #include "ppapi/proxy/plugin_dispatcher.h" |
29 #include "ppapi/proxy/plugin_globals.h" | 39 #include "ppapi/proxy/plugin_globals.h" |
30 #include "ppapi/proxy/plugin_message_filter.h" | 40 #include "ppapi/proxy/plugin_message_filter.h" |
31 #include "ppapi/proxy/plugin_proxy_delegate.h" | 41 #include "ppapi/proxy/plugin_proxy_delegate.h" |
32 #include "ppapi/proxy/resource_reply_thread_registrar.h" | 42 #include "ppapi/proxy/resource_reply_thread_registrar.h" |
33 #include "ppapi/shared_impl/ppapi_switches.h" | 43 #include "ppapi/shared_impl/ppapi_switches.h" |
34 #include "ppapi/shared_impl/ppb_audio_shared.h" | 44 #include "ppapi/shared_impl/ppb_audio_shared.h" |
35 | 45 |
46 #if defined(__native_client__) | |
47 #include "native_client/src/shared/srpc/nacl_srpc.h" | |
48 #endif | |
49 | |
36 #if defined(IPC_MESSAGE_LOG_ENABLED) | 50 #if defined(IPC_MESSAGE_LOG_ENABLED) |
37 #include "base/containers/hash_tables.h" | 51 #include "base/containers/hash_tables.h" |
38 | 52 |
39 LogFunctionMap g_log_function_mapping; | 53 LogFunctionMap g_log_function_mapping; |
40 | 54 |
41 #define IPC_MESSAGE_MACROS_LOG_ENABLED | 55 #define IPC_MESSAGE_MACROS_LOG_ENABLED |
42 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ | 56 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ |
43 g_log_function_mapping[msg_id] = logger | 57 g_log_function_mapping[msg_id] = logger |
44 | 58 |
45 #endif | 59 #endif |
46 #include "ppapi/proxy/ppapi_messages.h" | 60 #include "ppapi/proxy/ppapi_messages.h" |
47 | 61 |
48 using ppapi::proxy::PluginDispatcher; | 62 using ppapi::proxy::PluginDispatcher; |
49 using ppapi::proxy::PluginGlobals; | 63 using ppapi::proxy::PluginGlobals; |
50 using ppapi::proxy::PluginProxyDelegate; | 64 using ppapi::proxy::PluginProxyDelegate; |
51 using ppapi::proxy::ProxyChannel; | 65 using ppapi::proxy::ProxyChannel; |
52 using ppapi::proxy::SerializedHandle; | 66 using ppapi::proxy::SerializedHandle; |
53 | 67 |
54 namespace { | 68 namespace { |
55 | 69 |
70 // On non-SFI mode, the FDs of IPC channels are different from the hard coded | |
71 // ones. These values will be overwritten by SetIPCFileDescriptors() below. | |
72 // The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the | |
73 // browser, and the second one is to the renderer. | |
74 int g_nacl_ipc_browser_fd = NACL_CHROME_DESC_BASE; | |
75 int g_nacl_ipc_renderer_fd = NACL_CHROME_DESC_BASE + 1; | |
76 | |
56 // This class manages communication between the plugin and the browser, and | 77 // This class manages communication between the plugin and the browser, and |
57 // manages the PluginDispatcher instances for communication between the plugin | 78 // manages the PluginDispatcher instances for communication between the plugin |
58 // and the renderer. | 79 // and the renderer. |
59 class PpapiDispatcher : public ProxyChannel, | 80 class PpapiDispatcher : public ProxyChannel, |
60 public PluginDispatcher::PluginDelegate, | 81 public PluginDispatcher::PluginDelegate, |
61 public PluginProxyDelegate { | 82 public PluginProxyDelegate { |
62 public: | 83 public: |
63 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop); | 84 explicit PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop); |
64 | 85 |
65 // PluginDispatcher::PluginDelegate implementation. | 86 // PluginDispatcher::PluginDelegate implementation. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 base::WaitableEvent shutdown_event_; | 121 base::WaitableEvent shutdown_event_; |
101 }; | 122 }; |
102 | 123 |
103 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) | 124 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) |
104 : next_plugin_dispatcher_id_(0), | 125 : next_plugin_dispatcher_id_(0), |
105 message_loop_(io_loop), | 126 message_loop_(io_loop), |
106 shutdown_event_(true, false) { | 127 shutdown_event_(true, false) { |
107 // The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the | 128 // The first FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the |
108 // browser. | 129 // browser. |
109 IPC::ChannelHandle channel_handle( | 130 IPC::ChannelHandle channel_handle( |
110 "NaCl IPC", base::FileDescriptor(NACL_CHROME_DESC_BASE, false)); | 131 "NaCl IPC", base::FileDescriptor(g_nacl_ipc_browser_fd, false)); |
111 // We don't have/need a PID since handle sharing happens outside of the | 132 // We don't have/need a PID since handle sharing happens outside of the |
112 // NaCl sandbox. | 133 // NaCl sandbox. |
113 InitWithChannel(this, base::kNullProcessId, channel_handle, | 134 InitWithChannel(this, base::kNullProcessId, channel_handle, |
114 false); // Channel is server. | 135 false); // Channel is server. |
115 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter( | 136 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter( |
116 NULL, PluginGlobals::Get()->resource_reply_thread_registrar())); | 137 NULL, PluginGlobals::Get()->resource_reply_thread_registrar())); |
117 channel()->AddFilter( | 138 channel()->AddFilter( |
118 new tracing::ChildTraceMessageFilter(message_loop_.get())); | 139 new tracing::ChildTraceMessageFilter(message_loop_.get())); |
119 } | 140 } |
120 | 141 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 if (error) | 246 if (error) |
226 ::exit(error); | 247 ::exit(error); |
227 | 248 |
228 PluginDispatcher* dispatcher = | 249 PluginDispatcher* dispatcher = |
229 new PluginDispatcher(::PPP_GetInterface, args.permissions, | 250 new PluginDispatcher(::PPP_GetInterface, args.permissions, |
230 args.off_the_record); | 251 args.off_the_record); |
231 // The channel handle's true name is not revealed here. | 252 // The channel handle's true name is not revealed here. |
232 // The second FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the | 253 // The second FD (based on NACL_CHROME_DESC_BASE) is the IPC channel to the |
233 // renderer. | 254 // renderer. |
234 IPC::ChannelHandle channel_handle( | 255 IPC::ChannelHandle channel_handle( |
235 "nacl", base::FileDescriptor(NACL_CHROME_DESC_BASE + 1, false)); | 256 "nacl", base::FileDescriptor(g_nacl_ipc_renderer_fd, false)); |
236 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId, | 257 if (!dispatcher->InitPluginWithChannel(this, base::kNullProcessId, |
237 channel_handle, false)) { | 258 channel_handle, false)) { |
238 delete dispatcher; | 259 delete dispatcher; |
239 return; | 260 return; |
240 } | 261 } |
241 // From here, the dispatcher will manage its own lifetime according to the | |
242 // lifetime of the attached channel. | |
243 } | 262 } |
244 | 263 |
245 void PpapiDispatcher::OnPluginDispatcherMessageReceived( | 264 void PpapiDispatcher::OnPluginDispatcherMessageReceived( |
246 const IPC::Message& msg) { | 265 const IPC::Message& msg) { |
247 // The first parameter should be a plugin dispatcher ID. | 266 // The first parameter should be a plugin dispatcher ID. |
248 PickleIterator iter(msg); | 267 PickleIterator iter(msg); |
249 uint32 id = 0; | 268 uint32 id = 0; |
250 if (!msg.ReadUInt32(&iter, &id)) { | 269 if (!msg.ReadUInt32(&iter, &id)) { |
251 NOTREACHED(); | 270 NOTREACHED(); |
252 return; | 271 return; |
(...skipping 13 matching lines...) Expand all Loading... | |
266 ppapi::proxy::PluginGlobals::Get()-> | 285 ppapi::proxy::PluginGlobals::Get()-> |
267 set_keepalive_throttle_interval_milliseconds( | 286 set_keepalive_throttle_interval_milliseconds( |
268 keepalive_throttle_interval_milliseconds); | 287 keepalive_throttle_interval_milliseconds); |
269 } | 288 } |
270 } | 289 } |
271 | 290 |
272 } // namespace | 291 } // namespace |
273 | 292 |
274 void PpapiPluginRegisterThreadCreator( | 293 void PpapiPluginRegisterThreadCreator( |
275 const struct PP_ThreadFunctions* thread_functions) { | 294 const struct PP_ThreadFunctions* thread_functions) { |
295 #if defined(__native_client__) | |
296 // TODO(hidehiko): The thread creation for the PPB_Audio is not yet | |
297 // implemented on non-SFI mode. Support this. Now, this function invocation | |
298 // is just ignored. | |
299 | |
276 // Initialize all classes that need to create threads that call back into | 300 // Initialize all classes that need to create threads that call back into |
277 // user code. | 301 // user code. |
278 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); | 302 ppapi::PPB_Audio_Shared::SetThreadFunctions(thread_functions); |
303 #endif | |
279 } | 304 } |
280 | 305 |
281 int PpapiPluginMain() { | 306 int PpapiPluginMain() { |
282 // Though it isn't referenced here, we must instantiate an AtExitManager. | 307 // Though it isn't referenced here, we must instantiate an AtExitManager. |
283 base::AtExitManager exit_manager; | 308 base::AtExitManager exit_manager; |
284 base::MessageLoop loop; | 309 base::MessageLoop loop; |
310 #if defined(IPC_MESSAGE_LOG_ENABLED) | |
285 IPC::Logging::set_log_function_map(&g_log_function_mapping); | 311 IPC::Logging::set_log_function_map(&g_log_function_mapping); |
312 #endif | |
286 ppapi::proxy::PluginGlobals plugin_globals; | 313 ppapi::proxy::PluginGlobals plugin_globals; |
287 base::Thread io_thread("Chrome_NaClIOThread"); | 314 base::Thread io_thread("Chrome_NaClIOThread"); |
288 base::Thread::Options options; | 315 base::Thread::Options options; |
289 options.message_loop_type = base::MessageLoop::TYPE_IO; | 316 options.message_loop_type = base::MessageLoop::TYPE_IO; |
290 io_thread.StartWithOptions(options); | 317 io_thread.StartWithOptions(options); |
291 | 318 |
319 #if defined(__native_client__) | |
320 // Currently on non-SFI mode, we don't use SRPC server on plugin. | |
321 // TODO(hidehiko): Make sure this SRPC is actually used on SFI-mode. | |
322 | |
292 // Start up the SRPC server on another thread. Otherwise, when it blocks | 323 // Start up the SRPC server on another thread. Otherwise, when it blocks |
293 // on an RPC, the PPAPI proxy will hang. Do this before we initialize the | 324 // on an RPC, the PPAPI proxy will hang. Do this before we initialize the |
294 // module and start the PPAPI proxy so that the NaCl plugin can continue | 325 // module and start the PPAPI proxy so that the NaCl plugin can continue |
295 // loading the app. | 326 // loading the app. |
296 static struct NaClSrpcHandlerDesc srpc_methods[] = { { NULL, NULL } }; | 327 static struct NaClSrpcHandlerDesc srpc_methods[] = { { NULL, NULL } }; |
297 if (!NaClSrpcAcceptClientOnThread(srpc_methods)) { | 328 if (!NaClSrpcAcceptClientOnThread(srpc_methods)) { |
298 return 1; | 329 return 1; |
299 } | 330 } |
331 #endif | |
300 | 332 |
301 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); | 333 PpapiDispatcher ppapi_dispatcher(io_thread.message_loop_proxy()); |
302 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); | 334 plugin_globals.set_plugin_proxy_delegate(&ppapi_dispatcher); |
303 | 335 |
304 loop.Run(); | 336 loop.Run(); |
305 | 337 |
306 return 0; | 338 return 0; |
307 } | 339 } |
340 | |
341 void SetIPCFileDescriptors(int ipc_browser_fd, int ipc_renderer_fd) { | |
Mark Seaborn
2014/02/15 03:00:52
Nit: maybe put this above PpapiPluginRegisterThrea
hidehiko
2014/02/19 13:05:02
Done.
| |
342 // For non-SFI mode, the browser_ipc_fd and renderer_ipc_fd are different | |
343 // from the hard-coded numbers. So, this overwrites the values directly. | |
344 g_nacl_ipc_browser_fd = ipc_browser_fd; | |
345 g_nacl_ipc_renderer_fd = ipc_renderer_fd; | |
346 } | |
OLD | NEW |