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) const; | |
| 105 | |
| 106 // Sets whether this extension is using default enterprise policy limiting | |
| 107 // which URLs extensions can interact with. A default policy can be set with | |
| 108 // SetDefaultPolicyHostRestrictions. A policy specific to this extension | |
| 109 // can be set with SetPolicyHostRestrictions. | |
| 110 void SetUsesDefaultHostRestrictions(bool uses_default_restrictions) const; | |
| 111 | |
| 112 // Applies restrictions from enterprise policy limiting which URLs all | |
| 113 // extensions can interact with. This restriction can be overridden on a | |
| 114 // per-extension basis with SetPolicyHostRestrictions. | |
| 115 static void SetDefaultPolicyHostRestrictions( | |
| 116 const URLPatternSet& default_runtime_blocked_hosts, | |
| 117 const URLPatternSet& default_runtime_allowed_hosts); | |
| 118 | |
| 94 // Sets the active permissions, leaving withheld the same. | 119 // Sets the active permissions, leaving withheld the same. |
| 95 void SetActivePermissions(std::unique_ptr<const PermissionSet> active) const; | 120 void SetActivePermissions(std::unique_ptr<const PermissionSet> active) const; |
| 96 | 121 |
| 97 // Updates the tab-specific permissions of |tab_id| to include those from | 122 // Updates the tab-specific permissions of |tab_id| to include those from |
| 98 // |permissions|. | 123 // |permissions|. |
| 99 void UpdateTabSpecificPermissions(int tab_id, | 124 void UpdateTabSpecificPermissions(int tab_id, |
| 100 const PermissionSet& permissions) const; | 125 const PermissionSet& permissions) const; |
| 101 | 126 |
| 102 // Clears the tab-specific permissions of |tab_id|. | 127 // Clears the tab-specific permissions of |tab_id|. |
| 103 void ClearTabSpecificPermissions(int tab_id) const; | 128 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 { | 219 const PermissionSet& active_permissions() const { |
| 195 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); | 220 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); |
| 196 return *active_permissions_unsafe_; | 221 return *active_permissions_unsafe_; |
| 197 } | 222 } |
| 198 | 223 |
| 199 const PermissionSet& withheld_permissions() const { | 224 const PermissionSet& withheld_permissions() const { |
| 200 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); | 225 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); |
| 201 return *withheld_permissions_unsafe_; | 226 return *withheld_permissions_unsafe_; |
| 202 } | 227 } |
| 203 | 228 |
| 229 // Returns list of hosts this extension may not interact with by policy. | |
| 230 // This should only be used for 1. Serialization when initializing renderers | |
| 231 // or 2. Called from utility methods above. For all other uses, call utility | |
| 232 // methods instead (e.g. CanAccessPage()). | |
| 233 static const URLPatternSet& default_policy_blocked_hosts(); | |
| 234 | |
| 235 // Returns list of hosts this extension may interact with regardless of | |
| 236 // what is defined by policy_blocked_hosts(). | |
| 237 // This should only be used for 1. Serialization when initializing renderers | |
| 238 // or 2. Called from utility methods above. For all other uses, call utility | |
| 239 // methods instead (e.g. CanAccessPage()). | |
| 240 static const URLPatternSet& default_policy_allowed_hosts(); | |
| 241 | |
| 242 // Returns list of hosts this extension may not interact with by policy. | |
| 243 // This should only be used for 1. Serialization when initializing renderers | |
| 244 // or 2. Called from utility methods above. For all other uses, call utility | |
| 245 // methods instead (e.g. CanAccessPage()). | |
| 246 const URLPatternSet& policy_blocked_hosts() const; | |
| 247 | |
| 248 // Returns list of hosts this extension may interact with regardless of | |
| 249 // what is defined by policy_blocked_hosts(). | |
| 250 // This should only be used for 1. Serialization when initializing renderers | |
| 251 // or 2. Called from utility methods above. For all other uses, call utility | |
| 252 // methods instead (e.g. CanAccessPage()). | |
| 253 const URLPatternSet& policy_allowed_hosts() const; | |
| 254 | |
| 204 #if defined(UNIT_TEST) | 255 #if defined(UNIT_TEST) |
| 205 const PermissionSet* GetTabSpecificPermissionsForTesting(int tab_id) const { | 256 const PermissionSet* GetTabSpecificPermissionsForTesting(int tab_id) const { |
| 206 base::AutoLock auto_lock(runtime_lock_); | 257 base::AutoLock auto_lock(runtime_lock_); |
| 207 return GetTabSpecificPermissions(tab_id); | 258 return GetTabSpecificPermissions(tab_id); |
| 208 } | 259 } |
| 209 #endif | 260 #endif |
| 210 | 261 |
| 211 private: | 262 private: |
| 212 // Gets the tab-specific host permissions of |tab_id|, or NULL if there | 263 // Gets the tab-specific host permissions of |tab_id|, or NULL if there |
| 213 // aren't any. | 264 // aren't any. |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 226 // checking against |permitted_url_patterns| in addition to blocking special | 277 // checking against |permitted_url_patterns| in addition to blocking special |
| 227 // sites (like the webstore or chrome:// urls). | 278 // sites (like the webstore or chrome:// urls). |
| 228 // Must be called with |runtime_lock_| acquired. | 279 // Must be called with |runtime_lock_| acquired. |
| 229 AccessType CanRunOnPage(const Extension* extension, | 280 AccessType CanRunOnPage(const Extension* extension, |
| 230 const GURL& document_url, | 281 const GURL& document_url, |
| 231 int tab_id, | 282 int tab_id, |
| 232 const URLPatternSet& permitted_url_patterns, | 283 const URLPatternSet& permitted_url_patterns, |
| 233 const URLPatternSet& withheld_url_patterns, | 284 const URLPatternSet& withheld_url_patterns, |
| 234 std::string* error) const; | 285 std::string* error) const; |
| 235 | 286 |
| 287 // Check if a specific URL is blocked by policy from extension use at runtime. | |
| 288 bool IsRuntimeBlockedHost(const GURL& url) const; | |
| 289 | |
| 236 // The associated extension's id. | 290 // The associated extension's id. |
| 237 std::string extension_id_; | 291 std::string extension_id_; |
| 238 | 292 |
| 239 // The associated extension's manifest type. | 293 // The associated extension's manifest type. |
| 240 Manifest::Type manifest_type_; | 294 Manifest::Type manifest_type_; |
| 241 | 295 |
| 242 mutable base::Lock runtime_lock_; | 296 mutable base::Lock runtime_lock_; |
| 243 | 297 |
| 244 // The permission's which are currently active on the extension during | 298 // The permission's which are currently active on the extension during |
| 245 // runtime. | 299 // runtime. |
| 246 // Unsafe indicates that we must lock anytime this is directly accessed. | 300 // Unsafe indicates that we must lock anytime this is directly accessed. |
| 247 // Unless you need to change |active_permissions_unsafe_|, use the (safe) | 301 // Unless you need to change |active_permissions_unsafe_|, use the (safe) |
| 248 // active_permissions() accessor. | 302 // active_permissions() accessor. |
| 249 mutable std::unique_ptr<const PermissionSet> active_permissions_unsafe_; | 303 mutable std::unique_ptr<const PermissionSet> active_permissions_unsafe_; |
| 250 | 304 |
| 251 // The permissions the extension requested, but was not granted due because | 305 // The permissions the extension requested, but was not granted due because |
| 252 // they are too powerful. This includes things like all_hosts. | 306 // they are too powerful. This includes things like all_hosts. |
| 253 // Unsafe indicates that we must lock anytime this is directly accessed. | 307 // Unsafe indicates that we must lock anytime this is directly accessed. |
| 254 // Unless you need to change |withheld_permissions_unsafe_|, use the (safe) | 308 // Unless you need to change |withheld_permissions_unsafe_|, use the (safe) |
| 255 // withheld_permissions() accessor. | 309 // withheld_permissions() accessor. |
| 256 mutable std::unique_ptr<const PermissionSet> withheld_permissions_unsafe_; | 310 mutable std::unique_ptr<const PermissionSet> withheld_permissions_unsafe_; |
| 257 | 311 |
| 312 // The list of hosts an extension may not interact with by policy. | |
| 313 // Unless you need to change |policy_blocked_hosts_unsafe_|, use the (safe) | |
| 314 // policy_blocked_hosts() accessor. | |
| 315 mutable URLPatternSet policy_blocked_hosts_unsafe; | |
|
Devlin
2017/03/30 21:07:27
add trailing _
nrpeter
2017/03/31 21:43:35
Done.
| |
| 316 | |
| 317 // The exclusive list of hosts an extension may interact with by policy. | |
| 318 // Unless you need to change |policy_allowed_hosts_unsafe_|, use the (safe) | |
| 319 // policy_allowed_hosts() accessor. | |
| 320 mutable URLPatternSet policy_allowed_hosts_unsafe; | |
| 321 | |
| 322 // If the ExtensionSettings policy is not being used, or no per-extension | |
| 323 // exception to the default policy was declared for this extension. | |
| 324 mutable bool uses_default_policy_host_restrictions = true; | |
| 325 | |
| 258 mutable TabPermissionsMap tab_specific_permissions_; | 326 mutable TabPermissionsMap tab_specific_permissions_; |
| 259 | 327 |
| 260 mutable std::unique_ptr<base::ThreadChecker> thread_checker_; | 328 mutable std::unique_ptr<base::ThreadChecker> thread_checker_; |
| 261 | 329 |
| 262 DISALLOW_COPY_AND_ASSIGN(PermissionsData); | 330 DISALLOW_COPY_AND_ASSIGN(PermissionsData); |
| 263 }; | 331 }; |
| 264 | 332 |
| 265 } // namespace extensions | 333 } // namespace extensions |
| 266 | 334 |
| 267 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ | 335 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ |
| OLD | NEW |