Chromium Code Reviews| 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 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 626 autofill_manager->UploadPasswordGenerationForm(pending.form_data); | 626 autofill_manager->UploadPasswordGenerationForm(pending.form_data); |
| 627 UMA_HISTOGRAM_BOOLEAN("PasswordGeneration.UploadStarted", success); | 627 UMA_HISTOGRAM_BOOLEAN("PasswordGeneration.UploadStarted", success); |
| 628 } | 628 } |
| 629 } | 629 } |
| 630 } | 630 } |
| 631 } | 631 } |
| 632 | 632 |
| 633 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { | 633 int PasswordFormManager::ScoreResult(const PasswordForm& candidate) const { |
| 634 DCHECK_EQ(state_, MATCHING_PHASE); | 634 DCHECK_EQ(state_, MATCHING_PHASE); |
| 635 // For scoring of candidate login data: | 635 // For scoring of candidate login data: |
| 636 // The most important element that should match is the origin, followed by | 636 // The most important element that should match is the signon_realm followed |
| 637 // the action, the password name, the submit button name, and finally the | 637 // by the origin the action, the password name, the submit button name, and |
| 638 // username input field name. | 638 // finally the username input field name. |
| 639 // Exact signon realm match gives an addition of 128 (1 << 7). | |
| 639 // Exact origin match gives an addition of 64 (1 << 6) + # of matching url | 640 // Exact origin match gives an addition of 64 (1 << 6) + # of matching url |
| 640 // dirs. | 641 // dirs. |
| 641 // Partial match gives an addition of 32 (1 << 5) + # matching url dirs | 642 // Partial match gives an addition of 32 (1 << 5) + # matching url dirs |
| 642 // That way, a partial match cannot trump an exact match even if | 643 // That way, a partial match cannot trump an exact match even if |
| 643 // the partial one matches all other attributes (action, elements) (and | 644 // the partial one matches all other attributes (action, elements) (and |
| 644 // regardless of the matching depth in the URL path). | 645 // regardless of the matching depth in the URL path). |
| 645 // If public suffix origin match was not used, it gives an addition of | 646 // If public suffix origin match was not used, it gives an addition of |
| 646 // 16 (1 << 4). | 647 // 16 (1 << 4). |
| 647 int score = 0; | 648 int score = 0; |
| 648 if (candidate.origin == observed_form_.origin) { | 649 if (candidate.original_signon_realm.empty() || |
| 650 candidate.original_signon_realm == observed_form_.signon_realm) { | |
|
Garrett Casto
2014/04/17 21:12:39
Actually, I think this should just be !candidate.I
| |
| 651 // If credentials come from different signon realm, then | |
| 652 // original_signon_realm will be non-empty string | |
| 653 score += (1 << 7); | |
|
Garrett Casto
2014/04/17 21:12:39
This isn't completely consistent here, but I think
| |
| 654 } else if (candidate.origin == observed_form_.origin) { | |
| 649 // This check is here for the most common case which | 655 // This check is here for the most common case which |
| 650 // is we have a single match in the db for the given host, | 656 // is we have a single match in the db for the given host, |
| 651 // so we don't generally need to walk the entire URL path (the else | 657 // so we don't generally need to walk the entire URL path (the else |
| 652 // clause). | 658 // clause). |
| 653 score += (1 << 6) + static_cast<int>(form_path_tokens_.size()); | 659 score += (1 << 6) + static_cast<int>(form_path_tokens_.size()); |
| 654 } else { | 660 } else { |
| 655 // Walk the origin URL paths one directory at a time to see how | 661 // Walk the origin URL paths one directory at a time to see how |
| 656 // deep the two match. | 662 // deep the two match. |
| 657 std::vector<std::string> candidate_path_tokens; | 663 std::vector<std::string> candidate_path_tokens; |
| 658 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens); | 664 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens); |
| 659 size_t depth = 0; | 665 size_t depth = 0; |
| 660 size_t max_dirs = std::min(form_path_tokens_.size(), | 666 size_t max_dirs = std::min(form_path_tokens_.size(), |
| 661 candidate_path_tokens.size()); | 667 candidate_path_tokens.size()); |
| 662 while ((depth < max_dirs) && (form_path_tokens_[depth] == | 668 while ((depth < max_dirs) && (form_path_tokens_[depth] == |
| 663 candidate_path_tokens[depth])) { | 669 candidate_path_tokens[depth])) { |
| 664 depth++; | 670 depth++; |
| 665 score++; | 671 score++; |
| 666 } | 672 } |
| 667 // do we have a partial match? | 673 // do we have a partial match? |
| 668 score += (depth > 0) ? 1 << 5 : 0; | 674 score += (depth > 0) ? 1 << 5 : 0; |
| 669 } | 675 } |
| 670 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) { | 676 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) { |
| 671 if (!candidate.IsPublicSuffixMatch()) | 677 if (!candidate.IsPublicSuffixMatch()) |
|
Garrett Casto
2014/04/17 21:12:39
This should be removed.
| |
| 672 score += 1 << 4; | 678 score += 1 << 4; |
| 673 if (candidate.action == observed_form_.action) | 679 if (candidate.action == observed_form_.action) |
| 674 score += 1 << 3; | 680 score += 1 << 3; |
| 675 if (candidate.password_element == observed_form_.password_element) | 681 if (candidate.password_element == observed_form_.password_element) |
| 676 score += 1 << 2; | 682 score += 1 << 2; |
| 677 if (candidate.submit_element == observed_form_.submit_element) | 683 if (candidate.submit_element == observed_form_.submit_element) |
| 678 score += 1 << 1; | 684 score += 1 << 1; |
| 679 if (candidate.username_element == observed_form_.username_element) | 685 if (candidate.username_element == observed_form_.username_element) |
| 680 score += 1 << 0; | 686 score += 1 << 0; |
| 681 } | 687 } |
| 682 | 688 |
| 683 return score; | 689 return score; |
| 684 } | 690 } |
| 685 | 691 |
| 686 void PasswordFormManager::SubmitPassed() { | 692 void PasswordFormManager::SubmitPassed() { |
| 687 submit_result_ = kSubmitResultPassed; | 693 submit_result_ = kSubmitResultPassed; |
| 688 if (has_generated_password_) | 694 if (has_generated_password_) |
| 689 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); | 695 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); |
| 690 } | 696 } |
| 691 | 697 |
| 692 void PasswordFormManager::SubmitFailed() { | 698 void PasswordFormManager::SubmitFailed() { |
| 693 submit_result_ = kSubmitResultFailed; | 699 submit_result_ = kSubmitResultFailed; |
| 694 if (has_generated_password_) | 700 if (has_generated_password_) |
| 695 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); | 701 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); |
| 696 } | 702 } |
| 697 | 703 |
| 698 } // namespace password_manager | 704 } // namespace password_manager |
| OLD | NEW |