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 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 content::WebContents* web_contents) | 89 content::WebContents* web_contents) |
90 : content::WebContentsObserver(web_contents), | 90 : content::WebContentsObserver(web_contents), |
91 never_save_passwords_(false), | 91 never_save_passwords_(false), |
92 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), | 92 display_disposition_(metrics_util::AUTOMATIC_WITH_PASSWORD_PENDING), |
93 dismissal_reason_(metrics_util::NOT_DISPLAYED) { | 93 dismissal_reason_(metrics_util::NOT_DISPLAYED) { |
94 ManagePasswordsUIController* controller = | 94 ManagePasswordsUIController* controller = |
95 ManagePasswordsUIController::FromWebContents(web_contents); | 95 ManagePasswordsUIController::FromWebContents(web_contents); |
96 | 96 |
97 origin_ = controller->origin(); | 97 origin_ = controller->origin(); |
98 state_ = controller->state(); | 98 state_ = controller->state(); |
99 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) { | 99 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE || |
| 100 state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { |
100 pending_password_ = controller->PendingPassword(); | 101 pending_password_ = controller->PendingPassword(); |
101 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); | 102 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); |
102 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 103 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
103 // We don't need anything. | 104 // We don't need anything. |
104 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 105 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
105 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); | 106 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); |
106 federated_credentials_ = DeepCopyForms(controller->GetFederatedForms()); | 107 federated_credentials_ = DeepCopyForms(controller->GetFederatedForms()); |
107 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { | 108 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { |
108 pending_password_ = *controller->GetCurrentForms()[0]; | 109 pending_password_ = *controller->GetCurrentForms()[0]; |
109 } else { | 110 } else { |
110 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); | 111 local_credentials_ = DeepCopyForms(controller->GetCurrentForms()); |
111 } | 112 } |
112 | 113 |
113 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE) { | 114 if (state_ == password_manager::ui::PENDING_PASSWORD_STATE || |
| 115 state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE) { |
114 UpdatePendingStateTitle(); | 116 UpdatePendingStateTitle(); |
115 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { | 117 } else if (state_ == password_manager::ui::BLACKLIST_STATE) { |
116 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); | 118 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_BLACKLISTED_TITLE); |
117 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { | 119 } else if (state_ == password_manager::ui::CONFIRMATION_STATE) { |
118 title_ = | 120 title_ = |
119 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); | 121 l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CONFIRM_GENERATED_TITLE); |
120 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { | 122 } else if (state_ == password_manager::ui::CREDENTIAL_REQUEST_STATE) { |
121 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); | 123 title_ = l10n_util::GetStringUTF16(IDS_MANAGE_PASSWORDS_CHOOSE_TITLE); |
122 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { | 124 } else if (state_ == password_manager::ui::AUTO_SIGNIN_STATE) { |
123 // There is no title. | 125 // There is no title. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 | 243 |
242 void ManagePasswordsBubbleModel::OnSaveClicked() { | 244 void ManagePasswordsBubbleModel::OnSaveClicked() { |
243 dismissal_reason_ = metrics_util::CLICKED_SAVE; | 245 dismissal_reason_ = metrics_util::CLICKED_SAVE; |
244 RecordExperimentStatistics(web_contents(), dismissal_reason_); | 246 RecordExperimentStatistics(web_contents(), dismissal_reason_); |
245 ManagePasswordsUIController* manage_passwords_ui_controller = | 247 ManagePasswordsUIController* manage_passwords_ui_controller = |
246 ManagePasswordsUIController::FromWebContents(web_contents()); | 248 ManagePasswordsUIController::FromWebContents(web_contents()); |
247 manage_passwords_ui_controller->SavePassword(); | 249 manage_passwords_ui_controller->SavePassword(); |
248 state_ = password_manager::ui::MANAGE_STATE; | 250 state_ = password_manager::ui::MANAGE_STATE; |
249 } | 251 } |
250 | 252 |
| 253 void ManagePasswordsBubbleModel::OnUpdateClicked( |
| 254 const autofill::PasswordForm& password_form) { |
| 255 ManagePasswordsUIController* manage_passwords_ui_controller = |
| 256 ManagePasswordsUIController::FromWebContents(web_contents()); |
| 257 manage_passwords_ui_controller->UpdatePassword(password_form); |
| 258 state_ = password_manager::ui::MANAGE_STATE; |
| 259 } |
| 260 |
251 void ManagePasswordsBubbleModel::OnDoneClicked() { | 261 void ManagePasswordsBubbleModel::OnDoneClicked() { |
252 dismissal_reason_ = metrics_util::CLICKED_DONE; | 262 dismissal_reason_ = metrics_util::CLICKED_DONE; |
253 } | 263 } |
254 | 264 |
255 // TODO(gcasto): Is it worth having this be separate from OnDoneClicked()? | 265 // TODO(gcasto): Is it worth having this be separate from OnDoneClicked()? |
256 // User intent is pretty similar in both cases. | 266 // User intent is pretty similar in both cases. |
257 void ManagePasswordsBubbleModel::OnOKClicked() { | 267 void ManagePasswordsBubbleModel::OnOKClicked() { |
258 dismissal_reason_ = metrics_util::CLICKED_OK; | 268 dismissal_reason_ = metrics_util::CLICKED_OK; |
259 } | 269 } |
260 | 270 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 | 327 |
318 Profile* ManagePasswordsBubbleModel::GetProfile() const { | 328 Profile* ManagePasswordsBubbleModel::GetProfile() const { |
319 return GetProfileFromWebContents(web_contents()); | 329 return GetProfileFromWebContents(web_contents()); |
320 } | 330 } |
321 | 331 |
322 bool ManagePasswordsBubbleModel::IsNewUIActive() const { | 332 bool ManagePasswordsBubbleModel::IsNewUIActive() const { |
323 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 333 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
324 switches::kEnableCredentialManagerAPI); | 334 switches::kEnableCredentialManagerAPI); |
325 } | 335 } |
326 | 336 |
| 337 bool ManagePasswordsBubbleModel::ShouldShowMultipleAccountUpdateUI() const { |
| 338 return state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE && |
| 339 local_credentials_.size() > 1; |
| 340 } |
| 341 |
327 // static | 342 // static |
328 int ManagePasswordsBubbleModel::UsernameFieldWidth() { | 343 int ManagePasswordsBubbleModel::UsernameFieldWidth() { |
329 return GetFieldWidth(USERNAME_FIELD); | 344 return GetFieldWidth(USERNAME_FIELD); |
330 } | 345 } |
331 | 346 |
332 // static | 347 // static |
333 int ManagePasswordsBubbleModel::PasswordFieldWidth() { | 348 int ManagePasswordsBubbleModel::PasswordFieldWidth() { |
334 return GetFieldWidth(PASSWORD_FIELD); | 349 return GetFieldWidth(PASSWORD_FIELD); |
335 } | 350 } |
336 | 351 |
337 void ManagePasswordsBubbleModel::UpdatePendingStateTitle() { | 352 void ManagePasswordsBubbleModel::UpdatePendingStateTitle() { |
338 title_brand_link_range_ = gfx::Range(); | 353 title_brand_link_range_ = gfx::Range(); |
339 if (never_save_passwords_) { | 354 if (never_save_passwords_) { |
340 title_ = l10n_util::GetStringUTF16( | 355 title_ = l10n_util::GetStringUTF16( |
341 IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE); | 356 IDS_MANAGE_PASSWORDS_BLACKLIST_CONFIRMATION_TITLE); |
342 } else { | 357 } else { |
343 GetSavePasswordDialogTitleTextAndLinkRange( | 358 GetSavePasswordDialogTitleTextAndLinkRange( |
344 web_contents()->GetVisibleURL(), origin(), | 359 web_contents()->GetVisibleURL(), origin(), |
345 IsSmartLockBrandingEnabled(GetProfile()), &title_, | 360 IsSmartLockBrandingEnabled(GetProfile()), |
| 361 state_ == password_manager::ui::PENDING_PASSWORD_UPDATE_STATE, &title_, |
346 &title_brand_link_range_); | 362 &title_brand_link_range_); |
347 } | 363 } |
348 } | 364 } |
OLD | NEW |