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/website_settings_model.h" | 5 #include "chrome/browser/website_settings_model.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 13 #include "chrome/browser/content_settings/local_shared_objects_container.h" |
| 14 #include "chrome/browser/content_settings/tab_specific_content_settings.h" |
12 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
13 #include "chrome/browser/ssl/ssl_error_info.h" | 16 #include "chrome/browser/ssl/ssl_error_info.h" |
14 #include "content/public/browser/cert_store.h" | 17 #include "content/public/browser/cert_store.h" |
15 #include "content/public/common/ssl_status.h" | 18 #include "content/public/common/ssl_status.h" |
16 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
17 #include "grit/chromium_strings.h" | 20 #include "grit/chromium_strings.h" |
18 #include "grit/generated_resources.h" | 21 #include "grit/generated_resources.h" |
19 #include "net/base/cert_status_flags.h" | 22 #include "net/base/cert_status_flags.h" |
20 #include "net/base/ssl_cipher_suite_names.h" | 23 #include "net/base/ssl_cipher_suite_names.h" |
21 #include "net/base/ssl_connection_status_flags.h" | 24 #include "net/base/ssl_connection_status_flags.h" |
22 #include "net/base/x509_certificate.h" | 25 #include "net/base/x509_certificate.h" |
23 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
25 | 28 |
26 WebsiteSettingsModel::WebsiteSettingsModel(Profile* profile, | 29 // --- |
| 30 #include "base/bind.h" |
| 31 #include "base/bind_helpers.h" |
| 32 #include "content/public/browser/browser_thread.h" |
| 33 #include "net/base/registry_controlled_domain.h" |
| 34 |
| 35 using content::BrowserThread; |
| 36 |
| 37 namespace { |
| 38 |
| 39 ContentSettingsType kPermissionType[] = { |
| 40 CONTENT_SETTINGS_TYPE_POPUPS, |
| 41 CONTENT_SETTINGS_TYPE_PLUGINS, |
| 42 CONTENT_SETTINGS_TYPE_NOTIFICATIONS, |
| 43 CONTENT_SETTINGS_TYPE_GEOLOCATION, |
| 44 }; |
| 45 |
| 46 } // namespace |
| 47 |
| 48 class SiteData { |
| 49 public: |
| 50 SiteData(WebsiteSettingsModel* website_settings, |
| 51 GURL page_url, |
| 52 const LocalSharedObjectsContainer& local_shared_data, |
| 53 const LocalSharedObjectsContainer& blocked_local_shared_data); |
| 54 |
| 55 int GetAllowedLocalSharedObjectsCount() const; |
| 56 int GetBlockedLocalSharedObjectsCount() const; |
| 57 int GetThirdPartyCookiesCount() const; |
| 58 int GetBlockedThirdPartyCookiesCount() const; |
| 59 |
| 60 int GetThirdPartyDomainCount() const; |
| 61 |
| 62 private: |
| 63 typedef std::list<net::CookieMonster::CanonicalCookie> CookieList; |
| 64 typedef std::list<BrowsingDataDatabaseHelper::DatabaseInfo> |
| 65 DatabaseInfoList; |
| 66 typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> |
| 67 LocalStorageInfoList; |
| 68 typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo> |
| 69 SessionStorageInfoList; |
| 70 typedef std::list<BrowsingDataIndexedDBHelper::IndexedDBInfo> |
| 71 IndexedDBInfoList; |
| 72 typedef std::list<BrowsingDataFileSystemHelper::FileSystemInfo> |
| 73 FileSystemInfoList; |
| 74 |
| 75 // Callbacks for asynchrounous local data fetching |
| 76 void OnAllowedCookiesLoaded(const net::CookieList& cookie_list); |
| 77 void OnBlockedCookiesLoaded(const net::CookieList& cookie_list); |
| 78 void OnAllowedDatabaseInfoLoaded(const DatabaseInfoList& database_info); |
| 79 void OnBlockedDatabaseInfoLoaded(const DatabaseInfoList& database_info); |
| 80 |
| 81 void NotifyListener() const; |
| 82 |
| 83 WebsiteSettingsModel* website_settings_; |
| 84 |
| 85 GURL page_url_; |
| 86 |
| 87 net::CookieList allowed_cookies_list_; |
| 88 net::CookieList blocked_cookies_list_; |
| 89 net::CookieList allowed_third_party_cookies_; |
| 90 net::CookieList blocked_third_party_cookies_; |
| 91 |
| 92 DatabaseInfoList allowed_database_info_list_; |
| 93 DatabaseInfoList blocked_database_info_list_; |
| 94 |
| 95 int pending_callbacks_; |
| 96 |
| 97 DISALLOW_COPY_AND_ASSIGN(SiteData); |
| 98 }; |
| 99 |
| 100 SiteData::SiteData( |
| 101 WebsiteSettingsModel* website_settings, |
| 102 GURL page_url, |
| 103 const LocalSharedObjectsContainer& allowed_local_shared_objects, |
| 104 const LocalSharedObjectsContainer& blocked_local_shared_objects) |
| 105 : website_settings_(website_settings), |
| 106 page_url_(page_url), |
| 107 pending_callbacks_(0) { |
| 108 |
| 109 // 4 async calls will be made. |
| 110 pending_callbacks_ = 4; |
| 111 |
| 112 // Fetch cookies. |
| 113 DCHECK(allowed_local_shared_objects.cookies()); |
| 114 allowed_local_shared_objects.cookies()->StartFetching( |
| 115 base::Bind(&SiteData::OnAllowedCookiesLoaded, |
| 116 base::Unretained(this))); |
| 117 DCHECK(blocked_local_shared_objects.cookies()); |
| 118 blocked_local_shared_objects.cookies()->StartFetching( |
| 119 base::Bind(&SiteData::OnBlockedCookiesLoaded, |
| 120 base::Unretained(this))); |
| 121 |
| 122 // Fetch database infos. |
| 123 DCHECK(allowed_local_shared_objects.databases()); |
| 124 allowed_local_shared_objects.databases()->StartFetching( |
| 125 base::Bind(&SiteData::OnAllowedDatabaseInfoLoaded, |
| 126 base::Unretained(this))); |
| 127 DCHECK(allowed_local_shared_objects.databases()); |
| 128 blocked_local_shared_objects.databases()->StartFetching( |
| 129 base::Bind(&SiteData::OnBlockedDatabaseInfoLoaded, |
| 130 base::Unretained(this))); |
| 131 /* |
| 132 // Local Storage |
| 133 DCHECK(allowed_local_shared_objects.local_storage_helper_); |
| 134 local_storage_helper_->StartFetching( |
| 135 base::Bind(&SiteData::OnLocalStorageModelInfoLoaded, |
| 136 base::Unretained(this))); |
| 137 if (session_storage_helper_) { |
| 138 session_storage_helper_->StartFetching( |
| 139 base::Bind(&SiteData::OnSessionStorageModelInfoLoaded, |
| 140 base::Unretained(this))); |
| 141 } |
| 142 |
| 143 // TODO(michaeln): When all of the UI implementations have been updated, make |
| 144 // this a required parameter. |
| 145 if (appcache_helper_) { |
| 146 appcache_helper_->StartFetching( |
| 147 base::Bind(&CookiesTreeModel::OnAppCacheModelInfoLoaded, |
| 148 base::Unretained(this))); |
| 149 } |
| 150 |
| 151 if (indexed_db_helper_) { |
| 152 indexed_db_helper_->StartFetching( |
| 153 base::Bind(&CookiesTreeModel::OnIndexedDBModelInfoLoaded, |
| 154 base::Unretained(this))); |
| 155 } |
| 156 |
| 157 if (file_system_helper_) { |
| 158 file_system_helper_->StartFetching( |
| 159 base::Bind(&CookiesTreeModel::OnFileSystemModelInfoLoaded, |
| 160 base::Unretained(this))); |
| 161 } |
| 162 |
| 163 if (quota_helper_) { |
| 164 quota_helper_->StartFetching( |
| 165 base::Bind(&CookiesTreeModel::OnQuotaModelInfoLoaded, |
| 166 base::Unretained(this))); |
| 167 */ |
| 168 } |
| 169 |
| 170 int SiteData::GetAllowedLocalSharedObjectsCount() const { |
| 171 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 172 return allowed_cookies_list_.size() + |
| 173 allowed_database_info_list_.size(); |
| 174 } |
| 175 |
| 176 int SiteData::GetBlockedLocalSharedObjectsCount() const { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 178 return blocked_cookies_list_.size() + |
| 179 blocked_database_info_list_.size(); |
| 180 } |
| 181 |
| 182 int SiteData::GetThirdPartyCookiesCount() const { |
| 183 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 184 return allowed_third_party_cookies_.size(); |
| 185 } |
| 186 |
| 187 int SiteData::GetBlockedThirdPartyCookiesCount() const { |
| 188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 189 return blocked_third_party_cookies_.size(); |
| 190 } |
| 191 |
| 192 void SiteData::NotifyListener() const { |
| 193 if (pending_callbacks_ == 0) |
| 194 website_settings_->OnLocalSharedObjectsUpdated(); |
| 195 } |
| 196 |
| 197 void SiteData::OnAllowedDatabaseInfoLoaded( |
| 198 const DatabaseInfoList& database_info) { |
| 199 allowed_database_info_list_ = database_info; |
| 200 pending_callbacks_--; |
| 201 NotifyListener(); |
| 202 } |
| 203 |
| 204 void SiteData::OnBlockedDatabaseInfoLoaded( |
| 205 const DatabaseInfoList& database_info) { |
| 206 blocked_database_info_list_ = database_info; |
| 207 pending_callbacks_--; |
| 208 NotifyListener(); |
| 209 } |
| 210 |
| 211 void SiteData::OnAllowedCookiesLoaded(const net::CookieList& cookie_list) { |
| 212 for (net::CookieList::const_iterator cookie = cookie_list.begin(); |
| 213 cookie != cookie_list.end(); |
| 214 ++cookie) { |
| 215 // Strip leading dot. |
| 216 std::string domain = cookie->Domain(); |
| 217 if (domain.length() > 1 && domain[0] == '.') |
| 218 domain = domain.substr(1); |
| 219 // Test if the cookie is a first party cookie. |
| 220 bool first_party_cookie = |
| 221 net::RegistryControlledDomainService::SameDomainOrHost( |
| 222 page_url_, GURL(std::string(chrome::kHttpScheme) + |
| 223 chrome::kStandardSchemeSeparator + domain)); |
| 224 if (first_party_cookie) |
| 225 allowed_cookies_list_.push_back(*cookie); |
| 226 else |
| 227 allowed_third_party_cookies_.push_back(*cookie); |
| 228 } |
| 229 pending_callbacks_--; |
| 230 NotifyListener(); |
| 231 } |
| 232 |
| 233 int SiteData::GetThirdPartyDomainCount() const { |
| 234 std::set<std::string> domain_set; |
| 235 for (net::CookieList::const_iterator cookie = allowed_third_party_cookies_.beg
in(); |
| 236 cookie != allowed_third_party_cookies_.end(); |
| 237 ++cookie) { |
| 238 domain_set.insert(cookie->Domain()); |
| 239 LOG(ERROR) << " *** " << cookie->Domain(); |
| 240 } |
| 241 for (net::CookieList::const_iterator cookie = blocked_third_party_cookies_.beg
in(); |
| 242 cookie != blocked_third_party_cookies_.end(); |
| 243 ++cookie) { |
| 244 domain_set.insert(cookie->Domain()); |
| 245 LOG(ERROR) << " *** " << cookie->Domain(); |
| 246 } |
| 247 return domain_set.size(); |
| 248 } |
| 249 |
| 250 void SiteData::OnBlockedCookiesLoaded(const net::CookieList& cookie_list) { |
| 251 for (net::CookieList::const_iterator cookie = cookie_list.begin(); |
| 252 cookie != cookie_list.end(); |
| 253 ++cookie) { |
| 254 // Strip leading dot. |
| 255 std::string domain = cookie->Domain(); |
| 256 if (domain.length() > 1 && domain[0] == '.') |
| 257 domain = domain.substr(1); |
| 258 // Test if the cookie is a first party cookie. |
| 259 bool first_party_cookie = |
| 260 net::RegistryControlledDomainService::SameDomainOrHost( |
| 261 page_url_, GURL(std::string(chrome::kHttpScheme) + |
| 262 chrome::kStandardSchemeSeparator + domain)); |
| 263 if (first_party_cookie) |
| 264 blocked_cookies_list_.push_back(*cookie); |
| 265 else |
| 266 blocked_third_party_cookies_.push_back(*cookie); |
| 267 } |
| 268 pending_callbacks_--; |
| 269 NotifyListener(); |
| 270 } |
| 271 |
| 272 // |
| 273 // |
| 274 // |
| 275 WebsiteSettingsModel::WebsiteSettingsModel(WebsiteSettingsUI* ui, |
| 276 Profile* profile, |
27 const GURL& url, | 277 const GURL& url, |
28 const content::SSLStatus& ssl, | 278 const content::SSLStatus& ssl, |
29 content::CertStore* cert_store) | 279 content::CertStore* cert_store, |
30 : site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN), | 280 TabSpecificContentSettings* content_s
ettings) |
| 281 : ui_(ui), |
| 282 site_url_(url), |
| 283 site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN), |
31 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN), | 284 site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN), |
32 cert_store_(cert_store) { | 285 cert_store_(cert_store), |
| 286 content_settings_(profile->GetHostContentSettingsMap()) { |
33 Init(profile, url, ssl); | 287 Init(profile, url, ssl); |
| 288 site_data_.reset(new SiteData( |
| 289 this, |
| 290 url, |
| 291 content_settings->allowed_local_shared_objects(), |
| 292 content_settings->blocked_local_shared_objects())); |
| 293 |
34 // After initialization the status about the site's connection | 294 // After initialization the status about the site's connection |
35 // and it's identity must be available. | 295 // and it's identity must be available. |
36 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN); | 296 DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN); |
37 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN); | 297 DCHECK_NE(site_connection_status_, SITE_CONNECTION_STATUS_UNKNOWN); |
38 } | 298 } |
39 | 299 |
40 WebsiteSettingsModel::~WebsiteSettingsModel() { | 300 WebsiteSettingsModel::~WebsiteSettingsModel() { |
41 } | 301 } |
42 | 302 |
| 303 void WebsiteSettingsModel::OnLocalSharedObjectsUpdated() { |
| 304 ui_->Update(); |
| 305 } |
| 306 |
| 307 void WebsiteSettingsModel::GetCookieInfos(CookieInfoList* cookie_info_list) { |
| 308 cookie_info_list->clear(); |
| 309 |
| 310 WebsiteSettingsUI::CookieInfo info; |
| 311 info.text = |
| 312 net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_); |
| 313 info.allowed = site_data_->GetAllowedLocalSharedObjectsCount(); |
| 314 info.blocked = site_data_->GetBlockedLocalSharedObjectsCount(); |
| 315 cookie_info_list->push_back(info); |
| 316 |
| 317 int domain_count = site_data_->GetThirdPartyDomainCount(); |
| 318 info.text = domain_count ? base::IntToString(domain_count) + " " : ""; |
| 319 if (domain_count == 1) |
| 320 info.text += "Other site"; |
| 321 else |
| 322 info.text += "Other sites"; |
| 323 info.allowed = site_data_->GetThirdPartyCookiesCount(); |
| 324 info.blocked = site_data_->GetBlockedThirdPartyCookiesCount(); |
| 325 cookie_info_list->push_back(info); |
| 326 } |
| 327 |
| 328 void WebsiteSettingsModel::GetPermissionInfos( |
| 329 PermissionInfoList* permission_info_list) { |
| 330 permission_info_list->clear(); |
| 331 |
| 332 WebsiteSettingsUI::PermissionInfo permission_info; |
| 333 for (size_t i=0; i<arraysize(kPermissionType); ++i) { |
| 334 ContentSettingsType type = kPermissionType[i]; |
| 335 ContentSetting setting = content_settings_->GetContentSetting( |
| 336 site_url_, site_url_, type, ""); |
| 337 if (setting != CONTENT_SETTING_ASK) { |
| 338 permission_info.type = type; |
| 339 permission_info.setting = setting; |
| 340 permission_info_list->push_back(permission_info); |
| 341 } |
| 342 } |
| 343 } |
| 344 |
43 void WebsiteSettingsModel::Init(Profile* profile, | 345 void WebsiteSettingsModel::Init(Profile* profile, |
44 const GURL& url, | 346 const GURL& url, |
45 const content::SSLStatus& ssl) { | 347 const content::SSLStatus& ssl) { |
46 if (url.SchemeIs(chrome::kChromeUIScheme)) { | 348 if (url.SchemeIs(chrome::kChromeUIScheme)) { |
47 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE; | 349 site_identity_status_ = SITE_IDENTITY_STATUS_INTERNAL_PAGE; |
48 site_identity_details_ = | 350 site_identity_details_ = |
49 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE); | 351 l10n_util::GetStringUTF16(IDS_PAGE_INFO_INTERNAL_PAGE); |
50 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE; | 352 site_connection_status_ = SITE_CONNECTION_STATUS_INTERNAL_PAGE; |
51 return; | 353 return; |
52 } | 354 } |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 site_connection_details_ += l10n_util::GetStringUTF16( | 555 site_connection_details_ += l10n_util::GetStringUTF16( |
254 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE); | 556 IDS_PAGE_INFO_SECURITY_TAB_FALLBACK_MESSAGE); |
255 } | 557 } |
256 if (no_renegotiation) { | 558 if (no_renegotiation) { |
257 site_connection_details_ += ASCIIToUTF16("\n\n"); | 559 site_connection_details_ += ASCIIToUTF16("\n\n"); |
258 site_connection_details_ += l10n_util::GetStringUTF16( | 560 site_connection_details_ += l10n_util::GetStringUTF16( |
259 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE); | 561 IDS_PAGE_INFO_SECURITY_TAB_RENEGOTIATION_MESSAGE); |
260 } | 562 } |
261 } | 563 } |
262 } | 564 } |
OLD | NEW |