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 17 matching lines...) Expand all Loading... | |
28 class URLPatternSet; | 28 class URLPatternSet; |
29 class UserScript; | 29 class UserScript; |
30 | 30 |
31 // A container for the active permissions of an extension. | 31 // A container for the active permissions of an extension. |
32 // TODO(rdevlin.cronin): For the love of everything good, rename this class to | 32 // TODO(rdevlin.cronin): For the love of everything good, rename this class to |
33 // ActivePermissions. We do *not* need PermissionsParser, PermissionSet, | 33 // ActivePermissions. We do *not* need PermissionsParser, PermissionSet, |
34 // PermissionInfo, and PermissionsData. No one will be able to keep them | 34 // PermissionInfo, and PermissionsData. No one will be able to keep them |
35 // straight. | 35 // straight. |
36 class PermissionsData { | 36 class PermissionsData { |
37 public: | 37 public: |
38 // The possible types of access for a given frame. | |
39 enum AccessType { | |
40 DENY_ACCESS, // The extension is not allowed to access the given page. | |
41 ALLOW_ACCESS, // The extension is allowed to access the given page. | |
42 REQUEST_ACCESS // The browser must determine if the extension can access | |
not at google - send to devlin
2014/06/27 23:24:34
the concept of "request access" isn't really the c
Devlin
2014/06/30 17:06:10
Done (though sadly we use SCREAMING_STYLE instead
| |
43 // the given page. | |
44 }; | |
45 | |
38 // Delegate class to allow different contexts (e.g. browser vs renderer) to | 46 // Delegate class to allow different contexts (e.g. browser vs renderer) to |
39 // have control over policy decisions. | 47 // have control over policy decisions. |
40 class PolicyDelegate { | 48 class PolicyDelegate { |
41 public: | 49 public: |
42 virtual ~PolicyDelegate() {} | 50 virtual ~PolicyDelegate() {} |
43 | 51 |
44 // Returns false if script access should be blocked on this page. | 52 // Returns false if script access should be blocked on this page. |
45 // Otherwise, default policy should decide. | 53 // Otherwise, default policy should decide. |
46 virtual bool CanExecuteScriptOnPage(const Extension* extension, | 54 virtual bool CanExecuteScriptOnPage(const Extension* extension, |
47 const GURL& document_url, | 55 const GURL& document_url, |
(...skipping 23 matching lines...) Expand all Loading... | |
71 // Returns true if the given |url| is restricted for the given |extension|, | 79 // Returns true if the given |url| is restricted for the given |extension|, |
72 // as is commonly the case for chrome:// urls. | 80 // as is commonly the case for chrome:// urls. |
73 // NOTE: You probably want to use CanAccessPage(). | 81 // NOTE: You probably want to use CanAccessPage(). |
74 static bool IsRestrictedUrl(const GURL& document_url, | 82 static bool IsRestrictedUrl(const GURL& document_url, |
75 const GURL& top_frame_url, | 83 const GURL& top_frame_url, |
76 const Extension* extension, | 84 const Extension* extension, |
77 std::string* error); | 85 std::string* error); |
78 | 86 |
79 // Sets the runtime permissions of the given |extension| to |permissions|. | 87 // Sets the runtime permissions of the given |extension| to |permissions|. |
80 void SetActivePermissions(const PermissionSet* active) const; | 88 void SetActivePermissions(const PermissionSet* active) const; |
89 // Initializes the withheld/active permissions from |permissions|. | |
not at google - send to devlin
2014/06/27 23:24:34
blank line above here
Devlin
2014/06/30 17:06:10
Done.
| |
90 void InitializePermissions(const PermissionSet* permissions, | |
not at google - send to devlin
2014/06/27 23:24:34
it's odd to call this InitializePermissions when i
Devlin
2014/06/30 17:06:10
I don't feel really strongly about the name on thi
Devlin
2014/06/30 20:28:58
Per offline chat, this has basically been moved to
| |
91 const Extension* extension) const; | |
92 | |
93 // Sets the runtime permissions of the given |extension| to |active| and | |
94 // |withheld|. | |
95 // This should only be used as a means of "copying" permissions data, e.g. | |
96 // to duplicate the information in the renderer. | |
not at google - send to devlin
2014/06/27 23:24:34
I don't see this method being used that way, like
Devlin
2014/06/30 17:06:10
You're right - I didn't update the comment after t
| |
97 void SetPermissions(const PermissionSet* active, | |
98 const PermissionSet* withheld) const; | |
81 | 99 |
82 // Updates the tab-specific permissions of |tab_id| to include those from | 100 // Updates the tab-specific permissions of |tab_id| to include those from |
83 // |permissions|. | 101 // |permissions|. |
84 void UpdateTabSpecificPermissions( | 102 void UpdateTabSpecificPermissions( |
85 int tab_id, | 103 int tab_id, |
86 scoped_refptr<const PermissionSet> permissions) const; | 104 scoped_refptr<const PermissionSet> permissions) const; |
87 | 105 |
88 // Clears the tab-specific permissions of |tab_id|. | 106 // Clears the tab-specific permissions of |tab_id|. |
89 void ClearTabSpecificPermissions(int tab_id) const; | 107 void ClearTabSpecificPermissions(int tab_id) const; |
90 | 108 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
125 PermissionMessages GetPermissionMessages() const; | 143 PermissionMessages GetPermissionMessages() const; |
126 | 144 |
127 // Returns the full list of permission messages that should display at install | 145 // Returns the full list of permission messages that should display at install |
128 // time as strings. | 146 // time as strings. |
129 std::vector<base::string16> GetPermissionMessageStrings() const; | 147 std::vector<base::string16> GetPermissionMessageStrings() const; |
130 | 148 |
131 // Returns the full list of permission details for messages that should | 149 // Returns the full list of permission details for messages that should |
132 // display at install time as strings. | 150 // display at install time as strings. |
133 std::vector<base::string16> GetPermissionMessageDetailsStrings() const; | 151 std::vector<base::string16> GetPermissionMessageDetailsStrings() const; |
134 | 152 |
153 // The following three functions pertain to (possibly withheld) all-hosts | |
154 // permissions. Since all-hosts can take many different forms, we have | |
155 // these functions for them. Any additional withheld permissions should | |
156 // simply be checked, granted, and withheld via a generic | |
157 // HasWithheldPermission(), GrantWithheldPermission(), and | |
158 // WithholdPermission(). | |
159 | |
160 // Returns true if the extension has requested all-hosts permissions (or | |
161 // something close to it), but has had it withheld. | |
162 bool HasWithheldAllHosts() const; | |
not at google - send to devlin
2014/06/30 14:37:03
Why specifically all hosts? The way I was imaginin
Devlin
2014/06/30 17:06:10
See comment in ActiveTabPermissionGranter for why
not at google - send to devlin
2014/07/01 00:28:35
good points. moving this to PermissionsUpdater has
Devlin
2014/07/01 16:27:05
Yep.
| |
163 | |
164 // Grants any withheld all-hosts (or all-hosts-like) permissions. | |
165 void GrantWithheldAllHosts() const; | |
166 | |
167 // Revokes any requests all-hosts (or all-hosts-like) permissions. | |
168 void WithholdAllHosts() const; | |
169 | |
135 // Returns true if the |extension| has permission to access and interact with | 170 // Returns true if the |extension| has permission to access and interact with |
136 // the specified page, in order to do things like inject scripts or modify | 171 // the specified page, in order to do things like inject scripts or modify |
137 // the content. | 172 // the content. |
138 // If this returns false and |error| is non-NULL, |error| will be popualted | 173 // If this returns false and |error| is non-NULL, |error| will be popualted |
139 // with the reason the extension cannot access the page. | 174 // with the reason the extension cannot access the page. |
140 bool CanAccessPage(const Extension* extension, | 175 bool CanAccessPage(const Extension* extension, |
141 const GURL& document_url, | 176 const GURL& document_url, |
142 const GURL& top_document_url, | 177 const GURL& top_document_url, |
143 int tab_id, | 178 int tab_id, |
144 int process_id, | 179 int process_id, |
145 std::string* error) const; | 180 std::string* error) const; |
181 // Like CanAccessPage, but also takes withheld permissions into account. | |
182 // TODO(rdevlin.cronin) We shouldn't have two functions, but not all callers | |
183 // know how to wait for permission. | |
184 AccessType CanAccessPageWithUserConsent(const Extension* extension, | |
not at google - send to devlin
2014/06/27 23:24:34
in the spirit of the comment at the top of the enu
Devlin
2014/06/30 17:06:10
Shorter to write, yay.
| |
185 const GURL& document_url, | |
186 const GURL& top_document_url, | |
187 int tab_id, | |
188 int process_id, | |
189 std::string* error) const; | |
146 | 190 |
147 // Returns true if the |extension| has permission to inject a content script | 191 // Returns true if the |extension| has permission to inject a content script |
148 // on the page. | 192 // on the page. |
149 // If this returns false and |error| is non-NULL, |error| will be popualted | 193 // If this returns false and |error| is non-NULL, |error| will be popualted |
150 // with the reason the extension cannot script the page. | 194 // with the reason the extension cannot script the page. |
151 // NOTE: You almost certainly want to use CanAccessPage() instead of this | 195 // NOTE: You almost certainly want to use CanAccessPage() instead of this |
152 // method. | 196 // method. |
153 bool CanRunContentScriptOnPage(const Extension* extension, | 197 bool CanRunContentScriptOnPage(const Extension* extension, |
154 const GURL& document_url, | 198 const GURL& document_url, |
155 const GURL& top_document_url, | 199 const GURL& top_document_url, |
156 int tab_id, | 200 int tab_id, |
157 int process_id, | 201 int process_id, |
158 std::string* error) const; | 202 std::string* error) const; |
203 // Like CanRunContentScriptOnPage, but also takes withheld permissions into | |
204 // account. | |
205 // TODO(rdevlin.cronin) We shouldn't have two functions, but not all callers | |
206 // know how to wait for permission. | |
207 AccessType CanRunContentScriptOnPageWithUserConsent( | |
not at google - send to devlin
2014/06/27 23:24:34
likewise, GetContentScriptAccess
Devlin
2014/06/30 17:06:10
Done.
| |
208 const Extension* extension, | |
209 const GURL& document_url, | |
210 const GURL& top_document_url, | |
211 int tab_id, | |
212 int process_id, | |
213 std::string* error) const; | |
159 | 214 |
160 // Returns true if extension is allowed to obtain the contents of a page as | 215 // Returns true if extension is allowed to obtain the contents of a page as |
161 // an image. Since a page may contain sensitive information, this is | 216 // an image. Since a page may contain sensitive information, this is |
162 // restricted to the extension's host permissions as well as the extension | 217 // restricted to the extension's host permissions as well as the extension |
163 // page itself. | 218 // page itself. |
164 bool CanCaptureVisiblePage(int tab_id, std::string* error) const; | 219 bool CanCaptureVisiblePage(int tab_id, std::string* error) const; |
165 | 220 |
166 // Returns true if the user should be alerted that the |extension| is running | |
167 // a script. If |tab_id| and |url| are included, this also considers tab- | |
168 // specific permissions. | |
169 bool RequiresActionForScriptExecution(const Extension* extension) const; | |
170 bool RequiresActionForScriptExecution(const Extension* extension, | |
171 int tab_id, | |
172 const GURL& url) const; | |
173 | |
174 scoped_refptr<const PermissionSet> active_permissions() const { | 221 scoped_refptr<const PermissionSet> active_permissions() const { |
175 base::AutoLock auto_lock(runtime_lock_); | 222 base::AutoLock auto_lock(runtime_lock_); |
176 return active_permissions_unsafe_; | 223 return active_permissions_unsafe_; |
177 } | 224 } |
178 | 225 |
226 scoped_refptr<const PermissionSet> withheld_permissions() const { | |
227 base::AutoLock auto_lock(runtime_lock_); | |
228 return withheld_permissions_unsafe_; | |
229 } | |
230 | |
179 #if defined(UNIT_TEST) | 231 #if defined(UNIT_TEST) |
180 scoped_refptr<const PermissionSet> GetTabSpecificPermissionsForTesting( | 232 scoped_refptr<const PermissionSet> GetTabSpecificPermissionsForTesting( |
181 int tab_id) const { | 233 int tab_id) const { |
182 return GetTabSpecificPermissions(tab_id); | 234 return GetTabSpecificPermissions(tab_id); |
183 } | 235 } |
184 #endif | 236 #endif |
185 | 237 |
186 private: | 238 private: |
187 typedef std::map<int, scoped_refptr<const PermissionSet> > TabPermissionsMap; | 239 typedef std::map<int, scoped_refptr<const PermissionSet> > TabPermissionsMap; |
188 | 240 |
189 // Gets the tab-specific host permissions of |tab_id|, or NULL if there | 241 // Gets the tab-specific host permissions of |tab_id|, or NULL if there |
190 // aren't any. | 242 // aren't any. |
191 scoped_refptr<const PermissionSet> GetTabSpecificPermissions( | 243 scoped_refptr<const PermissionSet> GetTabSpecificPermissions( |
192 int tab_id) const; | 244 int tab_id) const; |
193 | 245 |
194 // Returns true if the |extension| has tab-specific permission to operate on | 246 // Returns true if the |extension| has tab-specific permission to operate on |
195 // the tab specified by |tab_id| with the given |url|. | 247 // the tab specified by |tab_id| with the given |url|. |
196 // Note that if this returns false, it doesn't mean the extension can't run on | 248 // Note that if this returns false, it doesn't mean the extension can't run on |
197 // the given tab, only that it does not have tab-specific permission to do so. | 249 // the given tab, only that it does not have tab-specific permission to do so. |
198 bool HasTabSpecificPermissionToExecuteScript(int tab_id, | 250 bool HasTabSpecificPermissionToExecuteScript(int tab_id, |
199 const GURL& url) const; | 251 const GURL& url) const; |
200 | 252 |
201 // Returns true if the extension is permitted to run on the given page, | 253 // Returns whether or not the extension is permitted to run on the given page, |
202 // checking against |permitted_url_patterns| in addition to blocking special | 254 // checking against |permitted_url_patterns| in addition to blocking special |
203 // sites (like the webstore or chrome:// urls). | 255 // sites (like the webstore or chrome:// urls). |
204 bool CanRunOnPage(const Extension* extension, | 256 AccessType CanRunOnPage(const Extension* extension, |
205 const GURL& document_url, | 257 const GURL& document_url, |
206 const GURL& top_document_url, | 258 const GURL& top_document_url, |
207 int tab_id, | 259 int tab_id, |
208 int process_id, | 260 int process_id, |
209 const URLPatternSet& permitted_url_patterns, | 261 const URLPatternSet& permitted_url_patterns, |
210 std::string* error) const; | 262 const URLPatternSet& withheld_url_patterns, |
263 std::string* error) const; | |
211 | 264 |
212 // The associated extension's id. | 265 // The associated extension's id. |
213 std::string extension_id_; | 266 std::string extension_id_; |
214 | 267 |
215 // The associated extension's manifest type. | 268 // The associated extension's manifest type. |
216 Manifest::Type manifest_type_; | 269 Manifest::Type manifest_type_; |
217 | 270 |
218 mutable base::Lock runtime_lock_; | 271 mutable base::Lock runtime_lock_; |
219 | 272 |
220 // The permission's which are currently active on the extension during | 273 // The permission's which are currently active on the extension during |
221 // runtime. | 274 // runtime. |
222 // Unsafe indicates that we must lock anytime this is directly accessed. | 275 // Unsafe indicates that we must lock anytime this is directly accessed. |
223 // Unless you need to change |active_permissions_unsafe_|, use the (safe) | 276 // Unless you need to change |active_permissions_unsafe_|, use the (safe) |
224 // active_permissions() accessor. | 277 // active_permissions() accessor. |
225 mutable scoped_refptr<const PermissionSet> active_permissions_unsafe_; | 278 mutable scoped_refptr<const PermissionSet> active_permissions_unsafe_; |
226 | 279 |
280 // The permissions the extension requested, but was not granted due because | |
281 // they are too powerful. This includes things like all_hosts. | |
282 // Unsafe indicates that we must lock anytime this is directly accessed. | |
283 // Unless you need to change |withheld_permissions_unsafe_|, use the (safe) | |
284 // withheld_permissions() accessor. | |
285 mutable scoped_refptr<const PermissionSet> withheld_permissions_unsafe_; | |
286 | |
227 mutable TabPermissionsMap tab_specific_permissions_; | 287 mutable TabPermissionsMap tab_specific_permissions_; |
228 | 288 |
229 DISALLOW_COPY_AND_ASSIGN(PermissionsData); | 289 DISALLOW_COPY_AND_ASSIGN(PermissionsData); |
230 }; | 290 }; |
231 | 291 |
232 } // namespace extensions | 292 } // namespace extensions |
233 | 293 |
234 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ | 294 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ |
OLD | NEW |