Chromium Code Reviews| 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 unlimited_extensions_.GrantsCapabilitiesTo(origin); | |
| 100 } | 102 } |
| 101 | 103 |
| 102 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { | 104 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { |
| 103 if (cookie_settings_.get() == NULL) | 105 if (cookie_settings_.get() == NULL) |
| 104 return false; | 106 return false; |
| 105 return cookie_settings_->IsCookieSessionOnly(origin); | 107 return cookie_settings_->IsCookieSessionOnly(origin); |
| 106 } | 108 } |
| 107 | 109 |
| 108 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { | 110 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { |
| 109 base::AutoLock locker(lock_); | 111 base::AutoLock locker(lock_); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( | 147 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( |
| 146 const GURL& origin) { | 148 const GURL& origin) { |
| 147 base::AutoLock locker(lock_); | 149 base::AutoLock locker(lock_); |
| 148 return protected_apps_.ExtensionsContaining(origin); | 150 return protected_apps_.ExtensionsContaining(origin); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( | 153 void ExtensionSpecialStoragePolicy::GrantRightsForExtension( |
| 152 const extensions::Extension* extension, | 154 const extensions::Extension* extension, |
| 153 content::BrowserContext* browser_context) { | 155 content::BrowserContext* browser_context) { |
| 154 DCHECK(extension); | 156 DCHECK(extension); |
| 155 if (!(NeedsProtection(extension) || | 157 |
| 158 int change_flags = 0; | |
| 159 if (extensions::ContentCapabilitiesInfo::Get(extension).permissions.count( | |
|
not at google - send to devlin
2014/12/12 16:33:40
Am I missing something; what guarantees the extens
Ken Rockot(use gerrit already)
2014/12/12 16:39:07
It's lazily constructed as needed. An extension wi
not at google - send to devlin
2014/12/12 17:35:39
Is that always the way these things work?
Ken Rockot(use gerrit already)
2014/12/12 20:51:13
It's the way some of them work. Others may be OK r
| |
| 160 APIPermission::kUnlimitedStorage) > 0) { | |
| 161 unlimited_extensions_.Add(extension); | |
|
not at google - send to devlin
2014/12/12 16:33:40
I'm not sure; am I reading this correctly, and doe
Ken Rockot(use gerrit already)
2014/12/12 16:39:08
This only adds the extension to the unlimited_exte
not at google - send to devlin
2014/12/12 17:35:39
Oh, I see. So unlimited extensions is just some ki
Ken Rockot(use gerrit already)
2014/12/12 20:51:13
It was pretty ugly, so I changed it. There's a sep
| |
| 162 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; | |
| 163 } | |
| 164 | |
| 165 if (NeedsProtection(extension) || | |
| 156 extension->permissions_data()->HasAPIPermission( | 166 extension->permissions_data()->HasAPIPermission( |
| 157 APIPermission::kUnlimitedStorage) || | 167 APIPermission::kUnlimitedStorage) || |
| 158 extension->permissions_data()->HasAPIPermission( | 168 extension->permissions_data()->HasAPIPermission( |
| 159 APIPermission::kFileBrowserHandler) || | 169 APIPermission::kFileBrowserHandler) || |
| 160 extensions::AppIsolationInfo::HasIsolatedStorage(extension) || | 170 extensions::AppIsolationInfo::HasIsolatedStorage(extension) || |
| 161 extension->is_app())) { | 171 extension->is_app()) { |
| 162 return; | |
| 163 } | |
| 164 | |
| 165 int change_flags = 0; | |
| 166 { | |
| 167 base::AutoLock locker(lock_); | 172 base::AutoLock locker(lock_); |
| 168 if (NeedsProtection(extension) && protected_apps_.Add(extension)) | 173 if (NeedsProtection(extension) && protected_apps_.Add(extension)) |
| 169 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED; | 174 change_flags |= SpecialStoragePolicy::STORAGE_PROTECTED; |
| 170 // FIXME: Does GrantRightsForExtension imply |extension| is installed? | 175 // FIXME: Does GrantRightsForExtension imply |extension| is installed? |
| 171 if (extension->is_app()) | 176 if (extension->is_app()) |
| 172 installed_apps_.Add(extension); | 177 installed_apps_.Add(extension); |
| 173 | 178 |
| 174 if (extension->permissions_data()->HasAPIPermission( | 179 if (extension->permissions_data()->HasAPIPermission( |
| 175 APIPermission::kUnlimitedStorage) && | 180 APIPermission::kUnlimitedStorage) && |
| 176 unlimited_extensions_.Add(extension)) { | 181 unlimited_extensions_.Add(extension)) { |
| 177 if (extension->is_hosted_app()) | 182 if (extension->is_hosted_app()) |
| 178 LogHostedAppUnlimitedStorageUsage(extension, browser_context); | 183 LogHostedAppUnlimitedStorageUsage(extension, browser_context); |
| 179 | |
| 180 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; | 184 change_flags |= SpecialStoragePolicy::STORAGE_UNLIMITED; |
| 181 } | 185 } |
| 182 | 186 |
| 183 if (extension->permissions_data()->HasAPIPermission( | 187 if (extension->permissions_data()->HasAPIPermission( |
| 184 APIPermission::kFileBrowserHandler)) | 188 APIPermission::kFileBrowserHandler)) |
| 185 file_handler_extensions_.Add(extension); | 189 file_handler_extensions_.Add(extension); |
| 186 | 190 |
| 187 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension)) | 191 if (extensions::AppIsolationInfo::HasIsolatedStorage(extension)) |
| 188 isolated_extensions_.Add(extension); | 192 isolated_extensions_.Add(extension); |
| 189 } | 193 } |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 | 295 |
| 292 ExtensionSpecialStoragePolicy::SpecialCollection::~SpecialCollection() { | 296 ExtensionSpecialStoragePolicy::SpecialCollection::~SpecialCollection() { |
| 293 STLDeleteValues(&cached_results_); | 297 STLDeleteValues(&cached_results_); |
| 294 } | 298 } |
| 295 | 299 |
| 296 bool ExtensionSpecialStoragePolicy::SpecialCollection::Contains( | 300 bool ExtensionSpecialStoragePolicy::SpecialCollection::Contains( |
| 297 const GURL& origin) { | 301 const GURL& origin) { |
| 298 return !ExtensionsContaining(origin)->is_empty(); | 302 return !ExtensionsContaining(origin)->is_empty(); |
| 299 } | 303 } |
| 300 | 304 |
| 305 bool ExtensionSpecialStoragePolicy::SpecialCollection::GrantsCapabilitiesTo( | |
| 306 const GURL& origin) { | |
| 307 for (scoped_refptr<const Extension> extension : extensions_) { | |
| 308 if (extensions::ContentCapabilitiesInfo::Get(extension.get()).url_patterns | |
| 309 .MatchesURL(origin)) { | |
| 310 return true; | |
| 311 } | |
| 312 } | |
| 313 return false; | |
| 314 } | |
| 315 | |
| 301 const extensions::ExtensionSet* | 316 const extensions::ExtensionSet* |
| 302 ExtensionSpecialStoragePolicy::SpecialCollection::ExtensionsContaining( | 317 ExtensionSpecialStoragePolicy::SpecialCollection::ExtensionsContaining( |
| 303 const GURL& origin) { | 318 const GURL& origin) { |
| 304 CachedResults::const_iterator found = cached_results_.find(origin); | 319 CachedResults::const_iterator found = cached_results_.find(origin); |
| 305 if (found != cached_results_.end()) | 320 if (found != cached_results_.end()) |
| 306 return found->second; | 321 return found->second; |
| 307 | 322 |
| 308 extensions::ExtensionSet* result = new extensions::ExtensionSet(); | 323 extensions::ExtensionSet* result = new extensions::ExtensionSet(); |
| 309 for (extensions::ExtensionSet::const_iterator iter = extensions_.begin(); | 324 for (extensions::ExtensionSet::const_iterator iter = extensions_.begin(); |
| 310 iter != extensions_.end(); ++iter) { | 325 iter != extensions_.end(); ++iter) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 334 | 349 |
| 335 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { | 350 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
| 336 ClearCache(); | 351 ClearCache(); |
| 337 extensions_.Clear(); | 352 extensions_.Clear(); |
| 338 } | 353 } |
| 339 | 354 |
| 340 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { | 355 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { |
| 341 STLDeleteValues(&cached_results_); | 356 STLDeleteValues(&cached_results_); |
| 342 cached_results_.clear(); | 357 cached_results_.clear(); |
| 343 } | 358 } |
| OLD | NEW |