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_SET_H_
6 #define EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_
9 #include "extensions/common/permissions/api_permission.h"
10 #include "extensions/common/permissions/base_set_operators.h"
16 namespace extensions
{
19 class APIPermissionSet
;
22 struct BaseSetOperatorsTraits
<APIPermissionSet
> {
23 typedef APIPermission ElementType
;
24 typedef APIPermission::ID ElementIDType
;
27 class APIPermissionSet
: public BaseSetOperators
<APIPermissionSet
> {
30 // Don't allow internal permissions to be parsed (e.g. entries in the
31 // "permissions" list in a manifest).
32 kDisallowInternalPermissions
,
34 // Allow internal permissions to be parsed (e.g. from the "api" field of a
35 // permissions list in the prefs).
36 kAllowInternalPermissions
,
39 void insert(APIPermission::ID id
);
41 // Insert |permission| into the APIPermissionSet. The APIPermissionSet will
42 // take the ownership of |permission|,
43 void insert(APIPermission
* permission
);
45 // Parses permissions from |permissions| and adds the parsed permissions to
46 // |api_permissions|. If |source| is kDisallowInternalPermissions, treat
47 // permissions with kFlagInternal as errors. If |unhandled_permissions| is
48 // not NULL, the names of all permissions that couldn't be parsed will be
49 // added to this vector. If |error| is NULL, parsing will continue with the
50 // next permission if invalid data is detected. If |error| is not NULL, it
51 // will be set to an error message and false is returned when an invalid
52 // permission is found.
53 static bool ParseFromJSON(
54 const base::ListValue
* permissions
,
56 APIPermissionSet
* api_permissions
,
57 base::string16
* error
,
58 std::vector
<std::string
>* unhandled_permissions
);
60 void AddImpliedPermissions();
63 } // namespace extensions
65 #endif // EXTENSIONS_COMMON_PERMISSIONS_API_PERMISSION_SET_H_