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