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

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: Fixups 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // If credentials come from different signon realm, then
650 // original_signon_realm will be non-empty string
Garrett Casto 2014/04/18 17:49:48 Nit:This comment seems unnecessary now.
651 score += 1 << 7;
652 } else if (candidate.origin == observed_form_.origin) {
649 // This check is here for the most common case which 653 // This check is here for the most common case which
650 // is we have a single match in the db for the given host, 654 // 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 655 // so we don't generally need to walk the entire URL path (the else
652 // clause). 656 // clause).
653 score += (1 << 6) + static_cast<int>(form_path_tokens_.size()); 657 score += (1 << 6) + static_cast<int>(form_path_tokens_.size());
654 } else { 658 } else {
655 // Walk the origin URL paths one directory at a time to see how 659 // Walk the origin URL paths one directory at a time to see how
656 // deep the two match. 660 // deep the two match.
657 std::vector<std::string> candidate_path_tokens; 661 std::vector<std::string> candidate_path_tokens;
658 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens); 662 base::SplitString(candidate.origin.path(), '/', &candidate_path_tokens);
659 size_t depth = 0; 663 size_t depth = 0;
660 size_t max_dirs = std::min(form_path_tokens_.size(), 664 size_t max_dirs = std::min(form_path_tokens_.size(),
661 candidate_path_tokens.size()); 665 candidate_path_tokens.size());
662 while ((depth < max_dirs) && (form_path_tokens_[depth] == 666 while ((depth < max_dirs) && (form_path_tokens_[depth] ==
663 candidate_path_tokens[depth])) { 667 candidate_path_tokens[depth])) {
664 depth++; 668 depth++;
665 score++; 669 score++;
666 } 670 }
667 // do we have a partial match? 671 // do we have a partial match?
668 score += (depth > 0) ? 1 << 5 : 0; 672 score += (depth > 0) ? 1 << 5 : 0;
669 } 673 }
670 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) { 674 if (observed_form_.scheme == PasswordForm::SCHEME_HTML) {
671 if (!candidate.IsPublicSuffixMatch())
672 score += 1 << 4;
673 if (candidate.action == observed_form_.action) 675 if (candidate.action == observed_form_.action)
674 score += 1 << 3; 676 score += 1 << 3;
675 if (candidate.password_element == observed_form_.password_element) 677 if (candidate.password_element == observed_form_.password_element)
676 score += 1 << 2; 678 score += 1 << 2;
677 if (candidate.submit_element == observed_form_.submit_element) 679 if (candidate.submit_element == observed_form_.submit_element)
678 score += 1 << 1; 680 score += 1 << 1;
679 if (candidate.username_element == observed_form_.username_element) 681 if (candidate.username_element == observed_form_.username_element)
680 score += 1 << 0; 682 score += 1 << 0;
681 } 683 }
682 684
683 return score; 685 return score;
684 } 686 }
685 687
686 void PasswordFormManager::SubmitPassed() { 688 void PasswordFormManager::SubmitPassed() {
687 submit_result_ = kSubmitResultPassed; 689 submit_result_ = kSubmitResultPassed;
688 if (has_generated_password_) 690 if (has_generated_password_)
689 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED); 691 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMITTED);
690 } 692 }
691 693
692 void PasswordFormManager::SubmitFailed() { 694 void PasswordFormManager::SubmitFailed() {
693 submit_result_ = kSubmitResultFailed; 695 submit_result_ = kSubmitResultFailed;
694 if (has_generated_password_) 696 if (has_generated_password_)
695 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED); 697 LogPasswordGenerationSubmissionEvent(PASSWORD_SUBMISSION_FAILED);
696 } 698 }
697 699
698 } // namespace password_manager 700 } // namespace password_manager
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698