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