OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ui/views/passwords/manage_passwords_bubble_view.h" | 5 #include "chrome/browser/ui/views/passwords/manage_passwords_bubble_view.h" |
6 | 6 |
7 #include "base/timer/timer.h" | 7 #include "base/timer/timer.h" |
8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/browser_finder.h" | 10 #include "chrome/browser/ui/browser_finder.h" |
(...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 SetLayoutManager(layout); | 625 SetLayoutManager(layout); |
626 | 626 |
627 // Add the title. | 627 // Add the title. |
628 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | 628 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
629 AddTitleRow(layout, parent_->model()); | 629 AddTitleRow(layout, parent_->model()); |
630 | 630 |
631 // If we have a list of passwords to store for the current site, display | 631 // If we have a list of passwords to store for the current site, display |
632 // them to the user for management. Otherwise, render a "No passwords for | 632 // them to the user for management. Otherwise, render a "No passwords for |
633 // this site" message. | 633 // this site" message. |
634 if (!parent_->model()->best_matches().empty()) { | 634 if (!parent_->model()->best_matches().empty()) { |
635 std::vector<const autofill::PasswordForm*> password_forms; | 635 std::vector<const autofill::PasswordForm*> password_forms; |
636 for (auto password_form : parent_->model()->best_matches()) { | 636 for (auto password_form : parent_->model()->best_matches()) { |
637 password_forms.push_back(password_form.second); | 637 password_forms.push_back(password_form.second); |
638 } | 638 } |
639 ManagePasswordItemsView* item = new ManagePasswordItemsView( | 639 ManagePasswordItemsView* item = new ManagePasswordItemsView( |
640 parent_->model(), password_forms); | 640 parent_->model(), password_forms); |
641 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 641 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
642 layout->AddView(item); | 642 layout->AddView(item); |
643 } else { | 643 } else { |
644 views::Label* empty_label = new views::Label( | 644 views::Label* empty_label = new views::Label( |
645 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); | 645 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); |
646 empty_label->SetMultiLine(true); | 646 empty_label->SetMultiLine(true); |
647 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 647 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
648 empty_label->SetFontList( | 648 empty_label->SetFontList( |
649 ui::ResourceBundle::GetSharedInstance().GetFontList( | 649 ui::ResourceBundle::GetSharedInstance().GetFontList( |
650 ui::ResourceBundle::SmallFont)); | 650 ui::ResourceBundle::SmallFont)); |
651 | 651 |
652 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 652 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 int event_flags) { | 695 int event_flags) { |
696 DCHECK_EQ(source, manage_link_); | 696 DCHECK_EQ(source, manage_link_); |
697 parent_->model()->OnManageLinkClicked(); | 697 parent_->model()->OnManageLinkClicked(); |
698 parent_->Close(); | 698 parent_->Close(); |
699 } | 699 } |
700 | 700 |
701 // ManagePasswordsBubbleView::ManageAccountsView ------------------------------ | 701 // ManagePasswordsBubbleView::ManageAccountsView ------------------------------ |
702 | 702 |
703 // A view offering the user a list of his currently saved through the Credential | 703 // A view offering the user a list of his currently saved through the Credential |
704 // Manager API accounts for the current page. | 704 // Manager API accounts for the current page. |
705 class ManagePasswordsBubbleView::ManageAccountsView : public views::View { | 705 class ManagePasswordsBubbleView::ManageAccountsView |
706 : public views::View, | |
707 public views::ButtonListener, | |
708 public views::LinkListener { | |
706 public: | 709 public: |
707 explicit ManageAccountsView(ManagePasswordsBubbleView* parent); | 710 explicit ManageAccountsView(ManagePasswordsBubbleView* parent); |
708 | 711 |
709 private: | 712 private: |
710 ManagePasswordsBubbleView* parent_; | 713 // views::ButtonListener: |
714 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
715 | |
716 // views::LinkListener: | |
717 void LinkClicked(views::Link* source, int event_flags) override; | |
718 | |
719 ManagePasswordsBubbleView* parent_; | |
720 | |
721 views::Link* manage_link_; | |
722 views::LabelButton* done_button_; | |
711 }; | 723 }; |
712 | 724 |
713 ManagePasswordsBubbleView::ManageAccountsView::ManageAccountsView( | 725 ManagePasswordsBubbleView::ManageAccountsView::ManageAccountsView( |
714 ManagePasswordsBubbleView* parent) | 726 ManagePasswordsBubbleView* parent) |
715 : parent_(parent) { | 727 : parent_(parent) { |
716 views::GridLayout* layout = new views::GridLayout(this); | 728 views::GridLayout* layout = new views::GridLayout(this); |
717 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 729 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
718 SetLayoutManager(layout); | 730 SetLayoutManager(layout); |
719 | 731 |
720 // Add the title. | 732 // Add the title. |
721 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | 733 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
722 AddTitleRow(layout, parent_->model()); | 734 AddTitleRow(layout, parent_->model()); |
723 | 735 |
724 for (const autofill::PasswordForm* form : | 736 if (!parent_->model()->local_pending_credentials().empty()) { |
725 parent_->model()->local_pending_credentials()) { | 737 for (const autofill::PasswordForm* form : |
726 // Add the title to the layout with appropriate padding. | 738 parent_->model()->local_pending_credentials()) { |
739 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | |
740 layout->AddView(new ManageCredentialItemView(parent_->model(), form)); | |
741 } | |
742 } else { | |
743 views::Label* empty_label = new views::Label( | |
744 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS), | |
Mike West
2015/02/25 11:40:26
Will you be folding blacklisting in here as well i
vasilii
2015/02/25 11:46:46
No, the "Blacklisted" bubble stays separate.
| |
745 ui::ResourceBundle::GetSharedInstance().GetFontList( | |
746 ui::ResourceBundle::SmallFont)); | |
747 empty_label->SetMultiLine(true); | |
748 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
749 | |
727 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 750 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
728 layout->AddView(new ManageCredentialItemView(parent_->model(), form)); | 751 layout->AddView(empty_label); |
752 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | |
729 } | 753 } |
730 | 754 |
755 // Then add the "manage passwords" link and "Done" button. | |
756 manage_link_ = new views::Link(parent_->model()->manage_link()); | |
757 manage_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
758 manage_link_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
759 ui::ResourceBundle::SmallFont)); | |
760 manage_link_->SetUnderline(false); | |
761 manage_link_->set_listener(this); | |
762 | |
763 done_button_ = | |
764 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE)); | |
765 done_button_->SetStyle(views::Button::STYLE_BUTTON); | |
766 done_button_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | |
767 ui::ResourceBundle::SmallFont)); | |
768 | |
769 BuildColumnSet(layout, LINK_BUTTON_COLUMN_SET); | |
770 layout->StartRowWithPadding( | |
771 0, LINK_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); | |
772 layout->AddView(manage_link_); | |
773 layout->AddView(done_button_); | |
774 | |
731 // Extra padding for visual awesomeness. | 775 // Extra padding for visual awesomeness. |
732 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 776 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
777 | |
778 parent_->set_initially_focused_view(done_button_); | |
779 } | |
780 | |
781 void ManagePasswordsBubbleView::ManageAccountsView::ButtonPressed( | |
782 views::Button* sender, const ui::Event& event) { | |
783 DCHECK(sender == done_button_); | |
784 parent_->model()->OnDoneClicked(); | |
785 parent_->Close(); | |
786 } | |
787 | |
788 void ManagePasswordsBubbleView::ManageAccountsView::LinkClicked( | |
789 views::Link* source, int event_flags) { | |
790 DCHECK_EQ(source, manage_link_); | |
791 parent_->model()->OnManageLinkClicked(); | |
792 parent_->Close(); | |
733 } | 793 } |
734 | 794 |
735 // ManagePasswordsBubbleView::BlacklistedView --------------------------------- | 795 // ManagePasswordsBubbleView::BlacklistedView --------------------------------- |
736 | 796 |
737 // A view offering the user the ability to re-enable the password manager for | 797 // A view offering the user the ability to re-enable the password manager for |
738 // a specific site after she's decided to "never save passwords". | 798 // a specific site after she's decided to "never save passwords". |
739 class ManagePasswordsBubbleView::BlacklistedView | 799 class ManagePasswordsBubbleView::BlacklistedView |
740 : public views::View, | 800 : public views::View, |
741 public views::ButtonListener { | 801 public views::ButtonListener { |
742 public: | 802 public: |
(...skipping 18 matching lines...) Expand all Loading... | |
761 SetLayoutManager(layout); | 821 SetLayoutManager(layout); |
762 | 822 |
763 // Add the title. | 823 // Add the title. |
764 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | 824 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
765 AddTitleRow(layout, parent_->model()); | 825 AddTitleRow(layout, parent_->model()); |
766 | 826 |
767 // Add the "Hey! You blacklisted this site!" text. | 827 // Add the "Hey! You blacklisted this site!" text. |
768 views::Label* blacklisted = new views::Label( | 828 views::Label* blacklisted = new views::Label( |
769 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED)); | 829 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED)); |
770 blacklisted->SetMultiLine(true); | 830 blacklisted->SetMultiLine(true); |
831 blacklisted->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
771 blacklisted->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 832 blacklisted->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
772 ui::ResourceBundle::SmallFont)); | 833 ui::ResourceBundle::SmallFont)); |
773 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 834 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
774 layout->AddView(blacklisted); | 835 layout->AddView(blacklisted); |
775 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); | 836 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing); |
776 | 837 |
777 // Then add the "enable password manager" and "Done" buttons. | 838 // Then add the "enable password manager" and "Done" buttons. |
778 unblacklist_button_ = new views::BlueButton( | 839 unblacklist_button_ = new views::BlueButton( |
779 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_UNBLACKLIST_BUTTON)); | 840 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_UNBLACKLIST_BUTTON)); |
780 unblacklist_button_->SetFontList( | 841 unblacklist_button_->SetFontList( |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1010 anchor_view_(anchor_view), | 1071 anchor_view_(anchor_view), |
1011 initially_focused_view_(NULL) { | 1072 initially_focused_view_(NULL) { |
1012 // Compensate for built-in vertical padding in the anchor view's image. | 1073 // Compensate for built-in vertical padding in the anchor view's image. |
1013 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); | 1074 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); |
1014 if (anchor_view) | 1075 if (anchor_view) |
1015 anchor_view->SetActive(true); | 1076 anchor_view->SetActive(true); |
1016 mouse_handler_.reset(new WebContentMouseHandler(this)); | 1077 mouse_handler_.reset(new WebContentMouseHandler(this)); |
1017 } | 1078 } |
1018 | 1079 |
1019 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { | 1080 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { |
1020 if (anchor_view_) | 1081 if (manage_passwords_bubble_ == this) |
1021 anchor_view_->SetActive(false); | 1082 manage_passwords_bubble_ = NULL; |
1022 } | 1083 } |
1023 | 1084 |
1024 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { | 1085 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { |
1025 return initially_focused_view_; | 1086 return initially_focused_view_; |
1026 } | 1087 } |
1027 | 1088 |
1028 void ManagePasswordsBubbleView::Init() { | 1089 void ManagePasswordsBubbleView::Init() { |
1029 views::FillLayout* layout = new views::FillLayout(); | 1090 views::FillLayout* layout = new views::FillLayout(); |
1030 SetLayoutManager(layout); | 1091 SetLayoutManager(layout); |
1031 | 1092 |
1032 Refresh(); | 1093 Refresh(); |
1033 } | 1094 } |
1034 | 1095 |
1035 void ManagePasswordsBubbleView::WindowClosing() { | |
1036 // Close() closes the window asynchronously, so by the time we reach here, | |
1037 // |manage_passwords_bubble_| may have already been reset. | |
1038 if (manage_passwords_bubble_ == this) | |
1039 manage_passwords_bubble_ = NULL; | |
1040 } | |
1041 | |
1042 void ManagePasswordsBubbleView::Close() { | 1096 void ManagePasswordsBubbleView::Close() { |
1043 mouse_handler_.reset(); | 1097 mouse_handler_.reset(); |
1044 ManagedFullScreenBubbleDelegateView::Close(); | 1098 ManagedFullScreenBubbleDelegateView::Close(); |
1045 } | 1099 } |
1046 | 1100 |
1101 void ManagePasswordsBubbleView::OnWidgetClosing(views::Widget* /*widget*/) { | |
1102 if (anchor_view_) | |
1103 anchor_view_->SetActive(false); | |
1104 } | |
1105 | |
1047 void ManagePasswordsBubbleView::Refresh() { | 1106 void ManagePasswordsBubbleView::Refresh() { |
1048 RemoveAllChildViews(true); | 1107 RemoveAllChildViews(true); |
1049 initially_focused_view_ = NULL; | 1108 initially_focused_view_ = NULL; |
1050 if (model()->state() == password_manager::ui::PENDING_PASSWORD_STATE) { | 1109 if (model()->state() == password_manager::ui::PENDING_PASSWORD_STATE) { |
1051 if (model()->never_save_passwords()) | 1110 if (model()->never_save_passwords()) |
1052 AddChildView(new ConfirmNeverView(this)); | 1111 AddChildView(new ConfirmNeverView(this)); |
1053 else | 1112 else |
1054 AddChildView(new PendingView(this)); | 1113 AddChildView(new PendingView(this)); |
1055 } else if (IsAskSubmitURLState(model()->state())) { | 1114 } else if (IsAskSubmitURLState(model()->state())) { |
1056 AddChildView(new AskUserToSubmitURLView(this)); | 1115 AddChildView(new AskUserToSubmitURLView(this)); |
(...skipping 24 matching lines...) Expand all Loading... | |
1081 | 1140 |
1082 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { | 1141 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { |
1083 if (model()->best_matches().empty()) { | 1142 if (model()->best_matches().empty()) { |
1084 // Skip confirmation if there are no existing passwords for this site. | 1143 // Skip confirmation if there are no existing passwords for this site. |
1085 NotifyConfirmedNeverForThisSite(); | 1144 NotifyConfirmedNeverForThisSite(); |
1086 } else { | 1145 } else { |
1087 model()->OnConfirmationForNeverForThisSite(); | 1146 model()->OnConfirmationForNeverForThisSite(); |
1088 Refresh(); | 1147 Refresh(); |
1089 } | 1148 } |
1090 } | 1149 } |
OLD | NEW |