Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / extensions / common / manifest_handlers / permissions_parser.h
blob81ffe0ec70ee37f1429bdc44072e7d86e6a87485
1 // Copyright 2014 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_MANIFEST_HANDLERS_PERMISSIONS_PARSER_H_
6 #define EXTENSIONS_COMMON_MANIFEST_HANDLERS_PERMISSIONS_PARSER_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "extensions/common/permissions/api_permission.h"
11 #include "extensions/common/permissions/permission_set.h"
13 namespace extensions {
15 class Extension;
16 class URLPatternSet;
18 // The class for parsing the kPermissions and kOptionalPermissions keys in the
19 // manifest. Because permissions are slightly different than other keys (they
20 // are used in many different handlers and need to be the first and last key
21 // touched), this is not an actual ManifestHandler (hence the difference in
22 // name).
23 class PermissionsParser {
24 public:
25 PermissionsParser();
26 ~PermissionsParser();
28 // Parse the manifest-specified permissions.
29 bool Parse(Extension* extension, base::string16* error);
31 // Finalize the permissions, setting the related manifest data on the
32 // extension.
33 void Finalize(Extension* extension);
35 // Modify the manifest permissions. These methods should only be used
36 // during initialization and will DCHECK() for safety.
37 static void AddAPIPermission(Extension* extension,
38 APIPermission::ID permission);
39 static void AddAPIPermission(Extension* extension, APIPermission* permission);
40 static bool HasAPIPermission(const Extension* extension,
41 APIPermission::ID permission);
42 static void SetScriptableHosts(Extension* extension,
43 const URLPatternSet& scriptable_hosts);
45 // Return the extension's manifest-specified permissions. In no cases should
46 // these permissions be used to determine if an action is allowed. Instead,
47 // use PermissionsData.
48 static scoped_refptr<const PermissionSet> GetRequiredPermissions(
49 const Extension* extension);
50 static scoped_refptr<const PermissionSet> GetOptionalPermissions(
51 const Extension* extension);
53 private:
54 struct InitialPermissions;
56 // The initial permissions for the extension, which can still be modified.
57 scoped_ptr<InitialPermissions> initial_required_permissions_;
58 scoped_ptr<InitialPermissions> initial_optional_permissions_;
61 } // namespace extensions
63 #endif // EXTENSIONS_COMMON_MANIFEST_HANDLERS_PERMISSIONS_PARSER_H_