OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ppapi/proxy/plugin_dispatcher.h" |
| 6 |
| 7 #include <map> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "ipc/ipc_message.h" |
| 11 #include "ipc/ipc_sync_channel.h" |
| 12 #include "ppapi/c/pp_errors.h" |
| 13 #include "ppapi/proxy/interface_proxy.h" |
| 14 #include "ppapi/proxy/plugin_var_serialization.h" |
| 15 #include "ppapi/proxy/ppapi_messages.h" |
| 16 #include "ppapi/proxy/ppp_class_proxy.h" |
| 17 |
| 18 namespace pp { |
| 19 namespace proxy { |
| 20 |
| 21 namespace { |
| 22 |
| 23 PluginDispatcher* g_dispatcher = NULL; |
| 24 |
| 25 const void* GetInterfaceFromDispatcher(const char* interface) { |
| 26 // TODO(brettw) need some kind of lock for multi-thread access. |
| 27 return pp::proxy::PluginDispatcher::Get()->GetProxiedInterface(interface); |
| 28 } |
| 29 |
| 30 } // namespace |
| 31 |
| 32 PluginDispatcher::PluginDispatcher(GetInterfaceFunc get_interface, |
| 33 InitModuleFunc init_module, |
| 34 ShutdownModuleFunc shutdown_module) |
| 35 : Dispatcher(get_interface), |
| 36 plugin_resource_tracker_(new PluginResourceTracker(this)), |
| 37 plugin_var_tracker_(new PluginVarTracker(this)) { |
| 38 SetSerialization(new PluginVarSerialization(plugin_var_tracker_.get())); |
| 39 |
| 40 // As a plugin, we always support the PPP_Class interface. There's no |
| 41 // GetInterface call or name for it, so we insert it into our table now. |
| 42 InjectProxy(INTERFACE_ID_PPP_CLASS, "$Internal_PPP_Class", |
| 43 new PPP_Class_Proxy(this)); |
| 44 } |
| 45 |
| 46 PluginDispatcher::~PluginDispatcher() { |
| 47 if (shutdown_module_) |
| 48 shutdown_module_(); |
| 49 } |
| 50 |
| 51 // static |
| 52 PluginDispatcher* PluginDispatcher::Get() { |
| 53 return g_dispatcher; |
| 54 } |
| 55 |
| 56 // static |
| 57 void PluginDispatcher::SetGlobal(PluginDispatcher* dispatcher) { |
| 58 DCHECK(!dispatcher || !g_dispatcher); |
| 59 g_dispatcher = dispatcher; |
| 60 } |
| 61 |
| 62 void PluginDispatcher::OnMessageReceived(const IPC::Message& msg) { |
| 63 if (msg.routing_id() == MSG_ROUTING_CONTROL) { |
| 64 // Handle some plugin-specific control messages. |
| 65 IPC_BEGIN_MESSAGE_MAP(PluginDispatcher, msg) |
| 66 IPC_MESSAGE_HANDLER(PpapiMsg_InitializeModule, OnInitializeModule) |
| 67 |
| 68 // Forward all other control messages to the superclass. |
| 69 IPC_MESSAGE_UNHANDLED(Dispatcher::OnMessageReceived(msg)) |
| 70 IPC_END_MESSAGE_MAP() |
| 71 return; |
| 72 } |
| 73 |
| 74 // All non-control messages get handled by the superclass. |
| 75 Dispatcher::OnMessageReceived(msg); |
| 76 } |
| 77 |
| 78 void PluginDispatcher::OnInitializeModule(PP_Module pp_module, bool* result) { |
| 79 set_pp_module(pp_module); |
| 80 *result = init_module_(pp_module, &GetInterfaceFromDispatcher) == PP_OK; |
| 81 } |
| 82 |
| 83 } // namespace proxy |
| 84 } // namespace pp |
| 85 |
OLD | NEW |