| Index: chrome/browser/website_settings_model.cc
|
| diff --git a/chrome/browser/website_settings_model.cc b/chrome/browser/website_settings_model.cc
|
| index 2c2abfefad6095417039a678de02c2dc19f58ba0..36d890cdb5746a65627f3d5860a08fc2115f856d 100644
|
| --- a/chrome/browser/website_settings_model.cc
|
| +++ b/chrome/browser/website_settings_model.cc
|
| @@ -9,6 +9,9 @@
|
|
|
| #include "base/string_number_conversions.h"
|
| #include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/content_settings/host_content_settings_map.h"
|
| +#include "chrome/browser/content_settings/local_shared_objects_container.h"
|
| +#include "chrome/browser/content_settings/tab_specific_content_settings.h"
|
| #include "chrome/browser/profiles/profile.h"
|
| #include "chrome/browser/ssl/ssl_error_info.h"
|
| #include "content/public/browser/cert_store.h"
|
| @@ -23,14 +26,271 @@
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/base/resource/resource_bundle.h"
|
|
|
| -WebsiteSettingsModel::WebsiteSettingsModel(Profile* profile,
|
| +// ---
|
| +#include "base/bind.h"
|
| +#include "base/bind_helpers.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +#include "net/base/registry_controlled_domain.h"
|
| +
|
| +using content::BrowserThread;
|
| +
|
| +namespace {
|
| +
|
| +ContentSettingsType kPermissionType[] = {
|
| + CONTENT_SETTINGS_TYPE_POPUPS,
|
| + CONTENT_SETTINGS_TYPE_PLUGINS,
|
| + CONTENT_SETTINGS_TYPE_NOTIFICATIONS,
|
| + CONTENT_SETTINGS_TYPE_GEOLOCATION,
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +class SiteData {
|
| + public:
|
| + SiteData(WebsiteSettingsModel* website_settings,
|
| + GURL page_url,
|
| + const LocalSharedObjectsContainer& local_shared_data,
|
| + const LocalSharedObjectsContainer& blocked_local_shared_data);
|
| +
|
| + int GetAllowedLocalSharedObjectsCount() const;
|
| + int GetBlockedLocalSharedObjectsCount() const;
|
| + int GetThirdPartyCookiesCount() const;
|
| + int GetBlockedThirdPartyCookiesCount() const;
|
| +
|
| + int GetThirdPartyDomainCount() const;
|
| +
|
| + private:
|
| + typedef std::list<net::CookieMonster::CanonicalCookie> CookieList;
|
| + typedef std::list<BrowsingDataDatabaseHelper::DatabaseInfo>
|
| + DatabaseInfoList;
|
| + typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>
|
| + LocalStorageInfoList;
|
| + typedef std::list<BrowsingDataLocalStorageHelper::LocalStorageInfo>
|
| + SessionStorageInfoList;
|
| + typedef std::list<BrowsingDataIndexedDBHelper::IndexedDBInfo>
|
| + IndexedDBInfoList;
|
| + typedef std::list<BrowsingDataFileSystemHelper::FileSystemInfo>
|
| + FileSystemInfoList;
|
| +
|
| + // Callbacks for asynchrounous local data fetching
|
| + void OnAllowedCookiesLoaded(const net::CookieList& cookie_list);
|
| + void OnBlockedCookiesLoaded(const net::CookieList& cookie_list);
|
| + void OnAllowedDatabaseInfoLoaded(const DatabaseInfoList& database_info);
|
| + void OnBlockedDatabaseInfoLoaded(const DatabaseInfoList& database_info);
|
| +
|
| + void NotifyListener() const;
|
| +
|
| + WebsiteSettingsModel* website_settings_;
|
| +
|
| + GURL page_url_;
|
| +
|
| + net::CookieList allowed_cookies_list_;
|
| + net::CookieList blocked_cookies_list_;
|
| + net::CookieList allowed_third_party_cookies_;
|
| + net::CookieList blocked_third_party_cookies_;
|
| +
|
| + DatabaseInfoList allowed_database_info_list_;
|
| + DatabaseInfoList blocked_database_info_list_;
|
| +
|
| + int pending_callbacks_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(SiteData);
|
| +};
|
| +
|
| +SiteData::SiteData(
|
| + WebsiteSettingsModel* website_settings,
|
| + GURL page_url,
|
| + const LocalSharedObjectsContainer& allowed_local_shared_objects,
|
| + const LocalSharedObjectsContainer& blocked_local_shared_objects)
|
| + : website_settings_(website_settings),
|
| + page_url_(page_url),
|
| + pending_callbacks_(0) {
|
| +
|
| + // 4 async calls will be made.
|
| + pending_callbacks_ = 4;
|
| +
|
| + // Fetch cookies.
|
| + DCHECK(allowed_local_shared_objects.cookies());
|
| + allowed_local_shared_objects.cookies()->StartFetching(
|
| + base::Bind(&SiteData::OnAllowedCookiesLoaded,
|
| + base::Unretained(this)));
|
| + DCHECK(blocked_local_shared_objects.cookies());
|
| + blocked_local_shared_objects.cookies()->StartFetching(
|
| + base::Bind(&SiteData::OnBlockedCookiesLoaded,
|
| + base::Unretained(this)));
|
| +
|
| + // Fetch database infos.
|
| + DCHECK(allowed_local_shared_objects.databases());
|
| + allowed_local_shared_objects.databases()->StartFetching(
|
| + base::Bind(&SiteData::OnAllowedDatabaseInfoLoaded,
|
| + base::Unretained(this)));
|
| + DCHECK(allowed_local_shared_objects.databases());
|
| + blocked_local_shared_objects.databases()->StartFetching(
|
| + base::Bind(&SiteData::OnBlockedDatabaseInfoLoaded,
|
| + base::Unretained(this)));
|
| +/*
|
| + // Local Storage
|
| + DCHECK(allowed_local_shared_objects.local_storage_helper_);
|
| + local_storage_helper_->StartFetching(
|
| + base::Bind(&SiteData::OnLocalStorageModelInfoLoaded,
|
| + base::Unretained(this)));
|
| + if (session_storage_helper_) {
|
| + session_storage_helper_->StartFetching(
|
| + base::Bind(&SiteData::OnSessionStorageModelInfoLoaded,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| + // TODO(michaeln): When all of the UI implementations have been updated, make
|
| + // this a required parameter.
|
| + if (appcache_helper_) {
|
| + appcache_helper_->StartFetching(
|
| + base::Bind(&CookiesTreeModel::OnAppCacheModelInfoLoaded,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| + if (indexed_db_helper_) {
|
| + indexed_db_helper_->StartFetching(
|
| + base::Bind(&CookiesTreeModel::OnIndexedDBModelInfoLoaded,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| + if (file_system_helper_) {
|
| + file_system_helper_->StartFetching(
|
| + base::Bind(&CookiesTreeModel::OnFileSystemModelInfoLoaded,
|
| + base::Unretained(this)));
|
| + }
|
| +
|
| + if (quota_helper_) {
|
| + quota_helper_->StartFetching(
|
| + base::Bind(&CookiesTreeModel::OnQuotaModelInfoLoaded,
|
| + base::Unretained(this)));
|
| + */
|
| +}
|
| +
|
| +int SiteData::GetAllowedLocalSharedObjectsCount() const {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + return allowed_cookies_list_.size() +
|
| + allowed_database_info_list_.size();
|
| +}
|
| +
|
| +int SiteData::GetBlockedLocalSharedObjectsCount() const {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + return blocked_cookies_list_.size() +
|
| + blocked_database_info_list_.size();
|
| +}
|
| +
|
| +int SiteData::GetThirdPartyCookiesCount() const {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + return allowed_third_party_cookies_.size();
|
| +}
|
| +
|
| +int SiteData::GetBlockedThirdPartyCookiesCount() const {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + return blocked_third_party_cookies_.size();
|
| +}
|
| +
|
| +void SiteData::NotifyListener() const {
|
| + if (pending_callbacks_ == 0)
|
| + website_settings_->OnLocalSharedObjectsUpdated();
|
| +}
|
| +
|
| +void SiteData::OnAllowedDatabaseInfoLoaded(
|
| + const DatabaseInfoList& database_info) {
|
| + allowed_database_info_list_ = database_info;
|
| + pending_callbacks_--;
|
| + NotifyListener();
|
| +}
|
| +
|
| +void SiteData::OnBlockedDatabaseInfoLoaded(
|
| + const DatabaseInfoList& database_info) {
|
| + blocked_database_info_list_ = database_info;
|
| + pending_callbacks_--;
|
| + NotifyListener();
|
| +}
|
| +
|
| +void SiteData::OnAllowedCookiesLoaded(const net::CookieList& cookie_list) {
|
| + for (net::CookieList::const_iterator cookie = cookie_list.begin();
|
| + cookie != cookie_list.end();
|
| + ++cookie) {
|
| + // Strip leading dot.
|
| + std::string domain = cookie->Domain();
|
| + if (domain.length() > 1 && domain[0] == '.')
|
| + domain = domain.substr(1);
|
| + // Test if the cookie is a first party cookie.
|
| + bool first_party_cookie =
|
| + net::RegistryControlledDomainService::SameDomainOrHost(
|
| + page_url_, GURL(std::string(chrome::kHttpScheme) +
|
| + chrome::kStandardSchemeSeparator + domain));
|
| + if (first_party_cookie)
|
| + allowed_cookies_list_.push_back(*cookie);
|
| + else
|
| + allowed_third_party_cookies_.push_back(*cookie);
|
| + }
|
| + pending_callbacks_--;
|
| + NotifyListener();
|
| +}
|
| +
|
| +int SiteData::GetThirdPartyDomainCount() const {
|
| + std::set<std::string> domain_set;
|
| + for (net::CookieList::const_iterator cookie = allowed_third_party_cookies_.begin();
|
| + cookie != allowed_third_party_cookies_.end();
|
| + ++cookie) {
|
| + domain_set.insert(cookie->Domain());
|
| + LOG(ERROR) << " *** " << cookie->Domain();
|
| + }
|
| + for (net::CookieList::const_iterator cookie = blocked_third_party_cookies_.begin();
|
| + cookie != blocked_third_party_cookies_.end();
|
| + ++cookie) {
|
| + domain_set.insert(cookie->Domain());
|
| + LOG(ERROR) << " *** " << cookie->Domain();
|
| + }
|
| + return domain_set.size();
|
| +}
|
| +
|
| +void SiteData::OnBlockedCookiesLoaded(const net::CookieList& cookie_list) {
|
| + for (net::CookieList::const_iterator cookie = cookie_list.begin();
|
| + cookie != cookie_list.end();
|
| + ++cookie) {
|
| + // Strip leading dot.
|
| + std::string domain = cookie->Domain();
|
| + if (domain.length() > 1 && domain[0] == '.')
|
| + domain = domain.substr(1);
|
| + // Test if the cookie is a first party cookie.
|
| + bool first_party_cookie =
|
| + net::RegistryControlledDomainService::SameDomainOrHost(
|
| + page_url_, GURL(std::string(chrome::kHttpScheme) +
|
| + chrome::kStandardSchemeSeparator + domain));
|
| + if (first_party_cookie)
|
| + blocked_cookies_list_.push_back(*cookie);
|
| + else
|
| + blocked_third_party_cookies_.push_back(*cookie);
|
| + }
|
| + pending_callbacks_--;
|
| + NotifyListener();
|
| +}
|
| +
|
| +//
|
| +//
|
| +//
|
| +WebsiteSettingsModel::WebsiteSettingsModel(WebsiteSettingsUI* ui,
|
| + Profile* profile,
|
| const GURL& url,
|
| const content::SSLStatus& ssl,
|
| - content::CertStore* cert_store)
|
| - : site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
|
| + content::CertStore* cert_store,
|
| + TabSpecificContentSettings* content_settings)
|
| + : ui_(ui),
|
| + site_url_(url),
|
| + site_identity_status_(SITE_IDENTITY_STATUS_UNKNOWN),
|
| site_connection_status_(SITE_CONNECTION_STATUS_UNKNOWN),
|
| - cert_store_(cert_store) {
|
| + cert_store_(cert_store),
|
| + content_settings_(profile->GetHostContentSettingsMap()) {
|
| Init(profile, url, ssl);
|
| + site_data_.reset(new SiteData(
|
| + this,
|
| + url,
|
| + content_settings->allowed_local_shared_objects(),
|
| + content_settings->blocked_local_shared_objects()));
|
| +
|
| // After initialization the status about the site's connection
|
| // and it's identity must be available.
|
| DCHECK_NE(site_identity_status_, SITE_IDENTITY_STATUS_UNKNOWN);
|
| @@ -40,6 +300,48 @@ WebsiteSettingsModel::WebsiteSettingsModel(Profile* profile,
|
| WebsiteSettingsModel::~WebsiteSettingsModel() {
|
| }
|
|
|
| +void WebsiteSettingsModel::OnLocalSharedObjectsUpdated() {
|
| + ui_->Update();
|
| +}
|
| +
|
| +void WebsiteSettingsModel::GetCookieInfos(CookieInfoList* cookie_info_list) {
|
| + cookie_info_list->clear();
|
| +
|
| + WebsiteSettingsUI::CookieInfo info;
|
| + info.text =
|
| + net::RegistryControlledDomainService::GetDomainAndRegistry(site_url_);
|
| + info.allowed = site_data_->GetAllowedLocalSharedObjectsCount();
|
| + info.blocked = site_data_->GetBlockedLocalSharedObjectsCount();
|
| + cookie_info_list->push_back(info);
|
| +
|
| + int domain_count = site_data_->GetThirdPartyDomainCount();
|
| + info.text = domain_count ? base::IntToString(domain_count) + " " : "";
|
| + if (domain_count == 1)
|
| + info.text += "Other site";
|
| + else
|
| + info.text += "Other sites";
|
| + info.allowed = site_data_->GetThirdPartyCookiesCount();
|
| + info.blocked = site_data_->GetBlockedThirdPartyCookiesCount();
|
| + cookie_info_list->push_back(info);
|
| +}
|
| +
|
| +void WebsiteSettingsModel::GetPermissionInfos(
|
| + PermissionInfoList* permission_info_list) {
|
| + permission_info_list->clear();
|
| +
|
| + WebsiteSettingsUI::PermissionInfo permission_info;
|
| + for (size_t i=0; i<arraysize(kPermissionType); ++i) {
|
| + ContentSettingsType type = kPermissionType[i];
|
| + ContentSetting setting = content_settings_->GetContentSetting(
|
| + site_url_, site_url_, type, "");
|
| + if (setting != CONTENT_SETTING_ASK) {
|
| + permission_info.type = type;
|
| + permission_info.setting = setting;
|
| + permission_info_list->push_back(permission_info);
|
| + }
|
| + }
|
| +}
|
| +
|
| void WebsiteSettingsModel::Init(Profile* profile,
|
| const GURL& url,
|
| const content::SSLStatus& ssl) {
|
|
|