Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ppapi / proxy / interface_list.h
bloba2b4569c8f1b3b3693af6f85b068e82095a334c4
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
3 // found in the LICENSE file.
5 #ifndef PPAPI_PROXY_INTERFACE_LIST_H_
6 #define PPAPI_PROXY_INTERFACE_LIST_H_
8 #include <map>
9 #include <string>
11 #include "base/basictypes.h"
12 #include "ppapi/proxy/interface_proxy.h"
13 #include "ppapi/proxy/ppapi_proxy_export.h"
14 #include "ppapi/shared_impl/ppapi_permissions.h"
16 namespace ppapi {
17 namespace proxy {
19 class PPAPI_PROXY_EXPORT InterfaceList {
20 public:
21 InterfaceList();
22 ~InterfaceList();
24 static InterfaceList* GetInstance();
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.
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 void SetProcessGlobalPermissions(const PpapiPermissions& permissions);
38 // Looks up the factory function for the given ID. Returns NULL if not
39 // supported.
40 InterfaceProxy::Factory GetFactoryForID(ApiID id) const;
42 // Returns the interface pointer for the given browser or plugin interface,
43 // or NULL if it's not supported.
44 const void* GetInterfaceForPPB(const std::string& name);
45 const void* GetInterfaceForPPP(const std::string& name) const;
47 private:
48 friend class InterfaceListTest;
50 struct InterfaceInfo {
51 InterfaceInfo()
52 : iface(NULL),
53 required_permission(PERMISSION_NONE),
54 interface_logged(false) {
56 InterfaceInfo(const void* in_interface, Permission in_perm)
57 : iface(in_interface),
58 required_permission(in_perm),
59 interface_logged(false) {
62 const void* iface;
64 // Permission required to return non-null for this interface. This will
65 // be checked with the value set via SetProcessGlobalPermissionBits when
66 // an interface is requested.
67 Permission required_permission;
69 // Interface usage is logged just once per-interface-per-plugin-process.
70 bool interface_logged;
73 typedef std::map<std::string, InterfaceInfo> NameToInterfaceInfoMap;
75 void AddProxy(ApiID id, InterfaceProxy::Factory factory);
77 // Permissions is the type of permission required to access the corresponding
78 // interface. Currently this must be just one unique permission (rather than
79 // a bitfield).
80 void AddPPB(const char* name, const void* iface, Permission permission);
81 void AddPPP(const char* name, const void* iface);
83 // Hash the interface name for UMA logging.
84 static int HashInterfaceName(const std::string& name);
86 PpapiPermissions permissions_;
88 NameToInterfaceInfoMap name_to_browser_info_;
89 NameToInterfaceInfoMap name_to_plugin_info_;
91 InterfaceProxy::Factory id_to_factory_[API_ID_COUNT];
93 DISALLOW_COPY_AND_ASSIGN(InterfaceList);
96 } // namespace proxy
97 } // namespace ppapi
99 #endif // PPAPI_PROXY_INTERFACE_LIST_H_