| Index: chrome/browser/cookies_tree_model.cc
|
| ===================================================================
|
| --- chrome/browser/cookies_tree_model.cc (revision 40156)
|
| +++ chrome/browser/cookies_tree_model.cc (working copy)
|
| @@ -76,12 +76,12 @@
|
| // 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 @@
|
| // 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 @@
|
| } // 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 @@
|
| // 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 @@
|
| 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<CookieTreeNode*>::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 @@
|
| : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_WEB_DATABASES)) {
|
| }
|
|
|
| -void CookieTreeDatabasesNode::AddDatabaseNode(
|
| - CookieTreeDatabaseNode* new_child) {
|
| - std::vector<CookieTreeNode*>::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,66 +265,39 @@
|
| : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_LOCAL_STORAGE)) {
|
| }
|
|
|
| -void CookieTreeLocalStoragesNode::AddLocalStorageNode(
|
| - CookieTreeLocalStorageNode* new_child) {
|
| - std::vector<CookieTreeNode*>::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
|
| +// CookieTreeNode, protected
|
|
|
| -bool CookieTreeCookieNode::CookieNodeComparator::operator() (
|
| +bool CookieTreeNode::NodeTitleComparator::operator() (
|
| const CookieTreeNode* lhs, const CookieTreeNode* rhs) {
|
| - const CookieTreeCookieNode* left =
|
| - static_cast<const CookieTreeCookieNode*>(lhs);
|
| - const CookieTreeCookieNode* right =
|
| - static_cast<const CookieTreeCookieNode*>(rhs);
|
| - return (left->cookie_->second.Name() < right->cookie_->second.Name());
|
| + const CookieTreeNode* left =
|
| + static_cast<const CookieTreeNode*>(lhs);
|
| + const CookieTreeNode* right =
|
| + static_cast<const CookieTreeNode*>(rhs);
|
| + return (left->GetTitleAsString16() < right->GetTitleAsString16());
|
| }
|
|
|
| -///////////////////////////////////////////////////////////////////////////////
|
| -// CookieTreeDatabaseNode, private
|
| -
|
| -bool CookieTreeDatabaseNode::CookieNodeComparator::operator() (
|
| - const CookieTreeNode* lhs, const CookieTreeNode* rhs) {
|
| - const CookieTreeDatabaseNode* left =
|
| - static_cast<const CookieTreeDatabaseNode*>(lhs);
|
| - const CookieTreeDatabaseNode* right =
|
| - static_cast<const CookieTreeDatabaseNode*>(rhs);
|
| - return (left->database_info_->database_name <
|
| - right->database_info_->database_name);
|
| +void CookieTreeNode::AddChildSortedByTitle(CookieTreeNode* new_child) {
|
| + std::vector<CookieTreeNode*>::iterator iter =
|
| + lower_bound(children().begin(),
|
| + children().end(),
|
| + new_child,
|
| + NodeTitleComparator());
|
| + GetModel()->Add(this, iter - children().begin(), new_child);
|
| }
|
|
|
| ///////////////////////////////////////////////////////////////////////////////
|
| -// CookieTreeLocalStorageNode, private
|
| -
|
| -bool CookieTreeLocalStorageNode::CookieNodeComparator::operator() (
|
| - const CookieTreeNode* lhs, const CookieTreeNode* rhs) {
|
| - const CookieTreeLocalStorageNode* left =
|
| - static_cast<const CookieTreeLocalStorageNode*>(lhs);
|
| - const CookieTreeLocalStorageNode* right =
|
| - static_cast<const CookieTreeLocalStorageNode*>(rhs);
|
| - return (left->local_storage_info_->origin <
|
| - right->local_storage_info_->origin);
|
| -}
|
| -
|
| -///////////////////////////////////////////////////////////////////////////////
|
| // CookiesTreeModel, public:
|
|
|
| CookiesTreeModel::CookiesTreeModel(
|
| Profile* profile,
|
| BrowsingDataDatabaseHelper* database_helper,
|
| - BrowsingDataLocalStorageHelper* local_storage_helper)
|
| + BrowsingDataLocalStorageHelper* local_storage_helper,
|
| + BrowsingDataAppCacheHelper* appcache_helper)
|
| : ALLOW_THIS_IN_INITIALIZER_LIST(TreeNodeModel<CookieTreeNode>(
|
| new CookieTreeRootNode(this))),
|
| profile_(profile),
|
| + appcache_helper_(appcache_helper),
|
| database_helper_(database_helper),
|
| local_storage_helper_(local_storage_helper) {
|
| LoadCookies();
|
| @@ -339,11 +307,20 @@
|
| 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,10 +354,11 @@
|
| 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,9 +417,35 @@
|
| 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<CookieTreeRootNode*>(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);
|
| +}
|
| +
|
| void CookiesTreeModel::OnDatabaseModelInfoLoaded(
|
| const DatabaseInfoList& database_info) {
|
| database_info_list_ = database_info;
|
| @@ -450,6 +454,8 @@
|
|
|
| void CookiesTreeModel::PopulateDatabaseInfoWithFilter(
|
| const std::wstring& filter) {
|
| + if (database_info_list_.empty())
|
| + return;
|
| CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
|
| for (DatabaseInfoList::iterator database_info = database_info_list_.begin();
|
| database_info != database_info_list_.end();
|
| @@ -477,6 +483,8 @@
|
|
|
| void CookiesTreeModel::PopulateLocalStorageInfoWithFilter(
|
| const std::wstring& filter) {
|
| + if (local_storage_info_list_.empty())
|
| + return;
|
| CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot());
|
| for (LocalStorageInfoList::iterator local_storage_info =
|
| local_storage_info_list_.begin();
|
|
|