Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: components/password_manager/core/browser/password_form_manager.cc

Issue 241033002: Fix for scoring password autofill candidates: (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.origin == observed_form_.origin) { 648 if (!candidate.IsPublicSuffixMatch()) {
649 score += 1 << 7;
650 } else if (candidate.origin == observed_form_.origin) {
Garrett Casto 2014/04/24 22:35:29 Sorry about this, but I realized this isn't quite
649 // This check is here for the most common case which 651 // This check is here for the most common case which
650 // is we have a single match in the db for the given host, 652 // 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 653 // so we don't generally need to walk the entire URL path (the else
652 // clause). 654 // clause).
653 score += (1 << 6) + static_cast<int>(form_path_tokens_.size()); 655 score += (1 << 6) + static_cast<int>(form_path_tokens_.size());
654 } else { 656 } else {
655 // Walk the origin URL paths one directory at a time to see how 657 // Walk the origin URL paths one directory at a time to see how
656 // deep the two match. 658 // deep the two match.
657 std::vector<std::string> candidate_path_tokens; 659 std::vector<std::string> candidate_path_tokens;
658 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens); 660 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens);
659 size_t depth = 0; 661 size_t depth = 0;
660 size_t max_dirs = std::min(form_path_tokens_.size(), 662 size_t max_dirs = std::min(form_path_tokens_.size(),
661 candidate_path_tokens.size()); 663 candidate_path_tokens.size());
662 while ((depth < max_dirs) && (form_path_tokens_[depth] == 664 while ((depth < max_dirs) && (form_path_tokens_[depth] ==
663 candidate_path_tokens[depth])) { 665 candidate_path_tokens[depth])) {
664 depth++; 666 depth++;
665 score++; 667 score++;
666 } 668 }
667 // do we have a partial match? 669 // do we have a partial match?
668 score += (depth > 0) ? 1 << 5 : 0; 670 score += (depth > 0) ? 1 << 5 : 0;
669 } 671 }
670 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) { 672 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) {
671 if (!candidate.IsPublicSuffixMatch())
672 score += 1 << 4;
673 if (candidate.action == observed_form_.action) 673 if (candidate.action == observed_form_.action)
674 score += 1 << 3; 674 score += 1 << 3;
675 if (candidate.password_element == observed_form_.password_element) 675 if (candidate.password_element == observed_form_.password_element)
676 score += 1 << 2; 676 score += 1 << 2;
677 if (candidate.submit_element == observed_form_.submit_element) 677 if (candidate.submit_element == observed_form_.submit_element)
678 score += 1 << 1; 678 score += 1 << 1;
679 if (candidate.username_element == observed_form_.username_element) 679 if (candidate.username_element == observed_form_.username_element)
680 score += 1 << 0; 680 score += 1 << 0;
681 } 681 }
682 682
683 return score; 683 return score;
684 } 684 }
685 685
686 void PasswordFormManager::SubmitPassed() { 686 void PasswordFormManager::SubmitPassed() {
687 submit_result_ = kSubmitResultPassed; 687 submit_result_ = kSubmitResultPassed;
688 if (has_generated_password_) 688 if (has_generated_password_)
689 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); 689 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED);
690 } 690 }
691 691
692 void PasswordFormManager::SubmitFailed() { 692 void PasswordFormManager::SubmitFailed() {
693 submit_result_ = kSubmitResultFailed; 693 submit_result_ = kSubmitResultFailed;
694 if (has_generated_password_) 694 if (has_generated_password_)
695 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); 695 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED);
696 } 696 }
697 697
698 } // namespace password_manager 698 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698