blob: 070c6f375d773684b3e913dbbe188bb1072a405b [file] [log] [blame]
[email protected]6761d632012-04-18 17:54:491// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]5c966022011-09-13 18:09:372// 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>
dchengced92242016-04-07 00:00:129#include <memory>
[email protected]5c966022011-09-13 18:09:3710#include <string>
avi6e1b4e72016-12-29 22:02:5711#include <unordered_map>
[email protected]5c966022011-09-13 18:09:3712
avie029c4132015-12-23 06:45:2213#include "base/macros.h"
dmichaelfee3a512014-09-18 21:32:1314#include "base/synchronization/lock.h"
[email protected]5c966022011-09-13 18:09:3715#include "ppapi/proxy/interface_proxy.h"
[email protected]195d4cde2012-10-02 18:12:4116#include "ppapi/proxy/ppapi_proxy_export.h"
17#include "ppapi/shared_impl/ppapi_permissions.h"
[email protected]5c966022011-09-13 18:09:3718
19namespace ppapi {
20namespace proxy {
21
[email protected]84350ef2013-12-19 17:10:5022class PPAPI_PROXY_EXPORT InterfaceList {
[email protected]5c966022011-09-13 18:09:3723 public:
24 InterfaceList();
25 ~InterfaceList();
26
27 static InterfaceList* GetInstance();
28
[email protected]195d4cde2012-10-02 18:12:4129 // 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]84350ef2013-12-19 17:10:5039 static void SetProcessGlobalPermissions(const PpapiPermissions& permissions);
[email protected]195d4cde2012-10-02 18:12:4140
[email protected]5c966022011-09-13 18:09:3741 // Looks up the factory function for the given ID. Returns NULL if not
42 // supported.
[email protected]ac4b54d2011-10-20 23:09:2843 InterfaceProxy::Factory GetFactoryForID(ApiID id) const;
[email protected]5c966022011-09-13 18:09:3744
45 // Returns the interface pointer for the given browser or plugin interface,
46 // or NULL if it's not supported.
[email protected]ea441832014-02-05 15:34:2147 const void* GetInterfaceForPPB(const std::string& name);
[email protected]5c966022011-09-13 18:09:3748 const void* GetInterfaceForPPP(const std::string& name) const;
49
50 private:
[email protected]84350ef2013-12-19 17:10:5051 friend class InterfaceListTest;
52
dmichaelfee3a512014-09-18 21:32:1353 class InterfaceInfo {
54 public:
[email protected]058cebc2013-12-17 17:49:3955 InterfaceInfo(const void* in_interface, Permission in_perm)
dmichaelfee3a512014-09-18 21:32:1356 : iface_(in_interface),
57 required_permission_(in_perm),
58 sent_to_uma_(false) {
[email protected]5c966022011-09-13 18:09:3759 }
60
dmichaelfee3a512014-09-18 21:32:1361 const void* iface() { return iface_; }
[email protected]195d4cde2012-10-02 18:12:4162
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 Weber199cd022019-02-07 19:07:5466 Permission required_permission() { return required_permission_; }
[email protected]ea441832014-02-05 15:34:2167
dmichaelfee3a512014-09-18 21:32:1368 // 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-Malekea753082021-04-07 22:38:1371 void LogWithUmaOnce(const std::string& name);
72
dmichaelfee3a512014-09-18 21:32:1373 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]5c966022011-09-13 18:09:3781 };
dmichaelfee3a512014-09-18 21:32:1382 // Give friendship for HashInterfaceName.
83 friend class InterfaceInfo;
[email protected]5c966022011-09-13 18:09:3784
avi6e1b4e72016-12-29 22:02:5785 using NameToInterfaceInfoMap =
86 std::unordered_map<std::string, std::unique_ptr<InterfaceInfo>>;
[email protected]5c966022011-09-13 18:09:3787
[email protected]ac4b54d2011-10-20 23:09:2888 void AddProxy(ApiID id, InterfaceProxy::Factory factory);
[email protected]5c966022011-09-13 18:09:3789
[email protected]195d4cde2012-10-02 18:12:4190 // 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]058cebc2013-12-17 17:49:3993 void AddPPB(const char* name, const void* iface, Permission permission);
94 void AddPPP(const char* name, const void* iface);
[email protected]5c966022011-09-13 18:09:3795
[email protected]ea441832014-02-05 15:34:2196 // Hash the interface name for UMA logging.
97 static int HashInterfaceName(const std::string& name);
98
[email protected]195d4cde2012-10-02 18:12:4199 PpapiPermissions permissions_;
100
[email protected]5c966022011-09-13 18:09:37101 NameToInterfaceInfoMap name_to_browser_info_;
102 NameToInterfaceInfoMap name_to_plugin_info_;
103
[email protected]ac4b54d2011-10-20 23:09:28104 InterfaceProxy::Factory id_to_factory_[API_ID_COUNT];
[email protected]5c966022011-09-13 18:09:37105
106 DISALLOW_COPY_AND_ASSIGN(InterfaceList);
107};
108
109} // namespace proxy
110} // namespace ppapi
111
112#endif // PPAPI_PROXY_INTERFACE_LIST_H_
113