| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/cookies_tree_model.h" | 5 #include "chrome/browser/cookies_tree_model.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 122 } |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 } // namespace | 125 } // namespace |
| 126 | 126 |
| 127 /////////////////////////////////////////////////////////////////////////////// | 127 /////////////////////////////////////////////////////////////////////////////// |
| 128 // CookieTreeDatabaseNode, public: | 128 // CookieTreeDatabaseNode, public: |
| 129 | 129 |
| 130 CookieTreeDatabaseNode::CookieTreeDatabaseNode( | 130 CookieTreeDatabaseNode::CookieTreeDatabaseNode( |
| 131 BrowsingDataDatabaseHelper::DatabaseInfo* database_info) | 131 BrowsingDataDatabaseHelper::DatabaseInfo* database_info) |
| 132 : CookieTreeNode(UTF8ToWide(database_info->database_name)), | 132 : CookieTreeNode(UTF8ToWide(database_info->database_name.empty() ? |
| 133 database_info->origin_identifier : |
| 134 database_info->database_name)), |
| 133 database_info_(database_info) { | 135 database_info_(database_info) { |
| 134 } | 136 } |
| 135 | 137 |
| 136 void CookieTreeDatabaseNode::DeleteStoredObjects() { | 138 void CookieTreeDatabaseNode::DeleteStoredObjects() { |
| 137 GetModel()->database_helper_->DeleteDatabase( | 139 GetModel()->database_helper_->DeleteDatabase( |
| 138 database_info_->origin_identifier, database_info_->database_name); | 140 database_info_->origin_identifier, database_info_->database_name); |
| 139 } | 141 } |
| 140 | 142 |
| 141 /////////////////////////////////////////////////////////////////////////////// | 143 /////////////////////////////////////////////////////////////////////////////// |
| 142 // CookieTreeLocalStorageNode, public: | 144 // CookieTreeLocalStorageNode, public: |
| 143 | 145 |
| 144 CookieTreeLocalStorageNode::CookieTreeLocalStorageNode( | 146 CookieTreeLocalStorageNode::CookieTreeLocalStorageNode( |
| 145 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info) | 147 BrowsingDataLocalStorageHelper::LocalStorageInfo* local_storage_info) |
| 146 : CookieTreeNode(UTF8ToWide(local_storage_info->origin)), | 148 : CookieTreeNode(UTF8ToWide( |
| 149 local_storage_info->origin.empty() ? |
| 150 local_storage_info->database_identifier : |
| 151 local_storage_info->origin)), |
| 147 local_storage_info_(local_storage_info) { | 152 local_storage_info_(local_storage_info) { |
| 148 } | 153 } |
| 149 | 154 |
| 150 void CookieTreeLocalStorageNode::DeleteStoredObjects() { | 155 void CookieTreeLocalStorageNode::DeleteStoredObjects() { |
| 151 GetModel()->local_storage_helper_->DeleteLocalStorageFile( | 156 GetModel()->local_storage_helper_->DeleteLocalStorageFile( |
| 152 local_storage_info_->file_path); | 157 local_storage_info_->file_path); |
| 153 } | 158 } |
| 154 | 159 |
| 155 /////////////////////////////////////////////////////////////////////////////// | 160 /////////////////////////////////////////////////////////////////////////////// |
| 156 // CookieTreeRootNode, public: | 161 // CookieTreeRootNode, public: |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 211 } |
| 207 | 212 |
| 208 CookieTreeLocalStoragesNode* | 213 CookieTreeLocalStoragesNode* |
| 209 CookieTreeOriginNode::GetOrCreateLocalStoragesNode() { | 214 CookieTreeOriginNode::GetOrCreateLocalStoragesNode() { |
| 210 if (local_storages_child_) | 215 if (local_storages_child_) |
| 211 return local_storages_child_; | 216 return local_storages_child_; |
| 212 // Need to make a LocalStorages node, add it to the tree, and return it. | 217 // Need to make a LocalStorages node, add it to the tree, and return it. |
| 213 CookieTreeLocalStoragesNode* retval = new CookieTreeLocalStoragesNode; | 218 CookieTreeLocalStoragesNode* retval = new CookieTreeLocalStoragesNode; |
| 214 int index = 0; | 219 int index = 0; |
| 215 if (cookies_child_) | 220 if (cookies_child_) |
| 216 index++; | 221 ++index; |
| 217 if (databases_child_) | 222 if (databases_child_) |
| 218 index++; | 223 ++index; |
| 219 GetModel()->Add(this, index, retval); | 224 GetModel()->Add(this, index, retval); |
| 220 local_storages_child_ = retval; | 225 local_storages_child_ = retval; |
| 221 return retval; | 226 return retval; |
| 222 } | 227 } |
| 223 | 228 |
| 224 /////////////////////////////////////////////////////////////////////////////// | 229 /////////////////////////////////////////////////////////////////////////////// |
| 225 // CookieTreeCookiesNode, public: | 230 // CookieTreeCookiesNode, public: |
| 226 | 231 |
| 227 CookieTreeCookiesNode::CookieTreeCookiesNode() | 232 CookieTreeCookiesNode::CookieTreeCookiesNode() |
| 228 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_COOKIES)) {} | 233 : CookieTreeNode(l10n_util::GetString(IDS_COOKIES_COOKIES)) {} |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 database_info_list_ = database_info; | 440 database_info_list_ = database_info; |
| 436 PopulateDatabaseInfoWithFilter(std::wstring()); | 441 PopulateDatabaseInfoWithFilter(std::wstring()); |
| 437 } | 442 } |
| 438 | 443 |
| 439 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( | 444 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( |
| 440 const std::wstring& filter) { | 445 const std::wstring& filter) { |
| 441 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 446 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 442 for (DatabaseInfoList::iterator database_info = database_info_list_.begin(); | 447 for (DatabaseInfoList::iterator database_info = database_info_list_.begin(); |
| 443 database_info != database_info_list_.end(); | 448 database_info != database_info_list_.end(); |
| 444 ++database_info) { | 449 ++database_info) { |
| 445 std::string origin = database_info->host; | 450 std::string origin = database_info->host.empty() ? |
| 451 database_info->origin_identifier : database_info->host; |
| 446 if (!filter.size() || | 452 if (!filter.size() || |
| 447 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) { | 453 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) { |
| 448 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode( | 454 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode( |
| 449 UTF8ToWide(database_info->host)); | 455 UTF8ToWide(database_info->host)); |
| 450 CookieTreeDatabasesNode* databases_node = | 456 CookieTreeDatabasesNode* databases_node = |
| 451 origin_node->GetOrCreateDatabasesNode(); | 457 origin_node->GetOrCreateDatabasesNode(); |
| 452 databases_node->AddDatabaseNode( | 458 databases_node->AddDatabaseNode( |
| 453 new CookieTreeDatabaseNode(&(*database_info))); | 459 new CookieTreeDatabaseNode(&(*database_info))); |
| 454 } | 460 } |
| 455 } | 461 } |
| 456 NotifyObserverTreeNodeChanged(root); | 462 NotifyObserverTreeNodeChanged(root); |
| 457 } | 463 } |
| 458 | 464 |
| 459 void CookiesTreeModel::OnStorageModelInfoLoaded( | 465 void CookiesTreeModel::OnStorageModelInfoLoaded( |
| 460 const LocalStorageInfoList& local_storage_info) { | 466 const LocalStorageInfoList& local_storage_info) { |
| 461 local_storage_info_list_ = local_storage_info; | 467 local_storage_info_list_ = local_storage_info; |
| 462 PopulateLocalStorageInfoWithFilter(std::wstring()); | 468 PopulateLocalStorageInfoWithFilter(std::wstring()); |
| 463 } | 469 } |
| 464 | 470 |
| 465 void CookiesTreeModel::PopulateLocalStorageInfoWithFilter( | 471 void CookiesTreeModel::PopulateLocalStorageInfoWithFilter( |
| 466 const std::wstring& filter) { | 472 const std::wstring& filter) { |
| 467 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | 473 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 468 for (LocalStorageInfoList::iterator local_storage_info = | 474 for (LocalStorageInfoList::iterator local_storage_info = |
| 469 local_storage_info_list_.begin(); | 475 local_storage_info_list_.begin(); |
| 470 local_storage_info != local_storage_info_list_.end(); | 476 local_storage_info != local_storage_info_list_.end(); |
| 471 ++local_storage_info) { | 477 ++local_storage_info) { |
| 472 std::string origin = local_storage_info->host; | 478 std::string origin = local_storage_info->host.empty() ? |
| 479 local_storage_info->database_identifier : local_storage_info->host; |
| 473 if (!filter.size() || | 480 if (!filter.size() || |
| 474 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) { | 481 (UTF8ToWide(origin).find(filter) != std::wstring::npos)) { |
| 475 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode( | 482 CookieTreeOriginNode* origin_node = root->GetOrCreateOriginNode( |
| 476 UTF8ToWide(local_storage_info->host)); | 483 UTF8ToWide(local_storage_info->host)); |
| 477 CookieTreeLocalStoragesNode* local_storages_node = | 484 CookieTreeLocalStoragesNode* local_storages_node = |
| 478 origin_node->GetOrCreateLocalStoragesNode(); | 485 origin_node->GetOrCreateLocalStoragesNode(); |
| 479 local_storages_node->AddLocalStorageNode( | 486 local_storages_node->AddLocalStorageNode( |
| 480 new CookieTreeLocalStorageNode(&(*local_storage_info))); | 487 new CookieTreeLocalStorageNode(&(*local_storage_info))); |
| 481 } | 488 } |
| 482 } | 489 } |
| 483 NotifyObserverTreeNodeChanged(root); | 490 NotifyObserverTreeNodeChanged(root); |
| 484 } | 491 } |
| OLD | NEW |