| 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/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chrome/browser/password_manager/password_store_factory.h" | 9 #include "chrome/browser/password_manager/password_store_factory.h" |
| 10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); | 104 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); |
| 105 federated_credentials_ = DeepCopyForms(controller->GetFederatedForms()); | 105 federated_credentials_ = DeepCopyForms(controller->GetFederatedForms()); |
| 106 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { | 106 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 107 pending_password_ = *controller->GetCurrentForms()[0]; | 107 pending_password_ = *controller->GetCurrentForms()[0]; |
| 108 } else { | 108 } else { |
| 109 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); | 109 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) { | 112 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) { |
| 113 UpdatePendingStateTitle(); | 113 UpdatePendingStateTitle(); |
| 114 save_button_text_ = l10n_util::GetStringUTF16( |
| 115 pending_password_.is_password_change_form_without_username |
| 116 ? IDS_PASSWORD_MANAGER_UPDATE_BUTTON |
| 117 : IDS_PASSWORD_MANAGER_SAVE_BUTTON); |
| 114 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 118 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
| 115 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); | 119 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); |
| 116 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 120 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
| 117 title_ = | 121 title_ = |
| 118 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); | 122 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); |
| 119 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 123 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
| 120 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); | 124 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); |
| 121 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { | 125 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { |
| 122 // There is no title. | 126 // There is no title. |
| 123 } else { | 127 } else { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 244 |
| 241 void ManagePasswordsBubbleModel::OnSaveClicked() { | 245 void ManagePasswordsBubbleModel::OnSaveClicked() { |
| 242 dismissal_reason_ = metrics_util::CLICKED_SAVE; | 246 dismissal_reason_ = metrics_util::CLICKED_SAVE; |
| 243 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 247 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 244 ManagePasswordsUIController* manage_passwords_ui_controller = | 248 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 245 ManagePasswordsUIController::FromWebContents(web_contents()); | 249 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 246 manage_passwords_ui_controller->SavePassword(); | 250 manage_passwords_ui_controller->SavePassword(); |
| 247 state_ = password_manager::ui::MANAGE_STATE; | 251 state_ = password_manager::ui::MANAGE_STATE; |
| 248 } | 252 } |
| 249 | 253 |
| 254 void ManagePasswordsBubbleModel::OnUpdateClicked( |
| 255 const autofill::PasswordForm& password_form) { |
| 256 dismissal_reason_ = metrics_util::CLICKED_UPDATE; |
| 257 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
| 258 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 259 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 260 manage_passwords_ui_controller->UpdatePassword(password_form); |
| 261 state_ = password_manager::ui::MANAGE_STATE; |
| 262 } |
| 263 |
| 250 void ManagePasswordsBubbleModel::OnDoneClicked() { | 264 void ManagePasswordsBubbleModel::OnDoneClicked() { |
| 251 dismissal_reason_ = metrics_util::CLICKED_DONE; | 265 dismissal_reason_ = metrics_util::CLICKED_DONE; |
| 252 } | 266 } |
| 253 | 267 |
| 254 // TODO(gcasto): Is it worth having this be separate from OnDoneClicked()? | 268 // TODO(gcasto): Is it worth having this be separate from OnDoneClicked()? |
| 255 // User intent is pretty similar in both cases. | 269 // User intent is pretty similar in both cases. |
| 256 void ManagePasswordsBubbleModel::OnOKClicked() { | 270 void ManagePasswordsBubbleModel::OnOKClicked() { |
| 257 dismissal_reason_ = metrics_util::CLICKED_OK; | 271 dismissal_reason_ = metrics_util::CLICKED_OK; |
| 258 } | 272 } |
| 259 | 273 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 | 330 |
| 317 Profile* ManagePasswordsBubbleModel::GetProfile() const { | 331 Profile* ManagePasswordsBubbleModel::GetProfile() const { |
| 318 return GetProfileFromWebContents(web_contents()); | 332 return GetProfileFromWebContents(web_contents()); |
| 319 } | 333 } |
| 320 | 334 |
| 321 bool ManagePasswordsBubbleModel::IsNewUIActive() const { | 335 bool ManagePasswordsBubbleModel::IsNewUIActive() const { |
| 322 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 336 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 323 switches::kEnableCredentialManagerAPI); | 337 switches::kEnableCredentialManagerAPI); |
| 324 } | 338 } |
| 325 | 339 |
| 340 bool ManagePasswordsBubbleModel::ShouldShowMultipleAccountUpdateUI() const { |
| 341 return pending_password_.is_password_change_form_without_username && |
| 342 local_credentials_.size() > 1; |
| 343 } |
| 344 |
| 326 // static | 345 // static |
| 327 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 346 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
| 328 return GetFieldWidth(USERNAME_FIELD); | 347 return GetFieldWidth(USERNAME_FIELD); |
| 329 } | 348 } |
| 330 | 349 |
| 331 // static | 350 // static |
| 332 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 351 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
| 333 return GetFieldWidth(PASSWORD_FIELD); | 352 return GetFieldWidth(PASSWORD_FIELD); |
| 334 } | 353 } |
| 335 | 354 |
| 336 void ManagePasswordsBubbleModel::UpdatePendingStateTitle() { | 355 void ManagePasswordsBubbleModel::UpdatePendingStateTitle() { |
| 337 title_brand_link_range_ = gfx::Range(); | 356 title_brand_link_range_ = gfx::Range(); |
| 357 int title_message_id = |
| 358 pending_password_.is_password_change_form_without_username |
| 359 ? IDS_UPDATE_PASSWORD |
| 360 : IDS_SAVE_PASSWORD; |
| 338 if (never_save_passwords_) { | 361 if (never_save_passwords_) { |
| 339 title_ = l10n_util::GetStringUTF16( | 362 title_ = l10n_util::GetStringUTF16( |
| 340 IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE); | 363 IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE); |
| 341 } else if (IsSmartLockBrandingEnabled(GetProfile())) { | 364 } else if (IsSmartLockBrandingEnabled(GetProfile())) { |
| 342 // "Google Smart Lock" should be a hyperlink. | 365 // "Google Smart Lock" should be a hyperlink. |
| 343 base::string16 brand_link = | 366 base::string16 brand_link = |
| 344 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK); | 367 l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SMART_LOCK); |
| 345 size_t offset = 0; | 368 size_t offset = 0; |
| 346 title_ = l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, brand_link, &offset); | 369 title_ = l10n_util::GetStringFUTF16(title_message_id, brand_link, &offset); |
| 347 title_brand_link_range_ = gfx::Range(offset, offset + brand_link.length()); | 370 title_brand_link_range_ = gfx::Range(offset, offset + brand_link.length()); |
| 348 } else { | 371 } else { |
| 349 base::string16 brand_link = | 372 base::string16 brand_link = |
| 350 l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD_TITLE_BRAND); | 373 l10n_util::GetStringUTF16(IDS_SAVE_PASSWORD_TITLE_BRAND); |
| 351 title_ = l10n_util::GetStringFUTF16(IDS_SAVE_PASSWORD, brand_link); | 374 title_ = l10n_util::GetStringFUTF16(title_message_id, brand_link); |
| 352 } | 375 } |
| 353 } | 376 } |
| OLD | NEW |