OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 5 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
14 #include "chrome/browser/content_settings/cookie_settings.h" | 14 #include "chrome/browser/content_settings/cookie_settings.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" | 16 #include "chrome/common/extensions/manifest_handlers/app_isolation_info.h" |
17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 17 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
18 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
19 #include "components/content_settings/core/common/content_settings.h" | 19 #include "components/content_settings/core/common/content_settings.h" |
20 #include "components/content_settings/core/common/content_settings_types.h" | 20 #include "components/content_settings/core/common/content_settings_types.h" |
21 #include "content/public/browser/browser_context.h" | 21 #include "content/public/browser/browser_context.h" |
22 #include "content/public/browser/browser_thread.h" | 22 #include "content/public/browser/browser_thread.h" |
23 #include "content/public/browser/storage_partition.h" | 23 #include "content/public/browser/storage_partition.h" |
24 #include "content/public/common/url_constants.h" | 24 #include "content/public/common/url_constants.h" |
25 #include "extensions/common/constants.h" | 25 #include "extensions/common/constants.h" |
26 #include "extensions/common/extension.h" | 26 #include "extensions/common/extension.h" |
27 #include "extensions/common/extension_set.h" | 27 #include "extensions/common/extension_set.h" |
28 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" | |
28 #include "extensions/common/permissions/permissions_data.h" | 29 #include "extensions/common/permissions/permissions_data.h" |
29 #include "storage/browser/quota/quota_manager.h" | 30 #include "storage/browser/quota/quota_manager.h" |
30 #include "storage/common/quota/quota_status_code.h" | 31 #include "storage/common/quota/quota_status_code.h" |
31 #include "storage/common/quota/quota_types.h" | 32 #include "storage/common/quota/quota_types.h" |
32 | 33 |
33 using content::BrowserThread; | 34 using content::BrowserThread; |
34 using extensions::APIPermission; | 35 using extensions::APIPermission; |
35 using extensions::Extension; | 36 using extensions::Extension; |
36 using storage::SpecialStoragePolicy; | 37 using storage::SpecialStoragePolicy; |
37 | 38 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
89 | 90 |
90 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { | 91 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { |
91 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUnlimitedStorage)) | 92 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kUnlimitedStorage)) |
92 return true; | 93 return true; |
93 | 94 |
94 if (origin.SchemeIs(content::kChromeDevToolsScheme) && | 95 if (origin.SchemeIs(content::kChromeDevToolsScheme) && |
95 origin.host() == chrome::kChromeUIDevToolsHost) | 96 origin.host() == chrome::kChromeUIDevToolsHost) |
96 return true; | 97 return true; |
97 | 98 |
98 base::AutoLock locker(lock_); | 99 base::AutoLock locker(lock_); |
99 return unlimited_extensions_.Contains(origin); | 100 return unlimited_extensions_.Contains(origin) || |
101 content_capabilities_unlimited_extensions_.GrantsCapabilitiesTo( | |
102 origin); | |
100 } | 103 } |
101 | 104 |
102 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { | 105 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { |
103 if (cookie_settings_.get() == NULL) | 106 if (cookie_settings_.get() == NULL) |
104 return false; | 107 return false; |
105 return cookie_settings_->IsCookieSessionOnly(origin); | 108 return cookie_settings_->IsCookieSessionOnly(origin); |
106 } | 109 } |
107 | 110 |
108 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { | 111 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { |
109 base::AutoLock locker(lock_); | 112 base::AutoLock locker(lock_); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( | 148 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( |
146 const GURL& origin) { | 149 const GURL& origin) { |
147 base::AutoLock locker(lock_); | 150 base::AutoLock locker(lock_); |
148 return protected_apps_.ExtensionsContaining(origin); | 151 return protected_apps_.ExtensionsContaining(origin); |
149 } | 152 } |
150 | 153 |
151 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( | 154 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( |
152 const extensions::Extension* extension, | 155 const extensions::Extension* extension, |
153 content::BrowserContext* browser_context) { | 156 content::BrowserContext* browser_context) { |
154 DCHECK(extension); | 157 DCHECK(extension); |
155 if (!(NeedsProtection(extension) || | 158 |
156 extension->permissions_data()->HasAPIPermission( | 159 int change_flags = 0; |
157 APIPermission::kUnlimitedStorage) || | 160 if (extensions::ContentCapabilitiesInfo::Get(extension) |
158 extension->permissions_data()->HasAPIPermission( | 161 .permissions.count(APIPermission::kUnlimitedStorage) > 0) { |
159 APIPermission::kFileBrowserHandler) || | 162 content_capabilities_unlimited_extensions_.Add(extension); |
160 extensions::AppIsolationInfo::HasIsolatedStorage(extension) || | 163 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; |
161 extension->is_app())) { | |
162 return; | |
163 } | 164 } |
164 | 165 |
165 int change_flags = 0; | 166 if (NeedsProtection(extension) || |
166 { | 167 extension->permissions_data()->HasAPIPermission( |
168 APIPermission::kUnlimitedStorage) || | |
169 extension->permissions_data()->HasAPIPermission( | |
170 APIPermission::kFileBrowserHandler) || | |
171 extensions::AppIsolationInfo::HasIsolatedStorage(extension) || | |
172 extension->is_app()) { | |
not at google - send to devlin
2014/12/12 21:03:06
Bleh, I don't like this code. It's basically:
if
Ken Rockot(use gerrit already)
2014/12/12 21:10:17
Doh, you're right. Moving the lock.
| |
167 base::AutoLock locker(lock_); | 173 base::AutoLock locker(lock_); |
168 if (NeedsProtection(extension) && protected_apps_.Add(extension)) | 174 if (NeedsProtection(extension) && protected_apps_.Add(extension)) |
169 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED; | 175 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED; |
170 // FIXME: Does GrantRightsForExtension imply |extension| is installed? | 176 // FIXME: Does GrantRightsForExtension imply |extension| is installed? |
171 if (extension->is_app()) | 177 if (extension->is_app()) |
172 installed_apps_.Add(extension); | 178 installed_apps_.Add(extension); |
173 | 179 |
174 if (extension->permissions_data()->HasAPIPermission( | 180 if (extension->permissions_data()->HasAPIPermission( |
175 APIPermission::kUnlimitedStorage) && | 181 APIPermission::kUnlimitedStorage) && |
176 unlimited_extensions_.Add(extension)) { | 182 unlimited_extensions_.Add(extension)) { |
177 if (extension->is_hosted_app()) | 183 if (extension->is_hosted_app()) |
178 LogHostedAppUnlimitedStorageUsage(extension, browser_context); | 184 LogHostedAppUnlimitedStorageUsage(extension, browser_context); |
179 | |
180 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; | 185 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; |
181 } | 186 } |
182 | 187 |
183 if (extension->permissions_data()->HasAPIPermission( | 188 if (extension->permissions_data()->HasAPIPermission( |
184 APIPermission::kFileBrowserHandler)) | 189 APIPermission::kFileBrowserHandler)) |
185 file_handler_extensions_.Add(extension); | 190 file_handler_extensions_.Add(extension); |
186 | 191 |
187 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension)) | 192 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension)) |
188 isolated_extensions_.Add(extension); | 193 isolated_extensions_.Add(extension); |
189 } | 194 } |
190 | 195 |
191 if (change_flags) { | 196 if (change_flags) { |
192 NotifyGranted(Extension::GetBaseURLFromExtensionId(extension->id()), | 197 NotifyGranted(Extension::GetBaseURLFromExtensionId(extension->id()), |
193 change_flags); | 198 change_flags); |
194 } | 199 } |
195 } | 200 } |
196 | 201 |
197 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( | 202 void ExtensionSpecialStoragePolicy::RevokeRightsForExtension( |
198 const extensions::Extension* extension) { | 203 const extensions::Extension* extension) { |
199 DCHECK(extension); | 204 DCHECK(extension); |
200 if (!(NeedsProtection(extension) || | 205 |
201 extension->permissions_data()->HasAPIPermission( | 206 int change_flags = 0; |
202 APIPermission::kUnlimitedStorage) || | 207 if (extensions::ContentCapabilitiesInfo::Get(extension) |
203 extension->permissions_data()->HasAPIPermission( | 208 .permissions.count(APIPermission::kUnlimitedStorage) > 0) { |
204 APIPermission::kFileBrowserHandler) || | 209 content_capabilities_unlimited_extensions_.Remove(extension); |
205 extensions::AppIsolationInfo::HasIsolatedStorage(extension) || | 210 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; |
206 extension->is_app())) { | |
207 return; | |
208 } | 211 } |
209 int change_flags = 0; | 212 |
210 { | 213 if (NeedsProtection(extension) || |
214 extension->permissions_data()->HasAPIPermission( | |
215 APIPermission::kUnlimitedStorage) || | |
216 extension->permissions_data()->HasAPIPermission( | |
217 APIPermission::kFileBrowserHandler) || | |
218 extensions::AppIsolationInfo::HasIsolatedStorage(extension) || | |
219 extension->is_app()) { | |
not at google - send to devlin
2014/12/12 21:03:06
Here too.
| |
211 base::AutoLock locker(lock_); | 220 base::AutoLock locker(lock_); |
212 if (NeedsProtection(extension) && protected_apps_.Remove(extension)) | 221 if (NeedsProtection(extension) && protected_apps_.Remove(extension)) |
213 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED; | 222 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED; |
214 | 223 |
215 if (extension->is_app()) | 224 if (extension->is_app()) |
216 installed_apps_.Remove(extension); | 225 installed_apps_.Remove(extension); |
217 | 226 |
218 if (extension->permissions_data()->HasAPIPermission( | 227 if (extension->permissions_data()->HasAPIPermission( |
219 APIPermission::kUnlimitedStorage) && | 228 APIPermission::kUnlimitedStorage) && |
220 unlimited_extensions_.Remove(extension)) | 229 unlimited_extensions_.Remove(extension)) |
(...skipping 14 matching lines...) Expand all Loading... | |
235 } | 244 } |
236 | 245 |
237 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { | 246 void ExtensionSpecialStoragePolicy::RevokeRightsForAllExtensions() { |
238 { | 247 { |
239 base::AutoLock locker(lock_); | 248 base::AutoLock locker(lock_); |
240 protected_apps_.Clear(); | 249 protected_apps_.Clear(); |
241 installed_apps_.Clear(); | 250 installed_apps_.Clear(); |
242 unlimited_extensions_.Clear(); | 251 unlimited_extensions_.Clear(); |
243 file_handler_extensions_.Clear(); | 252 file_handler_extensions_.Clear(); |
244 isolated_extensions_.Clear(); | 253 isolated_extensions_.Clear(); |
254 content_capabilities_unlimited_extensions_.Clear(); | |
245 } | 255 } |
246 | 256 |
247 NotifyCleared(); | 257 NotifyCleared(); |
248 } | 258 } |
249 | 259 |
250 void ExtensionSpecialStoragePolicy::NotifyGranted( | 260 void ExtensionSpecialStoragePolicy::NotifyGranted( |
251 const GURL& origin, | 261 const GURL& origin, |
252 int change_flags) { | 262 int change_flags) { |
253 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 263 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
254 BrowserThread::PostTask( | 264 BrowserThread::PostTask( |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
291 | 301 |
292 ExtensionSpecialStoragePolicy::SpecialCollection::~SpecialCollection() { | 302 ExtensionSpecialStoragePolicy::SpecialCollection::~SpecialCollection() { |
293 STLDeleteValues(&cached_results_); | 303 STLDeleteValues(&cached_results_); |
294 } | 304 } |
295 | 305 |
296 bool ExtensionSpecialStoragePolicy::SpecialCollection::Contains( | 306 bool ExtensionSpecialStoragePolicy::SpecialCollection::Contains( |
297 const GURL& origin) { | 307 const GURL& origin) { |
298 return !ExtensionsContaining(origin)->is_empty(); | 308 return !ExtensionsContaining(origin)->is_empty(); |
299 } | 309 } |
300 | 310 |
311 bool ExtensionSpecialStoragePolicy::SpecialCollection::GrantsCapabilitiesTo( | |
312 const GURL& origin) { | |
313 for (scoped_refptr<const Extension> extension : extensions_) { | |
not at google - send to devlin
2014/12/12 21:03:06
Should this be content_capabilities_unlimited_exte
Ken Rockot(use gerrit already)
2014/12/12 21:10:17
No, we're in a different data structure here. Ther
| |
314 if (extensions::ContentCapabilitiesInfo::Get(extension.get()) | |
315 .url_patterns.MatchesURL(origin)) { | |
316 return true; | |
317 } | |
318 } | |
319 return false; | |
320 } | |
321 | |
301 const extensions::ExtensionSet* | 322 const extensions::ExtensionSet* |
302 ExtensionSpecialStoragePolicy::SpecialCollection::ExtensionsContaining( | 323 ExtensionSpecialStoragePolicy::SpecialCollection::ExtensionsContaining( |
303 const GURL& origin) { | 324 const GURL& origin) { |
304 CachedResults::const_iterator found = cached_results_.find(origin); | 325 CachedResults::const_iterator found = cached_results_.find(origin); |
305 if (found != cached_results_.end()) | 326 if (found != cached_results_.end()) |
306 return found->second; | 327 return found->second; |
307 | 328 |
308 extensions::ExtensionSet* result = new extensions::ExtensionSet(); | 329 extensions::ExtensionSet* result = new extensions::ExtensionSet(); |
309 for (extensions::ExtensionSet::const_iterator iter = extensions_.begin(); | 330 for (extensions::ExtensionSet::const_iterator iter = extensions_.begin(); |
310 iter != extensions_.end(); ++iter) { | 331 iter != extensions_.end(); ++iter) { |
(...skipping 23 matching lines...) Expand all Loading... | |
334 | 355 |
335 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { | 356 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
336 ClearCache(); | 357 ClearCache(); |
337 extensions_.Clear(); | 358 extensions_.Clear(); |
338 } | 359 } |
339 | 360 |
340 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { | 361 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { |
341 STLDeleteValues(&cached_results_); | 362 STLDeleteValues(&cached_results_); |
342 cached_results_.clear(); | 363 cached_results_.clear(); |
343 } | 364 } |
OLD | NEW |