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