OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/interface_list.h" |
| 6 |
| 7 #include "base/memory/singleton.h" |
| 8 #include "ppapi/c/dev/ppb_buffer_dev.h" |
| 9 #include "ppapi/c/dev/ppb_char_set_dev.h" |
| 10 #include "ppapi/c/dev/ppb_console_dev.h" |
| 11 #include "ppapi/c/dev/ppb_context_3d_dev.h" |
| 12 #include "ppapi/c/dev/ppb_crypto_dev.h" |
| 13 #include "ppapi/c/dev/ppb_cursor_control_dev.h" |
| 14 #include "ppapi/c/dev/ppb_gles_chromium_texture_mapping_dev.h" |
| 15 #include "ppapi/c/dev/ppb_font_dev.h" |
| 16 #include "ppapi/c/dev/ppb_memory_dev.h" |
| 17 #include "ppapi/c/dev/ppb_mouse_lock_dev.h" |
| 18 #include "ppapi/c/dev/ppb_surface_3d_dev.h" |
| 19 #include "ppapi/c/dev/ppb_testing_dev.h" |
| 20 #include "ppapi/c/dev/ppb_url_util_dev.h" |
| 21 #include "ppapi/c/dev/ppb_var_deprecated.h" |
| 22 #include "ppapi/c/dev/ppb_video_capture_dev.h" |
| 23 #include "ppapi/c/pp_errors.h" |
| 24 #include "ppapi/c/ppb_audio.h" |
| 25 #include "ppapi/c/ppb_audio_config.h" |
| 26 #include "ppapi/c/ppb_core.h" |
| 27 #include "ppapi/c/ppb_file_ref.h" |
| 28 #include "ppapi/c/ppb_file_system.h" |
| 29 #include "ppapi/c/ppb_graphics_2d.h" |
| 30 #include "ppapi/c/ppb_image_data.h" |
| 31 #include "ppapi/c/ppb_input_event.h" |
| 32 #include "ppapi/c/ppb_instance.h" |
| 33 #include "ppapi/c/ppb_messaging.h" |
| 34 #include "ppapi/c/ppb_opengles.h" |
| 35 #include "ppapi/c/ppb_url_loader.h" |
| 36 #include "ppapi/c/ppb_url_request_info.h" |
| 37 #include "ppapi/c/ppb_url_response_info.h" |
| 38 #include "ppapi/c/ppb_var.h" |
| 39 #include "ppapi/c/ppp_instance.h" |
| 40 #include "ppapi/c/private/ppb_flash.h" |
| 41 #include "ppapi/c/private/ppb_flash_clipboard.h" |
| 42 #include "ppapi/c/private/ppb_flash_file.h" |
| 43 #include "ppapi/c/private/ppb_flash_menu.h" |
| 44 #include "ppapi/c/private/ppb_flash_net_connector.h" |
| 45 #include "ppapi/c/private/ppb_flash_tcp_socket.h" |
| 46 #include "ppapi/c/private/ppb_pdf.h" |
| 47 #include "ppapi/c/trusted/ppb_broker_trusted.h" |
| 48 #include "ppapi/c/trusted/ppb_url_loader_trusted.h" |
| 49 #include "ppapi/proxy/interface_proxy.h" |
| 50 #include "ppapi/proxy/ppb_audio_proxy.h" |
| 51 #include "ppapi/proxy/ppb_broker_proxy.h" |
| 52 #include "ppapi/proxy/ppb_buffer_proxy.h" |
| 53 #include "ppapi/proxy/ppb_char_set_proxy.h" |
| 54 #include "ppapi/proxy/ppb_context_3d_proxy.h" |
| 55 #include "ppapi/proxy/ppb_core_proxy.h" |
| 56 #include "ppapi/proxy/ppb_crypto_proxy.h" |
| 57 #include "ppapi/proxy/ppb_cursor_control_proxy.h" |
| 58 #include "ppapi/proxy/ppb_file_chooser_proxy.h" |
| 59 #include "ppapi/proxy/ppb_file_ref_proxy.h" |
| 60 #include "ppapi/proxy/ppb_file_system_proxy.h" |
| 61 #include "ppapi/proxy/ppb_flash_clipboard_proxy.h" |
| 62 #include "ppapi/proxy/ppb_flash_file_proxy.h" |
| 63 #include "ppapi/proxy/ppb_flash_proxy.h" |
| 64 #include "ppapi/proxy/ppb_flash_menu_proxy.h" |
| 65 #include "ppapi/proxy/ppb_flash_net_connector_proxy.h" |
| 66 #include "ppapi/proxy/ppb_flash_tcp_socket_proxy.h" |
| 67 #include "ppapi/proxy/ppb_font_proxy.h" |
| 68 #include "ppapi/proxy/ppb_graphics_2d_proxy.h" |
| 69 #include "ppapi/proxy/ppb_graphics_3d_proxy.h" |
| 70 #include "ppapi/proxy/ppb_image_data_proxy.h" |
| 71 #include "ppapi/proxy/ppb_instance_proxy.h" |
| 72 #include "ppapi/proxy/ppb_memory_proxy.h" |
| 73 #include "ppapi/proxy/ppp_mouse_lock_proxy.h" |
| 74 #include "ppapi/proxy/ppb_pdf_proxy.h" |
| 75 #include "ppapi/proxy/ppb_surface_3d_proxy.h" |
| 76 #include "ppapi/proxy/ppb_testing_proxy.h" |
| 77 #include "ppapi/proxy/ppb_url_loader_proxy.h" |
| 78 #include "ppapi/proxy/ppb_url_response_info_proxy.h" |
| 79 #include "ppapi/proxy/ppb_url_util_proxy.h" |
| 80 #include "ppapi/proxy/ppb_var_deprecated_proxy.h" |
| 81 #include "ppapi/proxy/ppb_var_proxy.h" |
| 82 #include "ppapi/proxy/ppb_video_capture_proxy.h" |
| 83 #include "ppapi/proxy/ppb_video_decoder_proxy.h" |
| 84 #include "ppapi/proxy/ppp_class_proxy.h" |
| 85 #include "ppapi/proxy/ppp_graphics_3d_proxy.h" |
| 86 #include "ppapi/proxy/ppp_input_event_proxy.h" |
| 87 #include "ppapi/proxy/ppp_instance_private_proxy.h" |
| 88 #include "ppapi/proxy/ppp_instance_proxy.h" |
| 89 #include "ppapi/proxy/ppp_messaging_proxy.h" |
| 90 #include "ppapi/proxy/ppp_video_decoder_proxy.h" |
| 91 #include "ppapi/proxy/resource_creation_proxy.h" |
| 92 #include "ppapi/shared_impl/opengles2_impl.h" |
| 93 #include "ppapi/thunk/thunk.h" |
| 94 |
| 95 // Helper to get the proxy name PPB_Foo_Proxy given the API name PPB_Foo. |
| 96 #define PROXY_CLASS_NAME(api_name) api_name##_Proxy |
| 97 |
| 98 // Helper to get the interface ID PPB_Foo_Proxy::kInterfaceID given the API |
| 99 // name PPB_Foo. |
| 100 #define PROXY_INTERFACE_ID(api_name) PROXY_CLASS_NAME(api_name)::kInterfaceID |
| 101 |
| 102 // Helper to get the name of the factory function CreatePPB_Foo_Proxy given |
| 103 // the API name PPB_Foo. |
| 104 #define PROXY_FACTORY_NAME(api_name) Create##api_name##_Proxy |
| 105 |
| 106 // Helper to get the name of the thunk GetPPB_Foo_1_0_Thunk given the interface |
| 107 // struct name PPB_Foo_1_0. |
| 108 #define INTERFACE_THUNK_NAME(iface_struct) thunk::Get##iface_struct##_Thunk |
| 109 |
| 110 namespace ppapi { |
| 111 namespace proxy { |
| 112 |
| 113 namespace { |
| 114 |
| 115 // The interface list has interfaces with no ID listed as "NoAPIName" which |
| 116 // means there's no corresponding _Proxy object. Our macros expand this to |
| 117 // NoAPIName_Proxy, and then they look for kInterfaceID inside it. |
| 118 // |
| 119 // This dummy class provides the correct definition for that interface ID, |
| 120 // which is "NONE". |
| 121 class NoAPIName_Proxy { |
| 122 public: |
| 123 static const InterfaceID kInterfaceID = INTERFACE_ID_NONE; |
| 124 }; |
| 125 |
| 126 // Define factory functions for each interface type. These are of the form: |
| 127 // InterfaceProxy* CreatePPB_URLLoader_Proxy(... |
| 128 #define PROXIED_API(api_name) \ |
| 129 InterfaceProxy* PROXY_FACTORY_NAME(api_name)(Dispatcher* dispatcher) { \ |
| 130 return new PROXY_CLASS_NAME(api_name)(dispatcher); \ |
| 131 } |
| 132 #include "ppapi/thunk/interfaces_ppb_public_stable.h" |
| 133 #include "ppapi/thunk/interfaces_ppb_public_dev.h" |
| 134 #include "ppapi/thunk/interfaces_ppb_private.h" |
| 135 #undef PROXIED_API |
| 136 |
| 137 } // namespace |
| 138 |
| 139 InterfaceList::InterfaceList() { |
| 140 memset(id_to_factory_, 0, sizeof(id_to_factory_)); |
| 141 |
| 142 // Register the API factories for each of the API types. This calls AddProxy |
| 143 // for each InterfaceProxy type we support. |
| 144 #define PROXIED_API(api_name) \ |
| 145 AddProxy(PROXY_INTERFACE_ID(api_name), &PROXY_FACTORY_NAME(api_name)); |
| 146 |
| 147 // Register each proxied interface by calling AddPPB for each supported |
| 148 // interface. |
| 149 #define PROXIED_IFACE(api_name, iface_str, iface_struct) \ |
| 150 AddPPB(iface_str, PROXY_INTERFACE_ID(api_name), \ |
| 151 INTERFACE_THUNK_NAME(iface_struct)()); |
| 152 |
| 153 #include "ppapi/thunk/interfaces_ppb_public_stable.h" |
| 154 #include "ppapi/thunk/interfaces_ppb_public_dev.h" |
| 155 #include "ppapi/thunk/interfaces_ppb_private.h" |
| 156 |
| 157 #undef PROXIED_API |
| 158 #undef PROXIED_IFACE |
| 159 |
| 160 // New-style AddPPB not converted to the macros above. |
| 161 AddPPB(PPB_CORE_INTERFACE, INTERFACE_ID_PPB_CORE, |
| 162 PPB_Core_Proxy::GetPPB_Core_Interface()); |
| 163 AddPPB(PPB_MEMORY_DEV_INTERFACE, INTERFACE_ID_NONE, |
| 164 GetPPB_Memory_Interface()); |
| 165 AddPPB(PPB_OPENGLES2_INTERFACE, INTERFACE_ID_NONE, |
| 166 OpenGLES2Impl::GetInterface()); |
| 167 AddPPB(PPB_VAR_INTERFACE, INTERFACE_ID_NONE, |
| 168 GetPPB_Var_Interface()); |
| 169 |
| 170 // Manually add some special proxies. These don't have interfaces that they |
| 171 // support, so aren't covered by the macros above, but have proxies for |
| 172 // message routing. |
| 173 AddProxy(INTERFACE_ID_RESOURCE_CREATION, &ResourceCreationProxy::Create); |
| 174 AddProxy(INTERFACE_ID_PPP_CLASS, &PPP_Class_Proxy::Create); |
| 175 |
| 176 // PPB (browser) interfaces. |
| 177 AddPPB(PPB_Crypto_Proxy::GetInfo()); |
| 178 AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo()); |
| 179 AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo()); |
| 180 AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo()); |
| 181 AddPPB(PPB_Flash_Menu_Proxy::GetInfo()); |
| 182 AddPPB(PPB_Flash_Proxy::GetInfo()); |
| 183 AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo()); |
| 184 AddPPB(PPB_Instance_Proxy::GetInfoFullscreen()); |
| 185 AddPPB(PPB_Instance_Proxy::GetInfoPrivate()); |
| 186 AddPPB(PPB_PDF_Proxy::GetInfo()); |
| 187 AddPPB(PPB_Testing_Proxy::GetInfo()); |
| 188 AddPPB(PPB_URLLoader_Proxy::GetTrustedInfo()); |
| 189 AddPPB(PPB_URLUtil_Proxy::GetInfo()); |
| 190 AddPPB(PPB_Var_Deprecated_Proxy::GetInfo()); |
| 191 |
| 192 #ifdef ENABLE_FLAPPER_HACKS |
| 193 AddPPB(PPB_Flash_NetConnector_Proxy::GetInfo()); |
| 194 #endif |
| 195 |
| 196 // PPP (plugin) interfaces. |
| 197 AddPPP(PPP_Graphics3D_Proxy::GetInfo()); |
| 198 AddPPP(PPP_InputEvent_Proxy::GetInfo()); |
| 199 AddPPP(PPP_Instance_Private_Proxy::GetInfo()); |
| 200 AddPPP(PPP_Instance_Proxy::GetInfo1_0()); |
| 201 AddPPP(PPP_Messaging_Proxy::GetInfo()); |
| 202 AddPPP(PPP_MouseLock_Proxy::GetInfo()); |
| 203 AddPPP(PPP_VideoCapture_Proxy::GetInfo()); |
| 204 AddPPP(PPP_VideoDecoder_Proxy::GetInfo()); |
| 205 } |
| 206 |
| 207 InterfaceList::~InterfaceList() { |
| 208 } |
| 209 |
| 210 // static |
| 211 InterfaceList* InterfaceList::GetInstance() { |
| 212 return Singleton<InterfaceList>::get(); |
| 213 } |
| 214 |
| 215 InterfaceID InterfaceList::GetIDForPPBInterface(const std::string& name) const { |
| 216 NameToInterfaceInfoMap::const_iterator found = |
| 217 name_to_browser_info_.find(name); |
| 218 if (found == name_to_browser_info_.end()) |
| 219 return INTERFACE_ID_NONE; |
| 220 return found->second.id; |
| 221 } |
| 222 |
| 223 InterfaceID InterfaceList::GetIDForPPPInterface(const std::string& name) const { |
| 224 NameToInterfaceInfoMap::const_iterator found = |
| 225 name_to_plugin_info_.find(name); |
| 226 if (found == name_to_plugin_info_.end()) |
| 227 return INTERFACE_ID_NONE; |
| 228 return found->second.id; |
| 229 } |
| 230 |
| 231 InterfaceProxy::Factory InterfaceList::GetFactoryForID(InterfaceID id) const { |
| 232 int index = static_cast<int>(id); |
| 233 COMPILE_ASSERT(INTERFACE_ID_NONE == 0, none_must_be_zero); |
| 234 if (id <= 0 || id >= INTERFACE_ID_COUNT) |
| 235 return NULL; |
| 236 return id_to_factory_[index]; |
| 237 } |
| 238 |
| 239 const void* InterfaceList::GetInterfaceForPPB(const std::string& name) const { |
| 240 NameToInterfaceInfoMap::const_iterator found = |
| 241 name_to_browser_info_.find(name); |
| 242 if (found == name_to_browser_info_.end()) |
| 243 return NULL; |
| 244 return found->second.interface; |
| 245 } |
| 246 |
| 247 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { |
| 248 NameToInterfaceInfoMap::const_iterator found = |
| 249 name_to_plugin_info_.find(name); |
| 250 if (found == name_to_plugin_info_.end()) |
| 251 return NULL; |
| 252 return found->second.interface; |
| 253 } |
| 254 |
| 255 void InterfaceList::AddProxy(InterfaceID id, |
| 256 InterfaceProxy::Factory factory) { |
| 257 // For interfaces with no corresponding _Proxy objects, the macros will |
| 258 // generate calls to this function with INTERFACE_ID_NONE. This means we |
| 259 // should just skip adding a factory for these functions. |
| 260 if (id == INTERFACE_ID_NONE) |
| 261 return; |
| 262 |
| 263 // The factory should be an exact dupe of the one we already have if it |
| 264 // has already been registered before. |
| 265 int index = static_cast<int>(id); |
| 266 DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory); |
| 267 |
| 268 id_to_factory_[index] = factory; |
| 269 } |
| 270 |
| 271 void InterfaceList::AddPPB(const char* name, |
| 272 InterfaceID id, |
| 273 const void* interface) { |
| 274 DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end()); |
| 275 name_to_browser_info_[name] = InterfaceInfo(id, interface); |
| 276 } |
| 277 |
| 278 void InterfaceList::AddPPP(const char* name, |
| 279 InterfaceID id, |
| 280 const void* interface) { |
| 281 DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end()); |
| 282 name_to_plugin_info_[name] = InterfaceInfo(id, interface); |
| 283 } |
| 284 |
| 285 void InterfaceList::AddPPB(const InterfaceProxy::Info* info) { |
| 286 AddProxy(info->id, info->create_proxy); |
| 287 AddPPB(info->name, info->id, info->interface_ptr); |
| 288 } |
| 289 |
| 290 void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { |
| 291 AddProxy(info->id, info->create_proxy); |
| 292 AddPPP(info->name, info->id, info->interface_ptr); |
| 293 } |
| 294 |
| 295 } // namespace proxy |
| 296 } // namespace ppapi |
OLD | NEW |