From f26795ebb86f6bcd4da9d4971e252eea933cfdf3 Mon Sep 17 00:00:00 2001 From: "michaeln@chromium.org" Date: Fri, 26 Feb 2010 23:45:35 +0000 Subject: Teach the cookie tree view and model about appcaches. Not hooked up to real data yet, but the view and model pieces are in place for windows and gtk (not yet done for the mac). Also adds a 'name' attribute to database details pane, cleans up the layout of the detail panes on windows. BUG=25977 TEST=manual Review URL: http://codereview.chromium.org/650110 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40181 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/cookies_tree_model.cc | 204 ++++++++++++++++++----------------- 1 file changed, 106 insertions(+), 98 deletions(-) (limited to 'chrome/browser/cookies_tree_model.cc') diff --git a/chrome/browser/cookies_tree_model.cc b/chrome/browser/cookies_tree_model.cc index 99cc0ad..c911b00 100644 --- a/chrome/browser/cookies_tree_model.cc +++ b/chrome/browser/cookies_tree_model.cc @@ -76,12 +76,12 @@ class OriginNodeComparator { // google.com, ad.google.com, www.google.com, // microsoft.com, ad.microsoft.com. CanonicalizeHost transforms the origins // into a form like google.com.www so that string comparisons work. - return (CanonicalizeHost(lhs->GetTitle()) < - CanonicalizeHost(rhs->GetTitle())); + return (CanonicalizeHost(lhs->GetTitleAsString16()) < + CanonicalizeHost(rhs->GetTitleAsString16())); } private: - static std::string CanonicalizeHost(const std::wstring& host_w) { + static std::string CanonicalizeHost(const string16& host16) { // The canonicalized representation makes the registry controlled domain // come first, and then adds subdomains in reverse order, e.g. // 1.mail.google.com would become google.com.mail.1, and then a standard @@ -89,7 +89,7 @@ class OriginNodeComparator { // first. Leading dots are ignored, ".google.com" is the same as // "google.com". - std::string host = WideToUTF8(host_w); + std::string host = UTF16ToUTF8(host16); std::string retval = net::RegistryControlledDomainService:: GetDomainAndRegistry(host); if (!retval.length()) // Is an IP address or other special origin. @@ -126,13 +126,27 @@ class OriginNodeComparator { } // namespace /////////////////////////////////////////////////////////////////////////////// +// CookieTreeAppCacheNode, public: + +CookieTreeAppCacheNode::CookieTreeAppCacheNode( + const BrowsingDataAppCacheHelper::AppCacheInfo* appcache_info) + : CookieTreeNode(UTF8ToWide(appcache_info->manifest_url.spec())), + appcache_info_(appcache_info) { +} + +void CookieTreeAppCacheNode::DeleteStoredObjects() { + DCHECK(GetModel()->appcache_helper_); + GetModel()->appcache_helper_->DeleteAppCache(appcache_info_->group_id); +} + +/////////////////////////////////////////////////////////////////////////////// // CookieTreeDatabaseNode, public: CookieTreeDatabaseNode::CookieTreeDatabaseNode( BrowsingDataDatabaseHelper::DatabaseInfo* database_info) - : CookieTreeNode(UTF8ToWide(database_info->database_name.empty() ? - database_info->origin_identifier : - database_info->database_name)), + : CookieTreeNode(database_info->database_name.empty() ? + l10n_util::GetString(IDS_COOKIES_WEB_DATABASE_UNNAMED_NAME) : + UTF8ToWide(database_info->database_name)), database_info_(database_info) { } @@ -162,7 +176,7 @@ void CookieTreeLocalStorageNode::DeleteStoredObjects() { // CookieTreeRootNode, public: CookieTreeOriginNode* CookieTreeRootNode::GetOrCreateOriginNode( const std::wstring& origin) { - // Strip the trailing dot if it exists. + // Strip the leading dot if it exists. std::wstring rewritten_origin = origin; if (origin.length() >= 1 && origin[0] == '.') rewritten_origin = origin.substr(1); @@ -193,55 +207,48 @@ CookieTreeOriginNode* CookieTreeRootNode::GetOrCreateOriginNode( CookieTreeCookiesNode* CookieTreeOriginNode::GetOrCreateCookiesNode() { if (cookies_child_) return cookies_child_; - // need to make a Cookies node, add it to the tree, and return it - CookieTreeCookiesNode* retval = new CookieTreeCookiesNode; - GetModel()->Add(this, 0, retval); - cookies_child_ = retval; - return retval; + cookies_child_ = new CookieTreeCookiesNode; + AddChildSortedByTitle(cookies_child_); + return cookies_child_; } -CookieTreeDatabasesNode* - CookieTreeOriginNode::GetOrCreateDatabasesNode() { +CookieTreeDatabasesNode* CookieTreeOriginNode::GetOrCreateDatabasesNode() { if (databases_child_) return databases_child_; - // Need to make a Database node, add it to the tree, and return it. - CookieTreeDatabasesNode* retval = new CookieTreeDatabasesNode; - GetModel()->Add(this, cookies_child_ ? 1 : 0, retval); - databases_child_ = retval; - return retval; + databases_child_ = new CookieTreeDatabasesNode; + AddChildSortedByTitle(databases_child_); + return databases_child_; } CookieTreeLocalStoragesNode* CookieTreeOriginNode::GetOrCreateLocalStoragesNode() { if (local_storages_child_) return local_storages_child_; - // Need to make a LocalStorages node, add it to the tree, and return it. - CookieTreeLocalStoragesNode* retval = new CookieTreeLocalStoragesNode; - int index = 0; - if (cookies_child_) - ++index; - if (databases_child_) - ++index; - GetModel()->Add(this, index, retval); - local_storages_child_ = retval; - return retval; + local_storages_child_ = new CookieTreeLocalStoragesNode; + AddChildSortedByTitle(local_storages_child_); + return local_storages_child_; +} + +CookieTreeAppCachesNode* CookieTreeOriginNode::GetOrCreateAppCachesNode() { + if (appcaches_child_) + return appcaches_child_; + appcaches_child_ = new CookieTreeAppCachesNode; + AddChildSortedByTitle(appcaches_child_); + return appcaches_child_; } /////////////////////////////////////////////////////////////////////////////// // CookieTreeCookiesNode, public: CookieTreeCookiesNode::CookieTreeCookiesNode() - : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_COOKIES)) {} + : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_COOKIES)) { +} +/////////////////////////////////////////////////////////////////////////////// +// CookieTreeAppCachesNode, public: -void CookieTreeCookiesNode::AddCookieNode( - CookieTreeCookieNode* new_child) { - std::vector::iterator cookie_iterator = - lower_bound(children().begin(), - children().end(), - new_child, - CookieTreeCookieNode::CookieNodeComparator()); - GetModel()->Add(this, (cookie_iterator - children().begin()), new_child); +CookieTreeAppCachesNode::CookieTreeAppCachesNode() + : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_APPLICATION_CACHES)) { } /////////////////////////////////////////////////////////////////////////////// @@ -251,18 +258,6 @@ CookieTreeDatabasesNode::CookieTreeDatabasesNode() : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_WEB_DATABASES)) { } -void CookieTreeDatabasesNode::AddDatabaseNode( - CookieTreeDatabaseNode* new_child) { - std::vector::iterator database_iterator = - lower_bound(children().begin(), - children().end(), - new_child, - CookieTreeDatabaseNode::CookieNodeComparator()); - GetModel()->Add(this, - (database_iterator - children().begin()), - new_child); -} - /////////////////////////////////////////////////////////////////////////////// // CookieTreeLocalStoragesNode, public: @@ -270,54 +265,25 @@ CookieTreeLocalStoragesNode::CookieTreeLocalStoragesNode() : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE)) { } -void CookieTreeLocalStoragesNode::AddLocalStorageNode( - CookieTreeLocalStorageNode* new_child) { - std::vector::iterator local_storage_iterator = - lower_bound(children().begin(), - children().end(), - new_child, - CookieTreeLocalStorageNode::CookieNodeComparator()); - GetModel()->Add(this, - (local_storage_iterator - children().begin()), - new_child); -} - -/////////////////////////////////////////////////////////////////////////////// -// CookieTreeCookieNode, private - -bool CookieTreeCookieNode::CookieNodeComparator::operator() ( - const CookieTreeNode* lhs, const CookieTreeNode* rhs) { - const CookieTreeCookieNode* left = - static_cast(lhs); - const CookieTreeCookieNode* right = - static_cast(rhs); - return (left->cookie_->second.Name() < right->cookie_->second.Name()); -} - /////////////////////////////////////////////////////////////////////////////// -// CookieTreeDatabaseNode, private +// CookieTreeNode, protected -bool CookieTreeDatabaseNode::CookieNodeComparator::operator() ( +bool CookieTreeNode::NodeTitleComparator::operator() ( const CookieTreeNode* lhs, const CookieTreeNode* rhs) { - const CookieTreeDatabaseNode* left = - static_cast(lhs); - const CookieTreeDatabaseNode* right = - static_cast(rhs); - return (left->database_info_->database_name < - right->database_info_->database_name); + const CookieTreeNode* left = + static_cast(lhs); + const CookieTreeNode* right = + static_cast(rhs); + return (left->GetTitleAsString16() < right->GetTitleAsString16()); } -/////////////////////////////////////////////////////////////////////////////// -// CookieTreeLocalStorageNode, private - -bool CookieTreeLocalStorageNode::CookieNodeComparator::operator() ( - const CookieTreeNode* lhs, const CookieTreeNode* rhs) { - const CookieTreeLocalStorageNode* left = - static_cast(lhs); - const CookieTreeLocalStorageNode* right = - static_cast(rhs); - return (left->local_storage_info_->origin < - right->local_storage_info_->origin); +void CookieTreeNode::AddChildSortedByTitle(CookieTreeNode* new_child) { + std::vector::iterator iter = + lower_bound(children().begin(), + children().end(), + new_child, + NodeTitleComparator()); + GetModel()->Add(this, iter - children().begin(), new_child); } /////////////////////////////////////////////////////////////////////////////// @@ -326,10 +292,12 @@ bool CookieTreeLocalStorageNode::CookieNodeComparator::operator() ( CookiesTreeModel::CookiesTreeModel( Profile* profile, BrowsingDataDatabaseHelper* database_helper, - BrowsingDataLocalStorageHelper* local_storage_helper) + BrowsingDataLocalStorageHelper* local_storage_helper, + BrowsingDataAppCacheHelper* appcache_helper) : ALLOW_THIS_IN_INITIALIZER_LIST(TreeNodeModel( new CookieTreeRootNode(this))), profile_(profile), + appcache_helper_(appcache_helper), database_helper_(database_helper), local_storage_helper_(local_storage_helper) { LoadCookies(); @@ -339,11 +307,20 @@ CookiesTreeModel::CookiesTreeModel( DCHECK(local_storage_helper_); local_storage_helper_->StartFetching(NewCallback( this, &CookiesTreeModel::OnStorageModelInfoLoaded)); + + // TODO(michaeln): when all of the ui impls have been updated, + // make this a required parameter. + if (appcache_helper_) { + appcache_helper_->StartFetching(NewCallback( + this, &CookiesTreeModel::OnAppCacheModelInfoLoaded)); + } } CookiesTreeModel::~CookiesTreeModel() { database_helper_->CancelNotification(); local_storage_helper_->CancelNotification(); + if (appcache_helper_) + appcache_helper_->CancelNotification(); } /////////////////////////////////////////////////////////////////////////////// @@ -377,9 +354,10 @@ int CookiesTreeModel::GetIconIndex(TreeModelNode* node) { return DATABASE; break; case CookieTreeNode::DetailedInfo::TYPE_LOCAL_STORAGE: - // The differences between local storage and HTML5 databases are semantic - // enough that the user will not likely care if they share an icon. - return DATABASE; + return DATABASE; // close enough + break; + case CookieTreeNode::DetailedInfo::TYPE_APPCACHE: + return DATABASE; // ditto break; default: return -1; @@ -439,6 +417,32 @@ void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) { LoadCookiesWithFilter(filter); PopulateDatabaseInfoWithFilter(filter); PopulateLocalStorageInfoWithFilter(filter); + PopulateAppCacheInfoWithFilter(filter); + NotifyObserverTreeNodeChanged(root); +} + +void CookiesTreeModel::OnAppCacheModelInfoLoaded() { + PopulateAppCacheInfoWithFilter(std::wstring()); +} + +void CookiesTreeModel::PopulateAppCacheInfoWithFilter( + const std::wstring& filter) { + if (!appcache_helper_ || appcache_helper_->info_list().empty()) + return; + CookieTreeRootNode* root = static_cast(GetRoot()); + for (AppCacheInfoList::const_iterator info = + appcache_helper_->info_list().begin(); + info != appcache_helper_->info_list().end(); ++info) { + std::wstring host = UTF8ToWide(info->manifest_url.host()); + if (filter.empty() || (host.find(filter) != std::wstring::npos)) { + CookieTreeOriginNode* host_node = + root->GetOrCreateOriginNode(host); + CookieTreeAppCachesNode* appcaches_node = + host_node->GetOrCreateAppCachesNode(); + appcaches_node->AddAppCacheNode( + new CookieTreeAppCacheNode(&(*info))); + } + } NotifyObserverTreeNodeChanged(root); } @@ -450,6 +454,8 @@ void CookiesTreeModel::OnDatabaseModelInfoLoaded( void CookiesTreeModel::PopulateDatabaseInfoWithFilter( const std::wstring& filter) { + if (database_info_list_.empty()) + return; CookieTreeRootNode* root = static_cast(GetRoot()); for (DatabaseInfoList::iterator database_info = database_info_list_.begin(); database_info != database_info_list_.end(); @@ -477,6 +483,8 @@ void CookiesTreeModel::OnStorageModelInfoLoaded( void CookiesTreeModel::PopulateLocalStorageInfoWithFilter( const std::wstring& filter) { + if (local_storage_info_list_.empty()) + return; CookieTreeRootNode* root = static_cast(GetRoot()); for (LocalStorageInfoList::iterator local_storage_info = local_storage_info_list_.begin(); -- cgit v1.1