OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/interface_list.h" | 5 #include "ppapi/proxy/interface_list.h" |
6 | 6 |
7 #include "base/memory/singleton.h" | 7 #include "base/memory/singleton.h" |
8 #include "ppapi/c/dev/ppb_buffer_dev.h" | 8 #include "ppapi/c/dev/ppb_buffer_dev.h" |
9 #include "ppapi/c/dev/ppb_char_set_dev.h" | 9 #include "ppapi/c/dev/ppb_char_set_dev.h" |
10 #include "ppapi/c/dev/ppb_console_dev.h" | 10 #include "ppapi/c/dev/ppb_console_dev.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 #include "ppapi/proxy/ppp_instance_proxy.h" | 92 #include "ppapi/proxy/ppp_instance_proxy.h" |
93 #include "ppapi/proxy/ppp_messaging_proxy.h" | 93 #include "ppapi/proxy/ppp_messaging_proxy.h" |
94 #include "ppapi/proxy/ppp_video_decoder_proxy.h" | 94 #include "ppapi/proxy/ppp_video_decoder_proxy.h" |
95 #include "ppapi/proxy/resource_creation_proxy.h" | 95 #include "ppapi/proxy/resource_creation_proxy.h" |
96 #include "ppapi/shared_impl/opengles2_impl.h" | 96 #include "ppapi/shared_impl/opengles2_impl.h" |
97 #include "ppapi/thunk/thunk.h" | 97 #include "ppapi/thunk/thunk.h" |
98 | 98 |
99 // Helper to get the proxy name PPB_Foo_Proxy given the API name PPB_Foo. | 99 // Helper to get the proxy name PPB_Foo_Proxy given the API name PPB_Foo. |
100 #define PROXY_CLASS_NAME(api_name) api_name##_Proxy | 100 #define PROXY_CLASS_NAME(api_name) api_name##_Proxy |
101 | 101 |
102 // Helper to get the interface ID PPB_Foo_Proxy::kInterfaceID given the API | 102 // Helper to get the interface ID PPB_Foo_Proxy::kApiID given the API |
103 // name PPB_Foo. | 103 // name PPB_Foo. |
104 #define PROXY_INTERFACE_ID(api_name) PROXY_CLASS_NAME(api_name)::kInterfaceID | 104 #define PROXY_API_ID(api_name) PROXY_CLASS_NAME(api_name)::kApiID |
105 | 105 |
106 // Helper to get the name of the factory function CreatePPB_Foo_Proxy given | 106 // Helper to get the name of the factory function CreatePPB_Foo_Proxy given |
107 // the API name PPB_Foo. | 107 // the API name PPB_Foo. |
108 #define PROXY_FACTORY_NAME(api_name) Create##api_name##_Proxy | 108 #define PROXY_FACTORY_NAME(api_name) Create##api_name##_Proxy |
109 | 109 |
110 // Helper to get the name of the thunk GetPPB_Foo_1_0_Thunk given the interface | 110 // Helper to get the name of the thunk GetPPB_Foo_1_0_Thunk given the interface |
111 // struct name PPB_Foo_1_0. | 111 // struct name PPB_Foo_1_0. |
112 #define INTERFACE_THUNK_NAME(iface_struct) thunk::Get##iface_struct##_Thunk | 112 #define INTERFACE_THUNK_NAME(iface_struct) thunk::Get##iface_struct##_Thunk |
113 | 113 |
114 namespace ppapi { | 114 namespace ppapi { |
115 namespace proxy { | 115 namespace proxy { |
116 | 116 |
117 namespace { | 117 namespace { |
118 | 118 |
119 // The interface list has interfaces with no ID listed as "NoAPIName" which | 119 // The interface list has interfaces with no ID listed as "NoAPIName" which |
120 // means there's no corresponding _Proxy object. Our macros expand this to | 120 // means there's no corresponding _Proxy object. Our macros expand this to |
121 // NoAPIName_Proxy, and then they look for kInterfaceID inside it. | 121 // NoAPIName_Proxy, and then they look for kApiID inside it. |
122 // | 122 // |
123 // This dummy class provides the correct definition for that interface ID, | 123 // This dummy class provides the correct definition for that interface ID, |
124 // which is "NONE". | 124 // which is "NONE". |
125 class NoAPIName_Proxy { | 125 class NoAPIName_Proxy { |
126 public: | 126 public: |
127 static const InterfaceID kInterfaceID = INTERFACE_ID_NONE; | 127 static const ApiID kApiID = API_ID_NONE; |
128 }; | 128 }; |
129 | 129 |
130 // Define factory functions for each interface type. These are of the form: | 130 // Define factory functions for each interface type. These are of the form: |
131 // InterfaceProxy* CreatePPB_URLLoader_Proxy(... | 131 // InterfaceProxy* CreatePPB_URLLoader_Proxy(... |
132 #define PROXIED_API(api_name) \ | 132 #define PROXIED_API(api_name) \ |
133 InterfaceProxy* PROXY_FACTORY_NAME(api_name)(Dispatcher* dispatcher) { \ | 133 InterfaceProxy* PROXY_FACTORY_NAME(api_name)(Dispatcher* dispatcher) { \ |
134 return new PROXY_CLASS_NAME(api_name)(dispatcher); \ | 134 return new PROXY_CLASS_NAME(api_name)(dispatcher); \ |
135 } | 135 } |
136 #include "ppapi/thunk/interfaces_ppb_public_stable.h" | 136 #include "ppapi/thunk/interfaces_ppb_public_stable.h" |
137 #include "ppapi/thunk/interfaces_ppb_public_dev.h" | 137 #include "ppapi/thunk/interfaces_ppb_public_dev.h" |
138 #include "ppapi/thunk/interfaces_ppb_private.h" | 138 #include "ppapi/thunk/interfaces_ppb_private.h" |
139 #undef PROXIED_API | 139 #undef PROXIED_API |
140 | 140 |
141 } // namespace | 141 } // namespace |
142 | 142 |
143 InterfaceList::InterfaceList() { | 143 InterfaceList::InterfaceList() { |
144 memset(id_to_factory_, 0, sizeof(id_to_factory_)); | 144 memset(id_to_factory_, 0, sizeof(id_to_factory_)); |
145 | 145 |
146 // Register the API factories for each of the API types. This calls AddProxy | 146 // Register the API factories for each of the API types. This calls AddProxy |
147 // for each InterfaceProxy type we support. | 147 // for each InterfaceProxy type we support. |
148 #define PROXIED_API(api_name) \ | 148 #define PROXIED_API(api_name) \ |
149 AddProxy(PROXY_INTERFACE_ID(api_name), &PROXY_FACTORY_NAME(api_name)); | 149 AddProxy(PROXY_API_ID(api_name), &PROXY_FACTORY_NAME(api_name)); |
150 | 150 |
151 // Register each proxied interface by calling AddPPB for each supported | 151 // Register each proxied interface by calling AddPPB for each supported |
152 // interface. | 152 // interface. |
153 #define PROXIED_IFACE(api_name, iface_str, iface_struct) \ | 153 #define PROXIED_IFACE(api_name, iface_str, iface_struct) \ |
154 AddPPB(iface_str, PROXY_INTERFACE_ID(api_name), \ | 154 AddPPB(iface_str, PROXY_API_ID(api_name), \ |
155 INTERFACE_THUNK_NAME(iface_struct)()); | 155 INTERFACE_THUNK_NAME(iface_struct)()); |
156 | 156 |
157 #include "ppapi/thunk/interfaces_ppb_public_stable.h" | 157 #include "ppapi/thunk/interfaces_ppb_public_stable.h" |
158 #include "ppapi/thunk/interfaces_ppb_public_dev.h" | 158 #include "ppapi/thunk/interfaces_ppb_public_dev.h" |
159 #include "ppapi/thunk/interfaces_ppb_private.h" | 159 #include "ppapi/thunk/interfaces_ppb_private.h" |
160 | 160 |
161 #undef PROXIED_API | 161 #undef PROXIED_API |
162 #undef PROXIED_IFACE | 162 #undef PROXIED_IFACE |
163 | 163 |
164 // Manually add some special proxies. Some of these don't have interfaces | 164 // Manually add some special proxies. Some of these don't have interfaces |
165 // that they support, so aren't covered by the macros above, but have proxies | 165 // that they support, so aren't covered by the macros above, but have proxies |
166 // for message routing. Others have different implementations between the | 166 // for message routing. Others have different implementations between the |
167 // proxy and the impl and there's no obvious message routing. | 167 // proxy and the impl and there's no obvious message routing. |
168 AddProxy(INTERFACE_ID_RESOURCE_CREATION, &ResourceCreationProxy::Create); | 168 AddProxy(API_ID_RESOURCE_CREATION, &ResourceCreationProxy::Create); |
169 AddProxy(INTERFACE_ID_PPP_CLASS, &PPP_Class_Proxy::Create); | 169 AddProxy(API_ID_PPP_CLASS, &PPP_Class_Proxy::Create); |
170 AddPPB(PPB_CORE_INTERFACE, INTERFACE_ID_PPB_CORE, | 170 AddPPB(PPB_CORE_INTERFACE, API_ID_PPB_CORE, |
171 PPB_Core_Proxy::GetPPB_Core_Interface()); | 171 PPB_Core_Proxy::GetPPB_Core_Interface()); |
172 AddPPB(PPB_OPENGLES2_INTERFACE, INTERFACE_ID_NONE, | 172 AddPPB(PPB_OPENGLES2_INTERFACE, API_ID_NONE, |
173 OpenGLES2Impl::GetInterface()); | 173 OpenGLES2Impl::GetInterface()); |
174 AddPPB(PPB_VAR_INTERFACE, INTERFACE_ID_NONE, | 174 AddPPB(PPB_VAR_INTERFACE, API_ID_NONE, |
175 GetPPB_Var_Interface()); | 175 GetPPB_Var_Interface()); |
176 | 176 |
177 // PPB (browser) interfaces. | 177 // PPB (browser) interfaces. |
178 AddPPB(PPB_FileChooser_Proxy::GetTrustedInfo()); | 178 AddPPB(PPB_FileChooser_Proxy::GetTrustedInfo()); |
179 AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo()); | 179 AddPPB(PPB_Flash_Clipboard_Proxy::GetInfo()); |
180 AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo()); | 180 AddPPB(PPB_Flash_File_FileRef_Proxy::GetInfo()); |
181 AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo()); | 181 AddPPB(PPB_Flash_File_ModuleLocal_Proxy::GetInfo()); |
182 AddPPB(PPB_Flash_Menu_Proxy::GetInfo()); | 182 AddPPB(PPB_Flash_Menu_Proxy::GetInfo()); |
183 AddPPB(PPB_Flash_Proxy::GetInfo()); | 183 AddPPB(PPB_Flash_Proxy::GetInfo()); |
184 AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo()); | 184 AddPPB(PPB_Flash_TCPSocket_Proxy::GetInfo()); |
(...skipping 20 matching lines...) Expand all Loading... |
205 } | 205 } |
206 | 206 |
207 InterfaceList::~InterfaceList() { | 207 InterfaceList::~InterfaceList() { |
208 } | 208 } |
209 | 209 |
210 // static | 210 // static |
211 InterfaceList* InterfaceList::GetInstance() { | 211 InterfaceList* InterfaceList::GetInstance() { |
212 return Singleton<InterfaceList>::get(); | 212 return Singleton<InterfaceList>::get(); |
213 } | 213 } |
214 | 214 |
215 InterfaceID InterfaceList::GetIDForPPBInterface(const std::string& name) const { | 215 ApiID InterfaceList::GetIDForPPBInterface(const std::string& name) const { |
216 NameToInterfaceInfoMap::const_iterator found = | 216 NameToInterfaceInfoMap::const_iterator found = |
217 name_to_browser_info_.find(name); | 217 name_to_browser_info_.find(name); |
218 if (found == name_to_browser_info_.end()) | 218 if (found == name_to_browser_info_.end()) |
219 return INTERFACE_ID_NONE; | 219 return API_ID_NONE; |
220 return found->second.id; | 220 return found->second.id; |
221 } | 221 } |
222 | 222 |
223 InterfaceID InterfaceList::GetIDForPPPInterface(const std::string& name) const { | 223 ApiID InterfaceList::GetIDForPPPInterface(const std::string& name) const { |
224 NameToInterfaceInfoMap::const_iterator found = | 224 NameToInterfaceInfoMap::const_iterator found = |
225 name_to_plugin_info_.find(name); | 225 name_to_plugin_info_.find(name); |
226 if (found == name_to_plugin_info_.end()) | 226 if (found == name_to_plugin_info_.end()) |
227 return INTERFACE_ID_NONE; | 227 return API_ID_NONE; |
228 return found->second.id; | 228 return found->second.id; |
229 } | 229 } |
230 | 230 |
231 InterfaceProxy::Factory InterfaceList::GetFactoryForID(InterfaceID id) const { | 231 InterfaceProxy::Factory InterfaceList::GetFactoryForID(ApiID id) const { |
232 int index = static_cast<int>(id); | 232 int index = static_cast<int>(id); |
233 COMPILE_ASSERT(INTERFACE_ID_NONE == 0, none_must_be_zero); | 233 COMPILE_ASSERT(API_ID_NONE == 0, none_must_be_zero); |
234 if (id <= 0 || id >= INTERFACE_ID_COUNT) | 234 if (id <= 0 || id >= API_ID_COUNT) |
235 return NULL; | 235 return NULL; |
236 return id_to_factory_[index]; | 236 return id_to_factory_[index]; |
237 } | 237 } |
238 | 238 |
239 const void* InterfaceList::GetInterfaceForPPB(const std::string& name) const { | 239 const void* InterfaceList::GetInterfaceForPPB(const std::string& name) const { |
240 NameToInterfaceInfoMap::const_iterator found = | 240 NameToInterfaceInfoMap::const_iterator found = |
241 name_to_browser_info_.find(name); | 241 name_to_browser_info_.find(name); |
242 if (found == name_to_browser_info_.end()) | 242 if (found == name_to_browser_info_.end()) |
243 return NULL; | 243 return NULL; |
244 return found->second.iface; | 244 return found->second.iface; |
245 } | 245 } |
246 | 246 |
247 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { | 247 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { |
248 NameToInterfaceInfoMap::const_iterator found = | 248 NameToInterfaceInfoMap::const_iterator found = |
249 name_to_plugin_info_.find(name); | 249 name_to_plugin_info_.find(name); |
250 if (found == name_to_plugin_info_.end()) | 250 if (found == name_to_plugin_info_.end()) |
251 return NULL; | 251 return NULL; |
252 return found->second.iface; | 252 return found->second.iface; |
253 } | 253 } |
254 | 254 |
255 void InterfaceList::AddProxy(InterfaceID id, | 255 void InterfaceList::AddProxy(ApiID id, |
256 InterfaceProxy::Factory factory) { | 256 InterfaceProxy::Factory factory) { |
257 // For interfaces with no corresponding _Proxy objects, the macros will | 257 // For interfaces with no corresponding _Proxy objects, the macros will |
258 // generate calls to this function with INTERFACE_ID_NONE. This means we | 258 // generate calls to this function with API_ID_NONE. This means we |
259 // should just skip adding a factory for these functions. | 259 // should just skip adding a factory for these functions. |
260 if (id == INTERFACE_ID_NONE) | 260 if (id == API_ID_NONE) |
261 return; | 261 return; |
262 | 262 |
263 // The factory should be an exact dupe of the one we already have if it | 263 // The factory should be an exact dupe of the one we already have if it |
264 // has already been registered before. | 264 // has already been registered before. |
265 int index = static_cast<int>(id); | 265 int index = static_cast<int>(id); |
266 DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory); | 266 DCHECK(!id_to_factory_[index] || id_to_factory_[index] == factory); |
267 | 267 |
268 id_to_factory_[index] = factory; | 268 id_to_factory_[index] = factory; |
269 } | 269 } |
270 | 270 |
271 void InterfaceList::AddPPB(const char* name, | 271 void InterfaceList::AddPPB(const char* name, |
272 InterfaceID id, | 272 ApiID id, |
273 const void* iface) { | 273 const void* iface) { |
274 DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end()); | 274 DCHECK(name_to_browser_info_.find(name) == name_to_browser_info_.end()); |
275 name_to_browser_info_[name] = InterfaceInfo(id, iface); | 275 name_to_browser_info_[name] = InterfaceInfo(id, iface); |
276 } | 276 } |
277 | 277 |
278 void InterfaceList::AddPPP(const char* name, | 278 void InterfaceList::AddPPP(const char* name, |
279 InterfaceID id, | 279 ApiID id, |
280 const void* iface) { | 280 const void* iface) { |
281 DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end()); | 281 DCHECK(name_to_plugin_info_.find(name) == name_to_plugin_info_.end()); |
282 name_to_plugin_info_[name] = InterfaceInfo(id, iface); | 282 name_to_plugin_info_[name] = InterfaceInfo(id, iface); |
283 } | 283 } |
284 | 284 |
285 void InterfaceList::AddPPB(const InterfaceProxy::Info* info) { | 285 void InterfaceList::AddPPB(const InterfaceProxy::Info* info) { |
286 AddProxy(info->id, info->create_proxy); | 286 AddProxy(info->id, info->create_proxy); |
287 AddPPB(info->name, info->id, info->interface_ptr); | 287 AddPPB(info->name, info->id, info->interface_ptr); |
288 } | 288 } |
289 | 289 |
290 void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { | 290 void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { |
291 AddProxy(info->id, info->create_proxy); | 291 AddProxy(info->id, info->create_proxy); |
292 AddPPP(info->name, info->id, info->interface_ptr); | 292 AddPPP(info->name, info->id, info->interface_ptr); |
293 } | 293 } |
294 | 294 |
295 } // namespace proxy | 295 } // namespace proxy |
296 } // namespace ppapi | 296 } // namespace ppapi |
OLD | NEW |