| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/browser/content_settings/cookie_settings_factory.h" | 17 #include "chrome/browser/content_settings/cookie_settings_factory.h" |
| 18 #include "chrome/browser/permissions/permission_manager.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 20 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
| 21 #include "components/content_settings/core/browser/cookie_settings.h" | 22 #include "components/content_settings/core/browser/cookie_settings.h" |
| 22 #include "components/content_settings/core/common/content_settings.h" | 23 #include "components/content_settings/core/common/content_settings.h" |
| 23 #include "components/content_settings/core/common/content_settings_types.h" | 24 #include "components/content_settings/core/common/content_settings_types.h" |
| 24 #include "content/public/browser/browser_context.h" | 25 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
| 27 #include "content/public/browser/permission_type.h" |
| 26 #include "content/public/browser/storage_partition.h" | 28 #include "content/public/browser/storage_partition.h" |
| 27 #include "content/public/common/url_constants.h" | 29 #include "content/public/common/url_constants.h" |
| 28 #include "extensions/common/constants.h" | 30 #include "extensions/common/constants.h" |
| 29 #include "extensions/common/extension.h" | 31 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/extension_set.h" | 32 #include "extensions/common/extension_set.h" |
| 31 #include "extensions/common/manifest_handlers/app_isolation_info.h" | 33 #include "extensions/common/manifest_handlers/app_isolation_info.h" |
| 32 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" | 34 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" |
| 33 #include "extensions/common/permissions/permissions_data.h" | 35 #include "extensions/common/permissions/permissions_data.h" |
| 34 #include "storage/browser/quota/quota_manager.h" | 36 #include "storage/browser/quota/quota_manager.h" |
| 35 #include "storage/common/quota/quota_status_code.h" | 37 #include "storage/common/quota/quota_status_code.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 53 } | 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 // Log the usage for a hosted app with unlimited storage. | 58 // Log the usage for a hosted app with unlimited storage. |
| 57 void LogHostedAppUnlimitedStorageUsage( | 59 void LogHostedAppUnlimitedStorageUsage( |
| 58 scoped_refptr<const Extension> extension, | 60 scoped_refptr<const Extension> extension, |
| 59 content::BrowserContext* browser_context) { | 61 content::BrowserContext* browser_context) { |
| 60 GURL launch_url = | 62 GURL launch_url = |
| 61 extensions::AppLaunchInfo::GetLaunchWebURL(extension.get()).GetOrigin(); | 63 extensions::AppLaunchInfo::GetLaunchWebURL(extension.get()).GetOrigin(); |
| 62 content::StoragePartition* partition = | 64 content::StoragePartition* partition = |
| 63 browser_context ? // |browser_context| can be NULL in unittests. | 65 browser_context ? // |browser_context| can be nullptr in unittests. |
| 64 content::BrowserContext::GetStoragePartitionForSite(browser_context, | 66 content::BrowserContext::GetStoragePartitionForSite(browser_context, |
| 65 launch_url) : | 67 launch_url) : |
| 66 NULL; | 68 nullptr; |
| 67 if (partition) { | 69 if (partition) { |
| 68 // We only have to query for kStorageTypePersistent data usage, because apps | 70 // We only have to query for kStorageTypePersistent data usage, because apps |
| 69 // cannot ask for any more temporary storage, according to | 71 // cannot ask for any more temporary storage, according to |
| 70 // https://developers.google.com/chrome/whitepapers/storage. | 72 // https://developers.google.com/chrome/whitepapers/storage. |
| 71 BrowserThread::PostAfterStartupTask( | 73 BrowserThread::PostAfterStartupTask( |
| 72 FROM_HERE, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), | 74 FROM_HERE, BrowserThread::GetTaskRunnerForThread(BrowserThread::IO), |
| 73 base::Bind(&storage::QuotaManager::GetUsageAndQuotaForWebApps, | 75 base::Bind(&storage::QuotaManager::GetUsageAndQuotaForWebApps, |
| 74 partition->GetQuotaManager(), launch_url, | 76 partition->GetQuotaManager(), launch_url, |
| 75 storage::kStorageTypePersistent, | 77 storage::kStorageTypePersistent, |
| 76 base::Bind(&ReportQuotaUsage))); | 78 base::Bind(&ReportQuotaUsage))); |
| 77 } | 79 } |
| 78 } | 80 } |
| 79 | 81 |
| 80 } // namespace | 82 } // namespace |
| 81 | 83 |
| 82 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( | 84 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy(Profile* profile) |
| 83 content_settings::CookieSettings* cookie_settings) | 85 : profile_(profile) { |
| 84 : cookie_settings_(cookie_settings) { | 86 if (profile_) { |
| 87 cookie_settings_ = CookieSettingsFactory::GetForProfile(profile_).get(); |
| 88 } |
| 85 } | 89 } |
| 86 | 90 |
| 87 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} | 91 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} |
| 88 | 92 |
| 89 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { | 93 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { |
| 90 if (origin.SchemeIs(extensions::kExtensionScheme)) | 94 if (origin.SchemeIs(extensions::kExtensionScheme)) |
| 91 return true; | 95 return true; |
| 92 base::AutoLock locker(lock_); | 96 base::AutoLock locker(lock_); |
| 93 return protected_apps_.Contains(origin); | 97 return protected_apps_.Contains(origin); |
| 94 } | 98 } |
| 95 | 99 |
| 96 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { | 100 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { |
| 97 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 101 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 98 switches::kUnlimitedStorage)) | 102 switches::kUnlimitedStorage)) |
| 99 return true; | 103 return true; |
| 100 | 104 |
| 101 if (origin.SchemeIs(content::kChromeDevToolsScheme) && | 105 if (origin.SchemeIs(content::kChromeDevToolsScheme) && |
| 102 origin.host_piece() == chrome::kChromeUIDevToolsHost) | 106 origin.host_piece() == chrome::kChromeUIDevToolsHost) |
| 103 return true; | 107 return true; |
| 104 | 108 |
| 105 base::AutoLock locker(lock_); | 109 base::AutoLock locker(lock_); |
| 106 return unlimited_extensions_.Contains(origin) || | 110 return unlimited_extensions_.Contains(origin) || |
| 107 content_capabilities_unlimited_extensions_.GrantsCapabilitiesTo( | 111 content_capabilities_unlimited_extensions_.GrantsCapabilitiesTo( |
| 108 origin); | 112 origin); |
| 109 } | 113 } |
| 110 | 114 |
| 111 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { | 115 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { |
| 112 if (cookie_settings_.get() == NULL) | 116 if (cookie_settings_ == nullptr) |
| 113 return false; | 117 return false; |
| 114 return cookie_settings_->IsCookieSessionOnly(origin); | 118 return cookie_settings_->IsCookieSessionOnly(origin); |
| 115 } | 119 } |
| 116 | 120 |
| 117 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { | 121 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { |
| 118 base::AutoLock locker(lock_); | 122 base::AutoLock locker(lock_); |
| 119 return installed_apps_.Contains(origin); | 123 return installed_apps_.Contains(origin); |
| 120 } | 124 } |
| 121 | 125 |
| 122 bool ExtensionSpecialStoragePolicy::HasSessionOnlyOrigins() { | 126 bool ExtensionSpecialStoragePolicy::HasSessionOnlyOrigins() { |
| 123 if (cookie_settings_.get() == NULL) | 127 if (cookie_settings_ == nullptr) |
| 124 return false; | 128 return false; |
| 125 if (cookie_settings_->GetDefaultCookieSetting(NULL) == | 129 if (cookie_settings_->GetDefaultCookieSetting(nullptr) == |
| 126 CONTENT_SETTING_SESSION_ONLY) | 130 CONTENT_SETTING_SESSION_ONLY) |
| 127 return true; | 131 return true; |
| 128 ContentSettingsForOneType entries; | 132 ContentSettingsForOneType entries; |
| 129 cookie_settings_->GetCookieSettings(&entries); | 133 cookie_settings_->GetCookieSettings(&entries); |
| 130 for (size_t i = 0; i < entries.size(); ++i) { | 134 for (size_t i = 0; i < entries.size(); ++i) { |
| 131 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) | 135 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) |
| 132 return true; | 136 return true; |
| 133 } | 137 } |
| 134 return false; | 138 return false; |
| 135 } | 139 } |
| 136 | 140 |
| 137 bool ExtensionSpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { | 141 bool ExtensionSpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { |
| 138 base::AutoLock locker(lock_); | 142 base::AutoLock locker(lock_); |
| 139 return isolated_extensions_.Contains(origin); | 143 return isolated_extensions_.Contains(origin); |
| 140 } | 144 } |
| 141 | 145 |
| 142 bool ExtensionSpecialStoragePolicy::IsStorageDurable(const GURL& origin) { | 146 bool ExtensionSpecialStoragePolicy::IsStorageDurable(const GURL& origin) { |
| 143 return cookie_settings_->IsStorageDurable(origin); | 147 blink::mojom::PermissionStatus status = |
| 148 PermissionManager::Get(profile_)->GetPermissionStatus( |
| 149 content::PermissionType::DURABLE_STORAGE, origin, origin); |
| 150 return status == blink::mojom::PermissionStatus::GRANTED; |
| 144 } | 151 } |
| 145 | 152 |
| 146 bool ExtensionSpecialStoragePolicy::NeedsProtection( | 153 bool ExtensionSpecialStoragePolicy::NeedsProtection( |
| 147 const extensions::Extension* extension) { | 154 const extensions::Extension* extension) { |
| 148 return extension->is_hosted_app() && !extension->from_bookmark(); | 155 return extension->is_hosted_app() && !extension->from_bookmark(); |
| 149 } | 156 } |
| 150 | 157 |
| 151 const extensions::ExtensionSet* | 158 const extensions::ExtensionSet* |
| 152 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( | 159 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( |
| 153 const GURL& origin) { | 160 const GURL& origin) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 } | 365 } |
| 359 | 366 |
| 360 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { | 367 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
| 361 ClearCache(); | 368 ClearCache(); |
| 362 extensions_.Clear(); | 369 extensions_.Clear(); |
| 363 } | 370 } |
| 364 | 371 |
| 365 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { | 372 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { |
| 366 base::STLDeleteValues(&cached_results_); | 373 base::STLDeleteValues(&cached_results_); |
| 367 } | 374 } |
| OLD | NEW |