blob: 29050f113a2307b0a24af8fe4541cd2fa052241b [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
dmichaelfee3a512014-09-18 21:32:1313#include "base/synchronization/lock.h"
[email protected]5c966022011-09-13 18:09:3714#include "ppapi/proxy/interface_proxy.h"
[email protected]195d4cde2012-10-02 18:12:4115#include "ppapi/proxy/ppapi_proxy_export.h"
16#include "ppapi/shared_impl/ppapi_permissions.h"
[email protected]5c966022011-09-13 18:09:3717
18namespace ppapi {
19namespace proxy {
20
[email protected]84350ef2013-12-19 17:10:5021class PPAPI_PROXY_EXPORT InterfaceList {
[email protected]5c966022011-09-13 18:09:3722 public:
23 InterfaceList();
Peter Boström3d5b3cb2021-09-23 21:35:4524
25 InterfaceList(const InterfaceList&) = delete;
26 InterfaceList& operator=(const InterfaceList&) = delete;
27
[email protected]5c966022011-09-13 18:09:3728 ~InterfaceList();
29
30 static InterfaceList* GetInstance();
31
[email protected]195d4cde2012-10-02 18:12:4132 // Sets the permissions that the interface list will use to compute
33 // whether an interface is available to the current process. By default,
34 // this will be "no permissions", which will give only access to public
35 // stable interfaces via GetInterface.
36 //
37 // IMPORTANT: This is not a security boundary. Malicious plugins can bypass
38 // this check since they run in the same address space as this code in the
39 // plugin process. A real security check is required for all IPC messages.
40 // This check just allows us to return NULL for interfaces you "shouldn't" be
41 // using to keep honest plugins honest.
[email protected]84350ef2013-12-19 17:10:5042 static void SetProcessGlobalPermissions(const PpapiPermissions& permissions);
[email protected]195d4cde2012-10-02 18:12:4143
[email protected]5c966022011-09-13 18:09:3744 // Looks up the factory function for the given ID. Returns NULL if not
45 // supported.
[email protected]ac4b54d2011-10-20 23:09:2846 InterfaceProxy::Factory GetFactoryForID(ApiID id) const;
[email protected]5c966022011-09-13 18:09:3747
48 // Returns the interface pointer for the given browser or plugin interface,
49 // or NULL if it's not supported.
[email protected]ea441832014-02-05 15:34:2150 const void* GetInterfaceForPPB(const std::string& name);
[email protected]5c966022011-09-13 18:09:3751 const void* GetInterfaceForPPP(const std::string& name) const;
52
53 private:
[email protected]84350ef2013-12-19 17:10:5054 friend class InterfaceListTest;
55
dmichaelfee3a512014-09-18 21:32:1356 class InterfaceInfo {
57 public:
[email protected]058cebc2013-12-17 17:49:3958 InterfaceInfo(const void* in_interface, Permission in_perm)
dmichaelfee3a512014-09-18 21:32:1359 : iface_(in_interface),
60 required_permission_(in_perm),
61 sent_to_uma_(false) {
[email protected]5c966022011-09-13 18:09:3762 }
63
Peter Boström896f1372021-11-05 01:12:3064 InterfaceInfo(const InterfaceInfo&) = delete;
65 InterfaceInfo& operator=(const InterfaceInfo&) = delete;
66
dmichaelfee3a512014-09-18 21:32:1367 const void* iface() { return iface_; }
[email protected]195d4cde2012-10-02 18:12:4168
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.
Nico Weber199cd022019-02-07 19:07:5472 Permission required_permission() { return required_permission_; }
[email protected]ea441832014-02-05 15:34:2173
dmichaelfee3a512014-09-18 21:32:1374 // Call this any time the interface is requested. It will log a UMA count
75 // only the first time. This is safe to call from any thread, regardless of
76 // whether the proxy lock is held.
John Abd-El-Malekea753082021-04-07 22:38:1377 void LogWithUmaOnce(const std::string& name);
78
dmichaelfee3a512014-09-18 21:32:1379 private:
dmichaelfee3a512014-09-18 21:32:1380 const void* const iface_;
81 const Permission required_permission_;
82
83 bool sent_to_uma_;
84 base::Lock sent_to_uma_lock_;
[email protected]5c966022011-09-13 18:09:3785 };
dmichaelfee3a512014-09-18 21:32:1386 // Give friendship for HashInterfaceName.
87 friend class InterfaceInfo;
[email protected]5c966022011-09-13 18:09:3788
avi6e1b4e72016-12-29 22:02:5789 using NameToInterfaceInfoMap =
90 std::unordered_map<std::string, std::unique_ptr<InterfaceInfo>>;
[email protected]5c966022011-09-13 18:09:3791
[email protected]ac4b54d2011-10-20 23:09:2892 void AddProxy(ApiID id, InterfaceProxy::Factory factory);
[email protected]5c966022011-09-13 18:09:3793
[email protected]195d4cde2012-10-02 18:12:4194 // Permissions is the type of permission required to access the corresponding
95 // interface. Currently this must be just one unique permission (rather than
96 // a bitfield).
[email protected]058cebc2013-12-17 17:49:3997 void AddPPB(const char* name, const void* iface, Permission permission);
98 void AddPPP(const char* name, const void* iface);
[email protected]5c966022011-09-13 18:09:3799
[email protected]ea441832014-02-05 15:34:21100 // Hash the interface name for UMA logging.
101 static int HashInterfaceName(const std::string& name);
102
[email protected]195d4cde2012-10-02 18:12:41103 PpapiPermissions permissions_;
104
[email protected]5c966022011-09-13 18:09:37105 NameToInterfaceInfoMap name_to_browser_info_;
106 NameToInterfaceInfoMap name_to_plugin_info_;
107
[email protected]ac4b54d2011-10-20 23:09:28108 InterfaceProxy::Factory id_to_factory_[API_ID_COUNT];
[email protected]5c966022011-09-13 18:09:37109};
110
111} // namespace proxy
112} // namespace ppapi
113
114#endif // PPAPI_PROXY_INTERFACE_LIST_H_