Chromium Code Reviews| 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 | 57 InitPasswordsModelFromController(controller, this); |
| 58 // directly rather than the model pulling from the controller. Perhaps like | |
| 59 // `controller->PopulateModel(this)`. | |
| 60 state_ = controller->state(); | |
| 61 if (password_manager::ui::IsPendingState(state_)) | |
| 62 pending_credentials_ = controller->PendingCredentials(); | |
| 63 best_matches_ = controller->best_matches(); | |
| 64 | 58 |
| 65 if (password_manager::ui::IsPendingState(state_)) { | 59 if (password_manager::ui::IsPendingState(state_)) { |
| 66 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD); | 60 title_ = l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD); |
| 67 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 61 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
| 68 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); | 62 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); |
| 69 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 63 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
| 70 title_ = | 64 title_ = |
| 71 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); | 65 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); |
| 66 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | |
| 67 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); | |
| 72 } else { | 68 } else { |
| 73 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); | 69 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); |
| 74 } | 70 } |
| 75 | 71 |
| 76 base::string16 save_confirmation_link = | 72 base::string16 save_confirmation_link = |
| 77 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); | 73 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); |
| 78 size_t offset; | 74 size_t offset; |
| 79 save_confirmation_text_ = | 75 save_confirmation_text_ = |
| 80 l10n_util::GetStringFUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT, | 76 l10n_util::GetStringFUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TEXT, |
| 81 save_confirmation_link, &offset); | 77 save_confirmation_link, &offset); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 95 display_disposition_ = metrics_util::MANUAL_WITH_PASSWORD_PENDING; | 91 display_disposition_ = metrics_util::MANUAL_WITH_PASSWORD_PENDING; |
| 96 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 92 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
| 97 display_disposition_ = metrics_util::MANUAL_BLACKLISTED; | 93 display_disposition_ = metrics_util::MANUAL_BLACKLISTED; |
| 98 } else { | 94 } else { |
| 99 display_disposition_ = metrics_util::MANUAL_MANAGE_PASSWORDS; | 95 display_disposition_ = metrics_util::MANUAL_MANAGE_PASSWORDS; |
| 100 } | 96 } |
| 101 } else { | 97 } else { |
| 102 if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 98 if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
| 103 display_disposition_ = | 99 display_disposition_ = |
| 104 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION; | 100 metrics_util::AUTOMATIC_GENERATED_PASSWORD_CONFIRMATION; |
| 101 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | |
| 102 display_disposition_ = metrics_util::AUTOMATIC_WITH_CREDENTIALS_PENDING; | |
| 105 } else { | 103 } else { |
| 106 display_disposition_ = metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; | 104 display_disposition_ = metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING; |
| 107 } | 105 } |
| 108 } | 106 } |
| 109 metrics_util::LogUIDisplayDisposition(display_disposition_); | 107 metrics_util::LogUIDisplayDisposition(display_disposition_); |
| 110 | 108 |
| 111 // Default to a dismissal reason of "no interaction". If the user interacts | 109 // 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 | 110 // with the button in such a way that it closes, we'll reset this value |
| 113 // accordingly. | 111 // accordingly. |
| 114 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION; | 112 dismissal_reason_ = metrics_util::NO_DIRECT_INTERACTION; |
| 113 | |
| 114 ManagePasswordsUIController* controller = | |
| 115 ManagePasswordsUIController::FromWebContents(web_contents()); | |
| 116 controller->OnBubbleShown(); | |
| 115 } | 117 } |
| 116 | 118 |
| 117 void ManagePasswordsBubbleModel::OnBubbleHidden() { | 119 void ManagePasswordsBubbleModel::OnBubbleHidden() { |
| 120 if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | |
| 121 // It's time to run the pending callback if it wasn't called in | |
| 122 // OnChooseCredentials(). | |
| 123 ManagePasswordsUIController* manage_passwords_ui_controller = | |
| 124 ManagePasswordsUIController::FromWebContents(web_contents()); | |
| 125 manage_passwords_ui_controller->ChooseCredential(false, | |
| 126 autofill::PasswordForm()); | |
| 127 state_ = password_manager::ui::INACTIVE_STATE; | |
| 128 } | |
| 118 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) | 129 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) |
| 119 return; | 130 return; |
| 120 | 131 |
| 121 metrics_util::LogUIDismissalReason(dismissal_reason_); | 132 metrics_util::LogUIDismissalReason(dismissal_reason_); |
| 122 // Other use cases have been reported in the callbacks like OnSaveClicked(). | 133 // Other use cases have been reported in the callbacks like OnSaveClicked(). |
| 123 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) | 134 if (dismissal_reason_ == metrics_util::NO_DIRECT_INTERACTION) |
| 124 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 135 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 125 } | 136 } |
| 126 | 137 |
| 127 void ManagePasswordsBubbleModel::OnNopeClicked() { | 138 void ManagePasswordsBubbleModel::OnNopeClicked() { |
| 128 dismissal_reason_ = metrics_util::CLICKED_NOPE; | 139 dismissal_reason_ = metrics_util::CLICKED_NOPE; |
| 129 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 140 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 130 state_ = password_manager::ui::PENDING_PASSWORD_STATE; | 141 if (state_ != password_manager::ui::CREDENTIAL_REQUEST_STATE) |
| 142 state_ = password_manager::ui::PENDING_PASSWORD_STATE; | |
| 131 } | 143 } |
| 132 | 144 |
| 133 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { | 145 void ManagePasswordsBubbleModel::OnNeverForThisSiteClicked() { |
| 134 dismissal_reason_ = metrics_util::CLICKED_NEVER; | 146 dismissal_reason_ = metrics_util::CLICKED_NEVER; |
| 135 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 147 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 136 ManagePasswordsUIController* manage_passwords_ui_controller = | 148 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 137 ManagePasswordsUIController::FromWebContents(web_contents()); | 149 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 138 manage_passwords_ui_controller->NeverSavePassword(); | 150 manage_passwords_ui_controller->NeverSavePassword(); |
| 139 state_ = password_manager::ui::BLACKLIST_STATE; | 151 state_ = password_manager::ui::BLACKLIST_STATE; |
| 140 } | 152 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 password_manager::PasswordStore* password_store = | 194 password_manager::PasswordStore* password_store = |
| 183 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) | 195 PasswordStoreFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS) |
| 184 .get(); | 196 .get(); |
| 185 DCHECK(password_store); | 197 DCHECK(password_store); |
| 186 if (action == REMOVE_PASSWORD) | 198 if (action == REMOVE_PASSWORD) |
| 187 password_store->RemoveLogin(password_form); | 199 password_store->RemoveLogin(password_form); |
| 188 else | 200 else |
| 189 password_store->AddLogin(password_form); | 201 password_store->AddLogin(password_form); |
| 190 } | 202 } |
| 191 | 203 |
| 204 void ManagePasswordsBubbleModel::OnChooseCredentials( | |
| 205 const autofill::PasswordForm& password_form) { | |
| 206 dismissal_reason_ = metrics_util::CLICKED_CREDENTIAL; | |
| 207 RecordExperimentStatistics(web_contents(), dismissal_reason_); | |
| 208 ManagePasswordsUIController* manage_passwords_ui_controller = | |
| 209 ManagePasswordsUIController::FromWebContents(web_contents()); | |
| 210 manage_passwords_ui_controller->ChooseCredential(true, password_form); | |
| 211 state_ = password_manager::ui::INACTIVE_STATE; | |
| 212 } | |
| 213 | |
| 192 // static | 214 // static |
| 193 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 215 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
| 194 return GetFieldWidth(USERNAME_FIELD); | 216 return GetFieldWidth(USERNAME_FIELD); |
| 195 } | 217 } |
| 196 | 218 |
| 197 // static | 219 // static |
| 198 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 220 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
| 199 return GetFieldWidth(PASSWORD_FIELD); | 221 return GetFieldWidth(PASSWORD_FIELD); |
| 200 } | 222 } |
| 223 | |
| 224 void InitPasswordsModelFromController(ManagePasswordsUIController* controller, | |
| 225 ManagePasswordsBubbleModel* model) { | |
|
Mike West
2014/11/21 11:21:12
I think I'd prefer to see this live either on the
vasilii
2014/11/21 16:45:37
Done.
| |
| 226 model->state_ = controller->state(); | |
| 227 if (password_manager::ui::IsPendingState(model->state_)) | |
| 228 model->pending_password_ = controller->PendingPassword(); | |
| 229 if (model->state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) | |
| 230 model->pending_credentials_.swap(controller->new_password_forms_); | |
| 231 else | |
| 232 model->best_matches_ = controller->best_matches(); | |
| 233 } | |
| OLD | NEW |