| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 |
| 11 #include "base/bind.h" |
| 11 #include "base/callback.h" | 12 #include "base/callback.h" |
| 12 #include "base/memory/linked_ptr.h" | 13 #include "base/memory/linked_ptr.h" |
| 13 #include "base/string_util.h" | 14 #include "base/string_util.h" |
| 14 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/content_settings/host_content_settings_map.h" | 16 #include "chrome/browser/content_settings/host_content_settings_map.h" |
| 16 #include "chrome/browser/extensions/extension_service.h" | 17 #include "chrome/browser/extensions/extension_service.h" |
| 17 #include "content/browser/in_process_webkit/webkit_context.h" | 18 #include "content/browser/in_process_webkit/webkit_context.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 20 #include "grit/ui_resources.h" | 21 #include "grit/ui_resources.h" |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 CookieTreeCookieNode::~CookieTreeCookieNode() {} | 56 CookieTreeCookieNode::~CookieTreeCookieNode() {} |
| 56 | 57 |
| 57 void CookieTreeCookieNode::DeleteStoredObjects() { | 58 void CookieTreeCookieNode::DeleteStoredObjects() { |
| 58 // notify CookieMonster that we should delete this cookie | 59 // notify CookieMonster that we should delete this cookie |
| 59 // We have stored a copy of all the cookies in the model, and our model is | 60 // We have stored a copy of all the cookies in the model, and our model is |
| 60 // never re-calculated. Thus, we just need to delete the nodes from our | 61 // never re-calculated. Thus, we just need to delete the nodes from our |
| 61 // model, and tell CookieMonster to delete the cookies. We can keep the | 62 // model, and tell CookieMonster to delete the cookies. We can keep the |
| 62 // vector storing the cookies in-tact and not delete from there (that would | 63 // vector storing the cookies in-tact and not delete from there (that would |
| 63 // invalidate our pointers), and the fact that it contains semi out-of-date | 64 // invalidate our pointers), and the fact that it contains semi out-of-date |
| 64 // data is not problematic as we don't re-build the model based on that. | 65 // data is not problematic as we don't re-build the model based on that. |
| 65 GetModel()->cookie_monster_->DeleteCanonicalCookie(*cookie_); | 66 GetModel()->cookie_helper_->DeleteCookie(*cookie_); |
| 66 } | 67 } |
| 67 | 68 |
| 68 CookieTreeNode::DetailedInfo CookieTreeCookieNode::GetDetailedInfo() const { | 69 CookieTreeNode::DetailedInfo CookieTreeCookieNode::GetDetailedInfo() const { |
| 69 return DetailedInfo(parent()->parent()->GetTitle(), | 70 return DetailedInfo(parent()->parent()->GetTitle(), |
| 70 DetailedInfo::TYPE_COOKIE, | 71 DetailedInfo::TYPE_COOKIE, |
| 71 cookie_, NULL, NULL, NULL, NULL, NULL, NULL); | 72 cookie_, NULL, NULL, NULL, NULL, NULL, NULL); |
| 72 } | 73 } |
| 73 | 74 |
| 74 namespace { | 75 namespace { |
| 75 // comparison functor, for use in CookieTreeRootNode | 76 // comparison functor, for use in CookieTreeRootNode |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 children().end(), | 545 children().end(), |
| 545 new_child, | 546 new_child, |
| 546 NodeTitleComparator()); | 547 NodeTitleComparator()); |
| 547 GetModel()->Add(this, new_child, iter - children().begin()); | 548 GetModel()->Add(this, new_child, iter - children().begin()); |
| 548 } | 549 } |
| 549 | 550 |
| 550 /////////////////////////////////////////////////////////////////////////////// | 551 /////////////////////////////////////////////////////////////////////////////// |
| 551 // CookiesTreeModel, public: | 552 // CookiesTreeModel, public: |
| 552 | 553 |
| 553 CookiesTreeModel::CookiesTreeModel( | 554 CookiesTreeModel::CookiesTreeModel( |
| 554 net::CookieMonster* cookie_monster, | 555 BrowsingDataCookieHelper* cookie_helper, |
| 555 BrowsingDataDatabaseHelper* database_helper, | 556 BrowsingDataDatabaseHelper* database_helper, |
| 556 BrowsingDataLocalStorageHelper* local_storage_helper, | 557 BrowsingDataLocalStorageHelper* local_storage_helper, |
| 557 BrowsingDataLocalStorageHelper* session_storage_helper, | 558 BrowsingDataLocalStorageHelper* session_storage_helper, |
| 558 BrowsingDataAppCacheHelper* appcache_helper, | 559 BrowsingDataAppCacheHelper* appcache_helper, |
| 559 BrowsingDataIndexedDBHelper* indexed_db_helper, | 560 BrowsingDataIndexedDBHelper* indexed_db_helper, |
| 560 BrowsingDataFileSystemHelper* file_system_helper, | 561 BrowsingDataFileSystemHelper* file_system_helper, |
| 561 bool use_cookie_source) | 562 bool use_cookie_source) |
| 562 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::TreeNodeModel<CookieTreeNode>( | 563 : ALLOW_THIS_IN_INITIALIZER_LIST(ui::TreeNodeModel<CookieTreeNode>( |
| 563 new CookieTreeRootNode(this))), | 564 new CookieTreeRootNode(this))), |
| 564 cookie_monster_(cookie_monster), | |
| 565 appcache_helper_(appcache_helper), | 565 appcache_helper_(appcache_helper), |
| 566 cookie_helper_(cookie_helper), |
| 566 database_helper_(database_helper), | 567 database_helper_(database_helper), |
| 567 local_storage_helper_(local_storage_helper), | 568 local_storage_helper_(local_storage_helper), |
| 568 session_storage_helper_(session_storage_helper), | 569 session_storage_helper_(session_storage_helper), |
| 569 indexed_db_helper_(indexed_db_helper), | 570 indexed_db_helper_(indexed_db_helper), |
| 570 file_system_helper_(file_system_helper), | 571 file_system_helper_(file_system_helper), |
| 571 batch_update_(0), | 572 batch_update_(0), |
| 572 use_cookie_source_(use_cookie_source) { | 573 use_cookie_source_(use_cookie_source) { |
| 573 LoadCookies(); | 574 DCHECK(cookie_helper_); |
| 575 cookie_helper_->StartFetching( |
| 576 base::Bind(&CookiesTreeModel::OnCookiesModelInfoLoaded, |
| 577 base::Unretained(this))); |
| 574 DCHECK(database_helper_); | 578 DCHECK(database_helper_); |
| 575 database_helper_->StartFetching(NewCallback( | 579 database_helper_->StartFetching(NewCallback( |
| 576 this, &CookiesTreeModel::OnDatabaseModelInfoLoaded)); | 580 this, &CookiesTreeModel::OnDatabaseModelInfoLoaded)); |
| 577 DCHECK(local_storage_helper_); | 581 DCHECK(local_storage_helper_); |
| 578 local_storage_helper_->StartFetching(NewCallback( | 582 local_storage_helper_->StartFetching(NewCallback( |
| 579 this, &CookiesTreeModel::OnLocalStorageModelInfoLoaded)); | 583 this, &CookiesTreeModel::OnLocalStorageModelInfoLoaded)); |
| 580 if (session_storage_helper_) { | 584 if (session_storage_helper_) { |
| 581 session_storage_helper_->StartFetching(NewCallback( | 585 session_storage_helper_->StartFetching(NewCallback( |
| 582 this, &CookiesTreeModel::OnSessionStorageModelInfoLoaded)); | 586 this, &CookiesTreeModel::OnSessionStorageModelInfoLoaded)); |
| 583 } | 587 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 594 this, &CookiesTreeModel::OnIndexedDBModelInfoLoaded)); | 598 this, &CookiesTreeModel::OnIndexedDBModelInfoLoaded)); |
| 595 } | 599 } |
| 596 | 600 |
| 597 if (file_system_helper_) { | 601 if (file_system_helper_) { |
| 598 file_system_helper_->StartFetching(NewCallback( | 602 file_system_helper_->StartFetching(NewCallback( |
| 599 this, &CookiesTreeModel::OnFileSystemModelInfoLoaded)); | 603 this, &CookiesTreeModel::OnFileSystemModelInfoLoaded)); |
| 600 } | 604 } |
| 601 } | 605 } |
| 602 | 606 |
| 603 CookiesTreeModel::~CookiesTreeModel() { | 607 CookiesTreeModel::~CookiesTreeModel() { |
| 608 cookie_helper_->CancelNotification(); |
| 604 database_helper_->CancelNotification(); | 609 database_helper_->CancelNotification(); |
| 605 local_storage_helper_->CancelNotification(); | 610 local_storage_helper_->CancelNotification(); |
| 606 if (session_storage_helper_) | 611 if (session_storage_helper_) |
| 607 session_storage_helper_->CancelNotification(); | 612 session_storage_helper_->CancelNotification(); |
| 608 if (appcache_helper_) | 613 if (appcache_helper_) |
| 609 appcache_helper_->CancelNotification(); | 614 appcache_helper_->CancelNotification(); |
| 610 if (indexed_db_helper_) | 615 if (indexed_db_helper_) |
| 611 indexed_db_helper_->CancelNotification(); | 616 indexed_db_helper_->CancelNotification(); |
| 612 if (file_system_helper_) | 617 if (file_system_helper_) |
| 613 file_system_helper_->CancelNotification(); | 618 file_system_helper_->CancelNotification(); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 649 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: | 654 case CookieTreeNode::DetailedInfo::TYPE_INDEXED_DB: |
| 650 return DATABASE; // ditto | 655 return DATABASE; // ditto |
| 651 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: | 656 case CookieTreeNode::DetailedInfo::TYPE_FILE_SYSTEM: |
| 652 return DATABASE; // ditto | 657 return DATABASE; // ditto |
| 653 default: | 658 default: |
| 654 break; | 659 break; |
| 655 } | 660 } |
| 656 return -1; | 661 return -1; |
| 657 } | 662 } |
| 658 | 663 |
| 659 void CookiesTreeModel::LoadCookies() { | |
| 660 LoadCookiesWithFilter(std::wstring()); | |
| 661 } | |
| 662 | |
| 663 void CookiesTreeModel::LoadCookiesWithFilter(const std::wstring& filter) { | |
| 664 // mmargh mmargh mmargh! delicious! | |
| 665 | |
| 666 all_cookies_ = cookie_monster_->GetAllCookies(); | |
| 667 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); | |
| 668 for (CookieList::iterator it = all_cookies_.begin(); | |
| 669 it != all_cookies_.end(); ++it) { | |
| 670 std::string source_string = it->Source(); | |
| 671 if (source_string.empty() || !use_cookie_source_) { | |
| 672 std::string domain = it->Domain(); | |
| 673 if (domain.length() > 1 && domain[0] == '.') | |
| 674 domain = domain.substr(1); | |
| 675 | |
| 676 // We treat secure cookies just the same as normal ones. | |
| 677 source_string = std::string(chrome::kHttpScheme) + | |
| 678 chrome::kStandardSchemeSeparator + domain + "/"; | |
| 679 } | |
| 680 | |
| 681 GURL source(source_string); | |
| 682 if (!filter.size() || | |
| 683 (CookieTreeOriginNode::TitleForUrl(source).find(filter) != | |
| 684 std::string::npos)) { | |
| 685 CookieTreeOriginNode* origin_node = | |
| 686 root->GetOrCreateOriginNode(source); | |
| 687 CookieTreeCookiesNode* cookies_node = | |
| 688 origin_node->GetOrCreateCookiesNode(); | |
| 689 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it); | |
| 690 cookies_node->AddCookieNode(new_cookie); | |
| 691 } | |
| 692 } | |
| 693 } | |
| 694 | |
| 695 void CookiesTreeModel::DeleteAllStoredObjects() { | 664 void CookiesTreeModel::DeleteAllStoredObjects() { |
| 696 NotifyObserverBeginBatch(); | 665 NotifyObserverBeginBatch(); |
| 697 CookieTreeNode* root = GetRoot(); | 666 CookieTreeNode* root = GetRoot(); |
| 698 root->DeleteStoredObjects(); | 667 root->DeleteStoredObjects(); |
| 699 int num_children = root->child_count(); | 668 int num_children = root->child_count(); |
| 700 for (int i = num_children - 1; i >= 0; --i) | 669 for (int i = num_children - 1; i >= 0; --i) |
| 701 delete Remove(root, root->GetChild(i)); | 670 delete Remove(root, root->GetChild(i)); |
| 702 NotifyObserverTreeNodeChanged(root); | 671 NotifyObserverTreeNodeChanged(root); |
| 703 NotifyObserverEndBatch(); | 672 NotifyObserverEndBatch(); |
| 704 } | 673 } |
| 705 | 674 |
| 706 void CookiesTreeModel::DeleteCookieNode(CookieTreeNode* cookie_node) { | 675 void CookiesTreeModel::DeleteCookieNode(CookieTreeNode* cookie_node) { |
| 707 if (cookie_node == GetRoot()) | 676 if (cookie_node == GetRoot()) |
| 708 return; | 677 return; |
| 709 cookie_node->DeleteStoredObjects(); | 678 cookie_node->DeleteStoredObjects(); |
| 710 CookieTreeNode* parent_node = cookie_node->parent(); | 679 CookieTreeNode* parent_node = cookie_node->parent(); |
| 711 delete Remove(parent_node, cookie_node); | 680 delete Remove(parent_node, cookie_node); |
| 712 if (parent_node->empty()) | 681 if (parent_node->empty()) |
| 713 DeleteCookieNode(parent_node); | 682 DeleteCookieNode(parent_node); |
| 714 } | 683 } |
| 715 | 684 |
| 716 void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) { | 685 void CookiesTreeModel::UpdateSearchResults(const std::wstring& filter) { |
| 717 CookieTreeNode* root = GetRoot(); | 686 CookieTreeNode* root = GetRoot(); |
| 718 int num_children = root->child_count(); | 687 int num_children = root->child_count(); |
| 719 NotifyObserverBeginBatch(); | 688 NotifyObserverBeginBatch(); |
| 720 for (int i = num_children - 1; i >= 0; --i) | 689 for (int i = num_children - 1; i >= 0; --i) |
| 721 delete Remove(root, root->GetChild(i)); | 690 delete Remove(root, root->GetChild(i)); |
| 722 LoadCookiesWithFilter(filter); | 691 PopulateCookieInfoWithFilter(filter); |
| 723 PopulateDatabaseInfoWithFilter(filter); | 692 PopulateDatabaseInfoWithFilter(filter); |
| 724 PopulateLocalStorageInfoWithFilter(filter); | 693 PopulateLocalStorageInfoWithFilter(filter); |
| 725 PopulateSessionStorageInfoWithFilter(filter); | 694 PopulateSessionStorageInfoWithFilter(filter); |
| 726 PopulateAppCacheInfoWithFilter(filter); | 695 PopulateAppCacheInfoWithFilter(filter); |
| 727 PopulateIndexedDBInfoWithFilter(filter); | 696 PopulateIndexedDBInfoWithFilter(filter); |
| 728 PopulateFileSystemInfoWithFilter(filter); | 697 PopulateFileSystemInfoWithFilter(filter); |
| 729 NotifyObserverTreeNodeChanged(root); | 698 NotifyObserverTreeNodeChanged(root); |
| 730 NotifyObserverEndBatch(); | 699 NotifyObserverEndBatch(); |
| 731 } | 700 } |
| 732 | 701 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 info != origin->second.end(); ++info) { | 742 info != origin->second.end(); ++info) { |
| 774 appcaches_node->AddAppCacheNode( | 743 appcaches_node->AddAppCacheNode( |
| 775 new CookieTreeAppCacheNode(&(*info))); | 744 new CookieTreeAppCacheNode(&(*info))); |
| 776 } | 745 } |
| 777 } | 746 } |
| 778 } | 747 } |
| 779 NotifyObserverTreeNodeChanged(root); | 748 NotifyObserverTreeNodeChanged(root); |
| 780 NotifyObserverEndBatch(); | 749 NotifyObserverEndBatch(); |
| 781 } | 750 } |
| 782 | 751 |
| 752 void CookiesTreeModel::OnCookiesModelInfoLoaded( |
| 753 const CookieList& cookie_list) { |
| 754 cookie_list_ = cookie_list; |
| 755 PopulateCookieInfoWithFilter(std::wstring()); |
| 756 } |
| 757 |
| 758 void CookiesTreeModel::PopulateCookieInfoWithFilter( |
| 759 const std::wstring& filter) { |
| 760 // mmargh mmargh mmargh! delicious! |
| 761 |
| 762 CookieTreeRootNode* root = static_cast<CookieTreeRootNode*>(GetRoot()); |
| 763 for (CookieList::iterator it = cookie_list_.begin(); |
| 764 it != cookie_list_.end(); ++it) { |
| 765 std::string source_string = it->Source(); |
| 766 if (source_string.empty() || !use_cookie_source_) { |
| 767 std::string domain = it->Domain(); |
| 768 if (domain.length() > 1 && domain[0] == '.') |
| 769 domain = domain.substr(1); |
| 770 |
| 771 // We treat secure cookies just the same as normal ones. |
| 772 source_string = std::string(chrome::kHttpScheme) + |
| 773 chrome::kStandardSchemeSeparator + domain + "/"; |
| 774 } |
| 775 |
| 776 GURL source(source_string); |
| 777 if (!filter.size() || |
| 778 (CookieTreeOriginNode::TitleForUrl(source).find(filter) != |
| 779 std::string::npos)) { |
| 780 CookieTreeOriginNode* origin_node = |
| 781 root->GetOrCreateOriginNode(source); |
| 782 CookieTreeCookiesNode* cookies_node = |
| 783 origin_node->GetOrCreateCookiesNode(); |
| 784 CookieTreeCookieNode* new_cookie = new CookieTreeCookieNode(&*it); |
| 785 cookies_node->AddCookieNode(new_cookie); |
| 786 } |
| 787 } |
| 788 } |
| 789 |
| 783 void CookiesTreeModel::OnDatabaseModelInfoLoaded( | 790 void CookiesTreeModel::OnDatabaseModelInfoLoaded( |
| 784 const DatabaseInfoList& database_info) { | 791 const DatabaseInfoList& database_info) { |
| 785 database_info_list_ = database_info; | 792 database_info_list_ = database_info; |
| 786 PopulateDatabaseInfoWithFilter(std::wstring()); | 793 PopulateDatabaseInfoWithFilter(std::wstring()); |
| 787 } | 794 } |
| 788 | 795 |
| 789 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( | 796 void CookiesTreeModel::PopulateDatabaseInfoWithFilter( |
| 790 const std::wstring& filter) { | 797 const std::wstring& filter) { |
| 791 if (database_info_list_.empty()) | 798 if (database_info_list_.empty()) |
| 792 return; | 799 return; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 | 962 |
| 956 void CookiesTreeModel::NotifyObserverEndBatch() { | 963 void CookiesTreeModel::NotifyObserverEndBatch() { |
| 957 // Only notify the observers if this is the outermost call to EndBatch() if | 964 // Only notify the observers if this is the outermost call to EndBatch() if |
| 958 // called in a nested manner. | 965 // called in a nested manner. |
| 959 if (--batch_update_ == 0) { | 966 if (--batch_update_ == 0) { |
| 960 FOR_EACH_OBSERVER(Observer, | 967 FOR_EACH_OBSERVER(Observer, |
| 961 cookies_observer_list_, | 968 cookies_observer_list_, |
| 962 TreeModelEndBatch(this)); | 969 TreeModelEndBatch(this)); |
| 963 } | 970 } |
| 964 } | 971 } |
| OLD | NEW |