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 <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 |
(...skipping 27 matching lines...) Expand all Loading... | |
38 | 38 |
39 LogFunctionMap g_log_function_mapping; | 39 LogFunctionMap g_log_function_mapping; |
40 | 40 |
41 #define IPC_MESSAGE_MACROS_LOG_ENABLED | 41 #define IPC_MESSAGE_MACROS_LOG_ENABLED |
42 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ | 42 #define IPC_LOG_TABLE_ADD_ENTRY(msg_id, logger) \ |
43 g_log_function_mapping[msg_id] = logger | 43 g_log_function_mapping[msg_id] = logger |
44 | 44 |
45 #endif | 45 #endif |
46 #include "ppapi/proxy/ppapi_messages.h" | 46 #include "ppapi/proxy/ppapi_messages.h" |
47 | 47 |
48 // This must match up with NACL_CHROME_INITIAL_IPC_DESC, | 48 // The FD # to communicate with the browser. This must match up with |
49 // defined in sel_main_chrome.h | 49 // the value set in nacl_listener.cc. |
50 #define NACL_IPC_FD 6 | 50 #define NACL_IPC_BROWSER_FD 6 |
Mark Seaborn
2014/02/04 19:28:12
Can you use NACL_CHROME_DESC_BASE instead, please?
hidehiko
2014/02/05 06:30:16
Done. Note that we cannot include sel_main_chrome.
Mark Seaborn
2014/02/05 17:25:14
If checkdeps complained about using sel_main_chrom
hidehiko
2014/02/06 19:27:30
Done. Note that, native_client/src/public was not
| |
51 | |
52 // The FD # to communicate with the renderer. This must match up with | |
53 // the value set in nacl_listener.cc. | |
54 #define NACL_IPC_RENDERER_FD 7 | |
51 | 55 |
52 using ppapi::proxy::PluginDispatcher; | 56 using ppapi::proxy::PluginDispatcher; |
53 using ppapi::proxy::PluginGlobals; | 57 using ppapi::proxy::PluginGlobals; |
54 using ppapi::proxy::PluginProxyDelegate; | 58 using ppapi::proxy::PluginProxyDelegate; |
55 using ppapi::proxy::ProxyChannel; | 59 using ppapi::proxy::ProxyChannel; |
56 using ppapi::proxy::SerializedHandle; | 60 using ppapi::proxy::SerializedHandle; |
57 | 61 |
58 namespace { | 62 namespace { |
59 | 63 |
60 // This class manages communication between the plugin and the browser, and | 64 // This class manages communication between the plugin and the browser, and |
(...skipping 24 matching lines...) Expand all Loading... | |
85 virtual PP_Resource CreateBrowserFont( | 89 virtual PP_Resource CreateBrowserFont( |
86 ppapi::proxy::Connection connection, | 90 ppapi::proxy::Connection connection, |
87 PP_Instance instance, | 91 PP_Instance instance, |
88 const PP_BrowserFont_Trusted_Description& desc, | 92 const PP_BrowserFont_Trusted_Description& desc, |
89 const ppapi::Preferences& prefs) OVERRIDE; | 93 const ppapi::Preferences& prefs) OVERRIDE; |
90 | 94 |
91 // IPC::Listener implementation. | 95 // IPC::Listener implementation. |
92 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 96 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
93 | 97 |
94 private: | 98 private: |
95 void OnMsgCreateNaClChannel(const ppapi::PpapiNaClChannelArgs& args, | 99 void OnMsgInitializeNaClDispatcher( |
96 SerializedHandle handle); | 100 const ppapi::PpapiInitializeNaClDispatcherArgs& args); |
97 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); | 101 void OnPluginDispatcherMessageReceived(const IPC::Message& msg); |
98 | 102 |
99 void SetPpapiKeepAliveThrottleFromCommandLine(); | 103 void SetPpapiKeepAliveThrottleFromCommandLine(); |
100 | 104 |
101 std::set<PP_Instance> instances_; | 105 std::set<PP_Instance> instances_; |
102 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; | 106 std::map<uint32, PluginDispatcher*> plugin_dispatchers_; |
103 uint32 next_plugin_dispatcher_id_; | 107 uint32 next_plugin_dispatcher_id_; |
104 scoped_refptr<base::MessageLoopProxy> message_loop_; | 108 scoped_refptr<base::MessageLoopProxy> message_loop_; |
105 base::WaitableEvent shutdown_event_; | 109 base::WaitableEvent shutdown_event_; |
106 }; | 110 }; |
107 | 111 |
108 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) | 112 PpapiDispatcher::PpapiDispatcher(scoped_refptr<base::MessageLoopProxy> io_loop) |
109 : next_plugin_dispatcher_id_(0), | 113 : next_plugin_dispatcher_id_(0), |
110 message_loop_(io_loop), | 114 message_loop_(io_loop), |
111 shutdown_event_(true, false) { | 115 shutdown_event_(true, false) { |
112 IPC::ChannelHandle channel_handle( | 116 IPC::ChannelHandle channel_handle( |
113 "NaCl IPC", base::FileDescriptor(NACL_IPC_FD, false)); | 117 "NaCl IPC", base::FileDescriptor(NACL_IPC_BROWSER_FD, false)); |
114 // We don't have/need a PID since handle sharing happens outside of the | 118 // We don't have/need a PID since handle sharing happens outside of the |
115 // NaCl sandbox. | 119 // NaCl sandbox. |
116 InitWithChannel(this, base::kNullProcessId, channel_handle, | 120 InitWithChannel(this, base::kNullProcessId, channel_handle, |
117 false); // Channel is server. | 121 false); // Channel is server. |
118 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter( | 122 channel()->AddFilter(new ppapi::proxy::PluginMessageFilter( |
119 NULL, PluginGlobals::Get()->resource_reply_thread_registrar())); | 123 NULL, PluginGlobals::Get()->resource_reply_thread_registrar())); |
120 channel()->AddFilter( | 124 channel()->AddFilter( |
121 new tracing::ChildTraceMessageFilter(message_loop_.get())); | 125 new tracing::ChildTraceMessageFilter(message_loop_.get())); |
122 } | 126 } |
123 | 127 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 ppapi::proxy::Connection connection, | 186 ppapi::proxy::Connection connection, |
183 PP_Instance instance, | 187 PP_Instance instance, |
184 const PP_BrowserFont_Trusted_Description& desc, | 188 const PP_BrowserFont_Trusted_Description& desc, |
185 const ppapi::Preferences& prefs) { | 189 const ppapi::Preferences& prefs) { |
186 NOTIMPLEMENTED(); | 190 NOTIMPLEMENTED(); |
187 return 0; | 191 return 0; |
188 } | 192 } |
189 | 193 |
190 bool PpapiDispatcher::OnMessageReceived(const IPC::Message& msg) { | 194 bool PpapiDispatcher::OnMessageReceived(const IPC::Message& msg) { |
191 IPC_BEGIN_MESSAGE_MAP(PpapiDispatcher, msg) | 195 IPC_BEGIN_MESSAGE_MAP(PpapiDispatcher, msg) |
192 IPC_MESSAGE_HANDLER(PpapiMsg_CreateNaClChannel, OnMsgCreateNaClChannel) | 196 IPC_MESSAGE_HANDLER(PpapiMsg_InitializeNaClDispatcher, |
197 OnMsgInitializeNaClDispatcher) | |
193 // All other messages are simply forwarded to a PluginDispatcher. | 198 // All other messages are simply forwarded to a PluginDispatcher. |
194 IPC_MESSAGE_UNHANDLED(OnPluginDispatcherMessageReceived(msg)) | 199 IPC_MESSAGE_UNHANDLED(OnPluginDispatcherMessageReceived(msg)) |
195 IPC_END_MESSAGE_MAP() | 200 IPC_END_MESSAGE_MAP() |
196 return true; | 201 return true; |
197 } | 202 } |
198 | 203 |
199 void PpapiDispatcher::OnMsgCreateNaClChannel( | 204 void PpapiDispatcher::OnMsgInitializeNaClDispatcher( |
Mark Seaborn
2014/02/04 19:28:12
Can you add a check that would abort or ignore the
hidehiko
2014/02/05 06:30:16
Done.
| |
200 const ppapi::PpapiNaClChannelArgs& args, | 205 const ppapi::PpapiInitializeNaClDispatcherArgs& args) { |
201 SerializedHandle handle) { | |
202 static bool command_line_and_logging_initialized = false; | 206 static bool command_line_and_logging_initialized = false; |
203 if (!command_line_and_logging_initialized) { | 207 if (!command_line_and_logging_initialized) { |
204 CommandLine::Init(0, NULL); | 208 CommandLine::Init(0, NULL); |
205 for (size_t i = 0; i < args.switch_names.size(); ++i) { | 209 for (size_t i = 0; i < args.switch_names.size(); ++i) { |
206 DCHECK(i < args.switch_values.size()); | 210 DCHECK(i < args.switch_values.size()); |
207 CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 211 CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
208 args.switch_names[i], args.switch_values[i]); | 212 args.switch_names[i], args.switch_values[i]); |
209 } | 213 } |
210 logging::LoggingSettings settings; | 214 logging::LoggingSettings settings; |
211 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; | 215 settings.logging_dest = logging::LOG_TO_SYSTEM_DEBUG_LOG; |
212 logging::InitLogging(settings); | 216 logging::InitLogging(settings); |
213 SetPpapiKeepAliveThrottleFromCommandLine(); | 217 SetPpapiKeepAliveThrottleFromCommandLine(); |
214 command_line_and_logging_initialized = true; | 218 command_line_and_logging_initialized = true; |
215 } | 219 } |
216 // Tell the process-global GetInterface which interfaces it can return to the | 220 // Tell the process-global GetInterface which interfaces it can return to the |
217 // plugin. | 221 // plugin. |
218 ppapi::proxy::InterfaceList::SetProcessGlobalPermissions( | 222 ppapi::proxy::InterfaceList::SetProcessGlobalPermissions( |
219 args.permissions); | 223 args.permissions); |
220 | 224 |
221 int32_t error = ::PPP_InitializeModule( | 225 int32_t error = ::PPP_InitializeModule( |
222 0 /* module */, | 226 0 /* module */, |
223 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); | 227 &ppapi::proxy::PluginDispatcher::GetBrowserInterface); |
224 if (error) | 228 if (error) |
225 ::exit(error); | 229 ::exit(error); |
226 | 230 |
227 PluginDispatcher* dispatcher = | 231 PluginDispatcher* dispatcher = |
228 new PluginDispatcher(::PPP_GetInterface, args.permissions, | 232 new PluginDispatcher(::PPP_GetInterface, args.permissions, |
229 args.off_the_record); | 233 args.off_the_record); |
230 // The channel handle's true name is not revealed here. | 234 // The channel handle's true name is not revealed here. |
231 IPC::ChannelHandle channel_handle("nacl", handle.descriptor()); | 235 IPC::ChannelHandle channel_handle( |
236 "nacl", base::FileDescriptor(NACL_IPC_RENDERER_FD, 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 Loading... | |
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 } |
OLD | NEW |