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

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

Issue 2833843004: Reland: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Removed unused URLPatternSet parameters in ExtensionMsg_PermissionSetStruct which was causing MSAN … Created 3 years, 8 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 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 // Marks this extension as 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() 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
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 }
260
261 bool IsRuntimeBlockedHostForTesting(const GURL& url) const {
262 base::AutoLock auto_lock(runtime_lock_);
263 return IsRuntimeBlockedHost(url);
264 }
209 #endif 265 #endif
210 266
211 private: 267 private:
212 // Gets the tab-specific host permissions of |tab_id|, or NULL if there 268 // Gets the tab-specific host permissions of |tab_id|, or NULL if there
213 // aren't any. 269 // aren't any.
214 // Must be called with |runtime_lock_| acquired. 270 // Must be called with |runtime_lock_| acquired.
215 const PermissionSet* GetTabSpecificPermissions(int tab_id) const; 271 const PermissionSet* GetTabSpecificPermissions(int tab_id) const;
216 272
217 // Returns true if the |extension| has tab-specific permission to operate on 273 // Returns true if the |extension| has tab-specific permission to operate on
218 // the tab specified by |tab_id| with the given |url|. 274 // the tab specified by |tab_id| with the given |url|.
219 // Note that if this returns false, it doesn't mean the extension can't run on 275 // Note that if this returns false, it doesn't mean the extension can't run on
220 // the given tab, only that it does not have tab-specific permission to do so. 276 // the given tab, only that it does not have tab-specific permission to do so.
221 // Must be called with |runtime_lock_| acquired. 277 // Must be called with |runtime_lock_| acquired.
222 bool HasTabSpecificPermissionToExecuteScript(int tab_id, 278 bool HasTabSpecificPermissionToExecuteScript(int tab_id,
223 const GURL& url) const; 279 const GURL& url) const;
224 280
225 // Returns whether or not the extension is permitted to run on the given page, 281 // Returns whether or not the extension is permitted to run on the given page,
226 // checking against |permitted_url_patterns| in addition to blocking special 282 // checking against |permitted_url_patterns| in addition to blocking special
227 // sites (like the webstore or chrome:// urls). 283 // sites (like the webstore or chrome:// urls).
228 // Must be called with |runtime_lock_| acquired. 284 // Must be called with |runtime_lock_| acquired.
229 AccessType CanRunOnPage(const Extension* extension, 285 AccessType CanRunOnPage(const Extension* extension,
230 const GURL& document_url, 286 const GURL& document_url,
231 int tab_id, 287 int tab_id,
232 const URLPatternSet& permitted_url_patterns, 288 const URLPatternSet& permitted_url_patterns,
233 const URLPatternSet& withheld_url_patterns, 289 const URLPatternSet& withheld_url_patterns,
234 std::string* error) const; 290 std::string* error) const;
235 291
292 // Check if a specific URL is blocked by policy from extension use at runtime.
293 bool IsRuntimeBlockedHost(const GURL& url) const;
294
295 // Same as policy_blocked_hosts but instead returns a reference.
296 // You must acquire runtime_lock_ before calling this.
297 const URLPatternSet& PolicyBlockedHostsUnsafe() const;
298
299 // Same as policy_allowed_hosts but instead returns a reference.
300 // You must acquire runtime_lock_ before calling this.
301 const URLPatternSet& PolicyAllowedHostsUnsafe() const;
302
236 // The associated extension's id. 303 // The associated extension's id.
237 std::string extension_id_; 304 std::string extension_id_;
238 305
239 // The associated extension's manifest type. 306 // The associated extension's manifest type.
240 Manifest::Type manifest_type_; 307 Manifest::Type manifest_type_;
241 308
242 mutable base::Lock runtime_lock_; 309 mutable base::Lock runtime_lock_;
243 310
244 // The permission's which are currently active on the extension during 311 // The permission's which are currently active on the extension during
245 // runtime. 312 // runtime.
246 // Unsafe indicates that we must lock anytime this is directly accessed. 313 // Unsafe indicates that we must lock anytime this is directly accessed.
247 // Unless you need to change |active_permissions_unsafe_|, use the (safe) 314 // Unless you need to change |active_permissions_unsafe_|, use the (safe)
248 // active_permissions() accessor. 315 // active_permissions() accessor.
249 mutable std::unique_ptr<const PermissionSet> active_permissions_unsafe_; 316 mutable std::unique_ptr<const PermissionSet> active_permissions_unsafe_;
250 317
251 // The permissions the extension requested, but was not granted due because 318 // The permissions the extension requested, but was not granted due because
252 // they are too powerful. This includes things like all_hosts. 319 // they are too powerful. This includes things like all_hosts.
253 // Unsafe indicates that we must lock anytime this is directly accessed. 320 // Unsafe indicates that we must lock anytime this is directly accessed.
254 // Unless you need to change |withheld_permissions_unsafe_|, use the (safe) 321 // Unless you need to change |withheld_permissions_unsafe_|, use the (safe)
255 // withheld_permissions() accessor. 322 // withheld_permissions() accessor.
256 mutable std::unique_ptr<const PermissionSet> withheld_permissions_unsafe_; 323 mutable std::unique_ptr<const PermissionSet> withheld_permissions_unsafe_;
257 324
325 // The list of hosts an extension may not interact with by policy.
326 // Unless you need to change |policy_blocked_hosts_unsafe_|, use the (safe)
327 // policy_blocked_hosts() accessor.
328 mutable URLPatternSet policy_blocked_hosts_unsafe_;
329
330 // The exclusive list of hosts an extension may interact with by policy.
331 // Unless you need to change |policy_allowed_hosts_unsafe_|, use the (safe)
332 // policy_allowed_hosts() accessor.
333 mutable URLPatternSet policy_allowed_hosts_unsafe_;
334
335 // If the ExtensionSettings policy is not being used, or no per-extension
336 // exception to the default policy was declared for this extension.
337 mutable bool uses_default_policy_host_restrictions = true;
338
258 mutable TabPermissionsMap tab_specific_permissions_; 339 mutable TabPermissionsMap tab_specific_permissions_;
259 340
260 mutable std::unique_ptr<base::ThreadChecker> thread_checker_; 341 mutable std::unique_ptr<base::ThreadChecker> thread_checker_;
261 342
262 DISALLOW_COPY_AND_ASSIGN(PermissionsData); 343 DISALLOW_COPY_AND_ASSIGN(PermissionsData);
263 }; 344 };
264 345
265 } // namespace extensions 346 } // namespace extensions
266 347
267 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_ 348 #endif // EXTENSIONS_COMMON_PERMISSIONS_PERMISSIONS_DATA_H_
OLDNEW
« no previous file with comments | « extensions/common/extension_messages.cc ('k') | extensions/common/permissions/permissions_data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698