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
3 // found in the LICENSE file.
5 #include "chrome/browser/content_settings/local_shared_objects_container.h"
7 #include "chrome/browser/browsing_data/browsing_data_appcache_helper.h"
8 #include "chrome/browser/browsing_data/browsing_data_cookie_helper.h"
9 #include "chrome/browser/browsing_data/browsing_data_database_helper.h"
10 #include "chrome/browser/browsing_data/browsing_data_file_system_helper.h"
11 #include "chrome/browser/browsing_data/browsing_data_indexed_db_helper.h"
12 #include "chrome/browser/browsing_data/browsing_data_local_storage_helper.h"
13 #include "chrome/browser/browsing_data/browsing_data_server_bound_cert_helper.h"
14 #include "chrome/browser/browsing_data/cookies_tree_model.h"
15 #include "chrome/browser/profiles/profile.h"
16 #include "content/public/browser/storage_partition.h"
17 #include "content/public/common/url_constants.h"
18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
19 #include "net/cookies/canonical_cookie.h"
24 // Helper wrapper for net::registry_controlled_domains::SameDomainOrHost
25 // which always excludes private registries.
26 bool SamePublicDomainOrHost(const GURL
& gurl1
, const GURL
& gurl2
) {
27 return net::registry_controlled_domains::SameDomainOrHost(
30 net::registry_controlled_domains::EXCLUDE_PRIVATE_REGISTRIES
);
35 LocalSharedObjectsContainer::LocalSharedObjectsContainer(Profile
* profile
)
36 : appcaches_(new CannedBrowsingDataAppCacheHelper(profile
)),
37 cookies_(new CannedBrowsingDataCookieHelper(
38 profile
->GetRequestContext())),
39 databases_(new CannedBrowsingDataDatabaseHelper(profile
)),
40 file_systems_(new CannedBrowsingDataFileSystemHelper(profile
)),
41 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper(
42 content::BrowserContext::GetDefaultStoragePartition(profile
)->
43 GetIndexedDBContext())),
44 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile
)),
45 server_bound_certs_(new CannedBrowsingDataServerBoundCertHelper()),
46 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile
)) {
49 LocalSharedObjectsContainer::~LocalSharedObjectsContainer() {
52 void LocalSharedObjectsContainer::Reset() {
56 file_systems_
->Reset();
57 indexed_dbs_
->Reset();
58 local_storages_
->Reset();
59 server_bound_certs_
->Reset();
60 session_storages_
->Reset();
63 size_t LocalSharedObjectsContainer::GetObjectCount() const {
65 count
+= appcaches()->GetAppCacheCount();
66 count
+= cookies()->GetCookieCount();
67 count
+= databases()->GetDatabaseCount();
68 count
+= file_systems()->GetFileSystemCount();
69 count
+= indexed_dbs()->GetIndexedDBCount();
70 count
+= local_storages()->GetLocalStorageCount();
71 count
+= server_bound_certs()->GetCertCount();
72 count
+= session_storages()->GetLocalStorageCount();
76 size_t LocalSharedObjectsContainer::GetObjectCountForDomain(
77 const GURL
& origin
) const {
80 // Count all cookies that have the same domain as the provided |origin|. This
81 // means count all cookies that has been set by a host that is not considered
82 // to be a third party regarding the domain of the provided |origin|.
83 // E.g. if the origin is "http://foo.com" then all cookies with domain foo.com,
84 // a.foo.com, b.a.foo.com or *.foo.com will be counted.
85 typedef CannedBrowsingDataCookieHelper::OriginCookieListMap
87 const OriginCookieListMap
& origin_cookies_list_map
=
88 cookies()->origin_cookie_list_map();
89 for (OriginCookieListMap::const_iterator it
=
90 origin_cookies_list_map
.begin();
91 it
!= origin_cookies_list_map
.end();
93 const net::CookieList
* cookie_list
= it
->second
;
94 for (net::CookieList::const_iterator cookie
= cookie_list
->begin();
95 cookie
!= cookie_list
->end();
97 // Strip leading '.'s.
98 std::string cookie_domain
= cookie
->Domain();
99 if (cookie_domain
[0] == '.')
100 cookie_domain
= cookie_domain
.substr(1);
101 // The |domain_url| is only created in order to use the
102 // SamePublicDomainOrHost method below. It does not matter which scheme is
103 // used as the scheme is ignored by the SamePublicDomainOrHost method.
104 GURL
domain_url(std::string(content::kHttpScheme
) +
105 content::kStandardSchemeSeparator
+ cookie_domain
);
106 if (SamePublicDomainOrHost(origin
, domain_url
))
111 // Count local storages for the domain of the given |origin|.
112 const std::set
<GURL
> local_storage_info
=
113 local_storages()->GetLocalStorageInfo();
114 for (std::set
<GURL
>::const_iterator it
= local_storage_info
.begin();
115 it
!= local_storage_info
.end();
117 if (SamePublicDomainOrHost(origin
, *it
))
121 // Count session storages for the domain of the given |origin|.
122 const std::set
<GURL
> urls
= session_storages()->GetLocalStorageInfo();
123 for (std::set
<GURL
>::const_iterator it
= urls
.begin();
126 if (SamePublicDomainOrHost(origin
, *it
))
130 // Count indexed dbs for the domain of the given |origin|.
131 typedef CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo IndexedDBInfo
;
132 const std::set
<IndexedDBInfo
>& indexed_db_info
=
133 indexed_dbs()->GetIndexedDBInfo();
134 for (std::set
<IndexedDBInfo
>::const_iterator it
=
135 indexed_db_info
.begin();
136 it
!= indexed_db_info
.end();
138 if (SamePublicDomainOrHost(origin
, it
->origin
))
142 // Count filesystems for the domain of the given |origin|.
143 typedef BrowsingDataFileSystemHelper::FileSystemInfo FileSystemInfo
;
144 typedef std::list
<FileSystemInfo
> FileSystemInfoList
;
145 const FileSystemInfoList
& file_system_info
=
146 file_systems()->GetFileSystemInfo();
147 for (FileSystemInfoList::const_iterator it
= file_system_info
.begin();
148 it
!= file_system_info
.end();
150 if (SamePublicDomainOrHost(origin
, it
->origin
))
154 // Count databases for the domain of the given |origin|.
155 typedef CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo DatabaseInfo
;
156 const std::set
<DatabaseInfo
>& database_list
=
157 databases()->GetPendingDatabaseInfo();
158 for (std::set
<DatabaseInfo
>::const_iterator it
=
159 database_list
.begin();
160 it
!= database_list
.end();
162 if (SamePublicDomainOrHost(origin
, it
->origin
))
166 // Count the AppCache manifest files for the domain of the given |origin|.
167 typedef BrowsingDataAppCacheHelper::OriginAppCacheInfoMap
168 OriginAppCacheInfoMap
;
169 const OriginAppCacheInfoMap
& map
= appcaches()->GetOriginAppCacheInfoMap();
170 for (OriginAppCacheInfoMap::const_iterator it
= map
.begin();
173 const appcache::AppCacheInfoVector
& info_vector
= it
->second
;
174 for (appcache::AppCacheInfoVector::const_iterator info
=
176 info
!= info_vector
.end();
178 if (SamePublicDomainOrHost(origin
, info
->manifest_url
))
186 scoped_ptr
<CookiesTreeModel
>
187 LocalSharedObjectsContainer::CreateCookiesTreeModel() const {
188 LocalDataContainer
* container
= new LocalDataContainer(
197 server_bound_certs(),
200 return make_scoped_ptr(new CookiesTreeModel(container
, NULL
, true));