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 3 // found in the LICENSE file. 4 5 #ifndef PPAPI_PROXY_INTERFACE_LIST_H_ 6 #define PPAPI_PROXY_INTERFACE_LIST_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/basictypes.h" 12 #include "ppapi/proxy/interface_proxy.h" 13 #include "ppapi/proxy/ppapi_proxy_export.h" 14 #include "ppapi/shared_impl/ppapi_permissions.h" 15 16 namespace ppapi { 17 namespace proxy { 18 19 class InterfaceList { 20 public: 21 InterfaceList(); 22 ~InterfaceList(); 23 24 static InterfaceList* GetInstance(); 25 26 // Sets the permissions that the interface list will use to compute 27 // whether an interface is available to the current process. By default, 28 // this will be "no permissions", which will give only access to public 29 // stable interfaces via GetInterface. 30 // 31 // IMPORTANT: This is not a security boundary. Malicious plugins can bypass 32 // this check since they run in the same address space as this code in the 33 // plugin process. A real security check is required for all IPC messages. 34 // This check just allows us to return NULL for interfaces you "shouldn't" be 35 // using to keep honest plugins honest. 36 static PPAPI_PROXY_EXPORT void SetProcessGlobalPermissions( 37 const PpapiPermissions& permissions); 38 static PPAPI_PROXY_EXPORT void SetSupportsDevChannel( 39 bool supports_dev_channel); 40 41 // Looks up the ID for the given interface name. Returns API_ID_NONE if 42 // the interface string is not found. 43 ApiID GetIDForPPBInterface(const std::string& name) const; 44 ApiID GetIDForPPPInterface(const std::string& name) const; 45 46 // Looks up the factory function for the given ID. Returns NULL if not 47 // supported. 48 InterfaceProxy::Factory GetFactoryForID(ApiID id) const; 49 50 // Returns the interface pointer for the given browser or plugin interface, 51 // or NULL if it's not supported. 52 const void* GetInterfaceForPPB(const std::string& name) const; 53 const void* GetInterfaceForPPP(const std::string& name) const; 54 55 private: 56 struct InterfaceInfo { 57 InterfaceInfo() 58 : id(API_ID_NONE), 59 iface(NULL), 60 required_permission(PERMISSION_NONE) { 61 } 62 InterfaceInfo(ApiID in_id, const void* in_interface, Permission in_perm) 63 : id(in_id), 64 iface(in_interface), 65 required_permission(in_perm) { 66 } 67 68 ApiID id; 69 const void* iface; 70 71 // Permission required to return non-null for this interface. This will 72 // be checked with the value set via SetProcessGlobalPermissionBits when 73 // an interface is requested. 74 Permission required_permission; 75 }; 76 77 typedef std::map<std::string, InterfaceInfo> NameToInterfaceInfoMap; 78 79 void AddProxy(ApiID id, InterfaceProxy::Factory factory); 80 81 // Permissions is the type of permission required to access the corresponding 82 // interface. Currently this must be just one unique permission (rather than 83 // a bitfield). 84 void AddPPB(const char* name, ApiID id, const void* iface, 85 Permission permission); 86 void AddPPP(const char* name, ApiID id, const void* iface); 87 88 // Old-style add functions. These should be removed when the rest of the 89 // proxies are converted over to using the new system. 90 void AddPPP(const InterfaceProxy::Info* info); 91 92 PpapiPermissions permissions_; 93 94 NameToInterfaceInfoMap name_to_browser_info_; 95 NameToInterfaceInfoMap name_to_plugin_info_; 96 97 InterfaceProxy::Factory id_to_factory_[API_ID_COUNT]; 98 99 DISALLOW_COPY_AND_ASSIGN(InterfaceList); 100 }; 101 102 } // namespace proxy 103 } // namespace ppapi 104 105 #endif // PPAPI_PROXY_INTERFACE_LIST_H_ 106 107