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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 has_autofilled_ = true; | 710 has_autofilled_ = true; |
711 metrics_recorder_->SetManagerAction( | 711 metrics_recorder_->SetManagerAction( |
712 PasswordFormMetricsRecorder::kManagerActionAutofilled); | 712 PasswordFormMetricsRecorder::kManagerActionAutofilled); |
713 metrics_recorder_->RecordFillEvent( | 713 metrics_recorder_->RecordFillEvent( |
714 PasswordFormMetricsRecorder::kManagerFillEventAutofilled); | 714 PasswordFormMetricsRecorder::kManagerFillEventAutofilled); |
715 password_manager_->AutofillHttpAuth(best_matches_, *preferred_match_); | 715 password_manager_->AutofillHttpAuth(best_matches_, *preferred_match_); |
716 } | 716 } |
717 | 717 |
718 void PasswordFormManager::ProcessUpdate() { | 718 void PasswordFormManager::ProcessUpdate() { |
719 DCHECK_EQ(FormFetcher::State::NOT_WAITING, form_fetcher_->GetState()); | 719 DCHECK_EQ(FormFetcher::State::NOT_WAITING, form_fetcher_->GetState()); |
720 DCHECK(preferred_match_ || !pending_credentials_.federation_origin.unique()); | 720 DCHECK(preferred_match_ || !pending_credentials_.federation_origin.opaque()); |
721 // If we're doing an Update, we either autofilled correctly and need to | 721 // If we're doing an Update, we either autofilled correctly and need to |
722 // update the stats, or the user typed in a new password for autofilled | 722 // update the stats, or the user typed in a new password for autofilled |
723 // username, or the user selected one of the non-preferred matches, | 723 // username, or the user selected one of the non-preferred matches, |
724 // thus requiring a swap of preferred bits. | 724 // thus requiring a swap of preferred bits. |
725 DCHECK(!IsNewLogin() && pending_credentials_.preferred); | 725 DCHECK(!IsNewLogin() && pending_credentials_.preferred); |
726 DCHECK(!client_->IsIncognito()); | 726 DCHECK(!client_->IsIncognito()); |
727 | 727 |
728 UpdateMetadataForUsage(&pending_credentials_); | 728 UpdateMetadataForUsage(&pending_credentials_); |
729 | 729 |
730 base::RecordAction( | 730 base::RecordAction( |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1250 // Return any existing credential that has the same |password| saved already. | 1250 // Return any existing credential that has the same |password| saved already. |
1251 for (const auto& key_value : best_matches_) { | 1251 for (const auto& key_value : best_matches_) { |
1252 if (key_value.second->password_value == password) | 1252 if (key_value.second->password_value == password) |
1253 return key_value.second; | 1253 return key_value.second; |
1254 } | 1254 } |
1255 return nullptr; | 1255 return nullptr; |
1256 } | 1256 } |
1257 | 1257 |
1258 const PasswordForm* PasswordFormManager::FindBestSavedMatch( | 1258 const PasswordForm* PasswordFormManager::FindBestSavedMatch( |
1259 const PasswordForm* submitted_form) const { | 1259 const PasswordForm* submitted_form) const { |
1260 if (!submitted_form->federation_origin.unique()) | 1260 if (!submitted_form->federation_origin.opaque()) |
1261 return nullptr; | 1261 return nullptr; |
1262 | 1262 |
1263 // Return form with matching |username_value|. | 1263 // Return form with matching |username_value|. |
1264 auto it = best_matches_.find(submitted_form->username_value); | 1264 auto it = best_matches_.find(submitted_form->username_value); |
1265 if (it != best_matches_.end()) | 1265 if (it != best_matches_.end()) |
1266 return it->second; | 1266 return it->second; |
1267 | 1267 |
1268 // Match Credential API forms only by username. Stop here if nothing was found | 1268 // Match Credential API forms only by username. Stop here if nothing was found |
1269 // above. | 1269 // above. |
1270 if (submitted_form->type == autofill::PasswordForm::TYPE_API) | 1270 if (submitted_form->type == autofill::PasswordForm::TYPE_API) |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1507 // Username has changed. We set this selected username as the real | 1507 // Username has changed. We set this selected username as the real |
1508 // username. Given that |username_value| is part of the Sync and | 1508 // username. Given that |username_value| is part of the Sync and |
1509 // PasswordStore primary key, the old primary key must be supplied. | 1509 // PasswordStore primary key, the old primary key must be supplied. |
1510 old_primary_key = pending_credentials_; | 1510 old_primary_key = pending_credentials_; |
1511 pending_credentials_.username_value = selected_username_; | 1511 pending_credentials_.username_value = selected_username_; |
1512 // TODO(crbug.com/188908) This branch currently never executes (bound to | 1512 // TODO(crbug.com/188908) This branch currently never executes (bound to |
1513 // the other usernames experiment). Updating related credentials would be | 1513 // the other usernames experiment). Updating related credentials would be |
1514 // complicated, so we skip that, given it influences no users. | 1514 // complicated, so we skip that, given it influences no users. |
1515 update_related_credentials = false; | 1515 update_related_credentials = false; |
1516 } else if (observed_form_.new_password_element.empty() && | 1516 } else if (observed_form_.new_password_element.empty() && |
1517 pending_credentials_.federation_origin.unique() && | 1517 pending_credentials_.federation_origin.opaque() && |
1518 !IsValidAndroidFacetURI(pending_credentials_.signon_realm) && | 1518 !IsValidAndroidFacetURI(pending_credentials_.signon_realm) && |
1519 (pending_credentials_.password_element.empty() || | 1519 (pending_credentials_.password_element.empty() || |
1520 pending_credentials_.username_element.empty() || | 1520 pending_credentials_.username_element.empty() || |
1521 pending_credentials_.submit_element.empty())) { | 1521 pending_credentials_.submit_element.empty())) { |
1522 // If |observed_form_| is a sign-in form and some of the element names are | 1522 // If |observed_form_| is a sign-in form and some of the element names are |
1523 // empty, it is likely the first time a credential saved on a | 1523 // empty, it is likely the first time a credential saved on a |
1524 // sign-up/change password form is used. Given that |password_element| and | 1524 // sign-up/change password form is used. Given that |password_element| and |
1525 // |username_element| are part of Sync and PasswordStore primary key, the | 1525 // |username_element| are part of Sync and PasswordStore primary key, the |
1526 // old primary key must be used if the new names shal be saved. | 1526 // old primary key must be used if the new names shal be saved. |
1527 old_primary_key = pending_credentials_; | 1527 old_primary_key = pending_credentials_; |
1528 pending_credentials_.password_element = observed_form_.password_element; | 1528 pending_credentials_.password_element = observed_form_.password_element; |
1529 pending_credentials_.username_element = observed_form_.username_element; | 1529 pending_credentials_.username_element = observed_form_.username_element; |
1530 pending_credentials_.submit_element = observed_form_.submit_element; | 1530 pending_credentials_.submit_element = observed_form_.submit_element; |
1531 update_related_credentials = true; | 1531 update_related_credentials = true; |
1532 } else { | 1532 } else { |
1533 update_related_credentials = | 1533 update_related_credentials = |
1534 pending_credentials_.federation_origin.unique(); | 1534 pending_credentials_.federation_origin.opaque(); |
1535 } | 1535 } |
1536 | 1536 |
1537 // If this was a password update, then update all non-best matches entries | 1537 // If this was a password update, then update all non-best matches entries |
1538 // with the same username and the same old password. | 1538 // with the same username and the same old password. |
1539 if (update_related_credentials) { | 1539 if (update_related_credentials) { |
1540 auto updated_password_it = | 1540 auto updated_password_it = |
1541 best_matches_.find(pending_credentials_.username_value); | 1541 best_matches_.find(pending_credentials_.username_value); |
1542 DCHECK(best_matches_.end() != updated_password_it); | 1542 DCHECK(best_matches_.end() != updated_password_it); |
1543 const base::string16& old_password = | 1543 const base::string16& old_password = |
1544 updated_password_it->second->password_value; | 1544 updated_password_it->second->password_value; |
1545 for (auto* not_best_match : not_best_matches_) { | 1545 for (auto* not_best_match : not_best_matches_) { |
1546 if (not_best_match->username_value == | 1546 if (not_best_match->username_value == |
1547 pending_credentials_.username_value && | 1547 pending_credentials_.username_value && |
1548 not_best_match->password_value == old_password) { | 1548 not_best_match->password_value == old_password) { |
1549 credentials_to_update->push_back(*not_best_match); | 1549 credentials_to_update->push_back(*not_best_match); |
1550 credentials_to_update->back().password_value = | 1550 credentials_to_update->back().password_value = |
1551 pending_credentials_.password_value; | 1551 pending_credentials_.password_value; |
1552 } | 1552 } |
1553 } | 1553 } |
1554 } | 1554 } |
1555 | 1555 |
1556 return old_primary_key; | 1556 return old_primary_key; |
1557 } | 1557 } |
1558 | 1558 |
1559 } // namespace password_manager | 1559 } // namespace password_manager |
OLD | NEW |