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/content_settings/local_shared_objects_container.h" | 5 #include "chrome/browser/content_settings/local_shared_objects_container.h" |
6 | 6 |
7 #include "chrome/browser/browsing_data_appcache_helper.h" | 7 #include "chrome/browser/browsing_data_appcache_helper.h" |
8 #include "chrome/browser/browsing_data_cookie_helper.h" | 8 #include "chrome/browser/browsing_data_cookie_helper.h" |
9 #include "chrome/browser/browsing_data_database_helper.h" | 9 #include "chrome/browser/browsing_data_database_helper.h" |
10 #include "chrome/browser/browsing_data_file_system_helper.h" | 10 #include "chrome/browser/browsing_data_file_system_helper.h" |
11 #include "chrome/browser/browsing_data_indexed_db_helper.h" | 11 #include "chrome/browser/browsing_data_indexed_db_helper.h" |
12 #include "chrome/browser/browsing_data_local_storage_helper.h" | 12 #include "chrome/browser/browsing_data_local_storage_helper.h" |
13 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" | 13 #include "chrome/browser/browsing_data_server_bound_cert_helper.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "content/public/common/url_constants.h" |
| 16 #include "googleurl/src/gurl.h" |
| 17 #include "net/base/registry_controlled_domain.h" |
15 | 18 |
16 LocalSharedObjectsContainer::LocalSharedObjectsContainer(Profile* profile) | 19 LocalSharedObjectsContainer::LocalSharedObjectsContainer(Profile* profile) |
17 : appcaches_(new CannedBrowsingDataAppCacheHelper(profile)), | 20 : appcaches_(new CannedBrowsingDataAppCacheHelper(profile)), |
18 cookies_(new CannedBrowsingDataCookieHelper(profile)), | 21 cookies_(new CannedBrowsingDataCookieHelper(profile)), |
19 databases_(new CannedBrowsingDataDatabaseHelper(profile)), | 22 databases_(new CannedBrowsingDataDatabaseHelper(profile)), |
20 file_systems_(new CannedBrowsingDataFileSystemHelper(profile)), | 23 file_systems_(new CannedBrowsingDataFileSystemHelper(profile)), |
21 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper()), | 24 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper()), |
22 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)), | 25 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile)), |
23 server_bound_certs_(new CannedBrowsingDataServerBoundCertHelper()), | 26 server_bound_certs_(new CannedBrowsingDataServerBoundCertHelper()), |
24 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) { | 27 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile)) { |
25 } | 28 } |
26 | 29 |
27 LocalSharedObjectsContainer::~LocalSharedObjectsContainer() { | 30 LocalSharedObjectsContainer::~LocalSharedObjectsContainer() { |
28 } | 31 } |
29 | 32 |
30 void LocalSharedObjectsContainer::Reset() { | 33 void LocalSharedObjectsContainer::Reset() { |
31 appcaches_->Reset(); | 34 appcaches_->Reset(); |
32 cookies_->Reset(); | 35 cookies_->Reset(); |
33 databases_->Reset(); | 36 databases_->Reset(); |
34 file_systems_->Reset(); | 37 file_systems_->Reset(); |
35 indexed_dbs_->Reset(); | 38 indexed_dbs_->Reset(); |
36 local_storages_->Reset(); | 39 local_storages_->Reset(); |
37 server_bound_certs_->Reset(); | 40 server_bound_certs_->Reset(); |
38 session_storages_->Reset(); | 41 session_storages_->Reset(); |
39 } | 42 } |
40 | 43 |
41 bool LocalSharedObjectsContainer::IsEmpty() const { | 44 size_t LocalSharedObjectsContainer::GetObjectCount() const { |
42 return appcaches_->empty() && | 45 size_t count = 0; |
43 cookies_->empty() && | 46 count += appcaches()->GetAppCacheCount(); |
44 databases_->empty() && | 47 count += cookies()->GetCookieCount(); |
45 file_systems_->empty() && | 48 count += databases()->GetDatabaseCount(); |
46 indexed_dbs_->empty() && | 49 count += file_systems()->GetFileSystemCount(); |
47 local_storages_->empty() && | 50 count += indexed_dbs()->GetIndexedDBCount(); |
48 server_bound_certs_->empty() && | 51 count += local_storages()->GetLocalStorageCount(); |
49 session_storages_->empty(); | 52 count += server_bound_certs()->GetCertCount(); |
| 53 count += session_storages()->GetLocalStorageCount(); |
| 54 return count; |
50 } | 55 } |
| 56 |
| 57 size_t LocalSharedObjectsContainer::GetObjectCountForDomain( |
| 58 const GURL& origin) const { |
| 59 size_t count = 0; |
| 60 |
| 61 // Count all cookies that have the same domain as the provided |origin|. This |
| 62 // means count all cookies that has been set by a host that is not considered |
| 63 // to be a third party regarding the domain of the provided |origin|. |
| 64 // E.g. if the origin is "http://foo.com" then all cookies with domain foo.com
, |
| 65 // a.foo.com, b.a.foo.com or *.foo.com will be counted. |
| 66 typedef CannedBrowsingDataCookieHelper::OriginCookieListMap |
| 67 OriginCookieListMap; |
| 68 const OriginCookieListMap& origin_cookies_list_map = |
| 69 cookies()->origin_cookie_list_map(); |
| 70 for (OriginCookieListMap::const_iterator it = |
| 71 origin_cookies_list_map.begin(); |
| 72 it != origin_cookies_list_map.end(); |
| 73 ++it) { |
| 74 const net::CookieList* cookie_list = it->second; |
| 75 for (net::CookieList::const_iterator cookie = cookie_list->begin(); |
| 76 cookie != cookie_list->end(); |
| 77 ++cookie) { |
| 78 // Strip leading '.'s. |
| 79 std::string cookie_domain = cookie->Domain(); |
| 80 if (cookie_domain[0] == '.') |
| 81 cookie_domain = cookie_domain.substr(1); |
| 82 // The |domain_url| is only created in order to use the SameDomainOrHost |
| 83 // method below. It does not matter which scheme is used as the scheme is |
| 84 // ignored by the SameDomainOrHost method. |
| 85 GURL domain_url(std::string(chrome::kHttpScheme) + |
| 86 content::kStandardSchemeSeparator + cookie_domain); |
| 87 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 88 origin, domain_url)) { |
| 89 ++count; |
| 90 } |
| 91 } |
| 92 } |
| 93 |
| 94 // Count local storages for the domain of the given |origin|. |
| 95 const std::set<GURL> local_storage_info = |
| 96 local_storages()->GetLocalStorageInfo(); |
| 97 for (std::set<GURL>::const_iterator it = local_storage_info.begin(); |
| 98 it != local_storage_info.end(); |
| 99 ++it) { |
| 100 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 101 origin, *it)) { |
| 102 ++count; |
| 103 } |
| 104 } |
| 105 |
| 106 // Count session storages for the domain of the given |origin|. |
| 107 const std::set<GURL> urls = session_storages()->GetLocalStorageInfo(); |
| 108 for (std::set<GURL>::const_iterator it = urls.begin(); |
| 109 it != urls.end(); |
| 110 ++it) { |
| 111 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 112 origin, *it)) { |
| 113 ++count; |
| 114 } |
| 115 } |
| 116 |
| 117 // Count indexed dbs for the domain of the given |origin|. |
| 118 typedef CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo IndexedDBInfo; |
| 119 const std::set<IndexedDBInfo>& indexed_db_info = |
| 120 indexed_dbs()->GetIndexedDBInfo(); |
| 121 for (std::set<IndexedDBInfo>::const_iterator it = |
| 122 indexed_db_info.begin(); |
| 123 it != indexed_db_info.end(); |
| 124 ++it) { |
| 125 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 126 origin, it->origin)) { |
| 127 ++count; |
| 128 } |
| 129 } |
| 130 |
| 131 // Count filesystems for the domain of the given |origin|. |
| 132 typedef BrowsingDataFileSystemHelper::FileSystemInfo FileSystemInfo; |
| 133 typedef std::list<FileSystemInfo> FileSystemInfoList; |
| 134 const FileSystemInfoList& file_system_info = |
| 135 file_systems()->GetFileSystemInfo(); |
| 136 for (FileSystemInfoList::const_iterator it = file_system_info.begin(); |
| 137 it != file_system_info.end(); |
| 138 ++it) { |
| 139 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 140 origin, it->origin)) { |
| 141 ++count; |
| 142 } |
| 143 } |
| 144 |
| 145 // Count databases for the domain of the given |origin|. |
| 146 typedef CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo DatabaseInfo; |
| 147 const std::set<DatabaseInfo>& database_list = |
| 148 databases()->GetPendingDatabaseInfo(); |
| 149 for (std::set<DatabaseInfo>::const_iterator it = |
| 150 database_list.begin(); |
| 151 it != database_list.end(); |
| 152 ++it) { |
| 153 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 154 origin, it->origin)) { |
| 155 ++count; |
| 156 } |
| 157 } |
| 158 |
| 159 // Count the AppCache manifest files for the domain of the given |origin|. |
| 160 typedef BrowsingDataAppCacheHelper::OriginAppCacheInfoMap |
| 161 OriginAppCacheInfoMap; |
| 162 const OriginAppCacheInfoMap& map = appcaches()->GetOriginAppCacheInfoMap(); |
| 163 for (OriginAppCacheInfoMap::const_iterator it = map.begin(); |
| 164 it != map.end(); |
| 165 ++it) { |
| 166 const appcache::AppCacheInfoVector& info_vector = it->second; |
| 167 for (appcache::AppCacheInfoVector::const_iterator info = |
| 168 info_vector.begin(); |
| 169 info != info_vector.end(); |
| 170 ++info) { |
| 171 if (net::RegistryControlledDomainService::SameDomainOrHost( |
| 172 origin, info->manifest_url)) { |
| 173 ++count; |
| 174 } |
| 175 } |
| 176 } |
| 177 |
| 178 return count; |
| 179 } |
OLD | NEW |