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