OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_ |
| 6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <set> |
| 10 |
| 11 #include "chrome/common/extensions/permissions/permission_message.h" |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 class PermissionsInfo; |
| 16 |
| 17 // The APIPermission is an immutable class that describes a single |
| 18 // named permission (API permission). |
| 19 class APIPermission { |
| 20 public: |
| 21 enum ID { |
| 22 // Error codes. |
| 23 kInvalid = -2, |
| 24 kUnknown = -1, |
| 25 |
| 26 // Real permissions. |
| 27 kActiveTab, |
| 28 kAlarms, |
| 29 kAppNotifications, |
| 30 kAudioCapture, |
| 31 kBackground, |
| 32 kBookmark, |
| 33 kBrowsingData, |
| 34 kChromeAuthPrivate, |
| 35 kChromeosInfoPrivate, |
| 36 kClipboardRead, |
| 37 kClipboardWrite, |
| 38 kContentSettings, |
| 39 kContextMenus, |
| 40 kCookie, |
| 41 kDebugger, |
| 42 kDeclarative, |
| 43 kDeclarativeWebRequest, |
| 44 kDevtools, |
| 45 kEchoPrivate, |
| 46 kDownloads, |
| 47 kExperimental, |
| 48 kFileBrowserHandler, |
| 49 kFileBrowserHandlerInternal, |
| 50 kFileBrowserPrivate, |
| 51 kFileSystem, |
| 52 kGeolocation, |
| 53 kHistory, |
| 54 kIdle, |
| 55 kInput, |
| 56 kInputMethodPrivate, |
| 57 kKeybinding, |
| 58 kManagedModePrivate, |
| 59 kManagement, |
| 60 kMediaPlayerPrivate, |
| 61 kMetricsPrivate, |
| 62 kNotification, |
| 63 kPageCapture, |
| 64 kPlugin, |
| 65 kPrivacy, |
| 66 kProxy, |
| 67 kSocket, |
| 68 kStorage, |
| 69 kSystemPrivate, |
| 70 kTab, |
| 71 kTerminalPrivate, |
| 72 kTopSites, |
| 73 kTts, |
| 74 kTtsEngine, |
| 75 kUnlimitedStorage, |
| 76 kUsb, |
| 77 kVideoCapture, |
| 78 kWebNavigation, |
| 79 kWebRequest, |
| 80 kWebRequestBlocking, |
| 81 kWebRequestInternal, |
| 82 kWebSocketProxyPrivate, |
| 83 kWebstorePrivate, |
| 84 kEnumBoundary |
| 85 }; |
| 86 |
| 87 enum Flag { |
| 88 kFlagNone = 0, |
| 89 |
| 90 // Indicates if the permission implies full access (native code). |
| 91 kFlagImpliesFullAccess = 1 << 0, |
| 92 |
| 93 // Indicates if the permission implies full URL access. |
| 94 kFlagImpliesFullURLAccess = 1 << 1, |
| 95 |
| 96 // Indicates that extensions cannot specify the permission as optional. |
| 97 kFlagCannotBeOptional = 1 << 3 |
| 98 }; |
| 99 |
| 100 typedef std::set<ID> IDSet; |
| 101 |
| 102 ~APIPermission(); |
| 103 |
| 104 // Returns the localized permission message associated with this api. |
| 105 PermissionMessage GetMessage() const; |
| 106 |
| 107 int flags() const { return flags_; } |
| 108 |
| 109 ID id() const { return id_; } |
| 110 |
| 111 // Returns the message id associated with this permission. |
| 112 PermissionMessage::ID message_id() const { |
| 113 return message_id_; |
| 114 } |
| 115 |
| 116 // Returns the name of this permission. |
| 117 const char* name() const { return name_; } |
| 118 |
| 119 // Returns true if this permission implies full access (e.g., native code). |
| 120 bool implies_full_access() const { |
| 121 return (flags_ & kFlagImpliesFullAccess) != 0; |
| 122 } |
| 123 |
| 124 // Returns true if this permission implies full URL access. |
| 125 bool implies_full_url_access() const { |
| 126 return (flags_ & kFlagImpliesFullURLAccess) != 0; |
| 127 } |
| 128 |
| 129 // Returns true if this permission can be added and removed via the |
| 130 // optional permissions extension API. |
| 131 bool supports_optional() const { |
| 132 return (flags_ & kFlagCannotBeOptional) == 0; |
| 133 } |
| 134 |
| 135 private: |
| 136 // Instances should only be constructed from within PermissionsInfo. |
| 137 friend class PermissionsInfo; |
| 138 |
| 139 explicit APIPermission( |
| 140 ID id, |
| 141 const char* name, |
| 142 int l10n_message_id, |
| 143 PermissionMessage::ID message_id, |
| 144 int flags); |
| 145 |
| 146 // Register ALL the permissions! |
| 147 static void RegisterAllPermissions(PermissionsInfo* info); |
| 148 |
| 149 ID id_; |
| 150 const char* name_; |
| 151 int flags_; |
| 152 int l10n_message_id_; |
| 153 PermissionMessage::ID message_id_; |
| 154 }; |
| 155 |
| 156 typedef std::set<APIPermission::ID> APIPermissionSet; |
| 157 |
| 158 } // namespace extensions |
| 159 |
| 160 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_API_PERMISSION_H_ |
OLD | NEW |