OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ | 5 #ifndef CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ |
6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ | 6 #define CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
16 #include "base/string16.h" | 16 #include "base/string16.h" |
17 #include "chrome/common/extensions/permissions/api_permission.h" | 17 #include "chrome/common/extensions/permissions/api_permission.h" |
| 18 #include "chrome/common/extensions/permissions/api_permission_set.h" |
18 #include "chrome/common/extensions/permissions/permission_message.h" | 19 #include "chrome/common/extensions/permissions/permission_message.h" |
19 #include "chrome/common/extensions/url_pattern_set.h" | 20 #include "chrome/common/extensions/url_pattern_set.h" |
20 | 21 |
21 namespace extensions { | 22 namespace extensions { |
22 | 23 |
23 class Extension; | 24 class Extension; |
24 | 25 |
25 // The PermissionSet is an immutable class that encapsulates an | 26 // The PermissionSet is an immutable class that encapsulates an |
26 // extension's permissions. The class exposes set operations for combining and | 27 // extension's permissions. The class exposes set operations for combining and |
27 // manipulating the permissions. | 28 // manipulating the permissions. |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // Gets the localized permission messages that represent this set (represented | 91 // Gets the localized permission messages that represent this set (represented |
91 // as strings). | 92 // as strings). |
92 std::vector<string16> GetWarningMessages() const; | 93 std::vector<string16> GetWarningMessages() const; |
93 | 94 |
94 // Returns true if this is an empty set (e.g., the default permission set). | 95 // Returns true if this is an empty set (e.g., the default permission set). |
95 bool IsEmpty() const; | 96 bool IsEmpty() const; |
96 | 97 |
97 // Returns true if the set has the specified API permission. | 98 // Returns true if the set has the specified API permission. |
98 bool HasAPIPermission(APIPermission::ID permission) const; | 99 bool HasAPIPermission(APIPermission::ID permission) const; |
99 | 100 |
| 101 // Returns true if the set allows the given permission with the default |
| 102 // permission detal. |
| 103 bool CheckAPIPermission(APIPermission::ID permission) const; |
| 104 |
| 105 // Returns true if the set allows the given permission and permission detail. |
| 106 bool CheckAPIPermissionWithDetail(APIPermission::ID permission, |
| 107 const APIPermissionDetail::DetailParam* detail) const; |
| 108 |
100 // Returns true if the permissions in this set grant access to the specified | 109 // Returns true if the permissions in this set grant access to the specified |
101 // |function_name|. | 110 // |function_name|. |
102 bool HasAccessToFunction(const std::string& function_name) const; | 111 bool HasAccessToFunction(const std::string& function_name) const; |
103 | 112 |
104 // Returns true if this includes permission to access |origin|. | 113 // Returns true if this includes permission to access |origin|. |
105 bool HasExplicitAccessToOrigin(const GURL& origin) const; | 114 bool HasExplicitAccessToOrigin(const GURL& origin) const; |
106 | 115 |
107 // Returns true if this permission set includes access to script |url|. | 116 // Returns true if this permission set includes access to script |url|. |
108 bool HasScriptableAccessToURL(const GURL& url) const; | 117 bool HasScriptableAccessToURL(const GURL& url) const; |
109 | 118 |
(...skipping 20 matching lines...) Expand all Loading... |
130 | 139 |
131 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; } | 140 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; } |
132 | 141 |
133 private: | 142 private: |
134 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, HasLessHostPrivilegesThan); | 143 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, HasLessHostPrivilegesThan); |
135 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetWarningMessages_AudioVideo); | 144 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetWarningMessages_AudioVideo); |
136 friend class base::RefCountedThreadSafe<PermissionSet>; | 145 friend class base::RefCountedThreadSafe<PermissionSet>; |
137 | 146 |
138 ~PermissionSet(); | 147 ~PermissionSet(); |
139 | 148 |
| 149 void AddAPIPermission(APIPermission::ID id); |
| 150 |
140 static std::set<std::string> GetDistinctHosts( | 151 static std::set<std::string> GetDistinctHosts( |
141 const URLPatternSet& host_patterns, | 152 const URLPatternSet& host_patterns, |
142 bool include_rcd, | 153 bool include_rcd, |
143 bool exclude_file_scheme); | 154 bool exclude_file_scheme); |
144 | 155 |
145 // Initializes the set based on |extension|'s manifest data. | 156 // Initializes the set based on |extension|'s manifest data. |
146 void InitImplicitExtensionPermissions(const extensions::Extension* extension); | 157 void InitImplicitExtensionPermissions(const extensions::Extension* extension); |
147 | 158 |
148 // Adds permissions implied independently of other context. | 159 // Adds permissions implied independently of other context. |
149 void InitImplicitPermissions(); | 160 void InitImplicitPermissions(); |
(...skipping 26 matching lines...) Expand all Loading... |
176 // TODO(jstritar): Rename to "user_script_hosts_"? | 187 // TODO(jstritar): Rename to "user_script_hosts_"? |
177 URLPatternSet scriptable_hosts_; | 188 URLPatternSet scriptable_hosts_; |
178 | 189 |
179 // The list of hosts this effectively grants access to. | 190 // The list of hosts this effectively grants access to. |
180 URLPatternSet effective_hosts_; | 191 URLPatternSet effective_hosts_; |
181 }; | 192 }; |
182 | 193 |
183 } // namespace extensions | 194 } // namespace extensions |
184 | 195 |
185 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ | 196 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ |
OLD | NEW |