| 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" |
| 11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 11 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
| 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| 13 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 13 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 14 #include "chrome/browser/ui/passwords/save_account_more_combobox_model.h" | 14 #include "chrome/browser/ui/passwords/save_account_more_combobox_model.h" |
| 15 #include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h" | 15 #include "chrome/browser/ui/passwords/save_password_refusal_combobox_model.h" |
| 16 #include "chrome/browser/ui/views/frame/browser_view.h" | 16 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 17 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" | 17 #include "chrome/browser/ui/views/passwords/credentials_item_view.h" |
| 18 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" |
| 18 #include "chrome/browser/ui/views/passwords/manage_credential_item_view.h" | 19 #include "chrome/browser/ui/views/passwords/manage_credential_item_view.h" |
| 19 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" | 20 #include "chrome/browser/ui/views/passwords/manage_password_items_view.h" |
| 20 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" | 21 #include "chrome/browser/ui/views/passwords/manage_passwords_icon_view.h" |
| 21 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 22 #include "content/public/browser/render_view_host.h" | 23 #include "content/public/browser/render_view_host.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/views/controls/button/blue_button.h" | 26 #include "ui/views/controls/button/blue_button.h" |
| 26 #include "ui/views/controls/button/label_button.h" | 27 #include "ui/views/controls/button/label_button.h" |
| 27 #include "ui/views/controls/combobox/combobox.h" | 28 #include "ui/views/controls/combobox/combobox.h" |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 if (event->type() == ui::ET_MOUSE_PRESSED) | 968 if (event->type() == ui::ET_MOUSE_PRESSED) |
| 968 bubble_->Close(); | 969 bubble_->Close(); |
| 969 } | 970 } |
| 970 | 971 |
| 971 void ManagePasswordsBubbleView::WebContentMouseHandler::OnTouchEvent( | 972 void ManagePasswordsBubbleView::WebContentMouseHandler::OnTouchEvent( |
| 972 ui::TouchEvent* event) { | 973 ui::TouchEvent* event) { |
| 973 if (event->type() == ui::ET_TOUCH_PRESSED) | 974 if (event->type() == ui::ET_TOUCH_PRESSED) |
| 974 bubble_->Close(); | 975 bubble_->Close(); |
| 975 } | 976 } |
| 976 | 977 |
| 978 // ManagePasswordsBubbleView::UpdatePendingView ------------------------------- |
| 979 |
| 980 // A view offering the user the ability to update credentials. Contains a |
| 981 // single ManagePasswordItemsView (in case of one credentials) or |
| 982 // CredentialsSelectionView otherwise, along with a "Update Passwords" button |
| 983 // and a rejection button. |
| 984 class ManagePasswordsBubbleView::UpdatePendingView |
| 985 : public views::View, |
| 986 public views::ButtonListener, |
| 987 public views::StyledLabelListener { |
| 988 public: |
| 989 explicit UpdatePendingView(ManagePasswordsBubbleView* parent); |
| 990 ~UpdatePendingView() override; |
| 991 |
| 992 private: |
| 993 // views::ButtonListener: |
| 994 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 995 |
| 996 // views::StyledLabelListener: |
| 997 void StyledLabelLinkClicked(const gfx::Range& range, |
| 998 int event_flags) override; |
| 999 |
| 1000 ManagePasswordsBubbleView* parent_; |
| 1001 |
| 1002 CredentialsSelectionView* selection_view_; |
| 1003 |
| 1004 views::BlueButton* update_button_; |
| 1005 |
| 1006 views::LabelButton* nope_button_; |
| 1007 |
| 1008 DISALLOW_COPY_AND_ASSIGN(UpdatePendingView); |
| 1009 }; |
| 1010 |
| 1011 ManagePasswordsBubbleView::UpdatePendingView::UpdatePendingView( |
| 1012 ManagePasswordsBubbleView* parent) |
| 1013 : parent_(parent), selection_view_(nullptr) { |
| 1014 views::GridLayout* layout = new views::GridLayout(this); |
| 1015 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
| 1016 SetLayoutManager(layout); |
| 1017 |
| 1018 // Create the pending credential item, update button. |
| 1019 View* item = nullptr; |
| 1020 if (parent->model()->ShouldShowMultipleAccountUpdateUI()) { |
| 1021 selection_view_ = new CredentialsSelectionView( |
| 1022 parent->model(), parent->model()->local_credentials().get(), |
| 1023 parent->model()->pending_password().username_value); |
| 1024 item = selection_view_; |
| 1025 } else { |
| 1026 DCHECK(parent->model()->local_credentials().size() == 1); |
| 1027 item = new ManagePasswordItemsView( |
| 1028 parent_->model(), parent->model()->local_credentials().get()); |
| 1029 } |
| 1030 nope_button_ = new views::LabelButton( |
| 1031 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON)); |
| 1032 nope_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 1033 nope_button_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 1034 ui::ResourceBundle::SmallFont)); |
| 1035 |
| 1036 update_button_ = new views::BlueButton( |
| 1037 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_UPDATE_BUTTON)); |
| 1038 update_button_->SetFontList( |
| 1039 ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 1040 ui::ResourceBundle::SmallFont)); |
| 1041 |
| 1042 // Title row. |
| 1043 views::StyledLabel* title_label = |
| 1044 new views::StyledLabel(parent_->model()->title(), this); |
| 1045 title_label->SetBaseFontList( |
| 1046 ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 1047 ui::ResourceBundle::MediumFont)); |
| 1048 if (!parent_->model()->title_brand_link_range().is_empty()) { |
| 1049 title_label->AddStyleRange( |
| 1050 parent_->model()->title_brand_link_range(), |
| 1051 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 1052 } |
| 1053 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
| 1054 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 1055 layout->AddView(title_label); |
| 1056 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 1057 |
| 1058 // Credential row. |
| 1059 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 1060 layout->AddView(item); |
| 1061 |
| 1062 // Button row. |
| 1063 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); |
| 1064 layout->StartRowWithPadding(0, DOUBLE_BUTTON_COLUMN_SET, 0, |
| 1065 views::kRelatedControlVerticalSpacing); |
| 1066 layout->AddView(update_button_); |
| 1067 layout->AddView(nope_button_); |
| 1068 |
| 1069 // Extra padding for visual awesomeness. |
| 1070 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 1071 |
| 1072 parent_->set_initially_focused_view(update_button_); |
| 1073 } |
| 1074 |
| 1075 ManagePasswordsBubbleView::UpdatePendingView::~UpdatePendingView() {} |
| 1076 |
| 1077 void ManagePasswordsBubbleView::UpdatePendingView::ButtonPressed( |
| 1078 views::Button* sender, |
| 1079 const ui::Event& event) { |
| 1080 DCHECK(sender == update_button_ || sender == nope_button_); |
| 1081 if (sender == update_button_) { |
| 1082 if (selection_view_) { |
| 1083 // Multi account case. |
| 1084 parent_->model()->OnUpdateClicked( |
| 1085 *selection_view_->GetSelectedCredentials()); |
| 1086 } else { |
| 1087 parent_->model()->OnUpdateClicked(parent_->model()->pending_password()); |
| 1088 } |
| 1089 } |
| 1090 parent_->Close(); |
| 1091 } |
| 1092 |
| 1093 void ManagePasswordsBubbleView::UpdatePendingView::StyledLabelLinkClicked( |
| 1094 const gfx::Range& range, |
| 1095 int event_flags) { |
| 1096 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); |
| 1097 parent_->model()->OnBrandLinkClicked(); |
| 1098 } |
| 1099 |
| 977 // ManagePasswordsBubbleView -------------------------------------------------- | 1100 // ManagePasswordsBubbleView -------------------------------------------------- |
| 978 | 1101 |
| 979 // static | 1102 // static |
| 980 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 1103 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
| 981 NULL; | 1104 NULL; |
| 982 | 1105 |
| 983 // static | 1106 // static |
| 984 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, | 1107 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, |
| 985 DisplayReason reason) { | 1108 DisplayReason reason) { |
| 986 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 1109 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1073 } | 1196 } |
| 1074 | 1197 |
| 1075 void ManagePasswordsBubbleView::Refresh() { | 1198 void ManagePasswordsBubbleView::Refresh() { |
| 1076 RemoveAllChildViews(true); | 1199 RemoveAllChildViews(true); |
| 1077 initially_focused_view_ = NULL; | 1200 initially_focused_view_ = NULL; |
| 1078 if (model()->state() == password_manager::ui::PENDING_PASSWORD_STATE) { | 1201 if (model()->state() == password_manager::ui::PENDING_PASSWORD_STATE) { |
| 1079 if (model()->never_save_passwords()) | 1202 if (model()->never_save_passwords()) |
| 1080 AddChildView(new ConfirmNeverView(this)); | 1203 AddChildView(new ConfirmNeverView(this)); |
| 1081 else | 1204 else |
| 1082 AddChildView(new PendingView(this)); | 1205 AddChildView(new PendingView(this)); |
| 1206 } else if (model()->state() == |
| 1207 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { |
| 1208 AddChildView(new UpdatePendingView(this)); |
| 1083 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { | 1209 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { |
| 1084 AddChildView(new BlacklistedView(this)); | 1210 AddChildView(new BlacklistedView(this)); |
| 1085 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) { | 1211 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) { |
| 1086 AddChildView(new SaveConfirmationView(this)); | 1212 AddChildView(new SaveConfirmationView(this)); |
| 1087 } else if (model()->state() == | 1213 } else if (model()->state() == |
| 1088 password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 1214 password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
| 1089 AddChildView(new AccountChooserView(this)); | 1215 AddChildView(new AccountChooserView(this)); |
| 1090 } else if (model()->state() == password_manager::ui::AUTO_SIGNIN_STATE) { | 1216 } else if (model()->state() == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 1091 AddChildView(new AutoSigninView(this)); | 1217 AddChildView(new AutoSigninView(this)); |
| 1092 } else { | 1218 } else { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1112 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { | 1238 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { |
| 1113 if (model()->local_credentials().empty()) { | 1239 if (model()->local_credentials().empty()) { |
| 1114 // Skip confirmation if there are no existing passwords for this site. | 1240 // Skip confirmation if there are no existing passwords for this site. |
| 1115 NotifyConfirmedNeverForThisSite(); | 1241 NotifyConfirmedNeverForThisSite(); |
| 1116 } else { | 1242 } else { |
| 1117 model()->OnConfirmationForNeverForThisSite(); | 1243 model()->OnConfirmationForNeverForThisSite(); |
| 1118 Refresh(); | 1244 Refresh(); |
| 1119 SizeToContents(); | 1245 SizeToContents(); |
| 1120 } | 1246 } |
| 1121 } | 1247 } |
| OLD | NEW |