Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: ppapi/proxy/interface_list.cc

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

Powered by Google App Engine
This is Rietveld 408576698