| 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/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" |
| 11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 12 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" | 12 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" |
| 13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
| 14 #include "components/feedback/feedback_data.h" | 14 #include "components/feedback/feedback_data.h" |
| 15 #include "components/feedback/feedback_util.h" | 15 #include "components/feedback/feedback_util.h" |
| 16 #include "components/password_manager/content/common/credential_manager_types.h" |
| 16 #include "components/password_manager/core/browser/password_manager_url_collecti
on_experiment.h" | 17 #include "components/password_manager/core/browser/password_manager_url_collecti
on_experiment.h" |
| 17 #include "components/password_manager/core/browser/password_store.h" | 18 #include "components/password_manager/core/browser/password_store.h" |
| 18 #include "components/password_manager/core/common/password_manager_ui.h" | 19 #include "components/password_manager/core/common/password_manager_ui.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
| 21 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 22 | 23 |
| 23 using autofill::PasswordFormMap; | 24 using autofill::PasswordFormMap; |
| 24 using feedback::FeedbackData; | 25 using feedback::FeedbackData; |
| 25 using content::WebContents; | 26 using content::WebContents; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 never_save_passwords_(false), | 115 never_save_passwords_(false), |
| 115 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), | 116 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), |
| 116 dismissal_reason_(metrics_util::NOT_DISPLAYED) { | 117 dismissal_reason_(metrics_util::NOT_DISPLAYED) { |
| 117 ManagePasswordsUIController* controller = | 118 ManagePasswordsUIController* controller = |
| 118 ManagePasswordsUIController::FromWebContents(web_contents); | 119 ManagePasswordsUIController::FromWebContents(web_contents); |
| 119 | 120 |
| 120 origin_ = controller->origin(); | 121 origin_ = controller->origin(); |
| 121 state_ = controller->state(); | 122 state_ = controller->state(); |
| 122 if (password_manager::ui::IsPendingState(state_)) | 123 if (password_manager::ui::IsPendingState(state_)) |
| 123 pending_password_ = controller->PendingPassword(); | 124 pending_password_ = controller->PendingPassword(); |
| 124 if (password_manager::ui::IsCredentialsState(state_)) | 125 if (password_manager::ui::IsCredentialsState(state_)) { |
| 125 pending_credentials_.swap(controller->new_password_forms()); | 126 local_pending_credentials_.swap(controller->local_credentials_forms()); |
| 126 else | 127 federated_pending_credentials_.swap( |
| 128 controller->federated_credentials_forms()); |
| 129 } else { |
| 127 best_matches_ = controller->best_matches(); | 130 best_matches_ = controller->best_matches(); |
| 131 } |
| 128 | 132 |
| 129 if (password_manager::ui::IsPendingState(state_)) { | 133 if (password_manager::ui::IsPendingState(state_)) { |
| 130 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); | 134 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); |
| 131 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 135 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
| 132 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); | 136 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); |
| 133 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 137 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
| 134 title_ = | 138 title_ = |
| 135 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); | 139 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); |
| 136 } else if (password_manager::ui::IsCredentialsState(state_)) { | 140 } else if (password_manager::ui::IsCredentialsState(state_)) { |
| 137 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); | 141 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 ManagePasswordsUIController::FromWebContents(web_contents()); | 194 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 191 controller->OnBubbleShown(); | 195 controller->OnBubbleShown(); |
| 192 } | 196 } |
| 193 | 197 |
| 194 void ManagePasswordsBubbleModel::OnBubbleHidden() { | 198 void ManagePasswordsBubbleModel::OnBubbleHidden() { |
| 195 if (password_manager::ui::IsCredentialsState(state_) && web_contents()) { | 199 if (password_manager::ui::IsCredentialsState(state_) && web_contents()) { |
| 196 // It's time to run the pending callback if it wasn't called in | 200 // It's time to run the pending callback if it wasn't called in |
| 197 // OnChooseCredentials(). | 201 // OnChooseCredentials(). |
| 198 ManagePasswordsUIController* manage_passwords_ui_controller = | 202 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 199 ManagePasswordsUIController::FromWebContents(web_contents()); | 203 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 200 manage_passwords_ui_controller->ChooseCredential(false, | 204 manage_passwords_ui_controller->ChooseCredential( |
| 201 autofill::PasswordForm()); | 205 autofill::PasswordForm(), |
| 206 password_manager::CredentialType::CREDENTIAL_TYPE_EMPTY); |
| 202 state_ = password_manager::ui::INACTIVE_STATE; | 207 state_ = password_manager::ui::INACTIVE_STATE; |
| 203 } | 208 } |
| 204 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) | 209 if (dismissal_reason_ == metrics_util::NOT_DISPLAYED) |
| 205 return; | 210 return; |
| 206 | 211 |
| 207 if (password_manager::ui::IsAskSubmitURLState(state_)) { | 212 if (password_manager::ui::IsAskSubmitURLState(state_)) { |
| 208 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE; | 213 state_ = password_manager::ui::ASK_USER_REPORT_URL_BUBBLE_SHOWN_STATE; |
| 209 metrics_util::LogAllowToCollectURLBubbleUIDismissalReason( | 214 metrics_util::LogAllowToCollectURLBubbleUIDismissalReason( |
| 210 dismissal_reason_); | 215 dismissal_reason_); |
| 211 // Return since we do not want to include "Allow to collect URL?" bubble | 216 // Return since we do not want to include "Allow to collect URL?" bubble |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 PasswordStoreFactory::GetForProfile( | 315 PasswordStoreFactory::GetForProfile( |
| 311 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); | 316 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); |
| 312 DCHECK(password_store); | 317 DCHECK(password_store); |
| 313 if (action == REMOVE_PASSWORD) | 318 if (action == REMOVE_PASSWORD) |
| 314 password_store->RemoveLogin(password_form); | 319 password_store->RemoveLogin(password_form); |
| 315 else | 320 else |
| 316 password_store->AddLogin(password_form); | 321 password_store->AddLogin(password_form); |
| 317 } | 322 } |
| 318 | 323 |
| 319 void ManagePasswordsBubbleModel::OnChooseCredentials( | 324 void ManagePasswordsBubbleModel::OnChooseCredentials( |
| 320 const autofill::PasswordForm& password_form) { | 325 const autofill::PasswordForm& password_form, |
| 326 password_manager::CredentialType credential_type) { |
| 321 dismissal_reason_ = metrics_util::CLICKED_CREDENTIAL; | 327 dismissal_reason_ = metrics_util::CLICKED_CREDENTIAL; |
| 322 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 328 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 323 ManagePasswordsUIController* manage_passwords_ui_controller = | 329 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 324 ManagePasswordsUIController::FromWebContents(web_contents()); | 330 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 325 manage_passwords_ui_controller->ChooseCredential(true, password_form); | 331 manage_passwords_ui_controller->ChooseCredential(password_form, |
| 332 credential_type); |
| 326 state_ = password_manager::ui::INACTIVE_STATE; | 333 state_ = password_manager::ui::INACTIVE_STATE; |
| 327 } | 334 } |
| 328 | 335 |
| 329 Profile* ManagePasswordsBubbleModel::GetProfile() const { | 336 Profile* ManagePasswordsBubbleModel::GetProfile() const { |
| 330 return GetProfileFromWebContents(web_contents()); | 337 return GetProfileFromWebContents(web_contents()); |
| 331 } | 338 } |
| 332 | 339 |
| 333 // static | 340 // static |
| 334 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 341 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
| 335 return GetFieldWidth(USERNAME_FIELD); | 342 return GetFieldWidth(USERNAME_FIELD); |
| 336 } | 343 } |
| 337 | 344 |
| 338 // static | 345 // static |
| 339 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 346 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
| 340 return GetFieldWidth(PASSWORD_FIELD); | 347 return GetFieldWidth(PASSWORD_FIELD); |
| 341 } | 348 } |
| OLD | NEW |