| 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 "base/strings/utf_string_conversions.h" |
| 7 #include "chrome/browser/password_manager/password_store_factory.h" | 8 #include "chrome/browser/password_manager/password_store_factory.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/browser_finder.h" | 11 #include "chrome/browser/ui/browser_finder.h" |
| 11 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" | 12 #include "chrome/browser/ui/passwords/manage_passwords_ui_controller.h" |
| 12 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" | 13 #include "chrome/browser/ui/passwords/password_bubble_experiment.h" |
| 13 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 14 #include "components/feedback/feedback_data.h" | 15 #include "components/feedback/feedback_data.h" |
| 15 #include "components/feedback/feedback_util.h" | 16 #include "components/feedback/feedback_util.h" |
| 16 #include "components/password_manager/content/common/credential_manager_types.h" | 17 #include "components/password_manager/content/common/credential_manager_types.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 dismissal_reason_(metrics_util::NOT_DISPLAYED) { | 118 dismissal_reason_(metrics_util::NOT_DISPLAYED) { |
| 118 ManagePasswordsUIController* controller = | 119 ManagePasswordsUIController* controller = |
| 119 ManagePasswordsUIController::FromWebContents(web_contents); | 120 ManagePasswordsUIController::FromWebContents(web_contents); |
| 120 | 121 |
| 121 origin_ = controller->origin(); | 122 origin_ = controller->origin(); |
| 122 state_ = controller->state(); | 123 state_ = controller->state(); |
| 123 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) { | 124 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) { |
| 124 pending_password_ = controller->PendingPassword(); | 125 pending_password_ = controller->PendingPassword(); |
| 125 best_matches_ = controller->best_matches(); | 126 best_matches_ = controller->best_matches(); |
| 126 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 127 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
| 128 // TODO(vasilii): stealing the credential is a bad idea if we decide to |
| 129 // be in MANAGE_ACCOUNTS_STATE after showing the credential chooser UI. |
| 127 local_pending_credentials_.swap(controller->local_credentials_forms()); | 130 local_pending_credentials_.swap(controller->local_credentials_forms()); |
| 128 federated_pending_credentials_.swap( | 131 federated_pending_credentials_.swap( |
| 129 controller->federated_credentials_forms()); | 132 controller->federated_credentials_forms()); |
| 130 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { | 133 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 131 pending_password_ = *controller->local_credentials_forms()[0]; | 134 pending_password_ = *controller->local_credentials_forms()[0]; |
| 135 } else if (state_ == password_manager::ui::MANAGE_ACCOUNTS_STATE) { |
| 136 const auto& forms = controller->local_credentials_forms(); |
| 137 local_pending_credentials_.reserve(forms.size()); |
| 138 for (autofill::PasswordForm* form : forms) |
| 139 local_pending_credentials_.push_back(new autofill::PasswordForm(*form)); |
| 132 } else { | 140 } else { |
| 133 best_matches_ = controller->best_matches(); | 141 best_matches_ = controller->best_matches(); |
| 134 } | 142 } |
| 135 | 143 |
| 136 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) { | 144 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) { |
| 137 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); | 145 title_ = PendingStateTitleBasedOnSavePasswordPref(never_save_passwords_); |
| 138 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 146 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
| 139 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); | 147 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); |
| 140 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 148 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
| 141 title_ = | 149 title_ = |
| 142 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); | 150 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); |
| 143 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 151 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
| 144 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); | 152 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); |
| 145 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { | 153 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 146 // There is no title. | 154 // There is no title. |
| 155 } else if (state_ == password_manager::ui::MANAGE_ACCOUNTS_STATE) { |
| 156 title_ = l10n_util::GetStringFUTF16(IDS_MANAGE_ACCOUNTS_TITLE, |
| 157 base::UTF8ToUTF16(origin_.spec())); |
| 147 } else if (password_manager::ui::IsAskSubmitURLState(state_)) { | 158 } else if (password_manager::ui::IsAskSubmitURLState(state_)) { |
| 148 title_ = | 159 title_ = |
| 149 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_ASK_TO_SUBMIT_URL_TITLE); | 160 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_ASK_TO_SUBMIT_URL_TITLE); |
| 150 } else { | 161 } else { |
| 151 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); | 162 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_TITLE); |
| 152 } | 163 } |
| 153 | 164 |
| 154 if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 165 if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
| 155 base::string16 save_confirmation_link = | 166 base::string16 save_confirmation_link = |
| 156 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); | 167 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_LINK); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 void ManagePasswordsBubbleModel::OnManageLinkClicked() { | 325 void ManagePasswordsBubbleModel::OnManageLinkClicked() { |
| 315 dismissal_reason_ = metrics_util::CLICKED_MANAGE; | 326 dismissal_reason_ = metrics_util::CLICKED_MANAGE; |
| 316 ManagePasswordsUIController::FromWebContents(web_contents()) | 327 ManagePasswordsUIController::FromWebContents(web_contents()) |
| 317 ->NavigateToPasswordManagerSettingsPage(); | 328 ->NavigateToPasswordManagerSettingsPage(); |
| 318 } | 329 } |
| 319 | 330 |
| 320 void ManagePasswordsBubbleModel::OnAutoSignInToastTimeout() { | 331 void ManagePasswordsBubbleModel::OnAutoSignInToastTimeout() { |
| 321 dismissal_reason_ = metrics_util::AUTO_SIGNIN_TOAST_TIMEOUT; | 332 dismissal_reason_ = metrics_util::AUTO_SIGNIN_TOAST_TIMEOUT; |
| 322 } | 333 } |
| 323 | 334 |
| 335 void ManagePasswordsBubbleModel::OnAutoSignInClicked() { |
| 336 dismissal_reason_ = metrics_util::AUTO_SIGNIN_TOAST_CLICKED; |
| 337 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 338 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 339 manage_passwords_ui_controller->ManageAccounts(); |
| 340 state_ = password_manager::ui::MANAGE_ACCOUNTS_STATE; |
| 341 } |
| 342 |
| 324 void ManagePasswordsBubbleModel::OnPasswordAction( | 343 void ManagePasswordsBubbleModel::OnPasswordAction( |
| 325 const autofill::PasswordForm& password_form, | 344 const autofill::PasswordForm& password_form, |
| 326 PasswordAction action) { | 345 PasswordAction action) { |
| 327 if (!web_contents()) | 346 if (!web_contents()) |
| 328 return; | 347 return; |
| 329 Profile* profile = | 348 Profile* profile = |
| 330 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 349 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 331 password_manager::PasswordStore* password_store = | 350 password_manager::PasswordStore* password_store = |
| 332 PasswordStoreFactory::GetForProfile( | 351 PasswordStoreFactory::GetForProfile( |
| 333 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); | 352 profile, ServiceAccessType::EXPLICIT_ACCESS).get(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 356 | 375 |
| 357 // static | 376 // static |
| 358 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 377 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
| 359 return GetFieldWidth(USERNAME_FIELD); | 378 return GetFieldWidth(USERNAME_FIELD); |
| 360 } | 379 } |
| 361 | 380 |
| 362 // static | 381 // static |
| 363 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 382 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
| 364 return GetFieldWidth(PASSWORD_FIELD); | 383 return GetFieldWidth(PASSWORD_FIELD); |
| 365 } | 384 } |
| OLD | NEW |