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 11 matching lines...) Expand all Loading... |
22 #include "ppapi/proxy/interface_list.h" | 22 #include "ppapi/proxy/interface_list.h" |
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_reply_thread_registrar.h" |
33 #include "ppapi/shared_impl/ppapi_globals.h" | 33 #include "ppapi/shared_impl/ppapi_globals.h" |
34 #include "ppapi/shared_impl/proxy_lock.h" | 34 #include "ppapi/shared_impl/proxy_lock.h" |
35 #include "ppapi/shared_impl/resource.h" | 35 #include "ppapi/shared_impl/resource.h" |
36 | 36 |
37 #if defined(OS_POSIX) && !defined(OS_NACL) | 37 #if defined(OS_POSIX) && !defined(OS_NACL) |
38 #include "ipc/ipc_channel_posix.h" | 38 #include "ipc/ipc_channel_posix.h" |
39 #endif | 39 #endif |
40 | 40 |
41 namespace ppapi { | 41 namespace ppapi { |
42 namespace proxy { | 42 namespace proxy { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 return false; | 166 return false; |
167 plugin_delegate_ = delegate; | 167 plugin_delegate_ = delegate; |
168 plugin_dispatcher_id_ = plugin_delegate_->Register(this); | 168 plugin_dispatcher_id_ = plugin_delegate_->Register(this); |
169 | 169 |
170 sync_filter_ = new IPC::SyncMessageFilter(delegate->GetShutdownEvent()); | 170 sync_filter_ = new IPC::SyncMessageFilter(delegate->GetShutdownEvent()); |
171 channel()->AddFilter(sync_filter_.get()); | 171 channel()->AddFilter(sync_filter_.get()); |
172 | 172 |
173 // The message filter will intercept and process certain messages directly | 173 // The message filter will intercept and process certain messages directly |
174 // on the I/O thread. | 174 // on the I/O thread. |
175 channel()->AddFilter( | 175 channel()->AddFilter( |
176 new PluginMessageFilter(delegate->GetGloballySeenInstanceIDSet())); | 176 new PluginMessageFilter( |
| 177 delegate->GetGloballySeenInstanceIDSet(), |
| 178 PluginGlobals::Get()->resource_reply_thread_registrar())); |
177 return true; | 179 return true; |
178 } | 180 } |
179 | 181 |
180 bool PluginDispatcher::IsPlugin() const { | 182 bool PluginDispatcher::IsPlugin() const { |
181 return true; | 183 return true; |
182 } | 184 } |
183 | 185 |
184 bool PluginDispatcher::SendMessage(IPC::Message* msg) { | 186 bool PluginDispatcher::SendMessage(IPC::Message* msg) { |
185 // Currently we need to choose between two different mechanisms for sending. | 187 // 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 | 188 // 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. | 221 // plugin making pepper calls on a different thread. |
220 ProxyAutoLock lock; | 222 ProxyAutoLock lock; |
221 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived", | 223 TRACE_EVENT2("ppapi proxy", "PluginDispatcher::OnMessageReceived", |
222 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), | 224 "Class", IPC_MESSAGE_ID_CLASS(msg.type()), |
223 "Line", IPC_MESSAGE_ID_LINE(msg.type())); | 225 "Line", IPC_MESSAGE_ID_LINE(msg.type())); |
224 | 226 |
225 if (msg.routing_id() == MSG_ROUTING_CONTROL) { | 227 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
226 // Handle some plugin-specific control messages. | 228 // Handle some plugin-specific control messages. |
227 bool handled = true; | 229 bool handled = true; |
228 IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) | 230 IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) |
229 IPC_MESSAGE_HANDLER(PpapiPluginMsg_ResourceReply, OnMsgResourceReply) | |
230 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) | 231 IPC_MESSAGE_HANDLER(PpapiMsg_SupportsInterface, OnMsgSupportsInterface) |
231 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences) | 232 IPC_MESSAGE_HANDLER(PpapiMsg_SetPreferences, OnMsgSetPreferences) |
232 IPC_MESSAGE_UNHANDLED(handled = false); | 233 IPC_MESSAGE_UNHANDLED(handled = false); |
233 IPC_END_MESSAGE_MAP() | 234 IPC_END_MESSAGE_MAP() |
234 if (handled) | 235 if (handled) |
235 return true; | 236 return true; |
236 } | 237 } |
237 return Dispatcher::OnMessageReceived(msg); | 238 return Dispatcher::OnMessageReceived(msg); |
238 } | 239 } |
239 | 240 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 thunk::PPB_Instance_API* PluginDispatcher::GetInstanceAPI() { | 281 thunk::PPB_Instance_API* PluginDispatcher::GetInstanceAPI() { |
281 return static_cast<PPB_Instance_Proxy*>( | 282 return static_cast<PPB_Instance_Proxy*>( |
282 GetInterfaceProxy(API_ID_PPB_INSTANCE)); | 283 GetInterfaceProxy(API_ID_PPB_INSTANCE)); |
283 } | 284 } |
284 | 285 |
285 thunk::ResourceCreationAPI* PluginDispatcher::GetResourceCreationAPI() { | 286 thunk::ResourceCreationAPI* PluginDispatcher::GetResourceCreationAPI() { |
286 return static_cast<ResourceCreationProxy*>( | 287 return static_cast<ResourceCreationProxy*>( |
287 GetInterfaceProxy(API_ID_RESOURCE_CREATION)); | 288 GetInterfaceProxy(API_ID_RESOURCE_CREATION)); |
288 } | 289 } |
289 | 290 |
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() { | 291 void PluginDispatcher::ForceFreeAllInstances() { |
301 if (!g_instance_to_dispatcher) | 292 if (!g_instance_to_dispatcher) |
302 return; | 293 return; |
303 | 294 |
304 // Iterating will remove each item from the map, so we need to make a copy | 295 // Iterating will remove each item from the map, so we need to make a copy |
305 // to avoid things changing out from under is. | 296 // to avoid things changing out from under is. |
306 InstanceToDispatcherMap temp_map = *g_instance_to_dispatcher; | 297 InstanceToDispatcherMap temp_map = *g_instance_to_dispatcher; |
307 for (InstanceToDispatcherMap::iterator i = temp_map.begin(); | 298 for (InstanceToDispatcherMap::iterator i = temp_map.begin(); |
308 i != temp_map.end(); ++i) { | 299 i != temp_map.end(); ++i) { |
309 if (i->second == this) { | 300 if (i->second == this) { |
310 // Synthesize an "instance destroyed" message, this will notify the | 301 // Synthesize an "instance destroyed" message, this will notify the |
311 // plugin and also remove it from our list of tracked plugins. | 302 // plugin and also remove it from our list of tracked plugins. |
312 PpapiMsg_PPPInstance_DidDestroy msg(API_ID_PPP_INSTANCE, i->first); | 303 PpapiMsg_PPPInstance_DidDestroy msg(API_ID_PPP_INSTANCE, i->first); |
313 OnMessageReceived(msg); | 304 OnMessageReceived(msg); |
314 } | 305 } |
315 } | 306 } |
316 } | 307 } |
317 | 308 |
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( | 309 void PluginDispatcher::OnMsgSupportsInterface( |
325 const std::string& interface_name, | 310 const std::string& interface_name, |
326 bool* result) { | 311 bool* result) { |
327 *result = !!GetPluginInterface(interface_name); | 312 *result = !!GetPluginInterface(interface_name); |
328 | 313 |
329 // Do fallback for PPP_Instance. This is a hack here and if we have more | 314 // 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 | 315 // 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 | 316 // 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 | 317 // 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. | 318 // supporting the 1.1 interface if either 1.1 or 1.0 is supported. |
334 if (!*result && interface_name == PPP_INSTANCE_INTERFACE) | 319 if (!*result && interface_name == PPP_INSTANCE_INTERFACE) |
335 *result = !!GetPluginInterface(PPP_INSTANCE_INTERFACE_1_0); | 320 *result = !!GetPluginInterface(PPP_INSTANCE_INTERFACE_1_0); |
336 } | 321 } |
337 | 322 |
338 void PluginDispatcher::OnMsgSetPreferences(const Preferences& prefs) { | 323 void PluginDispatcher::OnMsgSetPreferences(const Preferences& prefs) { |
339 // The renderer may send us preferences more than once (currently this | 324 // 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 | 325 // 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 | 326 // 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 | 327 // 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 | 328 // 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 | 329 // once they're set. The user will have to restart to get new font prefs |
345 // propogated to plugins. | 330 // propogated to plugins. |
346 if (!received_preferences_) { | 331 if (!received_preferences_) { |
347 received_preferences_ = true; | 332 received_preferences_ = true; |
348 preferences_ = prefs; | 333 preferences_ = prefs; |
349 } | 334 } |
350 } | 335 } |
351 | 336 |
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 | 337 } // namespace proxy |
368 } // namespace ppapi | 338 } // namespace ppapi |
OLD | NEW |