| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/credentials_selection_view.h" | 5 #include "chrome/browser/ui/views/passwords/credentials_selection_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" | 9 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
| 10 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" | 10 #include "components/password_manager/core/browser/password_manager_metrics_util
.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 23 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 24 ui::ResourceBundle::SmallFont)); | 24 ui::ResourceBundle::SmallFont)); |
| 25 label->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 25 label->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 26 label->SetObscured(true); | 26 label->SetObscured(true); |
| 27 return label; | 27 return label; |
| 28 } | 28 } |
| 29 | 29 |
| 30 } // namespace | 30 } // namespace |
| 31 | 31 |
| 32 CredentialsSelectionView::CredentialsSelectionView( | 32 CredentialsSelectionView::CredentialsSelectionView( |
| 33 ManagePasswordsBubbleModel* manage_passwords_bubble_model, | 33 ManagePasswordsBubbleModel* manage_passwords_bubble_model) |
| 34 const std::vector<const autofill::PasswordForm*>& password_forms, | 34 : password_forms_(&manage_passwords_bubble_model->local_credentials()), |
| 35 const base::string16& best_matched_username) | 35 default_index_(0), |
| 36 : password_forms_(password_forms), | 36 is_default_best_match_(false), |
| 37 is_default_preferred_(false), |
| 37 action_reported_(false) { | 38 action_reported_(false) { |
| 38 DCHECK(!password_forms.empty()); | 39 DCHECK(!password_forms_->empty()); |
| 39 | 40 |
| 40 // Layout. | 41 // Layout. |
| 41 views::GridLayout* layout = new views::GridLayout(this); | 42 views::GridLayout* layout = new views::GridLayout(this); |
| 42 SetLayoutManager(layout); | 43 SetLayoutManager(layout); |
| 43 | 44 |
| 44 // ColumnSet. | 45 // ColumnSet. |
| 45 int column_set_id = 0; | 46 int column_set_id = 0; |
| 46 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 47 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
| 47 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 48 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 48 views::GridLayout::FIXED, 0, 0); | 49 views::GridLayout::FIXED, 0, 0); |
| 49 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); | 50 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); |
| 50 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 51 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
| 51 views::GridLayout::FIXED, 0, 0); | 52 views::GridLayout::FIXED, 0, 0); |
| 52 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); | 53 column_set->AddPaddingColumn(0, views::kItemLabelSpacing); |
| 53 | 54 |
| 54 // The username combobox and password label. | 55 // The username combobox and password label. |
| 55 layout->StartRowWithPadding(0, column_set_id, 0, | 56 layout->StartRowWithPadding(0, column_set_id, 0, |
| 56 views::kRelatedControlVerticalSpacing); | 57 views::kRelatedControlVerticalSpacing); |
| 57 combobox_ = GenerateUsernameCombobox( | 58 combobox_ = GenerateUsernameCombobox( |
| 58 manage_passwords_bubble_model->local_credentials().get(), | 59 manage_passwords_bubble_model->pending_password().username_value); |
| 59 best_matched_username); | |
| 60 layout->AddView(combobox_); | 60 layout->AddView(combobox_); |
| 61 views::Label* label = | 61 views::Label* label = |
| 62 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password()); | 62 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password()); |
| 63 layout->AddView(label); | 63 layout->AddView(label); |
| 64 | 64 |
| 65 GetLayoutManager()->Layout(this); | 65 GetLayoutManager()->Layout(this); |
| 66 } | 66 } |
| 67 | 67 |
| 68 CredentialsSelectionView::~CredentialsSelectionView() { | 68 CredentialsSelectionView::~CredentialsSelectionView() { |
| 69 ReportUserActionOnce(true, -1); | 69 ReportUserActionOnce(true, -1); |
| 70 } | 70 } |
| 71 | 71 |
| 72 const autofill::PasswordForm* | 72 const autofill::PasswordForm* |
| 73 CredentialsSelectionView::GetSelectedCredentials() { | 73 CredentialsSelectionView::GetSelectedCredentials() { |
| 74 DCHECK_EQ(password_forms_.size(), | 74 DCHECK_EQ(password_forms_->size(), |
| 75 static_cast<size_t>(combobox_->model()->GetItemCount())); | 75 static_cast<size_t>(combobox_->model()->GetItemCount())); |
| 76 ReportUserActionOnce(false, combobox_->selected_index()); | 76 ReportUserActionOnce(false, combobox_->selected_index()); |
| 77 return password_forms_[combobox_->selected_index()]; | 77 return &password_forms_->at(combobox_->selected_index()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 views::Combobox* CredentialsSelectionView::GenerateUsernameCombobox( | 80 views::Combobox* CredentialsSelectionView::GenerateUsernameCombobox( |
| 81 const std::vector<const autofill::PasswordForm*>& forms, | |
| 82 const base::string16& best_matched_username) { | 81 const base::string16& best_matched_username) { |
| 83 std::vector<base::string16> usernames; | 82 std::vector<base::string16> usernames; |
| 84 size_t best_matched_username_index = forms.size(); | 83 size_t best_matched_username_index = password_forms_->size(); |
| 85 size_t preferred_form_index = forms.size(); | 84 size_t preferred_form_index = password_forms_->size(); |
| 86 for (size_t index = 0; index < forms.size(); ++index) { | 85 for (size_t index = 0; index < password_forms_->size(); ++index) { |
| 87 usernames.push_back(forms[index]->username_value); | 86 usernames.push_back(password_forms_->at(index).username_value); |
| 88 if (forms[index]->username_value == best_matched_username) { | 87 if (password_forms_->at(index).username_value == best_matched_username) { |
| 89 best_matched_username_index = index; | 88 best_matched_username_index = index; |
| 90 } | 89 } |
| 91 if (forms[index]->preferred) { | 90 if (password_forms_->at(index).preferred) { |
| 92 preferred_form_index = index; | 91 preferred_form_index = index; |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 | 94 |
| 96 views::Combobox* combobox = | 95 views::Combobox* combobox = |
| 97 new views::Combobox(new ui::SimpleComboboxModel(usernames)); | 96 new views::Combobox(new ui::SimpleComboboxModel(usernames)); |
| 98 | 97 |
| 99 default_index_ = 0; | 98 if (best_matched_username_index < password_forms_->size()) { |
| 100 is_default_best_match_ = false; | |
| 101 is_default_preferred_ = false; | |
| 102 | |
| 103 if (best_matched_username_index < forms.size()) { | |
| 104 is_default_best_match_ = true; | 99 is_default_best_match_ = true; |
| 105 default_index_ = best_matched_username_index; | 100 default_index_ = best_matched_username_index; |
| 106 combobox->SetSelectedIndex(best_matched_username_index); | 101 combobox->SetSelectedIndex(best_matched_username_index); |
| 107 } else if (preferred_form_index < forms.size()) { | 102 } else if (preferred_form_index < password_forms_->size()) { |
| 108 is_default_preferred_ = true; | 103 is_default_preferred_ = true; |
| 109 default_index_ = preferred_form_index; | 104 default_index_ = preferred_form_index; |
| 110 combobox->SetSelectedIndex(preferred_form_index); | 105 combobox->SetSelectedIndex(preferred_form_index); |
| 111 } | 106 } |
| 112 return combobox; | 107 return combobox; |
| 113 } | 108 } |
| 114 | 109 |
| 115 void CredentialsSelectionView::ReportUserActionOnce(bool was_update_rejected, | 110 void CredentialsSelectionView::ReportUserActionOnce(bool was_update_rejected, |
| 116 int selected_index) { | 111 int selected_index) { |
| 117 if (action_reported_) | 112 if (action_reported_) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 148 DEFAULT_ACCOUNT_PREFERRED_USER_CHANGED; | 143 DEFAULT_ACCOUNT_PREFERRED_USER_CHANGED; |
| 149 } else { | 144 } else { |
| 150 action = | 145 action = |
| 151 password_manager::metrics_util::DEFAULT_ACCOUNT_FIRST_USER_CHANGED; | 146 password_manager::metrics_util::DEFAULT_ACCOUNT_FIRST_USER_CHANGED; |
| 152 } | 147 } |
| 153 } | 148 } |
| 154 | 149 |
| 155 password_manager::metrics_util::LogMultiAccountUpdateBubbleUserAction(action); | 150 password_manager::metrics_util::LogMultiAccountUpdateBubbleUserAction(action); |
| 156 action_reported_ = true; | 151 action_reported_ = true; |
| 157 } | 152 } |
| OLD | NEW |