Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: chrome/browser/extensions/extension_special_storage_policy.cc

Issue 2351803002: Switching ExtensionSpecialStoragePolicy::IsStorageDurable to use DurableStoragePermissionContext. (Closed)
Patch Set: Update test to reflect that durable storage is only available on secure origins. Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/profiles/profile.h"
19 #include "chrome/browser/storage/durable_storage_permission_context.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"
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"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(
83 content_settings::CookieSettings* cookie_settings) 85 content::BrowserContext* browser_context)
84 : cookie_settings_(cookie_settings) { 86 : browser_context_(browser_context) {
87
88 Profile* profile = Profile::FromBrowserContext(browser_context_);
89 cookie_settings_ = CookieSettingsFactory::GetForProfile(profile).get();
85 } 90 }
86 91
87 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} 92 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {}
88 93
89 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { 94 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) {
90 if (origin.SchemeIs(extensions::kExtensionScheme)) 95 if (origin.SchemeIs(extensions::kExtensionScheme))
91 return true; 96 return true;
92 base::AutoLock locker(lock_); 97 base::AutoLock locker(lock_);
93 return protected_apps_.Contains(origin); 98 return protected_apps_.Contains(origin);
94 } 99 }
95 100
96 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) { 101 bool ExtensionSpecialStoragePolicy::IsStorageUnlimited(const GURL& origin) {
97 if (base::CommandLine::ForCurrentProcess()->HasSwitch( 102 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
98 switches::kUnlimitedStorage)) 103 switches::kUnlimitedStorage))
99 return true; 104 return true;
100 105
101 if (origin.SchemeIs(content::kChromeDevToolsScheme) && 106 if (origin.SchemeIs(content::kChromeDevToolsScheme) &&
102 origin.host_piece() == chrome::kChromeUIDevToolsHost) 107 origin.host_piece() == chrome::kChromeUIDevToolsHost)
103 return true; 108 return true;
104 109
105 base::AutoLock locker(lock_); 110 base::AutoLock locker(lock_);
106 return unlimited_extensions_.Contains(origin) || 111 return unlimited_extensions_.Contains(origin) ||
107 content_capabilities_unlimited_extensions_.GrantsCapabilitiesTo( 112 content_capabilities_unlimited_extensions_.GrantsCapabilitiesTo(
108 origin); 113 origin);
109 } 114 }
110 115
111 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) { 116 bool ExtensionSpecialStoragePolicy::IsStorageSessionOnly(const GURL& origin) {
112 if (cookie_settings_.get() == NULL) 117 if (cookie_settings_ == NULL)
113 return false; 118 return false;
114 return cookie_settings_->IsCookieSessionOnly(origin); 119 return cookie_settings_->IsCookieSessionOnly(origin);
115 } 120 }
116 121
117 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) { 122 bool ExtensionSpecialStoragePolicy::CanQueryDiskSize(const GURL& origin) {
118 base::AutoLock locker(lock_); 123 base::AutoLock locker(lock_);
119 return installed_apps_.Contains(origin); 124 return installed_apps_.Contains(origin);
120 } 125 }
121 126
122 bool ExtensionSpecialStoragePolicy::HasSessionOnlyOrigins() { 127 bool ExtensionSpecialStoragePolicy::HasSessionOnlyOrigins() {
123 if (cookie_settings_.get() == NULL) 128 if (cookie_settings_ == NULL)
124 return false; 129 return false;
125 if (cookie_settings_->GetDefaultCookieSetting(NULL) == 130 if (cookie_settings_->GetDefaultCookieSetting(NULL) ==
126 CONTENT_SETTING_SESSION_ONLY) 131 CONTENT_SETTING_SESSION_ONLY)
127 return true; 132 return true;
128 ContentSettingsForOneType entries; 133 ContentSettingsForOneType entries;
129 cookie_settings_->GetCookieSettings(&entries); 134 cookie_settings_->GetCookieSettings(&entries);
130 for (size_t i = 0; i < entries.size(); ++i) { 135 for (size_t i = 0; i < entries.size(); ++i) {
131 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY) 136 if (entries[i].setting == CONTENT_SETTING_SESSION_ONLY)
132 return true; 137 return true;
133 } 138 }
134 return false; 139 return false;
135 } 140 }
136 141
137 bool ExtensionSpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { 142 bool ExtensionSpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) {
138 base::AutoLock locker(lock_); 143 base::AutoLock locker(lock_);
139 return isolated_extensions_.Contains(origin); 144 return isolated_extensions_.Contains(origin);
140 } 145 }
141 146
142 bool ExtensionSpecialStoragePolicy::IsStorageDurable(const GURL& origin) { 147 bool ExtensionSpecialStoragePolicy::IsStorageDurable(const GURL& origin) {
143 return cookie_settings_->IsStorageDurable(origin); 148 Profile* profile = Profile::FromBrowserContext(browser_context_);
149 std::unique_ptr<DurableStoragePermissionContext> permission_context(
150 new DurableStoragePermissionContext(profile));
raymes 2016/09/21 07:23:32 We should go through the PermissionManager, someth
151 ContentSetting setting =
152 permission_context->GetPermissionStatus(origin, origin);
153 return setting == CONTENT_SETTING_ALLOW;
144 } 154 }
145 155
146 bool ExtensionSpecialStoragePolicy::NeedsProtection( 156 bool ExtensionSpecialStoragePolicy::NeedsProtection(
147 const extensions::Extension* extension) { 157 const extensions::Extension* extension) {
148 return extension->is_hosted_app() && !extension->from_bookmark(); 158 return extension->is_hosted_app() && !extension->from_bookmark();
149 } 159 }
150 160
151 const extensions::ExtensionSet* 161 const extensions::ExtensionSet*
152 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin( 162 ExtensionSpecialStoragePolicy::ExtensionsProtectingOrigin(
153 const GURL& origin) { 163 const GURL& origin) {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 } 368 }
359 369
360 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { 370 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() {
361 ClearCache(); 371 ClearCache();
362 extensions_.Clear(); 372 extensions_.Clear();
363 } 373 }
364 374
365 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { 375 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() {
366 base::STLDeleteValues(&cached_results_); 376 base::STLDeleteValues(&cached_results_);
367 } 377 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698