| 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 <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 class PermissionsData { | 36 class PermissionsData { |
| 37 public: | 37 public: |
| 38 // The possible types of access for a given frame. | 38 // The possible types of access for a given frame. |
| 39 enum AccessType { | 39 enum AccessType { |
| 40 ACCESS_DENIED, // The extension is not allowed to access the given page. | 40 ACCESS_DENIED, // The extension is not allowed to access the given page. |
| 41 ACCESS_ALLOWED, // The extension is allowed to access the given page. | 41 ACCESS_ALLOWED, // The extension is allowed to access the given page. |
| 42 ACCESS_WITHHELD // The browser must determine if the extension can access | 42 ACCESS_WITHHELD // The browser must determine if the extension can access |
| 43 // the given page. | 43 // the given page. |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 using TabPermissionsMap = std::map<int, scoped_refptr<const PermissionSet>>; |
| 47 |
| 46 // Delegate class to allow different contexts (e.g. browser vs renderer) to | 48 // Delegate class to allow different contexts (e.g. browser vs renderer) to |
| 47 // have control over policy decisions. | 49 // have control over policy decisions. |
| 48 class PolicyDelegate { | 50 class PolicyDelegate { |
| 49 public: | 51 public: |
| 50 virtual ~PolicyDelegate() {} | 52 virtual ~PolicyDelegate() {} |
| 51 | 53 |
| 52 // Returns false if script access should be blocked on this page. | 54 // Returns false if script access should be blocked on this page. |
| 53 // Otherwise, default policy should decide. | 55 // Otherwise, default policy should decide. |
| 54 virtual bool CanExecuteScriptOnPage(const Extension* extension, | 56 virtual bool CanExecuteScriptOnPage(const Extension* extension, |
| 55 const GURL& document_url, | 57 const GURL& document_url, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 // Note this does not include APIs with no corresponding permission, like | 110 // Note this does not include APIs with no corresponding permission, like |
| 109 // "runtime" or "browserAction". | 111 // "runtime" or "browserAction". |
| 110 // TODO(mpcomplete): drop the "API" from these names, it's confusing. | 112 // TODO(mpcomplete): drop the "API" from these names, it's confusing. |
| 111 bool HasAPIPermission(APIPermission::ID permission) const; | 113 bool HasAPIPermission(APIPermission::ID permission) const; |
| 112 bool HasAPIPermission(const std::string& permission_name) const; | 114 bool HasAPIPermission(const std::string& permission_name) const; |
| 113 bool HasAPIPermissionForTab(int tab_id, APIPermission::ID permission) const; | 115 bool HasAPIPermissionForTab(int tab_id, APIPermission::ID permission) const; |
| 114 bool CheckAPIPermissionWithParam( | 116 bool CheckAPIPermissionWithParam( |
| 115 APIPermission::ID permission, | 117 APIPermission::ID permission, |
| 116 const APIPermission::CheckParam* param) const; | 118 const APIPermission::CheckParam* param) const; |
| 117 | 119 |
| 118 // TODO(rdevlin.cronin): GetEffectiveHostPermissions(), HasHostPermission(), | 120 // Returns the hosts this extension effectively has access to, including |
| 119 // and HasEffectiveAccessToAllHosts() are just forwards for the active | 121 // explicit and scriptable hosts, and any hosts on tabs the extension has |
| 122 // active tab permissions for. |
| 123 URLPatternSet GetEffectiveHostPermissions() const; |
| 124 |
| 125 // TODO(rdevlin.cronin): HasHostPermission() and |
| 126 // HasEffectiveAccessToAllHosts() are just forwards for the active |
| 120 // permissions. We should either get rid of these, and have callers use | 127 // permissions. We should either get rid of these, and have callers use |
| 121 // active_permissions(), or should get rid of active_permissions(), and make | 128 // active_permissions(), or should get rid of active_permissions(), and make |
| 122 // callers use PermissionsData for everything. We should not do both. | 129 // callers use PermissionsData for everything. We should not do both. |
| 123 | 130 |
| 124 // Returns the effective hosts associated with the active permissions. | |
| 125 const URLPatternSet& GetEffectiveHostPermissions() const; | |
| 126 | |
| 127 // Whether the extension has access to the given |url|. | 131 // Whether the extension has access to the given |url|. |
| 128 bool HasHostPermission(const GURL& url) const; | 132 bool HasHostPermission(const GURL& url) const; |
| 129 | 133 |
| 130 // Whether the extension has effective access to all hosts. This is true if | 134 // Whether the extension has effective access to all hosts. This is true if |
| 131 // there is a content script that matches all hosts, if there is a host | 135 // there is a content script that matches all hosts, if there is a host |
| 132 // permission grants access to all hosts (like <all_urls>) or an api | 136 // permission grants access to all hosts (like <all_urls>) or an api |
| 133 // permission that effectively grants access to all hosts (e.g. proxy, | 137 // permission that effectively grants access to all hosts (e.g. proxy, |
| 134 // network, etc.) | 138 // network, etc.) |
| 135 bool HasEffectiveAccessToAllHosts() const; | 139 bool HasEffectiveAccessToAllHosts() const; |
| 136 | 140 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 int process_id, | 198 int process_id, |
| 195 std::string* error) const; | 199 std::string* error) const; |
| 196 | 200 |
| 197 // Returns true if extension is allowed to obtain the contents of a page as | 201 // Returns true if extension is allowed to obtain the contents of a page as |
| 198 // an image. Since a page may contain sensitive information, this is | 202 // an image. Since a page may contain sensitive information, this is |
| 199 // restricted to the extension's host permissions as well as the extension | 203 // restricted to the extension's host permissions as well as the extension |
| 200 // page itself. | 204 // page itself. |
| 201 bool CanCaptureVisiblePage(int tab_id, std::string* error) const; | 205 bool CanCaptureVisiblePage(int tab_id, std::string* error) const; |
| 202 | 206 |
| 203 const scoped_refptr<const PermissionSet>& active_permissions() const { | 207 const scoped_refptr<const PermissionSet>& active_permissions() const { |
| 204 // TODO(dcheng): What is the point of this lock? | 208 // We lock so that we can't also be setting the permissions while returning. |
| 205 base::AutoLock auto_lock(runtime_lock_); | 209 base::AutoLock auto_lock(runtime_lock_); |
| 206 return active_permissions_unsafe_; | 210 return active_permissions_unsafe_; |
| 207 } | 211 } |
| 208 | 212 |
| 209 const scoped_refptr<const PermissionSet>& withheld_permissions() const { | 213 const scoped_refptr<const PermissionSet>& withheld_permissions() const { |
| 210 // TODO(dcheng): What is the point of this lock? | 214 // We lock so that we can't also be setting the permissions while returning. |
| 215 base::AutoLock auto_lock(runtime_lock_); |
| 211 return withheld_permissions_unsafe_; | 216 return withheld_permissions_unsafe_; |
| 212 } | 217 } |
| 213 | 218 |
| 219 const TabPermissionsMap& tab_specific_permissions() const { |
| 220 // We lock so that we can't also be setting the permissions while returning. |
| 221 base::AutoLock auto_lock(runtime_lock_); |
| 222 return tab_specific_permissions_; |
| 223 } |
| 224 |
| 214 #if defined(UNIT_TEST) | 225 #if defined(UNIT_TEST) |
| 215 scoped_refptr<const PermissionSet> GetTabSpecificPermissionsForTesting( | 226 scoped_refptr<const PermissionSet> GetTabSpecificPermissionsForTesting( |
| 216 int tab_id) const { | 227 int tab_id) const { |
| 217 return GetTabSpecificPermissions(tab_id); | 228 return GetTabSpecificPermissions(tab_id); |
| 218 } | 229 } |
| 219 #endif | 230 #endif |
| 220 | 231 |
| 221 private: | 232 private: |
| 222 typedef std::map<int, scoped_refptr<const PermissionSet> > TabPermissionsMap; | |
| 223 | |
| 224 // Gets the tab-specific host permissions of |tab_id|, or NULL if there | 233 // Gets the tab-specific host permissions of |tab_id|, or NULL if there |
| 225 // aren't any. | 234 // aren't any. |
| 226 scoped_refptr<const PermissionSet> GetTabSpecificPermissions( | 235 scoped_refptr<const PermissionSet> GetTabSpecificPermissions( |
| 227 int tab_id) const; | 236 int tab_id) const; |
| 228 | 237 |
| 229 // Returns true if the |extension| has tab-specific permission to operate on | 238 // Returns true if the |extension| has tab-specific permission to operate on |
| 230 // the tab specified by |tab_id| with the given |url|. | 239 // the tab specified by |tab_id| with the given |url|. |
| 231 // Note that if this returns false, it doesn't mean the extension can't run on | 240 // Note that if this returns false, it doesn't mean the extension can't run on |
| 232 // the given tab, only that it does not have tab-specific permission to do so. | 241 // the given tab, only that it does not have tab-specific permission to do so. |
| 233 bool HasTabSpecificPermissionToExecuteScript(int tab_id, | 242 bool HasTabSpecificPermissionToExecuteScript(int tab_id, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 mutable scoped_refptr<const PermissionSet> withheld_permissions_unsafe_; | 277 mutable scoped_refptr<const PermissionSet> withheld_permissions_unsafe_; |
| 269 | 278 |
| 270 mutable TabPermissionsMap tab_specific_permissions_; | 279 mutable TabPermissionsMap tab_specific_permissions_; |
| 271 | 280 |
| 272 DISALLOW_COPY_AND_ASSIGN(PermissionsData); | 281 DISALLOW_COPY_AND_ASSIGN(PermissionsData); |
| 273 }; | 282 }; |
| 274 | 283 |
| 275 } // namespace extensions | 284 } // namespace extensions |
| 276 | 285 |
| 277 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ | 286 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ |
| OLD | NEW |