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/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.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/content_settings/host_content_settings_map_factory.h" |
| 19 #include "chrome/browser/permissions/permission_manager.h" |
18 #include "chrome/browser/permissions/permission_manager.h" | 20 #include "chrome/browser/permissions/permission_manager.h" |
19 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
20 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" | 22 #include "chrome/common/extensions/manifest_handlers/app_launch_info.h" |
21 #include "chrome/common/url_constants.h" | 23 #include "chrome/common/url_constants.h" |
22 #include "components/content_settings/core/browser/cookie_settings.h" | 24 #include "components/content_settings/core/browser/cookie_settings.h" |
| 25 #include "components/content_settings/core/browser/host_content_settings_map.h" |
23 #include "components/content_settings/core/common/content_settings.h" | 26 #include "components/content_settings/core/common/content_settings.h" |
24 #include "components/content_settings/core/common/content_settings_types.h" | 27 #include "components/content_settings/core/common/content_settings_types.h" |
25 #include "content/public/browser/browser_context.h" | 28 #include "content/public/browser/browser_context.h" |
26 #include "content/public/browser/browser_thread.h" | 29 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/permission_type.h" | 30 #include "content/public/browser/permission_type.h" |
28 #include "content/public/browser/storage_partition.h" | 31 #include "content/public/browser/storage_partition.h" |
29 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
30 #include "extensions/common/constants.h" | 33 #include "extensions/common/constants.h" |
31 #include "extensions/common/extension.h" | 34 #include "extensions/common/extension.h" |
32 #include "extensions/common/extension_set.h" | 35 #include "extensions/common/extension_set.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 partition->GetQuotaManager(), launch_url, | 79 partition->GetQuotaManager(), launch_url, |
77 storage::kStorageTypePersistent, | 80 storage::kStorageTypePersistent, |
78 base::Bind(&ReportQuotaUsage))); | 81 base::Bind(&ReportQuotaUsage))); |
79 } | 82 } |
80 } | 83 } |
81 | 84 |
82 } // namespace | 85 } // namespace |
83 | 86 |
84 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy(Profile* profile) | 87 ExtensionSpecialStoragePolicy::ExtensionSpecialStoragePolicy(Profile* profile) |
85 : profile_(profile) { | 88 : profile_(profile) { |
| 89 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
86 if (profile_) { | 90 if (profile_) { |
87 cookie_settings_ = CookieSettingsFactory::GetForProfile(profile_).get(); | 91 cookie_settings_ = CookieSettingsFactory::GetForProfile(profile_).get(); |
| 92 permission_manager_ = PermissionManager::Get(profile_); |
| 93 host_content_settings_map_ = |
| 94 HostContentSettingsMapFactory::GetForProfile(profile_); |
88 } | 95 } |
89 } | 96 } |
90 | 97 |
91 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} | 98 ExtensionSpecialStoragePolicy::~ExtensionSpecialStoragePolicy() {} |
92 | 99 |
93 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { | 100 bool ExtensionSpecialStoragePolicy::IsStorageProtected(const GURL& origin) { |
94 if (origin.SchemeIs(extensions::kExtensionScheme)) | 101 if (origin.SchemeIs(extensions::kExtensionScheme)) |
95 return true; | 102 return true; |
96 base::AutoLock locker(lock_); | 103 base::AutoLock locker(lock_); |
97 return protected_apps_.Contains(origin); | 104 return protected_apps_.Contains(origin); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 } | 144 } |
138 return false; | 145 return false; |
139 } | 146 } |
140 | 147 |
141 bool ExtensionSpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { | 148 bool ExtensionSpecialStoragePolicy::HasIsolatedStorage(const GURL& origin) { |
142 base::AutoLock locker(lock_); | 149 base::AutoLock locker(lock_); |
143 return isolated_extensions_.Contains(origin); | 150 return isolated_extensions_.Contains(origin); |
144 } | 151 } |
145 | 152 |
146 bool ExtensionSpecialStoragePolicy::IsStorageDurable(const GURL& origin) { | 153 bool ExtensionSpecialStoragePolicy::IsStorageDurable(const GURL& origin) { |
| 154 if (!host_content_settings_map_ || !permission_manager_) |
| 155 return false; |
| 156 |
147 blink::mojom::PermissionStatus status = | 157 blink::mojom::PermissionStatus status = |
148 PermissionManager::Get(profile_)->GetPermissionStatus( | 158 permission_manager_->GetPermissionStatus( |
| 159 host_content_settings_map_.get(), |
149 content::PermissionType::DURABLE_STORAGE, origin, origin); | 160 content::PermissionType::DURABLE_STORAGE, origin, origin); |
150 return status == blink::mojom::PermissionStatus::GRANTED; | 161 return status == blink::mojom::PermissionStatus::GRANTED; |
151 } | 162 } |
152 | 163 |
153 bool ExtensionSpecialStoragePolicy::NeedsProtection( | 164 bool ExtensionSpecialStoragePolicy::NeedsProtection( |
154 const extensions::Extension* extension) { | 165 const extensions::Extension* extension) { |
155 return extension->is_hosted_app() && !extension->from_bookmark(); | 166 return extension->is_hosted_app() && !extension->from_bookmark(); |
156 } | 167 } |
157 | 168 |
158 const extensions::ExtensionSet* | 169 const extensions::ExtensionSet* |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
362 } | 373 } |
363 | 374 |
364 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { | 375 void ExtensionSpecialStoragePolicy::SpecialCollection::Clear() { |
365 ClearCache(); | 376 ClearCache(); |
366 extensions_.Clear(); | 377 extensions_.Clear(); |
367 } | 378 } |
368 | 379 |
369 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { | 380 void ExtensionSpecialStoragePolicy::SpecialCollection::ClearCache() { |
370 cached_results_.clear(); | 381 cached_results_.clear(); |
371 } | 382 } |
OLD | NEW |