Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_PERMISSIONS_DATA_H_ | 5 #ifndef EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ |
| 6 #define EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ | 6 #define EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 // with the given |extension_id|. | 75 // with the given |extension_id|. |
| 76 static bool ShouldSkipPermissionWarnings(const std::string& extension_id); | 76 static bool ShouldSkipPermissionWarnings(const std::string& extension_id); |
| 77 | 77 |
| 78 // Returns true if the given |url| is restricted for the given |extension|, | 78 // Returns true if the given |url| is restricted for the given |extension|, |
| 79 // as is commonly the case for chrome:// urls. | 79 // as is commonly the case for chrome:// urls. |
| 80 // NOTE: You probably want to use CanAccessPage(). | 80 // NOTE: You probably want to use CanAccessPage(). |
| 81 static bool IsRestrictedUrl(const GURL& document_url, | 81 static bool IsRestrictedUrl(const GURL& document_url, |
| 82 const Extension* extension, | 82 const Extension* extension, |
| 83 std::string* error); | 83 std::string* error); |
| 84 | 84 |
| 85 // Is this extension using the default scope for policy_blocked_hosts and | |
| 86 // policy_allowed_hosts of the ExtensionSettings policy. | |
| 87 bool UsesDefaultPolicyHostRestrictions() const; | |
| 88 | |
| 85 // Locks the permissions data to the current thread. We don't do this on | 89 // Locks the permissions data to the current thread. We don't do this on |
| 86 // construction, since extensions are initialized across multiple threads. | 90 // construction, since extensions are initialized across multiple threads. |
| 87 void BindToCurrentThread() const; | 91 void BindToCurrentThread() const; |
| 88 | 92 |
| 89 // Sets the runtime permissions of the given |extension| to |active| and | 93 // Sets the runtime permissions of the given |extension| to |active| and |
| 90 // |withheld|. | 94 // |withheld|. |
| 91 void SetPermissions(std::unique_ptr<const PermissionSet> active, | 95 void SetPermissions(std::unique_ptr<const PermissionSet> active, |
| 92 std::unique_ptr<const PermissionSet> withheld) const; | 96 std::unique_ptr<const PermissionSet> withheld) const; |
| 93 | 97 |
| 98 // Applies restrictions from enterprise policy limiting which URLs this | |
| 99 // extension can interact with. The same policy can also define a default set | |
| 100 // of URL restrictions using SetDefaultPolicyHostRestrictions. This function | |
| 101 // overrides any default host restriction policy. | |
| 102 void SetPolicyHostRestrictions( | |
| 103 const URLPatternSet& runtime_blocked_hosts, | |
| 104 const URLPatternSet& runtime_allowed_hosts, | |
| 105 const bool is_default_runtime_blocked_allowed_hosts) const; | |
|
Devlin
2017/03/29 21:36:50
To me, it seems like this shouldn't take three par
nrpeter
2017/03/30 00:06:06
Done.
| |
| 106 | |
| 107 // Applies restrictions from enterprise policy limiting which URLs all | |
| 108 // extensions can interact with. This restriction can be overridden on a | |
| 109 // per-extnsion basis with SetPolicyHostRestrictions. | |
|
Devlin
2017/03/29 21:36:50
per-extension
nrpeter
2017/03/30 00:06:06
Done.
| |
| 110 static void SetDefaultPolicyHostRestrictions( | |
| 111 const URLPatternSet& default_runtime_blocked_hosts, | |
| 112 const URLPatternSet& default_runtime_allowed_hosts); | |
| 113 | |
| 94 // Sets the active permissions, leaving withheld the same. | 114 // Sets the active permissions, leaving withheld the same. |
| 95 void SetActivePermissions(std::unique_ptr<const PermissionSet> active) const; | 115 void SetActivePermissions(std::unique_ptr<const PermissionSet> active) const; |
| 96 | 116 |
| 97 // Updates the tab-specific permissions of |tab_id| to include those from | 117 // Updates the tab-specific permissions of |tab_id| to include those from |
| 98 // |permissions|. | 118 // |permissions|. |
| 99 void UpdateTabSpecificPermissions(int tab_id, | 119 void UpdateTabSpecificPermissions(int tab_id, |
| 100 const PermissionSet& permissions) const; | 120 const PermissionSet& permissions) const; |
| 101 | 121 |
| 102 // Clears the tab-specific permissions of |tab_id|. | 122 // Clears the tab-specific permissions of |tab_id|. |
| 103 void ClearTabSpecificPermissions(int tab_id) const; | 123 void ClearTabSpecificPermissions(int tab_id) const; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 const PermissionSet& active_permissions() const { | 214 const PermissionSet& active_permissions() const { |
| 195 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); | 215 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); |
| 196 return *active_permissions_unsafe_; | 216 return *active_permissions_unsafe_; |
| 197 } | 217 } |
| 198 | 218 |
| 199 const PermissionSet& withheld_permissions() const { | 219 const PermissionSet& withheld_permissions() const { |
| 200 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); | 220 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); |
| 201 return *withheld_permissions_unsafe_; | 221 return *withheld_permissions_unsafe_; |
| 202 } | 222 } |
| 203 | 223 |
| 224 // Returns list of hosts this extension may not interact with by policy. | |
| 225 // This should only be used for 1. Serialization when initializing renderers | |
| 226 // or 2. Called from utility methods above. For all other uses, call utility | |
| 227 // methods instead (e.g. CanAccessPage()). | |
| 228 static const URLPatternSet& default_policy_blocked_hosts(); | |
| 229 | |
| 230 // Returns list of hosts this extension may interact with regardless of | |
| 231 // what is defined by policy_blocked_hosts(). | |
| 232 // This should only be used for 1. Serialization when initializing renderers | |
| 233 // or 2. Called from utility methods above. For all other uses, call utility | |
| 234 // methods instead (e.g. CanAccessPage()). | |
| 235 static const URLPatternSet& default_policy_allowed_hosts(); | |
| 236 | |
| 237 // Returns list of hosts this extension may not interact with by policy. | |
| 238 // This should only be used for 1. Serialization when initializing renderers | |
| 239 // or 2. Called from utility methods above. For all other uses, call utility | |
| 240 // methods instead (e.g. CanAccessPage()). | |
| 241 const URLPatternSet& policy_blocked_hosts() const; | |
| 242 | |
| 243 // Returns list of hosts this extension may interact with regardless of | |
| 244 // what is defined by policy_blocked_hosts(). | |
| 245 // This should only be used for 1. Serialization when initializing renderers | |
| 246 // or 2. Called from utility methods above. For all other uses, call utility | |
| 247 // methods instead (e.g. CanAccessPage()). | |
| 248 const URLPatternSet& policy_allowed_hosts() const; | |
| 249 | |
| 204 #if defined(UNIT_TEST) | 250 #if defined(UNIT_TEST) |
| 205 const PermissionSet* GetTabSpecificPermissionsForTesting(int tab_id) const { | 251 const PermissionSet* GetTabSpecificPermissionsForTesting(int tab_id) const { |
| 206 base::AutoLock auto_lock(runtime_lock_); | 252 base::AutoLock auto_lock(runtime_lock_); |
| 207 return GetTabSpecificPermissions(tab_id); | 253 return GetTabSpecificPermissions(tab_id); |
| 208 } | 254 } |
| 209 #endif | 255 #endif |
| 210 | 256 |
| 211 private: | 257 private: |
| 212 // Gets the tab-specific host permissions of |tab_id|, or NULL if there | 258 // Gets the tab-specific host permissions of |tab_id|, or NULL if there |
| 213 // aren't any. | 259 // aren't any. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 226 // checking against |permitted_url_patterns| in addition to blocking special | 272 // checking against |permitted_url_patterns| in addition to blocking special |
| 227 // sites (like the webstore or chrome:// urls). | 273 // sites (like the webstore or chrome:// urls). |
| 228 // Must be called with |runtime_lock_| acquired. | 274 // Must be called with |runtime_lock_| acquired. |
| 229 AccessType CanRunOnPage(const Extension* extension, | 275 AccessType CanRunOnPage(const Extension* extension, |
| 230 const GURL& document_url, | 276 const GURL& document_url, |
| 231 int tab_id, | 277 int tab_id, |
| 232 const URLPatternSet& permitted_url_patterns, | 278 const URLPatternSet& permitted_url_patterns, |
| 233 const URLPatternSet& withheld_url_patterns, | 279 const URLPatternSet& withheld_url_patterns, |
| 234 std::string* error) const; | 280 std::string* error) const; |
| 235 | 281 |
| 282 // Check if a specific URL is blocked by policy from extension use at runtime. | |
| 283 bool IsRuntimeBlockedHost(const GURL& url) const; | |
| 284 | |
| 236 // The associated extension's id. | 285 // The associated extension's id. |
| 237 std::string extension_id_; | 286 std::string extension_id_; |
| 238 | 287 |
| 239 // The associated extension's manifest type. | 288 // The associated extension's manifest type. |
| 240 Manifest::Type manifest_type_; | 289 Manifest::Type manifest_type_; |
| 241 | 290 |
| 242 mutable base::Lock runtime_lock_; | 291 mutable base::Lock runtime_lock_; |
| 243 | 292 |
| 244 // The permission's which are currently active on the extension during | 293 // The permission's which are currently active on the extension during |
| 245 // runtime. | 294 // runtime. |
| 246 // Unsafe indicates that we must lock anytime this is directly accessed. | 295 // Unsafe indicates that we must lock anytime this is directly accessed. |
| 247 // Unless you need to change |active_permissions_unsafe_|, use the (safe) | 296 // Unless you need to change |active_permissions_unsafe_|, use the (safe) |
| 248 // active_permissions() accessor. | 297 // active_permissions() accessor. |
| 249 mutable std::unique_ptr<const PermissionSet> active_permissions_unsafe_; | 298 mutable std::unique_ptr<const PermissionSet> active_permissions_unsafe_; |
| 250 | 299 |
| 251 // The permissions the extension requested, but was not granted due because | 300 // The permissions the extension requested, but was not granted due because |
| 252 // they are too powerful. This includes things like all_hosts. | 301 // they are too powerful. This includes things like all_hosts. |
| 253 // Unsafe indicates that we must lock anytime this is directly accessed. | 302 // Unsafe indicates that we must lock anytime this is directly accessed. |
| 254 // Unless you need to change |withheld_permissions_unsafe_|, use the (safe) | 303 // Unless you need to change |withheld_permissions_unsafe_|, use the (safe) |
| 255 // withheld_permissions() accessor. | 304 // withheld_permissions() accessor. |
| 256 mutable std::unique_ptr<const PermissionSet> withheld_permissions_unsafe_; | 305 mutable std::unique_ptr<const PermissionSet> withheld_permissions_unsafe_; |
| 257 | 306 |
| 307 // The list of hosts an extension may not interact with by policy. | |
| 308 // Unless you need to change |policy_blocked_hosts_unsafe_|, use the (safe) | |
| 309 // policy_blocked_hosts() accessor. | |
| 310 mutable URLPatternSet policy_blocked_hosts_unsafe; | |
| 311 | |
| 312 // The exclusive list of hosts an extension may interact with by policy. | |
| 313 // Unless you need to change |policy_allowed_hosts_unsafe_|, use the (safe) | |
| 314 // policy_allowed_hosts() accessor. | |
| 315 mutable URLPatternSet policy_allowed_hosts_unsafe; | |
| 316 | |
| 317 // If the ExtensionSettings policy is not being used, or no per-extension | |
| 318 // exception to the default policy was declared for this extension. | |
| 319 mutable bool uses_default_policy_host_restrictions = true; | |
| 320 | |
| 258 mutable TabPermissionsMap tab_specific_permissions_; | 321 mutable TabPermissionsMap tab_specific_permissions_; |
| 259 | 322 |
| 260 mutable std::unique_ptr<base::ThreadChecker> thread_checker_; | 323 mutable std::unique_ptr<base::ThreadChecker> thread_checker_; |
| 261 | 324 |
| 262 DISALLOW_COPY_AND_ASSIGN(PermissionsData); | 325 DISALLOW_COPY_AND_ASSIGN(PermissionsData); |
| 263 }; | 326 }; |
| 264 | 327 |
| 265 } // namespace extensions | 328 } // namespace extensions |
| 266 | 329 |
| 267 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ | 330 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ |
| OLD | NEW |