Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: extensions/common/permissions/permissions_data.h

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Style fixes, prevent heap leak. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 runtime_blocked_hosts and
86 // runtime_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;
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.
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
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 static const URLPatternSet& default_runtime_blocked_hosts();
Devlin 2017/02/14 23:17:10 These should only be used for serialization during
nrpeter 2017/03/22 23:47:39 This has two uses 1. For serialization 2. For use
226
227 // Returns list of hosts this extension may interact with regardless of
228 // what is defined by runtime_blocked_hosts().
229 static const URLPatternSet& default_runtime_allowed_hosts();
230
231 // Returns list of hosts this extension may not interact with by policy.
232 const URLPatternSet& runtime_blocked_hosts() const;
233
234 // Returns list of hosts this extension may interact with regardless of
235 // what is defined by runtime_blocked_hosts().
236 const URLPatternSet& runtime_allowed_hosts() const;
237
204 #if defined(UNIT_TEST) 238 #if defined(UNIT_TEST)
205 const PermissionSet* GetTabSpecificPermissionsForTesting(int tab_id) const { 239 const PermissionSet* GetTabSpecificPermissionsForTesting(int tab_id) const {
206 base::AutoLock auto_lock(runtime_lock_); 240 base::AutoLock auto_lock(runtime_lock_);
207 return GetTabSpecificPermissions(tab_id); 241 return GetTabSpecificPermissions(tab_id);
208 } 242 }
209 #endif 243 #endif
210 244
211 private: 245 private:
212 // Gets the tab-specific host permissions of |tab_id|, or NULL if there 246 // Gets the tab-specific host permissions of |tab_id|, or NULL if there
213 // aren't any. 247 // aren't any.
(...skipping 12 matching lines...) Expand all
226 // checking against |permitted_url_patterns| in addition to blocking special 260 // checking against |permitted_url_patterns| in addition to blocking special
227 // sites (like the webstore or chrome:// urls). 261 // sites (like the webstore or chrome:// urls).
228 // Must be called with |runtime_lock_| acquired. 262 // Must be called with |runtime_lock_| acquired.
229 AccessType CanRunOnPage(const Extension* extension, 263 AccessType CanRunOnPage(const Extension* extension,
230 const GURL& document_url, 264 const GURL& document_url,
231 int tab_id, 265 int tab_id,
232 const URLPatternSet& permitted_url_patterns, 266 const URLPatternSet& permitted_url_patterns,
233 const URLPatternSet& withheld_url_patterns, 267 const URLPatternSet& withheld_url_patterns,
234 std::string* error) const; 268 std::string* error) const;
235 269
270 // Check if a specific URL is blocked by policy from extension use at runtime.
271 bool IsRuntimeBlockedHost(const GURL& url) const;
272
236 // The associated extension's id. 273 // The associated extension's id.
237 std::string extension_id_; 274 std::string extension_id_;
238 275
239 // The associated extension's manifest type. 276 // The associated extension's manifest type.
240 Manifest::Type manifest_type_; 277 Manifest::Type manifest_type_;
241 278
242 mutable base::Lock runtime_lock_; 279 mutable base::Lock runtime_lock_;
243 280
244 // The permission's which are currently active on the extension during 281 // The permission's which are currently active on the extension during
245 // runtime. 282 // runtime.
246 // Unsafe indicates that we must lock anytime this is directly accessed. 283 // Unsafe indicates that we must lock anytime this is directly accessed.
247 // Unless you need to change |active_permissions_unsafe_|, use the (safe) 284 // Unless you need to change |active_permissions_unsafe_|, use the (safe)
248 // active_permissions() accessor. 285 // active_permissions() accessor.
249 mutable std::unique_ptr<const PermissionSet> active_permissions_unsafe_; 286 mutable std::unique_ptr<const PermissionSet> active_permissions_unsafe_;
250 287
251 // The permissions the extension requested, but was not granted due because 288 // The permissions the extension requested, but was not granted due because
252 // they are too powerful. This includes things like all_hosts. 289 // they are too powerful. This includes things like all_hosts.
253 // Unsafe indicates that we must lock anytime this is directly accessed. 290 // Unsafe indicates that we must lock anytime this is directly accessed.
254 // Unless you need to change |withheld_permissions_unsafe_|, use the (safe) 291 // Unless you need to change |withheld_permissions_unsafe_|, use the (safe)
255 // withheld_permissions() accessor. 292 // withheld_permissions() accessor.
256 mutable std::unique_ptr<const PermissionSet> withheld_permissions_unsafe_; 293 mutable std::unique_ptr<const PermissionSet> withheld_permissions_unsafe_;
257 294
295 // The list of hosts an extension may not interact with by policy.
296 // Unless you need to change |runtime_blocked_hosts_unsafe_|, use the (safe)
297 // runtime_blocked_hosts() accessor.
298 mutable URLPatternSet runtime_blocked_hosts_unsafe_;
Devlin 2017/02/14 23:17:10 runtime_blocked_hosts sounds weird - maybe policy_
nrpeter 2017/03/22 23:47:39 Done.
299
300 // The exclusive list of hosts an extension may interact with by policy.
301 // Unless you need to change |runtime_allowed_hosts_unsafe_|, use the (safe)
302 // runtime_allowed_hosts() accessor.
303 mutable URLPatternSet runtime_allowed_hosts_unsafe_;
304
305 // If the ExtensionSettings policy is not being used, or no per-extension
306 // exception to the default policy was declared for this extension.
307 mutable bool uses_default_policy_host_restrictions_ = true;
308
258 mutable TabPermissionsMap tab_specific_permissions_; 309 mutable TabPermissionsMap tab_specific_permissions_;
259 310
260 mutable std::unique_ptr<base::ThreadChecker> thread_checker_; 311 mutable std::unique_ptr<base::ThreadChecker> thread_checker_;
261 312
262 DISALLOW_COPY_AND_ASSIGN(PermissionsData); 313 DISALLOW_COPY_AND_ASSIGN(PermissionsData);
263 }; 314 };
264 315
265 } // namespace extensions 316 } // namespace extensions
266 317
267 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ 318 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698