OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "components/password_manager/core/browser/password_form_manager.h" | 5 #include "components/password_manager/core/browser/password_form_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 pending_credentials_.other_possible_usernames = | 263 pending_credentials_.other_possible_usernames = |
264 credentials.other_possible_usernames; | 264 credentials.other_possible_usernames; |
265 } | 265 } |
266 | 266 |
267 pending_credentials_.action = credentials.action; | 267 pending_credentials_.action = credentials.action; |
268 // If the user selected credentials we autofilled from a PasswordForm | 268 // If the user selected credentials we autofilled from a PasswordForm |
269 // that contained no action URL (IE6/7 imported passwords, for example), | 269 // that contained no action URL (IE6/7 imported passwords, for example), |
270 // bless it with the action URL from the observed form. See bug 1107719. | 270 // bless it with the action URL from the observed form. See bug 1107719. |
271 if (pending_credentials_.action.is_empty()) | 271 if (pending_credentials_.action.is_empty()) |
272 pending_credentials_.action = observed_form_.action; | 272 pending_credentials_.action = observed_form_.action; |
273 // Similarly, bless incomplete credentials with *_element info. | |
274 if (pending_credentials_.password_element.empty()) | |
275 pending_credentials_.password_element = observed_form_.password_element; | |
276 if (pending_credentials_.username_element.empty()) | |
277 pending_credentials_.username_element = observed_form_.username_element; | |
278 if (pending_credentials_.submit_element.empty()) | |
279 pending_credentials_.submit_element = observed_form_.submit_element; | |
280 | 273 |
281 pending_credentials_.password_value = credentials.password_value; | 274 pending_credentials_.password_value = credentials.password_value; |
282 pending_credentials_.preferred = credentials.preferred; | 275 pending_credentials_.preferred = credentials.preferred; |
283 | 276 |
284 if (user_action_ == kUserActionOverridePassword && | 277 if (user_action_ == kUserActionOverridePassword && |
285 pending_credentials_.type == PasswordForm::TYPE_GENERATED && | 278 pending_credentials_.type == PasswordForm::TYPE_GENERATED && |
286 !has_generated_password_) { | 279 !has_generated_password_) { |
287 LogPasswordGenerationSubmissionEvent(PASSWORD_OVERRIDDEN); | 280 LogPasswordGenerationSubmissionEvent(PASSWORD_OVERRIDDEN); |
288 } | 281 } |
289 | 282 |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 // has a different preference on each site. For example, on /a, he wants the | 567 // has a different preference on each site. For example, on /a, he wants the |
575 // general empty-path login so it is flagged as preferred, but on /b he logs | 568 // general empty-path login so it is flagged as preferred, but on /b he logs |
576 // in with a different saved entry - we don't want to remove the preferred | 569 // in with a different saved entry - we don't want to remove the preferred |
577 // status of the former because upon return to /a it won't be the default- | 570 // status of the former because upon return to /a it won't be the default- |
578 // fill match. | 571 // fill match. |
579 // TODO(timsteele): Bug 1188626 - expire the master copies. | 572 // TODO(timsteele): Bug 1188626 - expire the master copies. |
580 PasswordForm copy(pending_credentials_); | 573 PasswordForm copy(pending_credentials_); |
581 copy.origin = observed_form_.origin; | 574 copy.origin = observed_form_.origin; |
582 copy.action = observed_form_.action; | 575 copy.action = observed_form_.action; |
583 password_store->AddLogin(copy); | 576 password_store->AddLogin(copy); |
| 577 } else if (pending_credentials_.password_element.empty() || |
| 578 pending_credentials_.username_element.empty() || |
| 579 pending_credentials_.submit_element.empty()) { |
| 580 // password_element and username_element can't be updated because they are |
| 581 // part of Sync and PasswordStore primary key. Thus, we must delete the old |
| 582 // one and add again. |
| 583 password_store->RemoveLogin(pending_credentials_); |
| 584 pending_credentials_.password_element = observed_form_.password_element; |
| 585 pending_credentials_.username_element = observed_form_.username_element; |
| 586 pending_credentials_.submit_element = observed_form_.submit_element; |
| 587 password_store->AddLogin(pending_credentials_); |
584 } else { | 588 } else { |
585 password_store->UpdateLogin(pending_credentials_); | 589 password_store->UpdateLogin(pending_credentials_); |
586 } | 590 } |
587 } | 591 } |
588 | 592 |
589 bool PasswordFormManager::UpdatePendingCredentialsIfOtherPossibleUsername( | 593 bool PasswordFormManager::UpdatePendingCredentialsIfOtherPossibleUsername( |
590 const base::string16& username) { | 594 const base::string16& username) { |
591 for (PasswordFormMap::const_iterator it = best_matches_.begin(); | 595 for (PasswordFormMap::const_iterator it = best_matches_.begin(); |
592 it != best_matches_.end(); ++it) { | 596 it != best_matches_.end(); ++it) { |
593 for (size_t i = 0; i < it->second->other_possible_usernames.size(); ++i) { | 597 for (size_t i = 0; i < it->second->other_possible_usernames.size(); ++i) { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); | 694 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); |
691 } | 695 } |
692 | 696 |
693 void PasswordFormManager::SubmitFailed() { | 697 void PasswordFormManager::SubmitFailed() { |
694 submit_result_ = kSubmitResultFailed; | 698 submit_result_ = kSubmitResultFailed; |
695 if (has_generated_password_) | 699 if (has_generated_password_) |
696 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); | 700 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); |
697 } | 701 } |
698 | 702 |
699 } // namespace password_manager | 703 } // namespace password_manager |
OLD | NEW |