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/passwords/manage_passwords_bubble_model.h" | 5 #include "chrome/browser/ui/passwords/manage_passwords_bubble_model.h" |
6 | 6 |
7 #include "chrome/browser/password_manager/password_store_factory.h" | 7 #include "chrome/browser/password_manager/password_store_factory.h" |
8 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
9 #include "chrome/browser/ui/browser_finder.h" | 9 #include "chrome/browser/ui/browser_finder.h" |
10 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 10 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( | 48 ManagePasswordsBubbleModel::ManagePasswordsBubbleModel( |
49 content::WebContents* web_contents) | 49 content::WebContents* web_contents) |
50 : content::WebContentsObserver(web_contents), | 50 : content::WebContentsObserver(web_contents), |
51 display_disposition_( | 51 display_disposition_( |
52 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), | 52 metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), |
53 dismissal_reason_(metrics_util::NOT_DISPLAYED) { | 53 dismissal_reason_(metrics_util::NOT_DISPLAYED) { |
54 ManagePasswordsUIController* controller = | 54 ManagePasswordsUIController* controller = |
55 ManagePasswordsUIController::FromWebContents(web_contents); | 55 ManagePasswordsUIController::FromWebContents(web_contents); |
56 | 56 |
57 // TODO(mkwst): Reverse this logic. The controller should populate the model | |
58 // directly rather than the model pulling from the controller. Perhaps like | |
59 // `controller->PopulateModel(this)`. | |
60 state_ = controller->state(); | 57 state_ = controller->state(); |
61 if (password_manager::ui::IsPendingState(state_)) | 58 if (password_manager::ui::IsPendingState(state_)) |
62 pending_credentials_ = controller->PendingCredentials(); | 59 pending_password_ = controller->PendingPassword(); |
63 best_matches_ = controller->best_matches(); | 60 if (password_manager::ui::IsCredentialsState(state_)) |
| 61 pending_credentials_.swap(controller->new_password_forms()); |
| 62 else |
| 63 best_matches_ = controller->best_matches(); |
64 | 64 |
65 if (password_manager::ui::IsPendingState(state_)) { | 65 if (password_manager::ui::IsPendingState(state_)) { |
66 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD); | 66 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD); |
67 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 67 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
68 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); | 68 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); |
69 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 69 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
70 title_ = | 70 title_ = |
71 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); | 71 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); |
| 72 } else if (password_manager::ui::IsCredentialsState(state_)) { |
| 73 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); |
72 } else { | 74 } else { |
73 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); | 75 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); |
74 } | 76 } |
75 | 77 |
76 base::string16 save_confirmation_link = | 78 base::string16 save_confirmation_link = |
77 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); | 79 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); |
78 size_t offset; | 80 size_t offset; |
79 save_confirmation_text_ = | 81 save_confirmation_text_ = |
80 l10n_util::GetStringFUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT, | 82 l10n_util::GetStringFUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT, |
81 save_confirmation_link, &offset); | 83 save_confirmation_link, &offset); |
(...skipping 13 matching lines...) Expand all Loading... |
95 display_disposition_ = metrics_util::MANUAL_WITH_PASSWORD_PENDING; | 97 display_disposition_ = metrics_util::MANUAL_WITH_PASSWORD_PENDING; |
96 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 98 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
97 display_disposition_ = metrics_util::MANUAL_BLACKLISTED; | 99 display_disposition_ = metrics_util::MANUAL_BLACKLISTED; |
98 } else { | 100 } else { |
99 display_disposition_ = metrics_util::MANUAL_MANAGE_PASSWORDS; | 101 display_disposition_ = metrics_util::MANUAL_MANAGE_PASSWORDS; |
100 } | 102 } |
101 } else { | 103 } else { |
102 if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 104 if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
103 display_disposition_ = | 105 display_disposition_ = |
104 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION; | 106 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION; |
| 107 } else if (password_manager::ui::IsCredentialsState(state_)) { |
| 108 display_disposition_ = metrics_util::AUTOMATIC_CREDENTIAL_REQUEST; |
105 } else { | 109 } else { |
106 display_disposition_ = metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; | 110 display_disposition_ = metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; |
107 } | 111 } |
108 } | 112 } |
109 metrics_util::LogUIDisplayDisposition(display_disposition_); | 113 metrics_util::LogUIDisplayDisposition(display_disposition_); |
110 | 114 |
111 // Default to a dismissal reason of "no interaction". If the user interacts | 115 // Default to a dismissal reason of "no interaction". If the user interacts |
112 // with the button in such a way that it closes, we'll reset this value | 116 // with the button in such a way that it closes, we'll reset this value |
113 // accordingly. | 117 // accordingly. |
114 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION; | 118 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION; |
| 119 |
| 120 ManagePasswordsUIController* controller = |
| 121 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 122 controller->OnBubbleShown(); |
115 } | 123 } |
116 | 124 |
117 void ManagePasswordsBubbleModel::OnBubbleHidden() { | 125 void ManagePasswordsBubbleModel::OnBubbleHidden() { |
| 126 if (password_manager::ui::IsCredentialsState(state_)) { |
| 127 // It's time to run the pending callback if it wasn't called in |
| 128 // OnChooseCredentials(). |
| 129 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 130 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 131 manage_passwords_ui_controller->ChooseCredential(false, |
| 132 autofill::PasswordForm()); |
| 133 state_ = password_manager::ui::INACTIVE_STATE; |
| 134 } |
118 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) | 135 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) |
119 return; | 136 return; |
120 | 137 |
121 metrics_util::LogUIDismissalReason(dismissal_reason_); | 138 metrics_util::LogUIDismissalReason(dismissal_reason_); |
122 // Other use cases have been reported in the callbacks like OnSaveClicked(). | 139 // Other use cases have been reported in the callbacks like OnSaveClicked(). |
123 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) | 140 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) |
124 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 141 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
125 } | 142 } |
126 | 143 |
127 void ManagePasswordsBubbleModel::OnNopeClicked() { | 144 void ManagePasswordsBubbleModel::OnNopeClicked() { |
128 dismissal_reason_ = metrics_util::CLICKED_NOPE; | 145 dismissal_reason_ = metrics_util::CLICKED_NOPE; |
129 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 146 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
130 state_ = password_manager::ui::PENDING_PASSWORD_STATE; | 147 if (!password_manager::ui::IsCredentialsState(state_)) |
| 148 state_ = password_manager::ui::PENDING_PASSWORD_STATE; |
131 } | 149 } |
132 | 150 |
133 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { | 151 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { |
134 dismissal_reason_ = metrics_util::CLICKED_NEVER; | 152 dismissal_reason_ = metrics_util::CLICKED_NEVER; |
135 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 153 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
136 ManagePasswordsUIController* manage_passwords_ui_controller = | 154 ManagePasswordsUIController* manage_passwords_ui_controller = |
137 ManagePasswordsUIController::FromWebContents(web_contents()); | 155 ManagePasswordsUIController::FromWebContents(web_contents()); |
138 manage_passwords_ui_controller->NeverSavePassword(); | 156 manage_passwords_ui_controller->NeverSavePassword(); |
139 state_ = password_manager::ui::BLACKLIST_STATE; | 157 state_ = password_manager::ui::BLACKLIST_STATE; |
140 } | 158 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 password_manager::PasswordStore* password_store = | 200 password_manager::PasswordStore* password_store = |
183 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) | 201 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) |
184 .get(); | 202 .get(); |
185 DCHECK(password_store); | 203 DCHECK(password_store); |
186 if (action == REMOVE_PASSWORD) | 204 if (action == REMOVE_PASSWORD) |
187 password_store->RemoveLogin(password_form); | 205 password_store->RemoveLogin(password_form); |
188 else | 206 else |
189 password_store->AddLogin(password_form); | 207 password_store->AddLogin(password_form); |
190 } | 208 } |
191 | 209 |
| 210 void ManagePasswordsBubbleModel::OnChooseCredentials( |
| 211 const autofill::PasswordForm& password_form) { |
| 212 dismissal_reason_ = metrics_util::CLICKED_CREDENTIAL; |
| 213 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 214 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 215 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 216 manage_passwords_ui_controller->ChooseCredential(true, password_form); |
| 217 state_ = password_manager::ui::INACTIVE_STATE; |
| 218 } |
| 219 |
192 // static | 220 // static |
193 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 221 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
194 return GetFieldWidth(USERNAME_FIELD); | 222 return GetFieldWidth(USERNAME_FIELD); |
195 } | 223 } |
196 | 224 |
197 // static | 225 // static |
198 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 226 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
199 return GetFieldWidth(PASSWORD_FIELD); | 227 return GetFieldWidth(PASSWORD_FIELD); |
200 } | 228 } |
OLD | NEW |