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 "ui/base/models/simple_combobox_model.h" | 11 #include "ui/base/models/simple_combobox_model.h" |
11 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/views/controls/button/button.h" | 13 #include "ui/views/controls/button/button.h" |
13 #include "ui/views/controls/combobox/combobox.h" | 14 #include "ui/views/controls/combobox/combobox.h" |
14 #include "ui/views/controls/label.h" | 15 #include "ui/views/controls/label.h" |
15 #include "ui/views/layout/grid_layout.h" | 16 #include "ui/views/layout/grid_layout.h" |
16 #include "ui/views/layout/layout_constants.h" | 17 #include "ui/views/layout/layout_constants.h" |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 views::Label* GeneratePasswordLabel(const autofill::PasswordForm& form) { | 21 views::Label* GeneratePasswordLabel(const autofill::PasswordForm& form) { |
21 views::Label* label = new views::Label(form.password_value); | 22 views::Label* label = new views::Label(form.password_value); |
22 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( | 23 label->SetFontList(ui::ResourceBundle::GetSharedInstance().GetFontList( |
23 ui::ResourceBundle::SmallFont)); | 24 ui::ResourceBundle::SmallFont)); |
24 label->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 25 label->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
25 label->SetObscured(true); | 26 label->SetObscured(true); |
26 return label; | 27 return label; |
27 } | 28 } |
28 | 29 |
29 views::Combobox* GenerateUsernameCombobox( | |
30 const std::vector<const autofill::PasswordForm*>& forms, | |
31 const base::string16& best_matched_username) { | |
32 std::vector<base::string16> usernames; | |
33 size_t best_matched_username_index = forms.size(); | |
34 size_t preferred_form_index = forms.size(); | |
35 for (size_t index = 0; index < forms.size(); ++index) { | |
36 usernames.push_back(forms[index]->username_value); | |
37 if (forms[index]->username_value == best_matched_username) { | |
38 best_matched_username_index = index; | |
39 } | |
40 if (forms[index]->preferred) { | |
41 preferred_form_index = index; | |
42 } | |
43 } | |
44 | |
45 views::Combobox* combobox = | |
46 new views::Combobox(new ui::SimpleComboboxModel(usernames)); | |
47 | |
48 if (best_matched_username_index < forms.size()) { | |
49 combobox->SetSelectedIndex(best_matched_username_index); | |
50 } else if (preferred_form_index < forms.size()) { | |
51 combobox->SetSelectedIndex(preferred_form_index); | |
52 } | |
53 return combobox; | |
54 } | |
55 | |
56 } // namespace | 30 } // namespace |
57 | 31 |
58 CredentialsSelectionView::CredentialsSelectionView( | 32 CredentialsSelectionView::CredentialsSelectionView( |
59 ManagePasswordsBubbleModel* manage_passwords_bubble_model, | 33 ManagePasswordsBubbleModel* manage_passwords_bubble_model, |
60 const std::vector<const autofill::PasswordForm*>& password_forms, | 34 const std::vector<const autofill::PasswordForm*>& password_forms, |
61 const base::string16& best_matched_username) | 35 const base::string16& best_matched_username) |
62 : password_forms_(password_forms) { | 36 : password_forms_(password_forms), |
| 37 action_reported_(false) { |
63 DCHECK(!password_forms.empty()); | 38 DCHECK(!password_forms.empty()); |
64 | 39 |
65 // Layout. | 40 // Layout. |
66 views::GridLayout* layout = new views::GridLayout(this); | 41 views::GridLayout* layout = new views::GridLayout(this); |
67 SetLayoutManager(layout); | 42 SetLayoutManager(layout); |
68 | 43 |
69 // ColumnSet. | 44 // ColumnSet. |
70 int column_set_id = 0; | 45 int column_set_id = 0; |
71 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); | 46 views::ColumnSet* column_set = layout->AddColumnSet(column_set_id); |
72 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, | 47 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1, |
(...skipping 10 matching lines...) Expand all Loading... |
83 manage_passwords_bubble_model->local_credentials().get(), | 58 manage_passwords_bubble_model->local_credentials().get(), |
84 best_matched_username); | 59 best_matched_username); |
85 layout->AddView(combobox_); | 60 layout->AddView(combobox_); |
86 views::Label* label = | 61 views::Label* label = |
87 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password()); | 62 GeneratePasswordLabel(manage_passwords_bubble_model->pending_password()); |
88 layout->AddView(label); | 63 layout->AddView(label); |
89 | 64 |
90 GetLayoutManager()->Layout(this); | 65 GetLayoutManager()->Layout(this); |
91 } | 66 } |
92 | 67 |
| 68 CredentialsSelectionView::~CredentialsSelectionView() { |
| 69 ReportUserActionOnce(true, -1); |
| 70 } |
| 71 |
93 const autofill::PasswordForm* | 72 const autofill::PasswordForm* |
94 CredentialsSelectionView::GetSelectedCredentials() { | 73 CredentialsSelectionView::GetSelectedCredentials() { |
95 DCHECK_EQ(password_forms_.size(), | 74 DCHECK_EQ(password_forms_.size(), |
96 static_cast<size_t>(combobox_->model()->GetItemCount())); | 75 static_cast<size_t>(combobox_->model()->GetItemCount())); |
| 76 ReportUserActionOnce(false, combobox_->selected_index()); |
97 return password_forms_[combobox_->selected_index()]; | 77 return password_forms_[combobox_->selected_index()]; |
98 } | 78 } |
| 79 |
| 80 views::Combobox* CredentialsSelectionView::GenerateUsernameCombobox( |
| 81 const std::vector<const autofill::PasswordForm*>& forms, |
| 82 const base::string16& best_matched_username) { |
| 83 std::vector<base::string16> usernames; |
| 84 size_t best_matched_username_index = forms.size(); |
| 85 size_t preferred_form_index = forms.size(); |
| 86 for (size_t index = 0; index < forms.size(); ++index) { |
| 87 usernames.push_back(forms[index]->username_value); |
| 88 if (forms[index]->username_value == best_matched_username) { |
| 89 best_matched_username_index = index; |
| 90 } |
| 91 if (forms[index]->preferred) { |
| 92 preferred_form_index = index; |
| 93 } |
| 94 } |
| 95 |
| 96 views::Combobox* combobox = |
| 97 new views::Combobox(new ui::SimpleComboboxModel(usernames)); |
| 98 |
| 99 default_index_ = 0; |
| 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; |
| 105 default_index_ = best_matched_username_index; |
| 106 combobox->SetSelectedIndex(best_matched_username_index); |
| 107 } else if (preferred_form_index < forms.size()) { |
| 108 is_default_preferred_ = true; |
| 109 default_index_ = preferred_form_index; |
| 110 combobox->SetSelectedIndex(preferred_form_index); |
| 111 } |
| 112 return combobox; |
| 113 } |
| 114 |
| 115 void CredentialsSelectionView::ReportUserActionOnce(bool was_update_rejected, |
| 116 int selected_index) { |
| 117 if (action_reported_) |
| 118 return; |
| 119 password_manager::metrics_util::MultiAccountUpdateBubbleUserAction action; |
| 120 if (was_update_rejected) { |
| 121 if (is_default_best_match_) { |
| 122 action = password_manager::metrics_util:: |
| 123 DEFAULT_ACCOUNT_MATCHED_BY_PASSWORD_USER_REJECTED_UPDATE; |
| 124 } else if (is_default_preferred_) { |
| 125 action = password_manager::metrics_util:: |
| 126 DEFAULT_ACCOUNT_PREFERRED_USER_REJECTED_UPDATE; |
| 127 } else { |
| 128 action = password_manager::metrics_util:: |
| 129 DEFAULT_ACCOUNT_FIRST_USER_REJECTED_UPDATE; |
| 130 } |
| 131 } else if (selected_index == default_index_) { |
| 132 if (is_default_best_match_) { |
| 133 action = password_manager::metrics_util:: |
| 134 DEFAULT_ACCOUNT_MATCHED_BY_PASSWORD_USER_NOT_CHANGED; |
| 135 } else if (is_default_preferred_) { |
| 136 action = password_manager::metrics_util:: |
| 137 DEFAULT_ACCOUNT_PREFERRED_USER_NOT_CHANGED; |
| 138 } else { |
| 139 action = password_manager::metrics_util:: |
| 140 DEFAULT_ACCOUNT_FIRST_USER_NOT_CHANGED; |
| 141 } |
| 142 } else { |
| 143 if (is_default_best_match_) { |
| 144 action = password_manager::metrics_util:: |
| 145 DEFAULT_ACCOUNT_MATCHED_BY_PASSWORD_USER_CHANGED; |
| 146 } else if (is_default_preferred_) { |
| 147 action = password_manager::metrics_util:: |
| 148 DEFAULT_ACCOUNT_PREFERRED_USER_CHANGED; |
| 149 } else { |
| 150 action = |
| 151 password_manager::metrics_util::DEFAULT_ACCOUNT_FIRST_USER_CHANGED; |
| 152 } |
| 153 } |
| 154 |
| 155 password_manager::metrics_util::LogMultiAccountUpdateBubbleUserAction(action); |
| 156 action_reported_ = true; |
| 157 } |
OLD | NEW |