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

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

Issue 2499493004: Communicate ExtensionSettings policy to renderers (Closed)
Patch Set: Add URLPattern effective TLD whitelisting, Switched IPC to UpdatePermissions, Removed shared memor… Created 3 years, 11 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 // Check if a specific URL is blocked by policy from extension use at runtime.
86 bool IsRuntimeBlockedHost(const GURL& url) const;
Devlin 2017/01/26 22:47:40 Why do we need to expose this? It should be handl
nrpeter 2017/02/03 19:32:24 Done, made this private.
87
88 // Is this extension using the default scope for runtime_blocked_hosts and
89 // runtime_allowed_hosts of the ExtensionSettings policy.
90 bool UsesDefaultPolicyHostRestrictions() const;
91
85 // Locks the permissions data to the current thread. We don't do this on 92 // Locks the permissions data to the current thread. We don't do this on
86 // construction, since extensions are initialized across multiple threads. 93 // construction, since extensions are initialized across multiple threads.
87 void BindToCurrentThread() const; 94 void BindToCurrentThread() const;
88 95
89 // Sets the runtime permissions of the given |extension| to |active| and 96 // Sets the runtime permissions of the given |extension| to |active| and
90 // |withheld|. 97 // |withheld|.
91 void SetPermissions(std::unique_ptr<const PermissionSet> active, 98 void SetPermissions(std::unique_ptr<const PermissionSet> active,
92 std::unique_ptr<const PermissionSet> withheld) const; 99 std::unique_ptr<const PermissionSet> withheld) const;
93 100
101 // Applies restrictions from enterprise policy limiting which URLs this
102 // extension can interact with. The same policy can also define a default set
103 // of URL restrictions using SetDefaultPolicyHostRestrictions. This function
104 // overrides any default host restriction policy.
105 void SetPolicyHostRestrictions(
106 const URLPatternSet runtime_blocked_hosts,
107 const URLPatternSet runtime_allowed_hosts,
108 const bool is_default_runtime_blocked_allowed_hosts) const;
109
110 // Applies restrictions from enterprise policy limiting which URLs all
111 // extensions can interact with. This restriction can be overridden on a
112 // per-extnsion basis with SetPolicyHostRestrictions.
113 static void SetDefaultPolicyHostRestrictions(
114 const URLPatternSet default_runtime_blocked_hosts,
115 const URLPatternSet default_runtime_allowed_hosts);
116
94 // Sets the active permissions, leaving withheld the same. 117 // Sets the active permissions, leaving withheld the same.
95 void SetActivePermissions(std::unique_ptr<const PermissionSet> active) const; 118 void SetActivePermissions(std::unique_ptr<const PermissionSet> active) const;
96 119
97 // Updates the tab-specific permissions of |tab_id| to include those from 120 // Updates the tab-specific permissions of |tab_id| to include those from
98 // |permissions|. 121 // |permissions|.
99 void UpdateTabSpecificPermissions(int tab_id, 122 void UpdateTabSpecificPermissions(int tab_id,
100 const PermissionSet& permissions) const; 123 const PermissionSet& permissions) const;
101 124
102 // Clears the tab-specific permissions of |tab_id|. 125 // Clears the tab-specific permissions of |tab_id|.
103 void ClearTabSpecificPermissions(int tab_id) const; 126 void ClearTabSpecificPermissions(int tab_id) const;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 const PermissionSet& active_permissions() const { 217 const PermissionSet& active_permissions() const {
195 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); 218 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread());
196 return *active_permissions_unsafe_; 219 return *active_permissions_unsafe_;
197 } 220 }
198 221
199 const PermissionSet& withheld_permissions() const { 222 const PermissionSet& withheld_permissions() const {
200 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread()); 223 DCHECK(!thread_checker_ || thread_checker_->CalledOnValidThread());
201 return *withheld_permissions_unsafe_; 224 return *withheld_permissions_unsafe_;
202 } 225 }
203 226
227 // Returns list of hosts this extension may not interact with by policy.
228 static const URLPatternSet& default_runtime_blocked_hosts();
229
230 // Returns list of hosts this extension may interact with regardless of
231 // what is defined by runtime_blocked_hosts().
232 static const URLPatternSet& default_runtime_allowed_hosts();
233
234 // Returns list of hosts this extension may not interact with by policy.
235 const URLPatternSet& runtime_blocked_hosts() const;
236
237 // Returns list of hosts this extension may interact with regardless of
238 // what is defined by runtime_blocked_hosts().
239 const URLPatternSet& runtime_allowed_hosts() const;
240
204 #if defined(UNIT_TEST) 241 #if defined(UNIT_TEST)
205 const PermissionSet* GetTabSpecificPermissionsForTesting(int tab_id) const { 242 const PermissionSet* GetTabSpecificPermissionsForTesting(int tab_id) const {
206 base::AutoLock auto_lock(runtime_lock_); 243 base::AutoLock auto_lock(runtime_lock_);
207 return GetTabSpecificPermissions(tab_id); 244 return GetTabSpecificPermissions(tab_id);
208 } 245 }
209 #endif 246 #endif
210 247
211 private: 248 private:
212 // Gets the tab-specific host permissions of |tab_id|, or NULL if there 249 // Gets the tab-specific host permissions of |tab_id|, or NULL if there
213 // aren't any. 250 // aren't any.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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_;
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