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/common/url_constants.h"
17 #include "googleurl/src/gurl.h"
18 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
19 #include "net/cookies/canonical_cookie.h"
21 LocalSharedObjectsContainer::LocalSharedObjectsContainer(Profile
* profile
)
22 : appcaches_(new CannedBrowsingDataAppCacheHelper(profile
)),
23 cookies_(new CannedBrowsingDataCookieHelper(
24 profile
->GetRequestContext())),
25 databases_(new CannedBrowsingDataDatabaseHelper(profile
)),
26 file_systems_(new CannedBrowsingDataFileSystemHelper(profile
)),
27 indexed_dbs_(new CannedBrowsingDataIndexedDBHelper()),
28 local_storages_(new CannedBrowsingDataLocalStorageHelper(profile
)),
29 server_bound_certs_(new CannedBrowsingDataServerBoundCertHelper()),
30 session_storages_(new CannedBrowsingDataLocalStorageHelper(profile
)) {
33 LocalSharedObjectsContainer::~LocalSharedObjectsContainer() {
36 void LocalSharedObjectsContainer::Reset() {
40 file_systems_
->Reset();
41 indexed_dbs_
->Reset();
42 local_storages_
->Reset();
43 server_bound_certs_
->Reset();
44 session_storages_
->Reset();
47 size_t LocalSharedObjectsContainer::GetObjectCount() const {
49 count
+= appcaches()->GetAppCacheCount();
50 count
+= cookies()->GetCookieCount();
51 count
+= databases()->GetDatabaseCount();
52 count
+= file_systems()->GetFileSystemCount();
53 count
+= indexed_dbs()->GetIndexedDBCount();
54 count
+= local_storages()->GetLocalStorageCount();
55 count
+= server_bound_certs()->GetCertCount();
56 count
+= session_storages()->GetLocalStorageCount();
60 size_t LocalSharedObjectsContainer::GetObjectCountForDomain(
61 const GURL
& origin
) const {
64 // Count all cookies that have the same domain as the provided |origin|. This
65 // means count all cookies that has been set by a host that is not considered
66 // to be a third party regarding the domain of the provided |origin|.
67 // E.g. if the origin is "http://foo.com" then all cookies with domain foo.com,
68 // a.foo.com, b.a.foo.com or *.foo.com will be counted.
69 typedef CannedBrowsingDataCookieHelper::OriginCookieListMap
71 const OriginCookieListMap
& origin_cookies_list_map
=
72 cookies()->origin_cookie_list_map();
73 for (OriginCookieListMap::const_iterator it
=
74 origin_cookies_list_map
.begin();
75 it
!= origin_cookies_list_map
.end();
77 const net::CookieList
* cookie_list
= it
->second
;
78 for (net::CookieList::const_iterator cookie
= cookie_list
->begin();
79 cookie
!= cookie_list
->end();
81 // Strip leading '.'s.
82 std::string cookie_domain
= cookie
->Domain();
83 if (cookie_domain
[0] == '.')
84 cookie_domain
= cookie_domain
.substr(1);
85 // The |domain_url| is only created in order to use the SameDomainOrHost
86 // method below. It does not matter which scheme is used as the scheme is
87 // ignored by the SameDomainOrHost method.
88 GURL
domain_url(std::string(chrome::kHttpScheme
) +
89 content::kStandardSchemeSeparator
+ cookie_domain
);
90 if (net::RegistryControlledDomainService::SameDomainOrHost(
91 origin
, domain_url
)) {
97 // Count local storages for the domain of the given |origin|.
98 const std::set
<GURL
> local_storage_info
=
99 local_storages()->GetLocalStorageInfo();
100 for (std::set
<GURL
>::const_iterator it
= local_storage_info
.begin();
101 it
!= local_storage_info
.end();
103 if (net::RegistryControlledDomainService::SameDomainOrHost(
109 // Count session storages for the domain of the given |origin|.
110 const std::set
<GURL
> urls
= session_storages()->GetLocalStorageInfo();
111 for (std::set
<GURL
>::const_iterator it
= urls
.begin();
114 if (net::RegistryControlledDomainService::SameDomainOrHost(
120 // Count indexed dbs for the domain of the given |origin|.
121 typedef CannedBrowsingDataIndexedDBHelper::PendingIndexedDBInfo IndexedDBInfo
;
122 const std::set
<IndexedDBInfo
>& indexed_db_info
=
123 indexed_dbs()->GetIndexedDBInfo();
124 for (std::set
<IndexedDBInfo
>::const_iterator it
=
125 indexed_db_info
.begin();
126 it
!= indexed_db_info
.end();
128 if (net::RegistryControlledDomainService::SameDomainOrHost(
129 origin
, it
->origin
)) {
134 // Count filesystems for the domain of the given |origin|.
135 typedef BrowsingDataFileSystemHelper::FileSystemInfo FileSystemInfo
;
136 typedef std::list
<FileSystemInfo
> FileSystemInfoList
;
137 const FileSystemInfoList
& file_system_info
=
138 file_systems()->GetFileSystemInfo();
139 for (FileSystemInfoList::const_iterator it
= file_system_info
.begin();
140 it
!= file_system_info
.end();
142 if (net::RegistryControlledDomainService::SameDomainOrHost(
143 origin
, it
->origin
)) {
148 // Count databases for the domain of the given |origin|.
149 typedef CannedBrowsingDataDatabaseHelper::PendingDatabaseInfo DatabaseInfo
;
150 const std::set
<DatabaseInfo
>& database_list
=
151 databases()->GetPendingDatabaseInfo();
152 for (std::set
<DatabaseInfo
>::const_iterator it
=
153 database_list
.begin();
154 it
!= database_list
.end();
156 if (net::RegistryControlledDomainService::SameDomainOrHost(
157 origin
, it
->origin
)) {
162 // Count the AppCache manifest files for the domain of the given |origin|.
163 typedef BrowsingDataAppCacheHelper::OriginAppCacheInfoMap
164 OriginAppCacheInfoMap
;
165 const OriginAppCacheInfoMap
& map
= appcaches()->GetOriginAppCacheInfoMap();
166 for (OriginAppCacheInfoMap::const_iterator it
= map
.begin();
169 const appcache::AppCacheInfoVector
& info_vector
= it
->second
;
170 for (appcache::AppCacheInfoVector::const_iterator info
=
172 info
!= info_vector
.end();
174 if (net::RegistryControlledDomainService::SameDomainOrHost(
175 origin
, info
->manifest_url
)) {
184 scoped_ptr
<CookiesTreeModel
>
185 LocalSharedObjectsContainer::CreateCookiesTreeModel() const {
186 ContainerMap apps_map
;
187 apps_map
[std::string()] = new LocalDataContainer(
188 std::string(), std::string(),
190 databases()->Clone(),
191 local_storages()->Clone(),
192 session_storages()->Clone(),
193 appcaches()->Clone(),
194 indexed_dbs()->Clone(),
195 file_systems()->Clone(),
197 server_bound_certs()->Clone(),
200 return make_scoped_ptr(new CookiesTreeModel(apps_map
, NULL
, true));