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> |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // require no permissions). | 72 // require no permissions). |
73 // TODO(kalman): return scoped_ptr to avoid copying. | 73 // TODO(kalman): return scoped_ptr to avoid copying. |
74 std::set<std::string> GetAPIsWithAnyAccessAsStrings() const; | 74 std::set<std::string> GetAPIsWithAnyAccessAsStrings() const; |
75 | 75 |
76 // Returns whether this namespace has any functions which the extension has | 76 // Returns whether this namespace has any functions which the extension has |
77 // permission to use. For example, even though the extension may not have | 77 // permission to use. For example, even though the extension may not have |
78 // the "tabs" permission, "tabs.create" requires no permissions so | 78 // the "tabs" permission, "tabs.create" requires no permissions so |
79 // HasAnyAPIPermission("tabs") will return true. | 79 // HasAnyAPIPermission("tabs") will return true. |
80 bool HasAnyAccessToAPI(const std::string& api_name) const; | 80 bool HasAnyAccessToAPI(const std::string& api_name) const; |
81 | 81 |
82 // Gets a list of the distinct hosts for displaying to the user. | |
83 // NOTE: do not use this for comparing permissions, since this disgards some | |
84 // information. | |
85 std::set<std::string> GetDistinctHostsForDisplay() const; | |
86 | |
87 // Gets the localized permission messages that represent this set. | 82 // Gets the localized permission messages that represent this set. |
88 PermissionMessages GetPermissionMessages() const; | 83 // The set of permission messages varies by extension type, hence the |
| 84 // |extension| parameter. |
| 85 PermissionMessages GetPermissionMessages(const Extension* extension) const; |
89 | 86 |
90 // Gets the localized permission messages that represent this set (represented | 87 // Gets the localized permission messages that represent this set (represented |
91 // as strings). | 88 // as strings). The set of permission messages varies by extension type, |
92 std::vector<string16> GetWarningMessages() const; | 89 // hence the |extension| parameter. |
| 90 std::vector<string16> GetWarningMessages(const Extension* extension) const; |
93 | 91 |
94 // Returns true if this is an empty set (e.g., the default permission set). | 92 // Returns true if this is an empty set (e.g., the default permission set). |
95 bool IsEmpty() const; | 93 bool IsEmpty() const; |
96 | 94 |
97 // Returns true if the set has the specified API permission. | 95 // Returns true if the set has the specified API permission. |
98 bool HasAPIPermission(APIPermission::ID permission) const; | 96 bool HasAPIPermission(APIPermission::ID permission) const; |
99 | 97 |
100 // Returns true if the permissions in this set grant access to the specified | 98 // Returns true if the permissions in this set grant access to the specified |
101 // |function_name|. | 99 // |function_name|. |
102 bool HasAccessToFunction(const std::string& function_name) const; | 100 bool HasAccessToFunction(const std::string& function_name) const; |
(...skipping 23 matching lines...) Expand all Loading... |
126 | 124 |
127 const URLPatternSet& effective_hosts() const { return effective_hosts_; } | 125 const URLPatternSet& effective_hosts() const { return effective_hosts_; } |
128 | 126 |
129 const URLPatternSet& explicit_hosts() const { return explicit_hosts_; } | 127 const URLPatternSet& explicit_hosts() const { return explicit_hosts_; } |
130 | 128 |
131 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; } | 129 const URLPatternSet& scriptable_hosts() const { return scriptable_hosts_; } |
132 | 130 |
133 private: | 131 private: |
134 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, HasLessHostPrivilegesThan); | 132 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, HasLessHostPrivilegesThan); |
135 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetWarningMessages_AudioVideo); | 133 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetWarningMessages_AudioVideo); |
| 134 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, GetDistinctHostsForDisplay); |
| 135 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, |
| 136 GetDistinctHostsForDisplay_ComIsBestRcd); |
| 137 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, |
| 138 GetDistinctHostsForDisplay_NetIs2ndBestRcd); |
| 139 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, |
| 140 GetDistinctHostsForDisplay_OrgIs3rdBestRcd); |
| 141 FRIEND_TEST_ALL_PREFIXES(PermissionsTest, |
| 142 GetDistinctHostsForDisplay_FirstInListIs4thBestRcd); |
136 friend class base::RefCountedThreadSafe<PermissionSet>; | 143 friend class base::RefCountedThreadSafe<PermissionSet>; |
137 | 144 |
138 ~PermissionSet(); | 145 ~PermissionSet(); |
139 | 146 |
140 static std::set<std::string> GetDistinctHosts( | 147 static std::set<std::string> GetDistinctHosts( |
141 const URLPatternSet& host_patterns, | 148 const URLPatternSet& host_patterns, |
142 bool include_rcd, | 149 bool include_rcd, |
143 bool exclude_file_scheme); | 150 bool exclude_file_scheme); |
144 | 151 |
145 // Initializes the set based on |extension|'s manifest data. | 152 // Initializes the set based on |extension|'s manifest data. |
(...skipping 11 matching lines...) Expand all Loading... |
157 // Returns true if |permissions| has an elevated API privilege level than | 164 // Returns true if |permissions| has an elevated API privilege level than |
158 // this set. | 165 // this set. |
159 bool HasLessAPIPrivilegesThan( | 166 bool HasLessAPIPrivilegesThan( |
160 const PermissionSet* permissions) const; | 167 const PermissionSet* permissions) const; |
161 | 168 |
162 // Returns true if |permissions| has more host permissions compared to this | 169 // Returns true if |permissions| has more host permissions compared to this |
163 // set. | 170 // set. |
164 bool HasLessHostPrivilegesThan( | 171 bool HasLessHostPrivilegesThan( |
165 const PermissionSet* permissions) const; | 172 const PermissionSet* permissions) const; |
166 | 173 |
| 174 // Gets a list of the distinct hosts for displaying to the user. |
| 175 // NOTE: do not use this for comparing permissions, since this disgards some |
| 176 // information. |
| 177 std::set<std::string> GetDistinctHostsForDisplay() const; |
| 178 |
167 // The api list is used when deciding if an extension can access certain | 179 // The api list is used when deciding if an extension can access certain |
168 // extension APIs and features. | 180 // extension APIs and features. |
169 APIPermissionSet apis_; | 181 APIPermissionSet apis_; |
170 | 182 |
171 // The list of hosts that can be accessed directly from the extension. | 183 // The list of hosts that can be accessed directly from the extension. |
172 // TODO(jstritar): Rename to "hosts_"? | 184 // TODO(jstritar): Rename to "hosts_"? |
173 URLPatternSet explicit_hosts_; | 185 URLPatternSet explicit_hosts_; |
174 | 186 |
175 // The list of hosts that can be scripted by content scripts. | 187 // The list of hosts that can be scripted by content scripts. |
176 // TODO(jstritar): Rename to "user_script_hosts_"? | 188 // TODO(jstritar): Rename to "user_script_hosts_"? |
177 URLPatternSet scriptable_hosts_; | 189 URLPatternSet scriptable_hosts_; |
178 | 190 |
179 // The list of hosts this effectively grants access to. | 191 // The list of hosts this effectively grants access to. |
180 URLPatternSet effective_hosts_; | 192 URLPatternSet effective_hosts_; |
181 }; | 193 }; |
182 | 194 |
183 } // namespace extensions | 195 } // namespace extensions |
184 | 196 |
185 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ | 197 #endif // CHROME_COMMON_EXTENSIONS_PERMISSIONS_PERMISSION_SET_H_ |
OLD | NEW |