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