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_dispatcher.h" | 5 #include "ppapi/proxy/plugin_dispatcher.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ppapi/proxy/interface_proxy.h" | 23 #include "ppapi/proxy/interface_proxy.h" |
24 #include "ppapi/proxy/plugin_globals.h" | 24 #include "ppapi/proxy/plugin_globals.h" |
25 #include "ppapi/proxy/plugin_message_filter.h" | 25 #include "ppapi/proxy/plugin_message_filter.h" |
26 #include "ppapi/proxy/plugin_resource_tracker.h" | 26 #include "ppapi/proxy/plugin_resource_tracker.h" |
27 #include "ppapi/proxy/plugin_var_serialization_rules.h" | 27 #include "ppapi/proxy/plugin_var_serialization_rules.h" |
28 #include "ppapi/proxy/ppapi_messages.h" | 28 #include "ppapi/proxy/ppapi_messages.h" |
29 #include "ppapi/proxy/ppb_instance_proxy.h" | 29 #include "ppapi/proxy/ppb_instance_proxy.h" |
30 #include "ppapi/proxy/ppp_class_proxy.h" | 30 #include "ppapi/proxy/ppp_class_proxy.h" |
31 #include "ppapi/proxy/resource_creation_proxy.h" | 31 #include "ppapi/proxy/resource_creation_proxy.h" |
32 #include "ppapi/proxy/resource_message_params.h" | 32 #include "ppapi/proxy/resource_message_params.h" |
| 33 #include "ppapi/proxy/resource_reply_thread_registrar.h" |
33 #include "ppapi/shared_impl/ppapi_globals.h" | 34 #include "ppapi/shared_impl/ppapi_globals.h" |
34 #include "ppapi/shared_impl/proxy_lock.h" | 35 #include "ppapi/shared_impl/proxy_lock.h" |
35 #include "ppapi/shared_impl/resource.h" | 36 #include "ppapi/shared_impl/resource.h" |
36 | 37 |
37 #if defined(OS_POSIX) && !defined(OS_NACL) | 38 #if defined(OS_POSIX) && !defined(OS_NACL) |
38 #include "ipc/ipc_channel_posix.h" | 39 #include "ipc/ipc_channel_posix.h" |
39 #endif | 40 #endif |
40 | 41 |
41 namespace ppapi { | 42 namespace ppapi { |
42 namespace proxy { | 43 namespace proxy { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return false; | 167 return false; |
167 plugin_delegate_ = delegate; | 168 plugin_delegate_ = delegate; |
168 plugin_dispatcher_id_ = plugin_delegate_->Register(this); | 169 plugin_dispatcher_id_ = plugin_delegate_->Register(this); |
169 | 170 |
170 sync_filter_ = new IPC::SyncMessageFilter(delegate->GetShutdownEvent()); | 171 sync_filter_ = new IPC::SyncMessageFilter(delegate->GetShutdownEvent()); |
171 channel()->AddFilter(sync_filter_.get()); | 172 channel()->AddFilter(sync_filter_.get()); |
172 | 173 |
173 // The message filter will intercept and process certain messages directly | 174 // The message filter will intercept and process certain messages directly |
174 // on the I/O thread. | 175 // on the I/O thread. |
175 channel()->AddFilter( | 176 channel()->AddFilter( |
176 new PluginMessageFilter(delegate->GetGloballySeenInstanceIDSet())); | 177 new PluginMessageFilter( |
| 178 delegate->GetGloballySeenInstanceIDSet(), |
| 179 PluginGlobals::Get()->resource_reply_thread_registrar())); |
177 return true; | 180 return true; |
178 } | 181 } |
179 | 182 |
180 bool PluginDispatcher::IsPlugin() const { | 183 bool PluginDispatcher::IsPlugin() const { |
181 return true; | 184 return true; |
182 } | 185 } |
183 | 186 |
184 bool PluginDispatcher::SendMessage(IPC::Message* msg) { | 187 bool PluginDispatcher::SendMessage(IPC::Message* msg) { |
185 // Currently we need to choose between two different mechanisms for sending. | 188 // Currently we need to choose between two different mechanisms for sending. |
186 // On the main thread we use the regular dispatch Send() method, on another | 189 // On the main thread we use the regular dispatch Send() method, on another |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 // plugin making pepper calls on a different thread. | 222 // plugin making pepper calls on a different thread. |
220 ProxyAutoLock lock; | 223 ProxyAutoLock lock; |
221 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived", | 224 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived", |
222 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), | 225 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), |
223 "Line", IPC_MESSAGE_ID_LINE(msg.type())); | 226 "Line", IPC_MESSAGE_ID_LINE(msg.type())); |
224 | 227 |
225 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 228 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
226 // Handle some plugin-specific control messages. | 229 // Handle some plugin-specific control messages. |
227 bool handled = true; | 230 bool handled = true; |
228 IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) | 231 IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) |
229 IPC_MESSAGE_HANDLER(PpapiPluginMsg_ResourceReply, OnMsgResourceReply) | |
230 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) | 232 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) |
231 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences) | 233 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences) |
232 IPC_MESSAGE_UNHANDLED(handled = false); | 234 IPC_MESSAGE_UNHANDLED(handled = false); |
233 IPC_END_MESSAGE_MAP() | 235 IPC_END_MESSAGE_MAP() |
234 if (handled) | 236 if (handled) |
235 return true; | 237 return true; |
236 } | 238 } |
237 return Dispatcher::OnMessageReceived(msg); | 239 return Dispatcher::OnMessageReceived(msg); |
238 } | 240 } |
239 | 241 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 thunk::PPB_Instance_API* PluginDispatcher::GetInstanceAPI() { | 282 thunk::PPB_Instance_API* PluginDispatcher::GetInstanceAPI() { |
281 return static_cast<PPB_Instance_Proxy*>( | 283 return static_cast<PPB_Instance_Proxy*>( |
282 GetInterfaceProxy(API_ID_PPB_INSTANCE)); | 284 GetInterfaceProxy(API_ID_PPB_INSTANCE)); |
283 } | 285 } |
284 | 286 |
285 thunk::ResourceCreationAPI* PluginDispatcher::GetResourceCreationAPI() { | 287 thunk::ResourceCreationAPI* PluginDispatcher::GetResourceCreationAPI() { |
286 return static_cast<ResourceCreationProxy*>( | 288 return static_cast<ResourceCreationProxy*>( |
287 GetInterfaceProxy(API_ID_RESOURCE_CREATION)); | 289 GetInterfaceProxy(API_ID_RESOURCE_CREATION)); |
288 } | 290 } |
289 | 291 |
290 // static | |
291 void PluginDispatcher::DispatchResourceReply( | |
292 const ppapi::proxy::ResourceMessageReplyParams& reply_params, | |
293 const IPC::Message& nested_msg) { | |
294 // We need to grab the proxy lock to ensure that we don't collide with the | |
295 // plugin making pepper calls on a different thread. | |
296 ProxyAutoLock lock; | |
297 LockedDispatchResourceReply(reply_params, nested_msg); | |
298 } | |
299 | |
300 void PluginDispatcher::ForceFreeAllInstances() { | 292 void PluginDispatcher::ForceFreeAllInstances() { |
301 if (!g_instance_to_dispatcher) | 293 if (!g_instance_to_dispatcher) |
302 return; | 294 return; |
303 | 295 |
304 // Iterating will remove each item from the map, so we need to make a copy | 296 // Iterating will remove each item from the map, so we need to make a copy |
305 // to avoid things changing out from under is. | 297 // to avoid things changing out from under is. |
306 InstanceToDispatcherMap temp_map = *g_instance_to_dispatcher; | 298 InstanceToDispatcherMap temp_map = *g_instance_to_dispatcher; |
307 for (InstanceToDispatcherMap::iterator i = temp_map.begin(); | 299 for (InstanceToDispatcherMap::iterator i = temp_map.begin(); |
308 i != temp_map.end(); ++i) { | 300 i != temp_map.end(); ++i) { |
309 if (i->second == this) { | 301 if (i->second == this) { |
310 // Synthesize an "instance destroyed" message, this will notify the | 302 // Synthesize an "instance destroyed" message, this will notify the |
311 // plugin and also remove it from our list of tracked plugins. | 303 // plugin and also remove it from our list of tracked plugins. |
312 PpapiMsg_PPPInstance_DidDestroy msg(API_ID_PPP_INSTANCE, i->first); | 304 PpapiMsg_PPPInstance_DidDestroy msg(API_ID_PPP_INSTANCE, i->first); |
313 OnMessageReceived(msg); | 305 OnMessageReceived(msg); |
314 } | 306 } |
315 } | 307 } |
316 } | 308 } |
317 | 309 |
318 void PluginDispatcher::OnMsgResourceReply( | |
319 const ppapi::proxy::ResourceMessageReplyParams& reply_params, | |
320 const IPC::Message& nested_msg) { | |
321 LockedDispatchResourceReply(reply_params, nested_msg); | |
322 } | |
323 | |
324 void PluginDispatcher::OnMsgSupportsInterface( | 310 void PluginDispatcher::OnMsgSupportsInterface( |
325 const std::string& interface_name, | 311 const std::string& interface_name, |
326 bool* result) { | 312 bool* result) { |
327 *result = !!GetPluginInterface(interface_name); | 313 *result = !!GetPluginInterface(interface_name); |
328 | 314 |
329 // Do fallback for PPP_Instance. This is a hack here and if we have more | 315 // Do fallback for PPP_Instance. This is a hack here and if we have more |
330 // cases like this it should be generalized. The PPP_Instance proxy always | 316 // cases like this it should be generalized. The PPP_Instance proxy always |
331 // proxies the 1.1 interface, and then does fallback to 1.0 inside the | 317 // proxies the 1.1 interface, and then does fallback to 1.0 inside the |
332 // plugin process (see PPP_Instance_Proxy). So here we return true for | 318 // plugin process (see PPP_Instance_Proxy). So here we return true for |
333 // supporting the 1.1 interface if either 1.1 or 1.0 is supported. | 319 // supporting the 1.1 interface if either 1.1 or 1.0 is supported. |
334 if (!*result && interface_name == PPP_INSTANCE_INTERFACE) | 320 if (!*result && interface_name == PPP_INSTANCE_INTERFACE) |
335 *result = !!GetPluginInterface(PPP_INSTANCE_INTERFACE_1_0); | 321 *result = !!GetPluginInterface(PPP_INSTANCE_INTERFACE_1_0); |
336 } | 322 } |
337 | 323 |
338 void PluginDispatcher::OnMsgSetPreferences(const Preferences& prefs) { | 324 void PluginDispatcher::OnMsgSetPreferences(const Preferences& prefs) { |
339 // The renderer may send us preferences more than once (currently this | 325 // The renderer may send us preferences more than once (currently this |
340 // happens every time a new plugin instance is created). Since we don't have | 326 // happens every time a new plugin instance is created). Since we don't have |
341 // a way to signal to the plugin that the preferences have changed, changing | 327 // a way to signal to the plugin that the preferences have changed, changing |
342 // the default fonts and such in the middle of a running plugin could be | 328 // the default fonts and such in the middle of a running plugin could be |
343 // confusing to it. As a result, we never allow the preferences to be changed | 329 // confusing to it. As a result, we never allow the preferences to be changed |
344 // once they're set. The user will have to restart to get new font prefs | 330 // once they're set. The user will have to restart to get new font prefs |
345 // propogated to plugins. | 331 // propogated to plugins. |
346 if (!received_preferences_) { | 332 if (!received_preferences_) { |
347 received_preferences_ = true; | 333 received_preferences_ = true; |
348 preferences_ = prefs; | 334 preferences_ = prefs; |
349 } | 335 } |
350 } | 336 } |
351 | 337 |
352 // static | |
353 void PluginDispatcher::LockedDispatchResourceReply( | |
354 const ppapi::proxy::ResourceMessageReplyParams& reply_params, | |
355 const IPC::Message& nested_msg) { | |
356 Resource* resource = PpapiGlobals::Get()->GetResourceTracker()->GetResource( | |
357 reply_params.pp_resource()); | |
358 if (!resource) { | |
359 DLOG_IF(INFO, reply_params.sequence() != 0) | |
360 << "Pepper resource reply message received but the resource doesn't " | |
361 "exist (probably has been destroyed)."; | |
362 return; | |
363 } | |
364 resource->OnReplyReceived(reply_params, nested_msg); | |
365 } | |
366 | |
367 } // namespace proxy | 338 } // namespace proxy |
368 } // namespace ppapi | 339 } // namespace ppapi |
OLD | NEW |