| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_ | 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_ |
| 6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_ | 6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/callback.h" | 12 #include "base/callback.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/pickle.h" | 14 #include "base/pickle.h" |
| 15 #include "base/values.h" | 15 #include "base/values.h" |
| 16 #include "extensions/common/permissions/permission_message.h" | 16 #include "extensions/common/permissions/permission_message.h" |
| 17 | 17 |
| 18 namespace IPC { | 18 namespace IPC { |
| 19 class Message; | 19 class Message; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace extensions { | 22 namespace extensions { |
| 23 | 23 |
| 24 class PermissionIDSet; |
| 24 class APIPermissionInfo; | 25 class APIPermissionInfo; |
| 25 class ChromeAPIPermissions; | 26 class ChromeAPIPermissions; |
| 26 | 27 |
| 27 // APIPermission is for handling some complex permissions. Please refer to | 28 // APIPermission is for handling some complex permissions. Please refer to |
| 28 // extensions::SocketPermission as an example. | 29 // extensions::SocketPermission as an example. |
| 29 // There is one instance per permission per loaded extension. | 30 // There is one instance per permission per loaded extension. |
| 30 class APIPermission { | 31 class APIPermission { |
| 31 public: | 32 public: |
| 32 // The IDs of all permissions available to apps. Add as many permissions here | 33 // The IDs of all permissions available to apps. Add as many permissions here |
| 33 // as needed to generate meaningful permission messages. Add the rules for the | 34 // as needed to generate meaningful permission messages. Add the rules for the |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 // permission message rule combinations. | 208 // permission message rule combinations. |
| 208 // TODO(sashab): Move these in-line with the other permission IDs. | 209 // TODO(sashab): Move these in-line with the other permission IDs. |
| 209 kBluetooth, | 210 kBluetooth, |
| 210 kBluetoothDevices, | 211 kBluetoothDevices, |
| 211 kFavicon, | 212 kFavicon, |
| 212 kFullAccess, | 213 kFullAccess, |
| 213 kHostReadOnly, | 214 kHostReadOnly, |
| 214 kHostReadWrite, | 215 kHostReadWrite, |
| 215 kHostsAll, | 216 kHostsAll, |
| 216 kHostsAllReadOnly, | 217 kHostsAllReadOnly, |
| 218 kMediaGalleriesAllGalleriesCopyTo, |
| 219 kMediaGalleriesAllGalleriesDelete, |
| 220 kMediaGalleriesAllGalleriesRead, |
| 221 kNetworkState, |
| 217 kOverrideBookmarksUI, | 222 kOverrideBookmarksUI, |
| 223 kShouldWarnAllHosts, |
| 218 kSocketAnyHost, | 224 kSocketAnyHost, |
| 219 kSocketDomainHostsSingular, | 225 kSocketDomainHosts, |
| 220 kSocketDomainHostsPlural, | 226 kSocketSpecificHosts, |
| 221 kSocketSpecificHostsSingular, | 227 kUsbDeviceList, |
| 222 kSocketSpecificHostsPlural, | 228 kUsbDeviceUnknownProduct, |
| 223 kNetworkState, | 229 kUsbDeviceUnknownVendor, |
| 224 | 230 |
| 225 kEnumBoundary | 231 kEnumBoundary |
| 226 }; | 232 }; |
| 227 | 233 |
| 228 struct CheckParam { | 234 struct CheckParam { |
| 229 }; | 235 }; |
| 230 | 236 |
| 231 explicit APIPermission(const APIPermissionInfo* info); | 237 explicit APIPermission(const APIPermissionInfo* info); |
| 232 | 238 |
| 233 virtual ~APIPermission(); | 239 virtual ~APIPermission(); |
| 234 | 240 |
| 235 // Returns the id of this permission. | 241 // Returns the id of this permission. |
| 236 ID id() const; | 242 ID id() const; |
| 237 | 243 |
| 238 // Returns the name of this permission. | 244 // Returns the name of this permission. |
| 239 const char* name() const; | 245 const char* name() const; |
| 240 | 246 |
| 241 // Returns the APIPermission of this permission. | 247 // Returns the APIPermission of this permission. |
| 242 const APIPermissionInfo* info() const { | 248 const APIPermissionInfo* info() const { |
| 243 return info_; | 249 return info_; |
| 244 } | 250 } |
| 245 | 251 |
| 252 // The set of permissions an app/extension with this API permission has. These |
| 253 // permissions are used by PermissionMessageProvider to generate meaningful |
| 254 // permission messages for the app/extension. |
| 255 // |
| 256 // For simple API permissions, this will return a set containing only the ID |
| 257 // of the permission. More complex permissions might have multiple IDs, one |
| 258 // for each of the capabilities the API permission has (e.g. read, write and |
| 259 // copy, in the case of the media gallery permission). Permissions that |
| 260 // require parameters may also contain a parameter string (along with the |
| 261 // permission's ID) which can be substituted into the permission message if a |
| 262 // rule is defined to do so. |
| 263 // |
| 264 // Permissions with multiple values, such as host permissions, are represented |
| 265 // by multiple entries in this set. Each permission in the subset has the same |
| 266 // ID (e.g. kHostReadOnly) but a different parameter (e.g. google.com). These |
| 267 // are grouped to form different kinds of permission messages (e.g. 'Access to |
| 268 // 2 hosts') depending on the number that are in the set. The rules that |
| 269 // define the grouping of related permissions with the same ID is defined in |
| 270 // ChromePermissionMessageProvider. |
| 271 virtual PermissionIDSet GetPermissions() const = 0; |
| 272 |
| 246 // Returns true if this permission has any PermissionMessages. | 273 // Returns true if this permission has any PermissionMessages. |
| 274 // TODO(sashab): Deprecate this in favor of GetPermissions() above. |
| 247 virtual bool HasMessages() const = 0; | 275 virtual bool HasMessages() const = 0; |
| 248 | 276 |
| 249 // Returns the localized permission messages of this permission. | 277 // Returns the localized permission messages of this permission. |
| 278 // TODO(sashab): Deprecate this in favor of GetPermissions() above. |
| 250 virtual PermissionMessages GetMessages() const = 0; | 279 virtual PermissionMessages GetMessages() const = 0; |
| 251 | 280 |
| 252 // Returns true if the given permission is allowed. | 281 // Returns true if the given permission is allowed. |
| 253 virtual bool Check(const CheckParam* param) const = 0; | 282 virtual bool Check(const CheckParam* param) const = 0; |
| 254 | 283 |
| 255 // Returns true if |rhs| is a subset of this. | 284 // Returns true if |rhs| is a subset of this. |
| 256 virtual bool Contains(const APIPermission* rhs) const = 0; | 285 virtual bool Contains(const APIPermission* rhs) const = 0; |
| 257 | 286 |
| 258 // Returns true if |rhs| is equal to this. | 287 // Returns true if |rhs| is equal to this. |
| 259 virtual bool Equal(const APIPermission* rhs) const = 0; | 288 virtual bool Equal(const APIPermission* rhs) const = 0; |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 const char* const name_; | 437 const char* const name_; |
| 409 const int flags_; | 438 const int flags_; |
| 410 const int l10n_message_id_; | 439 const int l10n_message_id_; |
| 411 const PermissionMessage::ID message_id_; | 440 const PermissionMessage::ID message_id_; |
| 412 const APIPermissionConstructor api_permission_constructor_; | 441 const APIPermissionConstructor api_permission_constructor_; |
| 413 }; | 442 }; |
| 414 | 443 |
| 415 } // namespace extensions | 444 } // namespace extensions |
| 416 | 445 |
| 417 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_ | 446 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_H_ |
| OLD | NEW |