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 // Perms are the permission bits in ppapi::Permissions that are required to |
bbudge
2012/10/01 17:32:01
Not clear what 'Perms' refers to. How about:
// Th
| |
80 // access the corresponding interface. | |
81 void AddPPB(const char* name, ApiID id, const void* iface, | |
82 Permission permission); | |
58 void AddPPP(const char* name, ApiID id, const void* iface); | 83 void AddPPP(const char* name, ApiID id, const void* iface); |
59 | 84 |
60 // Old-style add functions. These should be removed when the rest of the | 85 // Old-style add functions. These should be removed when the rest of the |
61 // proxies are converted over to using the new system. | 86 // proxies are converted over to using the new system. |
62 void AddPPB(const InterfaceProxy::Info* info); | 87 void AddPPB(const InterfaceProxy::Info* info, Permission perm); |
63 void AddPPP(const InterfaceProxy::Info* info); | 88 void AddPPP(const InterfaceProxy::Info* info); |
64 | 89 |
90 PpapiPermissions permissions_; | |
91 | |
65 NameToInterfaceInfoMap name_to_browser_info_; | 92 NameToInterfaceInfoMap name_to_browser_info_; |
66 NameToInterfaceInfoMap name_to_plugin_info_; | 93 NameToInterfaceInfoMap name_to_plugin_info_; |
67 | 94 |
68 InterfaceProxy::Factory id_to_factory_[API_ID_COUNT]; | 95 InterfaceProxy::Factory id_to_factory_[API_ID_COUNT]; |
69 | 96 |
70 DISALLOW_COPY_AND_ASSIGN(InterfaceList); | 97 DISALLOW_COPY_AND_ASSIGN(InterfaceList); |
71 }; | 98 }; |
72 | 99 |
73 } // namespace proxy | 100 } // namespace proxy |
74 } // namespace ppapi | 101 } // namespace ppapi |
75 | 102 |
76 #endif // PPAPI_PROXY_INTERFACE_LIST_H_ | 103 #endif // PPAPI_PROXY_INTERFACE_LIST_H_ |
77 | 104 |
OLD | NEW |