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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 explicit AccountChooserView(ManagePasswordsBubbleView* parent); | 156 explicit AccountChooserView(ManagePasswordsBubbleView* parent); |
157 ~AccountChooserView() override; | 157 ~AccountChooserView() override; |
158 | 158 |
159 private: | 159 private: |
160 // views::ButtonListener: | 160 // views::ButtonListener: |
161 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 161 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
162 | 162 |
163 // Adds |password_forms| to the layout remembering their |type|. | 163 // Adds |password_forms| to the layout remembering their |type|. |
164 void AddCredentialItemsWithType( | 164 void AddCredentialItemsWithType( |
165 views::GridLayout* layout, | 165 views::GridLayout* layout, |
166 const ScopedVector<autofill::PasswordForm>& password_forms, | 166 const ScopedVector<const autofill::PasswordForm>& password_forms, |
167 password_manager::CredentialType type); | 167 password_manager::CredentialType type); |
168 | 168 |
169 ManagePasswordsBubbleView* parent_; | 169 ManagePasswordsBubbleView* parent_; |
170 views::LabelButton* cancel_button_; | 170 views::LabelButton* cancel_button_; |
171 }; | 171 }; |
172 | 172 |
173 ManagePasswordsBubbleView::AccountChooserView::AccountChooserView( | 173 ManagePasswordsBubbleView::AccountChooserView::AccountChooserView( |
174 ManagePasswordsBubbleView* parent) | 174 ManagePasswordsBubbleView* parent) |
175 : parent_(parent) { | 175 : parent_(parent) { |
176 views::GridLayout* layout = new views::GridLayout(this); | 176 views::GridLayout* layout = new views::GridLayout(this); |
177 SetLayoutManager(layout); | 177 SetLayoutManager(layout); |
178 | 178 |
179 cancel_button_ = | 179 cancel_button_ = |
180 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_CANCEL)); | 180 new views::LabelButton(this, l10n_util::GetStringUTF16(IDS_CANCEL)); |
181 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); | 181 cancel_button_->SetStyle(views::Button::STYLE_BUTTON); |
182 cancel_button_->SetFontList( | 182 cancel_button_->SetFontList( |
183 ui::ResourceBundle::GetSharedInstance().GetFontList( | 183 ui::ResourceBundle::GetSharedInstance().GetFontList( |
184 ui::ResourceBundle::SmallFont)); | 184 ui::ResourceBundle::SmallFont)); |
185 | 185 |
186 // Title row. | 186 // Title row. |
187 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | 187 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
188 AddTitleRow(layout, parent_->model()); | 188 AddTitleRow(layout, parent_->model()); |
189 | 189 |
190 AddCredentialItemsWithType( | 190 AddCredentialItemsWithType( |
191 layout, parent_->model()->local_pending_credentials(), | 191 layout, parent_->model()->local_credentials(), |
192 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); | 192 password_manager::CredentialType::CREDENTIAL_TYPE_LOCAL); |
193 | 193 |
194 AddCredentialItemsWithType( | 194 AddCredentialItemsWithType( |
195 layout, parent_->model()->federated_pending_credentials(), | 195 layout, parent_->model()->federated_credentials(), |
196 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED); | 196 password_manager::CredentialType::CREDENTIAL_TYPE_FEDERATED); |
197 | 197 |
198 // Button row. | 198 // Button row. |
199 BuildColumnSet(layout, SINGLE_BUTTON_COLUMN_SET); | 199 BuildColumnSet(layout, SINGLE_BUTTON_COLUMN_SET); |
200 layout->StartRowWithPadding( | 200 layout->StartRowWithPadding( |
201 0, SINGLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); | 201 0, SINGLE_BUTTON_COLUMN_SET, 0, views::kRelatedControlVerticalSpacing); |
202 layout->AddView(cancel_button_); | 202 layout->AddView(cancel_button_); |
203 | 203 |
204 // Extra padding for visual awesomeness. | 204 // Extra padding for visual awesomeness. |
205 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); | 205 layout->AddPaddingRow(0, views::kRelatedControlVerticalSpacing); |
206 | 206 |
207 parent_->set_initially_focused_view(cancel_button_); | 207 parent_->set_initially_focused_view(cancel_button_); |
208 } | 208 } |
209 | 209 |
210 ManagePasswordsBubbleView::AccountChooserView::~AccountChooserView() { | 210 ManagePasswordsBubbleView::AccountChooserView::~AccountChooserView() { |
211 } | 211 } |
212 | 212 |
213 void ManagePasswordsBubbleView::AccountChooserView::AddCredentialItemsWithType( | 213 void ManagePasswordsBubbleView::AccountChooserView::AddCredentialItemsWithType( |
214 views::GridLayout* layout, | 214 views::GridLayout* layout, |
215 const ScopedVector<autofill::PasswordForm>& password_forms, | 215 const ScopedVector<const autofill::PasswordForm>& password_forms, |
216 password_manager::CredentialType type) { | 216 password_manager::CredentialType type) { |
217 net::URLRequestContextGetter* request_context = | 217 net::URLRequestContextGetter* request_context = |
218 parent_->model()->GetProfile()->GetRequestContext(); | 218 parent_->model()->GetProfile()->GetRequestContext(); |
219 for (autofill::PasswordForm* form : password_forms) { | 219 for (const autofill::PasswordForm* form : password_forms) { |
220 // Add the title to the layout with appropriate padding. | 220 // Add the title to the layout with appropriate padding. |
221 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 221 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
222 layout->AddView(new CredentialsItemView( | 222 layout->AddView(new CredentialsItemView( |
223 this, form, type, CredentialsItemView::ACCOUNT_CHOOSER, | 223 this, form, type, CredentialsItemView::ACCOUNT_CHOOSER, |
224 request_context)); | 224 request_context)); |
225 } | 225 } |
226 } | 226 } |
227 | 227 |
228 void ManagePasswordsBubbleView::AccountChooserView::ButtonPressed( | 228 void ManagePasswordsBubbleView::AccountChooserView::ButtonPressed( |
229 views::Button* sender, const ui::Event& event) { | 229 views::Button* sender, const ui::Event& event) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 504 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
505 SetLayoutManager(layout); | 505 SetLayoutManager(layout); |
506 | 506 |
507 // Add the title. | 507 // Add the title. |
508 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | 508 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
509 AddTitleRow(layout, parent_->model()); | 509 AddTitleRow(layout, parent_->model()); |
510 | 510 |
511 // If we have a list of passwords to store for the current site, display | 511 // If we have a list of passwords to store for the current site, display |
512 // them to the user for management. Otherwise, render a "No passwords for | 512 // them to the user for management. Otherwise, render a "No passwords for |
513 // this site" message. | 513 // this site" message. |
514 if (!parent_->model()->best_matches().empty()) { | 514 if (!parent_->model()->local_credentials().empty()) { |
515 std::vector<const autofill::PasswordForm*> password_forms; | |
516 for (auto password_form : parent_->model()->best_matches()) { | |
517 password_forms.push_back(password_form.second); | |
518 } | |
519 ManagePasswordItemsView* item = new ManagePasswordItemsView( | 515 ManagePasswordItemsView* item = new ManagePasswordItemsView( |
520 parent_->model(), password_forms); | 516 parent_->model(), parent_->model()->local_credentials().get()); |
521 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 517 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
522 layout->AddView(item); | 518 layout->AddView(item); |
523 } else { | 519 } else { |
524 views::Label* empty_label = new views::Label( | 520 views::Label* empty_label = new views::Label( |
525 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); | 521 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS)); |
526 empty_label->SetMultiLine(true); | 522 empty_label->SetMultiLine(true); |
527 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 523 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
528 empty_label->SetFontList( | 524 empty_label->SetFontList( |
529 ui::ResourceBundle::GetSharedInstance().GetFontList( | 525 ui::ResourceBundle::GetSharedInstance().GetFontList( |
530 ui::ResourceBundle::SmallFont)); | 526 ui::ResourceBundle::SmallFont)); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
606 ManagePasswordsBubbleView* parent) | 602 ManagePasswordsBubbleView* parent) |
607 : parent_(parent) { | 603 : parent_(parent) { |
608 views::GridLayout* layout = new views::GridLayout(this); | 604 views::GridLayout* layout = new views::GridLayout(this); |
609 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); | 605 layout->set_minimum_size(gfx::Size(kDesiredBubbleWidth, 0)); |
610 SetLayoutManager(layout); | 606 SetLayoutManager(layout); |
611 | 607 |
612 // Add the title. | 608 // Add the title. |
613 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); | 609 BuildColumnSet(layout, SINGLE_VIEW_COLUMN_SET); |
614 AddTitleRow(layout, parent_->model()); | 610 AddTitleRow(layout, parent_->model()); |
615 | 611 |
616 if (!parent_->model()->local_pending_credentials().empty()) { | 612 if (!parent_->model()->local_credentials().empty()) { |
617 for (const autofill::PasswordForm* form : | 613 for (const autofill::PasswordForm* form : |
618 parent_->model()->local_pending_credentials()) { | 614 parent_->model()->local_credentials()) { |
619 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); | 615 layout->StartRow(0, SINGLE_VIEW_COLUMN_SET); |
620 layout->AddView(new ManageCredentialItemView(parent_->model(), form)); | 616 layout->AddView(new ManageCredentialItemView(parent_->model(), form)); |
621 } | 617 } |
622 } else { | 618 } else { |
623 views::Label* empty_label = new views::Label( | 619 views::Label* empty_label = new views::Label( |
624 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS), | 620 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_NO_PASSWORDS), |
625 ui::ResourceBundle::GetSharedInstance().GetFontList( | 621 ui::ResourceBundle::GetSharedInstance().GetFontList( |
626 ui::ResourceBundle::SmallFont)); | 622 ui::ResourceBundle::SmallFont)); |
627 empty_label->SetMultiLine(true); | 623 empty_label->SetMultiLine(true); |
628 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 624 empty_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1010 model()->OnNeverForThisSiteClicked(); | 1006 model()->OnNeverForThisSiteClicked(); |
1011 Close(); | 1007 Close(); |
1012 } | 1008 } |
1013 | 1009 |
1014 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() { | 1010 void ManagePasswordsBubbleView::NotifyUndoNeverForThisSite() { |
1015 model()->OnUndoNeverForThisSite(); | 1011 model()->OnUndoNeverForThisSite(); |
1016 Refresh(); | 1012 Refresh(); |
1017 } | 1013 } |
1018 | 1014 |
1019 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { | 1015 void ManagePasswordsBubbleView::NotifyNeverForThisSiteClicked() { |
1020 if (model()->best_matches().empty()) { | 1016 if (model()->local_credentials().empty()) { |
1021 // Skip confirmation if there are no existing passwords for this site. | 1017 // Skip confirmation if there are no existing passwords for this site. |
1022 NotifyConfirmedNeverForThisSite(); | 1018 NotifyConfirmedNeverForThisSite(); |
1023 } else { | 1019 } else { |
1024 model()->OnConfirmationForNeverForThisSite(); | 1020 model()->OnConfirmationForNeverForThisSite(); |
1025 Refresh(); | 1021 Refresh(); |
1026 } | 1022 } |
1027 } | 1023 } |
OLD | NEW |