Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / content_settings / local_shared_objects_container.cc
blob05564de8dbe9f70cbdb8f2460401decb2403b5e5
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() {
37 appcaches_->Reset();
38 cookies_->Reset();
39 databases_->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 {
48 size_t count = 0;
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();
57 return count;
60 size_t LocalSharedObjectsContainer::GetObjectCountForDomain(
61 const GURL& origin) const {
62 size_t count = 0;
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
70 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();
76 ++it) {
77 const net::CookieList* cookie_list = it->second;
78 for (net::CookieList::const_iterator cookie = cookie_list->begin();
79 cookie != cookie_list->end();
80 ++cookie) {
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)) {
92 ++count;
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();
102 ++it) {
103 if (net::RegistryControlledDomainService::SameDomainOrHost(
104 origin, *it)) {
105 ++count;
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();
112 it != urls.end();
113 ++it) {
114 if (net::RegistryControlledDomainService::SameDomainOrHost(
115 origin, *it)) {
116 ++count;
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();
127 ++it) {
128 if (net::RegistryControlledDomainService::SameDomainOrHost(
129 origin, it->origin)) {
130 ++count;
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();
141 ++it) {
142 if (net::RegistryControlledDomainService::SameDomainOrHost(
143 origin, it->origin)) {
144 ++count;
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();
155 ++it) {
156 if (net::RegistryControlledDomainService::SameDomainOrHost(
157 origin, it->origin)) {
158 ++count;
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();
167 it != map.end();
168 ++it) {
169 const appcache::AppCacheInfoVector& info_vector = it->second;
170 for (appcache::AppCacheInfoVector::const_iterator info =
171 info_vector.begin();
172 info != info_vector.end();
173 ++info) {
174 if (net::RegistryControlledDomainService::SameDomainOrHost(
175 origin, info->manifest_url)) {
176 ++count;
181 return count;
184 scoped_ptr<CookiesTreeModel>
185 LocalSharedObjectsContainer::CreateCookiesTreeModel() const {
186 ContainerMap apps_map;
187 apps_map[std::string()] = new LocalDataContainer(
188 std::string(), std::string(),
189 cookies()->Clone(),
190 databases()->Clone(),
191 local_storages()->Clone(),
192 session_storages()->Clone(),
193 appcaches()->Clone(),
194 indexed_dbs()->Clone(),
195 file_systems()->Clone(),
196 NULL,
197 server_bound_certs()->Clone(),
198 NULL);
200 return make_scoped_ptr(new CookiesTreeModel(apps_map, NULL, true));