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 <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/browser/profiles/profile.h" | |
| 18 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 21 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
| 20 #include "chrome/common/url_constants.h" | 22 #include "chrome/common/url_constants.h" |
| 21 #include "components/content_settings/core/browser/cookie_settings.h" | 23 #include "components/content_settings/core/browser/cookie_settings.h" |
| 22 #include "components/content_settings/core/common/content_settings.h" | 24 #include "components/content_settings/core/common/content_settings.h" |
| 23 #include "components/content_settings/core/common/content_settings_types.h" | 25 #include "components/content_settings/core/common/content_settings_types.h" |
| 24 #include "content/public/browser/browser_context.h" | 26 #include "content/public/browser/browser_context.h" |
| 25 #include "content/public/browser/browser_thread.h" | 27 #include "content/public/browser/browser_thread.h" |
| 28 #include "content/public/browser/permission_type.h" | |
| 26 #include "content/public/browser/storage_partition.h" | 29 #include "content/public/browser/storage_partition.h" |
| 27 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
| 28 #include "extensions/common/constants.h" | 31 #include "extensions/common/constants.h" |
| 29 #include "extensions/common/extension.h" | 32 #include "extensions/common/extension.h" |
| 30 #include "extensions/common/extension_set.h" | 33 #include "extensions/common/extension_set.h" |
| 31 #include "extensions/common/manifest_handlers/app_isolation_info.h" | 34 #include "extensions/common/manifest_handlers/app_isolation_info.h" |
| 32 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" | 35 #include "extensions/common/manifest_handlers/content_capabilities_handler.h" |
| 33 #include "extensions/common/permissions/permissions_data.h" | 36 #include "extensions/common/permissions/permissions_data.h" |
| 34 #include "storage/browser/quota/quota_manager.h" | 37 #include "storage/browser/quota/quota_manager.h" |
| 35 #include "storage/common/quota/quota_status_code.h" | 38 #include "storage/common/quota/quota_status_code.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 base::Bind(&storage::QuotaManager::GetUsageAndQuotaForWebApps, | 76 base::Bind(&storage::QuotaManager::GetUsageAndQuotaForWebApps, |
| 74 partition->GetQuotaManager(), launch_url, | 77 partition->GetQuotaManager(), launch_url, |
| 75 storage::kStorageTypePersistent, | 78 storage::kStorageTypePersistent, |
| 76 base::Bind(&ReportQuotaUsage))); | 79 base::Bind(&ReportQuotaUsage))); |
| 77 } | 80 } |
| 78 } | 81 } |
| 79 | 82 |
| 80 } // namespace | 83 } // namespace |
| 81 | 84 |
| 82 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( | 85 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy( |
| 83 content_settings::CookieSettings* cookie_settings) | 86 content::BrowserContext* browser_context) |
| 84 : cookie_settings_(cookie_settings) { | 87 : browser_context_(browser_context) { |
| 88 if (browser_context_) { | |
| 89 Profile* profile = Profile::FromBrowserContext(browser_context_); | |
| 90 cookie_settings_ = CookieSettingsFactory::GetForProfile(profile).get(); | |
| 91 } | |
| 85 } | 92 } |
| 86 | 93 |
| 87 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} | 94 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} |
| 88 | 95 |
| 89 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { | 96 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { |
| 90 if (origin.SchemeIs(extensions::kExtensionScheme)) | 97 if (origin.SchemeIs(extensions::kExtensionScheme)) |
| 91 return true; | 98 return true; |
| 92 base::AutoLock locker(lock_); | 99 base::AutoLock locker(lock_); |
| 93 return protected_apps_.Contains(origin); | 100 return protected_apps_.Contains(origin); |
| 94 } | 101 } |
| 95 | 102 |
| 96 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { | 103 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { |
| 97 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 104 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 98 switches::kUnlimitedStorage)) | 105 switches::kUnlimitedStorage)) |
| 99 return true; | 106 return true; |
| 100 | 107 |
| 101 if (origin.SchemeIs(content::kChromeDevToolsScheme) && | 108 if (origin.SchemeIs(content::kChromeDevToolsScheme) && |
| 102 origin.host_piece() == chrome::kChromeUIDevToolsHost) | 109 origin.host_piece() == chrome::kChromeUIDevToolsHost) |
| 103 return true; | 110 return true; |
| 104 | 111 |
| 105 base::AutoLock locker(lock_); | 112 base::AutoLock locker(lock_); |
| 106 return unlimited_extensions_.Contains(origin) || | 113 return unlimited_extensions_.Contains(origin) || |
| 107 content_capabilities_unlimited_extensions_.GrantsCapabilitiesTo( | 114 content_capabilities_unlimited_extensions_.GrantsCapabilitiesTo( |
| 108 origin); | 115 origin); |
| 109 } | 116 } |
| 110 | 117 |
| 111 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { | 118 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { |
| 112 if (cookie_settings_.get() == NULL) | 119 if (cookie_settings_ == NULL) |
|
pfeldman
2016/09/23 17:12:20
Since you touch those lines, you could migrate the
| |
| 113 return false; | 120 return false; |
| 114 return cookie_settings_->IsCookieSessionOnly(origin); | 121 return cookie_settings_->IsCookieSessionOnly(origin); |
| 115 } | 122 } |
| 116 | 123 |
| 117 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { | 124 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { |
| 118 base::AutoLock locker(lock_); | 125 base::AutoLock locker(lock_); |
| 119 return installed_apps_.Contains(origin); | 126 return installed_apps_.Contains(origin); |
| 120 } | 127 } |
| 121 | 128 |
| 122 bool ExtensionSpecialStoragePolicy::HasSessionOnlyOrigins() { | 129 bool ExtensionSpecialStoragePolicy::HasSessionOnlyOrigins() { |
| 123 if (cookie_settings_.get() == NULL) | 130 if (cookie_settings_ == NULL) |
| 124 return false; | 131 return false; |
| 125 if (cookie_settings_->GetDefaultCookieSetting(NULL) == | 132 if (cookie_settings_->GetDefaultCookieSetting(NULL) == |
| 126 CONTENT_SETTING_SESSION_ONLY) | 133 CONTENT_SETTING_SESSION_ONLY) |
| 127 return true; | 134 return true; |
| 128 ContentSettingsForOneType entries; | 135 ContentSettingsForOneType entries; |
| 129 cookie_settings_->GetCookieSettings(&entries); | 136 cookie_settings_->GetCookieSettings(&entries); |
| 130 for (size_t i = 0; i < entries.size(); ++i) { | 137 for (size_t i = 0; i < entries.size(); ++i) { |
| 131 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) | 138 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) |
| 132 return true; | 139 return true; |
| 133 } | 140 } |
| 134 return false; | 141 return false; |
| 135 } | 142 } |
| 136 | 143 |
| 137 bool ExtensionSpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { | 144 bool ExtensionSpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { |
| 138 base::AutoLock locker(lock_); | 145 base::AutoLock locker(lock_); |
| 139 return isolated_extensions_.Contains(origin); | 146 return isolated_extensions_.Contains(origin); |
| 140 } | 147 } |
| 141 | 148 |
| 142 bool ExtensionSpecialStoragePolicy::IsStorageDurable(const GURL& origin) { | 149 bool ExtensionSpecialStoragePolicy::IsStorageDurable(const GURL& origin) { |
| 143 return cookie_settings_->IsStorageDurable(origin); | 150 Profile* profile = Profile::FromBrowserContext(browser_context_); |
|
pfeldman
2016/09/23 17:12:20
Just store a pointer to the profile, no need to co
| |
| 151 blink::mojom::PermissionStatus status = | |
| 152 PermissionManager::Get(profile)->GetPermissionStatus( | |
| 153 content::PermissionType::DURABLE_STORAGE, origin, origin); | |
| 154 return status == blink::mojom::PermissionStatus::GRANTED; | |
| 144 } | 155 } |
| 145 | 156 |
| 146 bool ExtensionSpecialStoragePolicy::NeedsProtection( | 157 bool ExtensionSpecialStoragePolicy::NeedsProtection( |
| 147 const extensions::Extension* extension) { | 158 const extensions::Extension* extension) { |
| 148 return extension->is_hosted_app() && !extension->from_bookmark(); | 159 return extension->is_hosted_app() && !extension->from_bookmark(); |
| 149 } | 160 } |
| 150 | 161 |
| 151 const extensions::ExtensionSet* | 162 const extensions::ExtensionSet* |
| 152 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( | 163 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( |
| 153 const GURL& origin) { | 164 const GURL& origin) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 } | 369 } |
| 359 | 370 |
| 360 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { | 371 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
| 361 ClearCache(); | 372 ClearCache(); |
| 362 extensions_.Clear(); | 373 extensions_.Clear(); |
| 363 } | 374 } |
| 364 | 375 |
| 365 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { | 376 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { |
| 366 base::STLDeleteValues(&cached_results_); | 377 base::STLDeleteValues(&cached_results_); |
| 367 } | 378 } |
| OLD | NEW |