[email protected] | 6761d63 | 2012-04-18 17:54:49 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 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> |
dcheng | ced9224 | 2016-04-07 00:00:12 | [diff] [blame] | 9 | #include <memory> |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 10 | #include <string> |
avi | 6e1b4e7 | 2016-12-29 22:02:57 | [diff] [blame] | 11 | #include <unordered_map> |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 12 | |
avi | e029c413 | 2015-12-23 06:45:22 | [diff] [blame] | 13 | #include "base/macros.h" |
dmichael | fee3a51 | 2014-09-18 21:32:13 | [diff] [blame] | 14 | #include "base/synchronization/lock.h" |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 15 | #include "ppapi/proxy/interface_proxy.h" |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 16 | #include "ppapi/proxy/ppapi_proxy_export.h" |
| 17 | #include "ppapi/shared_impl/ppapi_permissions.h" |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 18 | |
| 19 | namespace ppapi { |
| 20 | namespace proxy { |
| 21 | |
[email protected] | 84350ef | 2013-12-19 17:10:50 | [diff] [blame] | 22 | class PPAPI_PROXY_EXPORT InterfaceList { |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 23 | public: |
| 24 | InterfaceList(); |
| 25 | ~InterfaceList(); |
| 26 | |
| 27 | static InterfaceList* GetInstance(); |
| 28 | |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 29 | // Sets the permissions that the interface list will use to compute |
| 30 | // whether an interface is available to the current process. By default, |
| 31 | // this will be "no permissions", which will give only access to public |
| 32 | // stable interfaces via GetInterface. |
| 33 | // |
| 34 | // IMPORTANT: This is not a security boundary. Malicious plugins can bypass |
| 35 | // this check since they run in the same address space as this code in the |
| 36 | // plugin process. A real security check is required for all IPC messages. |
| 37 | // This check just allows us to return NULL for interfaces you "shouldn't" be |
| 38 | // using to keep honest plugins honest. |
[email protected] | 84350ef | 2013-12-19 17:10:50 | [diff] [blame] | 39 | static void SetProcessGlobalPermissions(const PpapiPermissions& permissions); |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 40 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 41 | // Looks up the factory function for the given ID. Returns NULL if not |
| 42 | // supported. |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 43 | InterfaceProxy::Factory GetFactoryForID(ApiID id) const; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 44 | |
| 45 | // Returns the interface pointer for the given browser or plugin interface, |
| 46 | // or NULL if it's not supported. |
[email protected] | ea44183 | 2014-02-05 15:34:21 | [diff] [blame] | 47 | const void* GetInterfaceForPPB(const std::string& name); |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 48 | const void* GetInterfaceForPPP(const std::string& name) const; |
| 49 | |
| 50 | private: |
[email protected] | 84350ef | 2013-12-19 17:10:50 | [diff] [blame] | 51 | friend class InterfaceListTest; |
| 52 | |
dmichael | fee3a51 | 2014-09-18 21:32:13 | [diff] [blame] | 53 | class InterfaceInfo { |
| 54 | public: |
[email protected] | 058cebc | 2013-12-17 17:49:39 | [diff] [blame] | 55 | InterfaceInfo(const void* in_interface, Permission in_perm) |
dmichael | fee3a51 | 2014-09-18 21:32:13 | [diff] [blame] | 56 | : iface_(in_interface), |
| 57 | required_permission_(in_perm), |
| 58 | sent_to_uma_(false) { |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 59 | } |
| 60 | |
dmichael | fee3a51 | 2014-09-18 21:32:13 | [diff] [blame] | 61 | const void* iface() { return iface_; } |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 62 | |
| 63 | // Permission required to return non-null for this interface. This will |
| 64 | // be checked with the value set via SetProcessGlobalPermissionBits when |
| 65 | // an interface is requested. |
Nico Weber | 199cd02 | 2019-02-07 19:07:54 | [diff] [blame] | 66 | Permission required_permission() { return required_permission_; } |
[email protected] | ea44183 | 2014-02-05 15:34:21 | [diff] [blame] | 67 | |
dmichael | fee3a51 | 2014-09-18 21:32:13 | [diff] [blame] | 68 | // Call this any time the interface is requested. It will log a UMA count |
| 69 | // only the first time. This is safe to call from any thread, regardless of |
| 70 | // whether the proxy lock is held. |
John Abd-El-Malek | ea75308 | 2021-04-07 22:38:13 | [diff] [blame^] | 71 | void LogWithUmaOnce(const std::string& name); |
| 72 | |
dmichael | fee3a51 | 2014-09-18 21:32:13 | [diff] [blame] | 73 | private: |
| 74 | DISALLOW_COPY_AND_ASSIGN(InterfaceInfo); |
| 75 | |
| 76 | const void* const iface_; |
| 77 | const Permission required_permission_; |
| 78 | |
| 79 | bool sent_to_uma_; |
| 80 | base::Lock sent_to_uma_lock_; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 81 | }; |
dmichael | fee3a51 | 2014-09-18 21:32:13 | [diff] [blame] | 82 | // Give friendship for HashInterfaceName. |
| 83 | friend class InterfaceInfo; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 84 | |
avi | 6e1b4e7 | 2016-12-29 22:02:57 | [diff] [blame] | 85 | using NameToInterfaceInfoMap = |
| 86 | std::unordered_map<std::string, std::unique_ptr<InterfaceInfo>>; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 87 | |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 88 | void AddProxy(ApiID id, InterfaceProxy::Factory factory); |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 89 | |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 90 | // Permissions is the type of permission required to access the corresponding |
| 91 | // interface. Currently this must be just one unique permission (rather than |
| 92 | // a bitfield). |
[email protected] | 058cebc | 2013-12-17 17:49:39 | [diff] [blame] | 93 | void AddPPB(const char* name, const void* iface, Permission permission); |
| 94 | void AddPPP(const char* name, const void* iface); |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 95 | |
[email protected] | ea44183 | 2014-02-05 15:34:21 | [diff] [blame] | 96 | // Hash the interface name for UMA logging. |
| 97 | static int HashInterfaceName(const std::string& name); |
| 98 | |
[email protected] | 195d4cde | 2012-10-02 18:12:41 | [diff] [blame] | 99 | PpapiPermissions permissions_; |
| 100 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 101 | NameToInterfaceInfoMap name_to_browser_info_; |
| 102 | NameToInterfaceInfoMap name_to_plugin_info_; |
| 103 | |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 104 | InterfaceProxy::Factory id_to_factory_[API_ID_COUNT]; |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 105 | |
| 106 | DISALLOW_COPY_AND_ASSIGN(InterfaceList); |
| 107 | }; |
| 108 | |
| 109 | } // namespace proxy |
| 110 | } // namespace ppapi |
| 111 | |
| 112 | #endif // PPAPI_PROXY_INTERFACE_LIST_H_ |
| 113 | |