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

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

Issue 962673004: [Autofill/Autocomplete Feature] Substring matching instead of prefix matching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addresses Evan's review comments. Created 5 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_autofill_manager.h" 5 #include "components/password_manager/core/browser/password_autofill_manager.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/string_util.h" 11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "components/autofill/core/browser/autofill_driver.h" 13 #include "components/autofill/core/browser/autofill_driver.h"
14 #include "components/autofill/core/browser/popup_item_ids.h" 14 #include "components/autofill/core/browser/popup_item_ids.h"
15 #include "components/autofill/core/browser/suggestion.h" 15 #include "components/autofill/core/browser/suggestion.h"
16 #include "components/autofill/core/common/autofill_constants.h" 16 #include "components/autofill/core/common/autofill_constants.h"
17 #include "components/autofill/core/common/autofill_data_validation.h" 17 #include "components/autofill/core/common/autofill_data_validation.h"
18 #include "components/autofill/core/common/autofill_util.h"
18 #include "components/password_manager/core/browser/affiliation_utils.h" 19 #include "components/password_manager/core/browser/affiliation_utils.h"
19 #include "components/password_manager/core/browser/password_manager_driver.h" 20 #include "components/password_manager/core/browser/password_manager_driver.h"
20 #include "components/strings/grit/components_strings.h" 21 #include "components/strings/grit/components_strings.h"
21 #include "grit/components_strings.h" 22 #include "grit/components_strings.h"
22 #include "ui/base/l10n/l10n_util.h" 23 #include "ui/base/l10n/l10n_util.h"
23 24
24 namespace password_manager { 25 namespace password_manager {
25 26
26 namespace { 27 namespace {
27 28
(...skipping 22 matching lines...) Expand all
50 base::string16 GetHumanReadableRealm(const std::string& signon_realm) { 51 base::string16 GetHumanReadableRealm(const std::string& signon_realm) {
51 // For Android application realms, remove the hash component. Otherwise, make 52 // For Android application realms, remove the hash component. Otherwise, make
52 // no changes. 53 // no changes.
53 FacetURI maybe_facet_uri(FacetURI::FromPotentiallyInvalidSpec(signon_realm)); 54 FacetURI maybe_facet_uri(FacetURI::FromPotentiallyInvalidSpec(signon_realm));
54 if (maybe_facet_uri.IsValidAndroidFacetURI()) 55 if (maybe_facet_uri.IsValidAndroidFacetURI())
55 return base::UTF8ToUTF16("android://" + 56 return base::UTF8ToUTF16("android://" +
56 maybe_facet_uri.android_package_name() + "/"); 57 maybe_facet_uri.android_package_name() + "/");
57 return base::UTF8ToUTF16(signon_realm); 58 return base::UTF8ToUTF16(signon_realm);
58 } 59 }
59 60
61 // Use this to check if a given suggestion matches the current contents of a
62 // field.
63 bool DoesSuggestionMatchContents(const base::string16& field_suggestion,
64 const base::string16& field_contents) {
65 return autofill::IsContentsPrefixOfSuggestionToken(field_suggestion,
66 field_contents, false) ||
67 StartsWith(field_suggestion, field_contents, false);
vabr (Chromium) 2015/04/01 11:33:00 StartsWith is much simpler (and therefore faster)
Pritam Nikam 2015/04/01 12:59:37 Done. Yeah, point taken!
68 }
69
70 // If |field_suggestion| matches |field_content|, creates a Suggestion out of it
71 // and appends to |suggestions|.
72 void AppendSuggestionIfMatching(
73 const base::string16& field_suggestion,
74 const base::string16& field_contents,
75 const std::string& signon_realm,
76 bool show_all,
77 std::vector<autofill::Suggestion>* suggestions) {
78 if (show_all ||
79 DoesSuggestionMatchContents(field_suggestion, field_contents)) {
80 autofill::Suggestion suggestion(ReplaceEmptyUsername(field_suggestion));
81 suggestion.label = GetHumanReadableRealm(signon_realm);
82 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
83 suggestions->push_back(suggestion);
84 }
85 }
86
60 // This function attempts to fill |suggestions| and |realms| form |fill_data| 87 // This function attempts to fill |suggestions| and |realms| form |fill_data|
61 // based on |current_username|. Unless |show_all| is true, it only picks 88 // based on |current_username|. Unless |show_all| is true, it only picks
62 // suggestions where the username has |current_username| as a prefix. 89 // suggestions where the username matches |current_username|.
63 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, 90 void GetSuggestions(const autofill::PasswordFormFillData& fill_data,
64 const base::string16& current_username, 91 const base::string16& current_username,
65 std::vector<autofill::Suggestion>* suggestions, 92 std::vector<autofill::Suggestion>* suggestions,
66 bool show_all) { 93 bool show_all) {
67 if (show_all || 94 AppendSuggestionIfMatching(fill_data.username_field.value, current_username,
68 StartsWith(fill_data.username_field.value, current_username, false)) { 95 fill_data.preferred_realm, show_all, suggestions);
69 autofill::Suggestion suggestion(
70 ReplaceEmptyUsername(fill_data.username_field.value));
71 suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm);
72 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
73 suggestions->push_back(suggestion);
74 }
75 96
76 for (const auto& login : fill_data.additional_logins) { 97 for (const auto& login : fill_data.additional_logins) {
77 if (show_all || StartsWith(login.first, current_username, false)) { 98 AppendSuggestionIfMatching(login.first, current_username,
78 autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); 99 login.second.realm, show_all, suggestions);
79 suggestion.label = GetHumanReadableRealm(login.second.realm);
80 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
81 suggestions->push_back(suggestion);
82 }
83 } 100 }
84 101
85 for (const auto& usernames : fill_data.other_possible_usernames) { 102 for (const auto& usernames : fill_data.other_possible_usernames) {
86 for (size_t i = 0; i < usernames.second.size(); ++i) { 103 for (size_t i = 0; i < usernames.second.size(); ++i) {
87 if (show_all || 104 AppendSuggestionIfMatching(usernames.second[i], current_username,
88 StartsWith(usernames.second[i], current_username, false)) { 105 usernames.first.realm, show_all, suggestions);
89 autofill::Suggestion suggestion(
90 ReplaceEmptyUsername(usernames.second[i]));
91 suggestion.label = GetHumanReadableRealm(usernames.first.realm);
92 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
93 suggestions->push_back(suggestion);
94 }
95 } 106 }
96 } 107 }
97 } 108 }
98 109
99 } // namespace 110 } // namespace
100 111
101 //////////////////////////////////////////////////////////////////////////////// 112 ////////////////////////////////////////////////////////////////////////////////
102 // PasswordAutofillManager, public: 113 // PasswordAutofillManager, public:
103 114
104 PasswordAutofillManager::PasswordAutofillManager( 115 PasswordAutofillManager::PasswordAutofillManager(
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 autofill::PasswordFormFillData* found_password) { 287 autofill::PasswordFormFillData* found_password) {
277 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); 288 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key);
278 if (iter == login_to_password_info_.end()) 289 if (iter == login_to_password_info_.end())
279 return false; 290 return false;
280 291
281 *found_password = iter->second; 292 *found_password = iter->second;
282 return true; 293 return true;
283 } 294 }
284 295
285 } // namespace password_manager 296 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698