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_EQ(1u, parent->model()->local_credentials().size()); |
| 1027 DCHECK_EQ(parent->model()->local_credentials()[0]->username_value, |
| 1028 parent->model()->pending_password().username_value); |
| 1029 std::vector<const autofill::PasswordForm*> forms; |
| 1030 forms.push_back(&parent->model()->pending_password()); |
| 1031 item = new ManagePasswordItemsView(parent_->model(), forms); |
| 1032 } |
| 1033 nope_button_ = new views::LabelButton( |
| 1034 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_CANCEL_BUTTON)); |
| 1035 nope_button_->SetStyle(views::Button::STYLE_BUTTON); |
| 1036 nope_button_->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 1037 ui::ResourceBundle::SmallFont)); |
| 1038 |
| 1039 update_button_ = new views::BlueButton( |
| 1040 this, l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_UPDATE_BUTTON)); |
| 1041 update_button_->SetFontList( |
| 1042 ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 1043 ui::ResourceBundle::SmallFont)); |
| 1044 |
| 1045 // Title row. |
| 1046 views::StyledLabel* title_label = |
| 1047 new views::StyledLabel(parent_->model()->title(), this); |
| 1048 title_label->SetBaseFontList( |
| 1049 ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 1050 ui::ResourceBundle::MediumFont)); |
| 1051 if (!parent_->model()->title_brand_link_range().is_empty()) { |
| 1052 title_label->AddStyleRange( |
| 1053 parent_->model()->title_brand_link_range(), |
| 1054 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
| 1055 } |
| 1056 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
| 1057 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 1058 layout->AddView(title_label); |
| 1059 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 1060 |
| 1061 // Credential row. |
| 1062 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
| 1063 layout->AddView(item); |
| 1064 |
| 1065 // Button row. |
| 1066 BuildColumnSet(layout, DOUBLE_BUTTON_COLUMN_SET); |
| 1067 layout->StartRowWithPadding(0, DOUBLE_BUTTON_COLUMN_SET, 0, |
| 1068 views::kRelatedControlVerticalSpacing); |
| 1069 layout->AddView(update_button_); |
| 1070 layout->AddView(nope_button_); |
| 1071 |
| 1072 // Extra padding for visual awesomeness. |
| 1073 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
| 1074 |
| 1075 parent_->set_initially_focused_view(update_button_); |
| 1076 } |
| 1077 |
| 1078 ManagePasswordsBubbleView::UpdatePendingView::~UpdatePendingView() {} |
| 1079 |
| 1080 void ManagePasswordsBubbleView::UpdatePendingView::ButtonPressed( |
| 1081 views::Button* sender, |
| 1082 const ui::Event& event) { |
| 1083 DCHECK(sender == update_button_ || sender == nope_button_); |
| 1084 if (sender == update_button_) { |
| 1085 if (selection_view_) { |
| 1086 // Multi account case. |
| 1087 parent_->model()->OnUpdateClicked( |
| 1088 *selection_view_->GetSelectedCredentials()); |
| 1089 } else { |
| 1090 parent_->model()->OnUpdateClicked( |
| 1091 *parent_->model()->local_credentials()[0]); |
| 1092 } |
| 1093 } |
| 1094 parent_->Close(); |
| 1095 } |
| 1096 |
| 1097 void ManagePasswordsBubbleView::UpdatePendingView::StyledLabelLinkClicked( |
| 1098 const gfx::Range& range, |
| 1099 int event_flags) { |
| 1100 DCHECK_EQ(range, parent_->model()->title_brand_link_range()); |
| 1101 parent_->model()->OnBrandLinkClicked(); |
| 1102 } |
| 1103 |
977 // ManagePasswordsBubbleView -------------------------------------------------- | 1104 // ManagePasswordsBubbleView -------------------------------------------------- |
978 | 1105 |
979 // static | 1106 // static |
980 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = | 1107 ManagePasswordsBubbleView* ManagePasswordsBubbleView::manage_passwords_bubble_ = |
981 NULL; | 1108 NULL; |
982 | 1109 |
983 // static | 1110 // static |
984 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, | 1111 void ManagePasswordsBubbleView::ShowBubble(content::WebContents* web_contents, |
985 DisplayReason reason) { | 1112 DisplayReason reason) { |
986 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); | 1113 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 } | 1200 } |
1074 | 1201 |
1075 void ManagePasswordsBubbleView::Refresh() { | 1202 void ManagePasswordsBubbleView::Refresh() { |
1076 RemoveAllChildViews(true); | 1203 RemoveAllChildViews(true); |
1077 initially_focused_view_ = NULL; | 1204 initially_focused_view_ = NULL; |
1078 if (model()->state() == password_manager::ui::PENDING_PASSWORD_STATE) { | 1205 if (model()->state() == password_manager::ui::PENDING_PASSWORD_STATE) { |
1079 if (model()->never_save_passwords()) | 1206 if (model()->never_save_passwords()) |
1080 AddChildView(new ConfirmNeverView(this)); | 1207 AddChildView(new ConfirmNeverView(this)); |
1081 else | 1208 else |
1082 AddChildView(new PendingView(this)); | 1209 AddChildView(new PendingView(this)); |
| 1210 } else if (model()->state() == |
| 1211 password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { |
| 1212 AddChildView(new UpdatePendingView(this)); |
1083 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { | 1213 } else if (model()->state() == password_manager::ui::BLACKLIST_STATE) { |
1084 AddChildView(new BlacklistedView(this)); | 1214 AddChildView(new BlacklistedView(this)); |
1085 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) { | 1215 } else if (model()->state() == password_manager::ui::CONFIRMATION_STATE) { |
1086 AddChildView(new SaveConfirmationView(this)); | 1216 AddChildView(new SaveConfirmationView(this)); |
1087 } else if (model()->state() == | 1217 } else if (model()->state() == |
1088 password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 1218 password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
1089 AddChildView(new AccountChooserView(this)); | 1219 AddChildView(new AccountChooserView(this)); |
1090 } else if (model()->state() == password_manager::ui::AUTO_SIGNIN_STATE) { | 1220 } else if (model()->state() == password_manager::ui::AUTO_SIGNIN_STATE) { |
1091 AddChildView(new AutoSigninView(this)); | 1221 AddChildView(new AutoSigninView(this)); |
1092 } else { | 1222 } else { |
(...skipping 19 matching lines...) Expand all Loading... |
1112 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { | 1242 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { |
1113 if (model()->local_credentials().empty()) { | 1243 if (model()->local_credentials().empty()) { |
1114 // Skip confirmation if there are no existing passwords for this site. | 1244 // Skip confirmation if there are no existing passwords for this site. |
1115 NotifyConfirmedNeverForThisSite(); | 1245 NotifyConfirmedNeverForThisSite(); |
1116 } else { | 1246 } else { |
1117 model()->OnConfirmationForNeverForThisSite(); | 1247 model()->OnConfirmationForNeverForThisSite(); |
1118 Refresh(); | 1248 Refresh(); |
1119 SizeToContents(); | 1249 SizeToContents(); |
1120 } | 1250 } |
1121 } | 1251 } |
OLD | NEW |