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/interface_list.h" | 5 #include "ppapi/proxy/interface_list.h" |
6 | 6 |
7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
8 #include "base/memory/singleton.h" | 8 #include "base/memory/singleton.h" |
9 #include "ppapi/c/dev/ppb_alarms_dev.h" | 9 #include "ppapi/c/dev/ppb_alarms_dev.h" |
10 #include "ppapi/c/dev/ppb_audio_input_dev.h" | 10 #include "ppapi/c/dev/ppb_audio_input_dev.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 public: | 158 public: |
159 static const ApiID kApiID = API_ID_NONE; | 159 static const ApiID kApiID = API_ID_NONE; |
160 }; | 160 }; |
161 | 161 |
162 template<typename ProxyClass> | 162 template<typename ProxyClass> |
163 InterfaceProxy* ProxyFactory(Dispatcher* dispatcher) { | 163 InterfaceProxy* ProxyFactory(Dispatcher* dispatcher) { |
164 return new ProxyClass(dispatcher); | 164 return new ProxyClass(dispatcher); |
165 } | 165 } |
166 | 166 |
167 base::LazyInstance<PpapiPermissions> g_process_global_permissions; | 167 base::LazyInstance<PpapiPermissions> g_process_global_permissions; |
| 168 base::LazyInstance<bool> g_supports_dev_channel; |
168 | 169 |
169 } // namespace | 170 } // namespace |
170 | 171 |
171 InterfaceList::InterfaceList() { | 172 InterfaceList::InterfaceList() { |
172 memset(id_to_factory_, 0, sizeof(id_to_factory_)); | 173 memset(id_to_factory_, 0, sizeof(id_to_factory_)); |
173 | 174 |
174 // Register the API factories for each of the API types. This calls AddProxy | 175 // Register the API factories for each of the API types. This calls AddProxy |
175 // for each InterfaceProxy type we support. | 176 // for each InterfaceProxy type we support. |
176 #define PROXIED_API(api_name) \ | 177 #define PROXIED_API(api_name) \ |
177 AddProxy(PROXY_API_ID(api_name), &PROXY_FACTORY_NAME(api_name)); | 178 AddProxy(PROXY_API_ID(api_name), &PROXY_FACTORY_NAME(api_name)); |
178 | 179 |
179 // Register each proxied interface by calling AddPPB for each supported | 180 // Register each proxied interface by calling AddPPB for each supported |
180 // interface. Set current_required_permission to the appropriate value for | 181 // interface. Set current_required_permission to the appropriate value for |
181 // the value you want expanded by this macro. | 182 // the value you want expanded by this macro. |
182 #define PROXIED_IFACE(api_name, iface_str, iface_struct) \ | 183 #define PROXIED_IFACE(api_name, iface_str, iface_struct) \ |
183 AddPPB(iface_str, PROXY_API_ID(api_name), \ | 184 AddPPB(iface_str, PROXY_API_ID(api_name), \ |
184 INTERFACE_THUNK_NAME(iface_struct)(), \ | 185 INTERFACE_THUNK_NAME(iface_struct)(), \ |
185 current_required_permission); | 186 current_required_permission); |
186 | 187 |
187 { | 188 { |
188 Permission current_required_permission = PERMISSION_NONE; | 189 Permission current_required_permission = PERMISSION_NONE; |
189 #include "ppapi/thunk/interfaces_ppb_private_no_permissions.h" | 190 #include "ppapi/thunk/interfaces_ppb_private_no_permissions.h" |
190 #include "ppapi/thunk/interfaces_ppb_public_stable.h" | 191 #include "ppapi/thunk/interfaces_ppb_public_stable.h" |
191 } | 192 } |
192 | |
193 { | 193 { |
194 Permission current_required_permission = PERMISSION_DEV; | 194 Permission current_required_permission = PERMISSION_DEV; |
195 #include "ppapi/thunk/interfaces_ppb_public_dev.h" | 195 #include "ppapi/thunk/interfaces_ppb_public_dev.h" |
196 } | 196 } |
197 { | 197 { |
198 Permission current_required_permission = PERMISSION_PRIVATE; | 198 Permission current_required_permission = PERMISSION_PRIVATE; |
199 #include "ppapi/thunk/interfaces_ppb_private.h" | 199 #include "ppapi/thunk/interfaces_ppb_private.h" |
200 } | 200 } |
201 { | 201 { |
202 #if !defined(OS_NACL) | 202 #if !defined(OS_NACL) |
203 Permission current_required_permission = PERMISSION_FLASH; | 203 Permission current_required_permission = PERMISSION_FLASH; |
204 #include "ppapi/thunk/interfaces_ppb_private_flash.h" | 204 #include "ppapi/thunk/interfaces_ppb_private_flash.h" |
205 #endif // !defined(OS_NACL) | 205 #endif // !defined(OS_NACL) |
206 } | 206 } |
207 | 207 |
| 208 // TODO(teravest): Add dev channel interfaces here. |
| 209 |
208 #undef PROXIED_API | 210 #undef PROXIED_API |
209 #undef PROXIED_IFACE | 211 #undef PROXIED_IFACE |
210 | 212 |
211 // Manually add some special proxies. Some of these don't have interfaces | 213 // Manually add some special proxies. Some of these don't have interfaces |
212 // that they support, so aren't covered by the macros above, but have proxies | 214 // that they support, so aren't covered by the macros above, but have proxies |
213 // for message routing. Others have different implementations between the | 215 // for message routing. Others have different implementations between the |
214 // proxy and the impl and there's no obvious message routing. | 216 // proxy and the impl and there's no obvious message routing. |
215 AddProxy(API_ID_RESOURCE_CREATION, &ResourceCreationProxy::Create); | 217 AddProxy(API_ID_RESOURCE_CREATION, &ResourceCreationProxy::Create); |
216 AddProxy(API_ID_PPP_CLASS, &PPP_Class_Proxy::Create); | 218 AddProxy(API_ID_PPP_CLASS, &PPP_Class_Proxy::Create); |
217 AddPPB(PPB_CORE_INTERFACE_1_0, API_ID_PPB_CORE, | 219 AddPPB(PPB_CORE_INTERFACE_1_0, API_ID_PPB_CORE, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 InterfaceList* InterfaceList::GetInstance() { | 305 InterfaceList* InterfaceList::GetInstance() { |
304 return Singleton<InterfaceList>::get(); | 306 return Singleton<InterfaceList>::get(); |
305 } | 307 } |
306 | 308 |
307 // static | 309 // static |
308 void InterfaceList::SetProcessGlobalPermissions( | 310 void InterfaceList::SetProcessGlobalPermissions( |
309 const PpapiPermissions& permissions) { | 311 const PpapiPermissions& permissions) { |
310 g_process_global_permissions.Get() = permissions; | 312 g_process_global_permissions.Get() = permissions; |
311 } | 313 } |
312 | 314 |
| 315 // static |
| 316 void InterfaceList::SetSupportsDevChannel( |
| 317 bool supports_dev_channel) { |
| 318 g_supports_dev_channel.Get() = supports_dev_channel; |
| 319 } |
| 320 |
313 ApiID InterfaceList::GetIDForPPBInterface(const std::string& name) const { | 321 ApiID InterfaceList::GetIDForPPBInterface(const std::string& name) const { |
314 NameToInterfaceInfoMap::const_iterator found = | 322 NameToInterfaceInfoMap::const_iterator found = |
315 name_to_browser_info_.find(name); | 323 name_to_browser_info_.find(name); |
316 if (found == name_to_browser_info_.end()) | 324 if (found == name_to_browser_info_.end()) |
317 return API_ID_NONE; | 325 return API_ID_NONE; |
318 return found->second.id; | 326 return found->second.id; |
319 } | 327 } |
320 | 328 |
321 ApiID InterfaceList::GetIDForPPPInterface(const std::string& name) const { | 329 ApiID InterfaceList::GetIDForPPPInterface(const std::string& name) const { |
322 NameToInterfaceInfoMap::const_iterator found = | 330 NameToInterfaceInfoMap::const_iterator found = |
(...skipping 10 matching lines...) Expand all Loading... |
333 return NULL; | 341 return NULL; |
334 return id_to_factory_[index]; | 342 return id_to_factory_[index]; |
335 } | 343 } |
336 | 344 |
337 const void* InterfaceList::GetInterfaceForPPB(const std::string& name) const { | 345 const void* InterfaceList::GetInterfaceForPPB(const std::string& name) const { |
338 NameToInterfaceInfoMap::const_iterator found = | 346 NameToInterfaceInfoMap::const_iterator found = |
339 name_to_browser_info_.find(name); | 347 name_to_browser_info_.find(name); |
340 if (found == name_to_browser_info_.end()) | 348 if (found == name_to_browser_info_.end()) |
341 return NULL; | 349 return NULL; |
342 | 350 |
| 351 // Dev channel checking goes here. |
| 352 |
343 if (g_process_global_permissions.Get().HasPermission( | 353 if (g_process_global_permissions.Get().HasPermission( |
344 found->second.required_permission)) | 354 found->second.required_permission)) |
345 return found->second.iface; | 355 return found->second.iface; |
346 return NULL; | 356 return NULL; |
347 } | 357 } |
348 | 358 |
349 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { | 359 const void* InterfaceList::GetInterfaceForPPP(const std::string& name) const { |
350 NameToInterfaceInfoMap::const_iterator found = | 360 NameToInterfaceInfoMap::const_iterator found = |
351 name_to_plugin_info_.find(name); | 361 name_to_plugin_info_.find(name); |
352 if (found == name_to_plugin_info_.end()) | 362 if (found == name_to_plugin_info_.end()) |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 name_to_plugin_info_[name] = InterfaceInfo(id, iface, PERMISSION_NONE); | 395 name_to_plugin_info_[name] = InterfaceInfo(id, iface, PERMISSION_NONE); |
386 } | 396 } |
387 | 397 |
388 void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { | 398 void InterfaceList::AddPPP(const InterfaceProxy::Info* info) { |
389 AddProxy(info->id, info->create_proxy); | 399 AddProxy(info->id, info->create_proxy); |
390 AddPPP(info->name, info->id, info->interface_ptr); | 400 AddPPP(info->name, info->id, info->interface_ptr); |
391 } | 401 } |
392 | 402 |
393 } // namespace proxy | 403 } // namespace proxy |
394 } // namespace ppapi | 404 } // namespace ppapi |
OLD | NEW |