Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Side by Side Diff: chrome/browser/ui/views/passwords/manage_passwords_bubble_view.cc

Issue 952023002: Credential Manager API: pop up the new "Manage accounts" bubble. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 ManagePasswordsBubbleView* parent) 293 ManagePasswordsBubbleView* parent)
294 : parent_(parent) { 294 : parent_(parent) {
295 SetLayoutManager(new views::FillLayout); 295 SetLayoutManager(new views::FillLayout);
296 CredentialsItemView* credential = new CredentialsItemView( 296 CredentialsItemView* credential = new CredentialsItemView(
297 this, 297 this,
298 &parent_->model()->pending_password(), 298 &parent_->model()->pending_password(),
299 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL, 299 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL,
300 CredentialsItemView::AUTO_SIGNIN, 300 CredentialsItemView::AUTO_SIGNIN,
301 parent_->model()->GetProfile()->GetRequestContext()); 301 parent_->model()->GetProfile()->GetRequestContext());
302 AddChildView(credential); 302 AddChildView(credential);
303 // TODO(vasilii): enable the button to switch to the "Managed" state.
304 credential->SetEnabled(false);
305 parent_->set_initially_focused_view(credential); 303 parent_->set_initially_focused_view(credential);
306 304
307 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kAutoSigninToastTimeout), 305 timer_.Start(FROM_HERE, base::TimeDelta::FromSeconds(kAutoSigninToastTimeout),
308 this, &AutoSigninView::OnTimer); 306 this, &AutoSigninView::OnTimer);
309 } 307 }
310 308
311 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed( 309 void ManagePasswordsBubbleView::AutoSigninView::ButtonPressed(
312 views::Button* sender, const ui::Event& event) { 310 views::Button* sender, const ui::Event& event) {
313 // TODO(vasilii): close the toast and switch to the "Managed" state. 311 parent_->model()->OnAutoSignInClicked();
312 parent_->Close();
314 } 313 }
315 314
316 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() { 315 void ManagePasswordsBubbleView::AutoSigninView::OnTimer() {
317 parent_->model()->OnAutoSignInToastTimeout(); 316 parent_->model()->OnAutoSignInToastTimeout();
318 parent_->Close(); 317 parent_->Close();
319 } 318 }
320 319
321 // ManagePasswordsBubbleView::AskUserToSubmitURLView ------------------------- 320 // ManagePasswordsBubbleView::AskUserToSubmitURLView -------------------------
322 321
323 // Asks users if they want to report the URL when the password manager failed 322 // Asks users if they want to report the URL when the password manager failed
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
625 SetLayoutManager(layout); 624 SetLayoutManager(layout);
626 625
627 // Add the title. 626 // Add the title.
628 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); 627 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET);
629 AddTitleRow(layout, parent_->model()); 628 AddTitleRow(layout, parent_->model());
630 629
631 // If we have a list of passwords to store for the current site, display 630 // 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 631 // them to the user for management. Otherwise, render a "No passwords for
633 // this site" message. 632 // this site" message.
634 if (!parent_->model()->best_matches().empty()) { 633 if (!parent_->model()->best_matches().empty()) {
635 std::vector<const autofill::PasswordForm*> password_forms; 634 std::vector<const autofill::PasswordForm*> password_forms;
636 for (auto password_form : parent_->model()->best_matches()) { 635 for (auto password_form : parent_->model()->best_matches()) {
637 password_forms.push_back(password_form.second); 636 password_forms.push_back(password_form.second);
638 } 637 }
639 ManagePasswordItemsView* item = new ManagePasswordItemsView( 638 ManagePasswordItemsView* item = new ManagePasswordItemsView(
640 parent_->model(), password_forms); 639 parent_->model(), password_forms);
641 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); 640 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
642 layout->AddView(item); 641 layout->AddView(item);
643 } else { 642 } else {
644 views::Label* empty_label = new views::Label( 643 views::Label* empty_label = new views::Label(
645 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); 644 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS));
646 empty_label->SetMultiLine(true); 645 empty_label->SetMultiLine(true);
647 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 646 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
648 empty_label->SetFontList( 647 empty_label->SetFontList(
649 ui::ResourceBundle::GetSharedInstance().GetFontList( 648 ui::ResourceBundle::GetSharedInstance().GetFontList(
650 ui::ResourceBundle::SmallFont)); 649 ui::ResourceBundle::SmallFont));
651 650
652 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); 651 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 int event_flags) { 694 int event_flags) {
696 DCHECK_EQ(source, manage_link_); 695 DCHECK_EQ(source, manage_link_);
697 parent_->model()->OnManageLinkClicked(); 696 parent_->model()->OnManageLinkClicked();
698 parent_->Close(); 697 parent_->Close();
699 } 698 }
700 699
701 // ManagePasswordsBubbleView::ManageAccountsView ------------------------------ 700 // ManagePasswordsBubbleView::ManageAccountsView ------------------------------
702 701
703 // A view offering the user a list of his currently saved through the Credential 702 // A view offering the user a list of his currently saved through the Credential
704 // Manager API accounts for the current page. 703 // Manager API accounts for the current page.
705 class ManagePasswordsBubbleView::ManageAccountsView : public views::View { 704 class ManagePasswordsBubbleView::ManageAccountsView
705 : public views::View,
706 public views::ButtonListener {
706 public: 707 public:
707 explicit ManageAccountsView(ManagePasswordsBubbleView* parent); 708 explicit ManageAccountsView(ManagePasswordsBubbleView* parent);
708 709
709 private: 710 private:
710 ManagePasswordsBubbleView* parent_; 711 // views::ButtonListener:
712 void ButtonPressed(views::Button* sender, const ui::Event& event) override;
713
714 ManagePasswordsBubbleView* parent_;
715
716 views::LabelButton* done_button_;
711 }; 717 };
712 718
713 ManagePasswordsBubbleView::ManageAccountsView::ManageAccountsView( 719 ManagePasswordsBubbleView::ManageAccountsView::ManageAccountsView(
714 ManagePasswordsBubbleView* parent) 720 ManagePasswordsBubbleView* parent)
715 : parent_(parent) { 721 : parent_(parent) {
716 views::GridLayout* layout = new views::GridLayout(this); 722 views::GridLayout* layout = new views::GridLayout(this);
717 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); 723 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0));
718 SetLayoutManager(layout); 724 SetLayoutManager(layout);
719 725
720 // Add the title. 726 // Add the title.
721 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); 727 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET);
722 AddTitleRow(layout, parent_->model()); 728 AddTitleRow(layout, parent_->model());
723 729
724 for (const autofill::PasswordForm* form : 730 if (!parent_->model()->local_pending_credentials().empty()) {
725 parent_->model()->local_pending_credentials()) { 731 for (const autofill::PasswordForm* form :
726 // Add the title to the layout with appropriate padding. 732 parent_->model()->local_pending_credentials()) {
733 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
734 layout->AddView(new ManageCredentialItemView(parent_->model(), form));
735 }
736 } else {
737 views::Label* empty_label = new views::Label(
738 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS),
739 ui::ResourceBundle::GetSharedInstance().GetFontList(
740 ui::ResourceBundle::SmallFont));
741 empty_label->SetMultiLine(true);
742 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
743
727 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); 744 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET);
728 layout->AddView(new ManageCredentialItemView(parent_->model(), form)); 745 layout->AddView(empty_label);
746 layout->AddPaddingRow(0, views::kRelatedControlSmallVerticalSpacing);
729 } 747 }
730 748
749 done_button_ =
750 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_DONE));
751 done_button_->SetStyle(views::Button::STYLE_BUTTON);
752 done_button_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList(
753 ui::ResourceBundle::SmallFont));
754 BuildColumnSet(layout, SINGLE_BUTTON_COLUMN_SET);
755 layout->StartRowWithPadding(
756 0, SINGLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing);
757 layout->AddView(done_button_);
758
731 // Extra padding for visual awesomeness. 759 // Extra padding for visual awesomeness.
732 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); 760 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing);
761
762 parent_->set_initially_focused_view(done_button_);
763 }
764
765 void ManagePasswordsBubbleView::ManageAccountsView::ButtonPressed(
766 views::Button* sender, const ui::Event& event) {
767 DCHECK(sender == done_button_);
768 parent_->model()->OnDoneClicked();
769 parent_->Close();
733 } 770 }
734 771
735 // ManagePasswordsBubbleView::BlacklistedView --------------------------------- 772 // ManagePasswordsBubbleView::BlacklistedView ---------------------------------
736 773
737 // A view offering the user the ability to re-enable the password manager for 774 // 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". 775 // a specific site after she's decided to "never save passwords".
739 class ManagePasswordsBubbleView::BlacklistedView 776 class ManagePasswordsBubbleView::BlacklistedView
740 : public views::View, 777 : public views::View,
741 public views::ButtonListener { 778 public views::ButtonListener {
742 public: 779 public:
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1010 anchor_view_(anchor_view), 1047 anchor_view_(anchor_view),
1011 initially_focused_view_(NULL) { 1048 initially_focused_view_(NULL) {
1012 // Compensate for built-in vertical padding in the anchor view's image. 1049 // Compensate for built-in vertical padding in the anchor view's image.
1013 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0)); 1050 set_anchor_view_insets(gfx::Insets(5, 0, 5, 0));
1014 if (anchor_view) 1051 if (anchor_view)
1015 anchor_view->SetActive(true); 1052 anchor_view->SetActive(true);
1016 mouse_handler_.reset(new WebContentMouseHandler(this)); 1053 mouse_handler_.reset(new WebContentMouseHandler(this));
1017 } 1054 }
1018 1055
1019 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() { 1056 ManagePasswordsBubbleView::~ManagePasswordsBubbleView() {
1020 if (anchor_view_) 1057 if (manage_passwords_bubble_ == this)
1021 anchor_view_->SetActive(false); 1058 manage_passwords_bubble_ = NULL;
1022 } 1059 }
1023 1060
1024 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() { 1061 views::View* ManagePasswordsBubbleView::GetInitiallyFocusedView() {
1025 return initially_focused_view_; 1062 return initially_focused_view_;
1026 } 1063 }
1027 1064
1028 void ManagePasswordsBubbleView::Init() { 1065 void ManagePasswordsBubbleView::Init() {
1029 views::FillLayout* layout = new views::FillLayout(); 1066 views::FillLayout* layout = new views::FillLayout();
1030 SetLayoutManager(layout); 1067 SetLayoutManager(layout);
1031 1068
1032 Refresh(); 1069 Refresh();
1033 } 1070 }
1034 1071
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() { 1072 void ManagePasswordsBubbleView::Close() {
1043 mouse_handler_.reset(); 1073 mouse_handler_.reset();
1044 ManagedFullScreenBubbleDelegateView::Close(); 1074 ManagedFullScreenBubbleDelegateView::Close();
1045 } 1075 }
1046 1076
1077 void ManagePasswordsBubbleView::OnWidgetClosing(views::Widget* /*widget*/) {
1078 if (anchor_view_)
1079 anchor_view_->SetActive(false);
1080 }
1081
1047 void ManagePasswordsBubbleView::Refresh() { 1082 void ManagePasswordsBubbleView::Refresh() {
1048 RemoveAllChildViews(true); 1083 RemoveAllChildViews(true);
1049 initially_focused_view_ = NULL; 1084 initially_focused_view_ = NULL;
1050 if (model()->state() == password_manager::ui::PENDING_PASSWORD_STATE) { 1085 if (model()->state() == password_manager::ui::PENDING_PASSWORD_STATE) {
1051 if (model()->never_save_passwords()) 1086 if (model()->never_save_passwords())
1052 AddChildView(new ConfirmNeverView(this)); 1087 AddChildView(new ConfirmNeverView(this));
1053 else 1088 else
1054 AddChildView(new PendingView(this)); 1089 AddChildView(new PendingView(this));
1055 } else if (IsAskSubmitURLState(model()->state())) { 1090 } else if (IsAskSubmitURLState(model()->state())) {
1056 AddChildView(new AskUserToSubmitURLView(this)); 1091 AddChildView(new AskUserToSubmitURLView(this));
1057 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { 1092 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) {
1058 AddChildView(new BlacklistedView(this)); 1093 AddChildView(new BlacklistedView(this));
1059 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) { 1094 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) {
1060 AddChildView(new SaveConfirmationView(this)); 1095 AddChildView(new SaveConfirmationView(this));
1061 } else if (model()->state() == 1096 } else if (model()->state() ==
1062 password_manager::ui::CREDENTIAL_REQUEST_STATE) { 1097 password_manager::ui::CREDENTIAL_REQUEST_STATE) {
1063 AddChildView(new AccountChooserView(this)); 1098 AddChildView(new AccountChooserView(this));
1064 } else if (model()->state() == password_manager::ui::AUTO_SIGNIN_STATE) { 1099 } else if (model()->state() == password_manager::ui::AUTO_SIGNIN_STATE) {
1065 AddChildView(new AutoSigninView(this)); 1100 AddChildView(new AutoSigninView(this));
1101 } else if (model()->state() == password_manager::ui::MANAGE_ACCOUNTS_STATE) {
1102 AddChildView(new ManageAccountsView(this));
1066 } else { 1103 } else {
1067 AddChildView(new ManageView(this)); 1104 AddChildView(new ManageView(this));
1068 } 1105 }
1069 GetLayoutManager()->Layout(this); 1106 GetLayoutManager()->Layout(this);
1070 } 1107 }
1071 1108
1072 void ManagePasswordsBubbleView::NotifyConfirmedNeverForThisSite() { 1109 void ManagePasswordsBubbleView::NotifyConfirmedNeverForThisSite() {
1073 model()->OnNeverForThisSiteClicked(); 1110 model()->OnNeverForThisSiteClicked();
1074 Close(); 1111 Close();
1075 } 1112 }
1076 1113
1077 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() { 1114 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() {
1078 model()->OnUndoNeverForThisSite(); 1115 model()->OnUndoNeverForThisSite();
1079 Refresh(); 1116 Refresh();
1080 } 1117 }
1081 1118
1082 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { 1119 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() {
1083 if (model()->best_matches().empty()) { 1120 if (model()->best_matches().empty()) {
1084 // Skip confirmation if there are no existing passwords for this site. 1121 // Skip confirmation if there are no existing passwords for this site.
1085 NotifyConfirmedNeverForThisSite(); 1122 NotifyConfirmedNeverForThisSite();
1086 } else { 1123 } else {
1087 model()->OnConfirmationForNeverForThisSite(); 1124 model()->OnConfirmationForNeverForThisSite();
1088 Refresh(); 1125 Refresh();
1089 } 1126 }
1090 } 1127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698