Connect PPAPI IPC channels for non-SFI mode.
[chromium-blink-merge.git] / extensions / common / permissions / api_permission.h
blobaaf1d6efa4e04b17c6d4fac05ae752e937e56d6a
1 // Copyright 2013 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 EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_
6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_
8 #include <map>
9 #include <set>
10 #include <string>
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/pickle.h"
15 #include "base/values.h"
16 #include "extensions/common/permissions/permission_message.h"
18 namespace IPC {
19 class Message;
22 namespace extensions {
24 class APIPermissionInfo;
25 class ChromeAPIPermissions;
27 // APIPermission is for handling some complex permissions. Please refer to
28 // extensions::SocketPermission as an example.
29 // There is one instance per permission per loaded extension.
30 class APIPermission {
31 public:
32 enum ID {
33 // Error codes.
34 kInvalid = -2,
35 kUnknown = -1,
37 // Real permissions.
38 kActiveTab,
39 kActivityLogPrivate,
40 kAdView,
41 kAlarms,
42 kAlwaysOnTopWindows,
43 kAudio,
44 kAudioCapture,
45 kAutoTestPrivate,
46 kBackground,
47 kBookmark,
48 kBookmarkManagerPrivate,
49 kBrailleDisplayPrivate,
50 kBrowsingData,
51 kCast,
52 kCastStreaming,
53 kChromeosInfoPrivate,
54 kClipboardRead,
55 kClipboardWrite,
56 kCloudPrintPrivate,
57 kCommandLinePrivate,
58 kContentSettings,
59 kContextMenus,
60 kCookie,
61 kDiagnostics,
62 kDial,
63 kDebugger,
64 kDeclarative,
65 kDeclarativeContent,
66 kDeclarativeWebRequest,
67 kDesktopCapture,
68 kDeveloperPrivate,
69 kDevtools,
70 kDns,
71 kDownloads,
72 kDownloadsInternal,
73 kDownloadsOpen,
74 kDownloadsShelf,
75 kEchoPrivate,
76 kEnterprisePlatformKeysPrivate,
77 kExperimental,
78 kFeedbackPrivate,
79 kFileBrowserHandler,
80 kFileBrowserHandlerInternal,
81 kFileBrowserPrivate,
82 kFileSystem,
83 kFileSystemDirectory,
84 kFileSystemProvider,
85 kFileSystemRetainEntries,
86 kFileSystemWrite,
87 kFileSystemWriteDirectory,
88 kFontSettings,
89 kFullscreen,
90 kGcm,
91 kGeolocation,
92 kHid,
93 kHistory,
94 kHomepage,
95 kHotwordPrivate,
96 kIdentity,
97 kIdentityPrivate,
98 kIdltest,
99 kIdle,
100 kInfobars,
101 kInput,
102 kInputMethodPrivate,
103 kLocation,
104 kLogPrivate,
105 kManagement,
106 kMediaGalleries,
107 kMediaGalleriesPrivate,
108 kMediaPlayerPrivate,
109 kMetricsPrivate,
110 kMDns,
111 kMusicManagerPrivate,
112 kNativeMessaging,
113 kNetworkingPrivate,
114 kNotification,
115 kOverrideEscFullscreen,
116 kPageCapture,
117 kPointerLock,
118 kPlugin,
119 kPower,
120 kPreferencesPrivate,
121 kPrincipalsPrivate,
122 kPrivacy,
123 kProcesses,
124 kProxy,
125 kPushMessaging,
126 kImageWriterPrivate,
127 kReadingListPrivate,
128 kRtcPrivate,
129 kSearchProvider,
130 kSerial,
131 kSessions,
132 kSignedInDevices,
133 kSocket,
134 kStartupPages,
135 kStorage,
136 kStreamsPrivate,
137 kSyncFileSystem,
138 kSystemPrivate,
139 kSystemIndicator,
140 kSystemDisplay,
141 kSystemStorage,
142 kTab,
143 kTabCapture,
144 kTabCaptureForTab,
145 kTerminalPrivate,
146 kTopSites,
147 kTts,
148 kTtsEngine,
149 kUnlimitedStorage,
150 kUsb,
151 kUsbDevice,
152 kVideoCapture,
153 kVirtualKeyboardPrivate,
154 kWallpaper,
155 kWallpaperPrivate,
156 kWebConnectable, // for externally_connectable manifest key
157 kWebNavigation,
158 kWebRequest,
159 kWebRequestBlocking,
160 kWebRequestInternal,
161 kWebrtcAudioPrivate,
162 kWebrtcLoggingPrivate,
163 kWebstorePrivate,
164 kWebView,
165 kScreenlockPrivate,
166 kSystemCpu,
167 kSystemMemory,
168 kSystemNetwork,
169 kSystemInfoCpu,
170 kSystemInfoMemory,
171 kFirstRunPrivate,
172 kEnumBoundary
175 struct CheckParam {
178 explicit APIPermission(const APIPermissionInfo* info);
180 virtual ~APIPermission();
182 // Returns the id of this permission.
183 ID id() const;
185 // Returns the name of this permission.
186 const char* name() const;
188 // Returns the APIPermission of this permission.
189 const APIPermissionInfo* info() const {
190 return info_;
193 // Returns true if this permission has any PermissionMessages.
194 virtual bool HasMessages() const = 0;
196 // Returns the localized permission messages of this permission.
197 virtual PermissionMessages GetMessages() const = 0;
199 // Returns true if the given permission is allowed.
200 virtual bool Check(const CheckParam* param) const = 0;
202 // Returns true if |rhs| is a subset of this.
203 virtual bool Contains(const APIPermission* rhs) const = 0;
205 // Returns true if |rhs| is equal to this.
206 virtual bool Equal(const APIPermission* rhs) const = 0;
208 // Parses the APIPermission from |value|. Returns false if an error happens
209 // and optionally set |error| if |error| is not NULL.
210 virtual bool FromValue(const base::Value* value, std::string* error) = 0;
212 // Stores this into a new created |value|.
213 virtual scoped_ptr<base::Value> ToValue() const = 0;
215 // Clones this.
216 virtual APIPermission* Clone() const = 0;
218 // Returns a new API permission which equals this - |rhs|.
219 virtual APIPermission* Diff(const APIPermission* rhs) const = 0;
221 // Returns a new API permission which equals the union of this and |rhs|.
222 virtual APIPermission* Union(const APIPermission* rhs) const = 0;
224 // Returns a new API permission which equals the intersect of this and |rhs|.
225 virtual APIPermission* Intersect(const APIPermission* rhs) const = 0;
227 // IPC functions
228 // Writes this into the given IPC message |m|.
229 virtual void Write(IPC::Message* m) const = 0;
231 // Reads from the given IPC message |m|.
232 virtual bool Read(const IPC::Message* m, PickleIterator* iter) = 0;
234 // Logs this permission.
235 virtual void Log(std::string* log) const = 0;
237 protected:
238 // Returns the localized permission message associated with this api.
239 // Use GetMessage_ to avoid name conflict with macro GetMessage on Windows.
240 PermissionMessage GetMessage_() const;
242 private:
243 const APIPermissionInfo* const info_;
247 // The APIPermissionInfo is an immutable class that describes a single
248 // named permission (API permission).
249 // There is one instance per permission.
250 class APIPermissionInfo {
251 public:
252 enum Flag {
253 kFlagNone = 0,
255 // Indicates if the permission implies full access (native code).
256 kFlagImpliesFullAccess = 1 << 0,
258 // Indicates if the permission implies full URL access.
259 kFlagImpliesFullURLAccess = 1 << 1,
261 // Indicates that extensions cannot specify the permission as optional.
262 kFlagCannotBeOptional = 1 << 3,
264 // Indicates that the permission is internal to the extensions
265 // system and cannot be specified in the "permissions" list.
266 kFlagInternal = 1 << 4,
269 typedef APIPermission* (*APIPermissionConstructor)(const APIPermissionInfo*);
271 typedef std::set<APIPermission::ID> IDSet;
273 ~APIPermissionInfo();
275 // Creates a APIPermission instance.
276 APIPermission* CreateAPIPermission() const;
278 int flags() const { return flags_; }
280 APIPermission::ID id() const { return id_; }
282 // Returns the message id associated with this permission.
283 PermissionMessage::ID message_id() const {
284 return message_id_;
287 // Returns the name of this permission.
288 const char* name() const { return name_; }
290 // Returns true if this permission implies full access (e.g., native code).
291 bool implies_full_access() const {
292 return (flags_ & kFlagImpliesFullAccess) != 0;
295 // Returns true if this permission implies full URL access.
296 bool implies_full_url_access() const {
297 return (flags_ & kFlagImpliesFullURLAccess) != 0;
300 // Returns true if this permission can be added and removed via the
301 // optional permissions extension API.
302 bool supports_optional() const {
303 return (flags_ & kFlagCannotBeOptional) == 0;
306 // Returns true if this permission is internal rather than a
307 // "permissions" list entry.
308 bool is_internal() const {
309 return (flags_ & kFlagInternal) != 0;
312 private:
313 // Instances should only be constructed from within a PermissionsProvider.
314 friend class ChromeAPIPermissions;
315 // Implementations of APIPermission will want to get the permission message,
316 // but this class's implementation should be hidden from everyone else.
317 friend class APIPermission;
319 explicit APIPermissionInfo(
320 APIPermission::ID id,
321 const char* name,
322 int l10n_message_id,
323 PermissionMessage::ID message_id,
324 int flags,
325 APIPermissionConstructor api_permission_constructor);
327 // Returns the localized permission message associated with this api.
328 // Use GetMessage_ to avoid name conflict with macro GetMessage on Windows.
329 PermissionMessage GetMessage_() const;
331 const APIPermission::ID id_;
332 const char* const name_;
333 const int flags_;
334 const int l10n_message_id_;
335 const PermissionMessage::ID message_id_;
336 const APIPermissionConstructor api_permission_constructor_;
339 } // namespace extensions
341 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_