| 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 // If public suffix origin match was not used, it gives an addition of |
| 640 // 128 (1 << 7). |
| 639 // Exact origin match gives an addition of 64 (1 << 6) + # of matching url | 641 // Exact origin match gives an addition of 64 (1 << 6) + # of matching url |
| 640 // dirs. | 642 // dirs. |
| 641 // Partial match gives an addition of 32 (1 << 5) + # matching url dirs | 643 // 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 | 644 // That way, a partial match cannot trump an exact match even if |
| 643 // the partial one matches all other attributes (action, elements) (and | 645 // the partial one matches all other attributes (action, elements) (and |
| 644 // regardless of the matching depth in the URL path). | 646 // regardless of the matching depth in the URL path). |
| 645 // If public suffix origin match was not used, it gives an addition of | |
| 646 // 16 (1 << 4). | |
| 647 int score = 0; | 647 int score = 0; |
| 648 if (!candidate.IsPublicSuffixMatch()) { |
| 649 score += 1 << 7; |
| 650 } |
| 648 if (candidate.origin == observed_form_.origin) { | 651 if (candidate.origin == observed_form_.origin) { |
| 649 // This check is here for the most common case which | 652 // This check is here for the most common case which |
| 650 // is we have a single match in the db for the given host, | 653 // 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 | 654 // so we don't generally need to walk the entire URL path (the else |
| 652 // clause). | 655 // clause). |
| 653 score += (1 << 6) + static_cast<int>(form_path_tokens_.size()); | 656 score += (1 << 6) + static_cast<int>(form_path_tokens_.size()); |
| 654 } else { | 657 } else { |
| 655 // Walk the origin URL paths one directory at a time to see how | 658 // Walk the origin URL paths one directory at a time to see how |
| 656 // deep the two match. | 659 // deep the two match. |
| 657 std::vector<std::string> candidate_path_tokens; | 660 std::vector<std::string> candidate_path_tokens; |
| 658 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens); | 661 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens); |
| 659 size_t depth = 0; | 662 size_t depth = 0; |
| 660 size_t max_dirs = std::min(form_path_tokens_.size(), | 663 size_t max_dirs = std::min(form_path_tokens_.size(), |
| 661 candidate_path_tokens.size()); | 664 candidate_path_tokens.size()); |
| 662 while ((depth < max_dirs) && (form_path_tokens_[depth] == | 665 while ((depth < max_dirs) && (form_path_tokens_[depth] == |
| 663 candidate_path_tokens[depth])) { | 666 candidate_path_tokens[depth])) { |
| 664 depth++; | 667 depth++; |
| 665 score++; | 668 score++; |
| 666 } | 669 } |
| 667 // do we have a partial match? | 670 // do we have a partial match? |
| 668 score += (depth > 0) ? 1 << 5 : 0; | 671 score += (depth > 0) ? 1 << 5 : 0; |
| 669 } | 672 } |
| 670 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) { | 673 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) { |
| 671 if (!candidate.IsPublicSuffixMatch()) | |
| 672 score += 1 << 4; | |
| 673 if (candidate.action == observed_form_.action) | 674 if (candidate.action == observed_form_.action) |
| 674 score += 1 << 3; | 675 score += 1 << 3; |
| 675 if (candidate.password_element == observed_form_.password_element) | 676 if (candidate.password_element == observed_form_.password_element) |
| 676 score += 1 << 2; | 677 score += 1 << 2; |
| 677 if (candidate.submit_element == observed_form_.submit_element) | 678 if (candidate.submit_element == observed_form_.submit_element) |
| 678 score += 1 << 1; | 679 score += 1 << 1; |
| 679 if (candidate.username_element == observed_form_.username_element) | 680 if (candidate.username_element == observed_form_.username_element) |
| 680 score += 1 << 0; | 681 score += 1 << 0; |
| 681 } | 682 } |
| 682 | 683 |
| 683 return score; | 684 return score; |
| 684 } | 685 } |
| 685 | 686 |
| 686 void PasswordFormManager::SubmitPassed() { | 687 void PasswordFormManager::SubmitPassed() { |
| 687 submit_result_ = kSubmitResultPassed; | 688 submit_result_ = kSubmitResultPassed; |
| 688 if (has_generated_password_) | 689 if (has_generated_password_) |
| 689 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); | 690 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); |
| 690 } | 691 } |
| 691 | 692 |
| 692 void PasswordFormManager::SubmitFailed() { | 693 void PasswordFormManager::SubmitFailed() { |
| 693 submit_result_ = kSubmitResultFailed; | 694 submit_result_ = kSubmitResultFailed; |
| 694 if (has_generated_password_) | 695 if (has_generated_password_) |
| 695 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); | 696 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); |
| 696 } | 697 } |
| 697 | 698 |
| 698 } // namespace password_manager | 699 } // namespace password_manager |
| OLD | NEW |