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

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: Removed suggestions ordering prefix/substring and unittests. 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::IsFeatureSubstringMatchEnabled() &&
66 autofill::IsContentsPrefixOfSuggestionToken(
67 field_suggestion, field_contents, autofill::CASE_IGNORE);
68 }
69
70 // Helper function to fill username suggestion and adds it to |suggestions|
vabr (Chromium) 2015/03/27 10:13:35 grammar: to fill ... and adds it ... Also, how doe
Pritam Nikam 2015/03/27 14:57:42 Done.
71 // list.
72 void FillUsernameSuggestion(const base::string16& field_suggestion,
73 const base::string16& field_contents,
74 const std::string& signon_realm,
75 bool show_all,
76 std::vector<autofill::Suggestion>* suggestions) {
77 if (show_all || StartsWith(field_suggestion, field_contents, false) ||
vabr (Chromium) 2015/03/27 10:13:35 What about moving the StartsWith check to DoesSugg
Pritam Nikam 2015/03/27 14:57:43 Done.
78 DoesSuggestionMatchContents(field_suggestion, field_contents)) {
79 autofill::Suggestion suggestion(ReplaceEmptyUsername(field_suggestion));
80 suggestion.label = GetHumanReadableRealm(signon_realm);
81 suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
82 suggestions->push_back(suggestion);
83 }
84 }
85
60 // This function attempts to fill |suggestions| and |realms| form |fill_data| 86 // This function attempts to fill |suggestions| and |realms| form |fill_data|
61 // based on |current_username|. Unless |show_all| is true, it only picks 87 // based on |current_username|. Unless |show_all| is true, it only picks
62 // suggestions where the username has |current_username| as a prefix. 88 // suggestions where the username has |current_username| as a substring.
vabr (Chromium) 2015/03/27 10:13:35 Saying "substring" does not make the comment true
Pritam Nikam 2015/03/27 14:57:42 Done.
63 void GetSuggestions(const autofill::PasswordFormFillData& fill_data, 89 void GetSuggestions(const autofill::PasswordFormFillData& fill_data,
64 const base::string16& current_username, 90 const base::string16& current_username,
65 std::vector<autofill::Suggestion>* suggestions, 91 std::vector<autofill::Suggestion>* suggestions,
66 bool show_all) { 92 bool show_all) {
67 if (show_all || 93 FillUsernameSuggestion(fill_data.username_field.value, current_username,
68 StartsWith(fill_data.username_field.value, current_username, false)) { 94 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 95
76 for (const auto& login : fill_data.additional_logins) { 96 for (const auto& login : fill_data.additional_logins) {
77 if (show_all || StartsWith(login.first, current_username, false)) { 97 FillUsernameSuggestion(login.first, current_username, login.second.realm,
78 autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first)); 98 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 } 99 }
84 100
85 for (const auto& usernames : fill_data.other_possible_usernames) { 101 for (const auto& usernames : fill_data.other_possible_usernames) {
86 for (size_t i = 0; i < usernames.second.size(); ++i) { 102 for (size_t i = 0; i < usernames.second.size(); ++i) {
87 if (show_all || 103 FillUsernameSuggestion(usernames.second[i], current_username,
88 StartsWith(usernames.second[i], current_username, false)) { 104 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 } 105 }
96 } 106 }
97 } 107 }
98 108
99 } // namespace 109 } // namespace
100 110
101 //////////////////////////////////////////////////////////////////////////////// 111 ////////////////////////////////////////////////////////////////////////////////
102 // PasswordAutofillManager, public: 112 // PasswordAutofillManager, public:
103 113
104 PasswordAutofillManager::PasswordAutofillManager( 114 PasswordAutofillManager::PasswordAutofillManager(
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 autofill::PasswordFormFillData* found_password) { 286 autofill::PasswordFormFillData* found_password) {
277 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key); 287 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(key);
278 if (iter == login_to_password_info_.end()) 288 if (iter == login_to_password_info_.end())
279 return false; 289 return false;
280 290
281 *found_password = iter->second; 291 *found_password = iter->second;
282 return true; 292 return true;
283 } 293 }
284 294
285 } // namespace password_manager 295 } // namespace password_manager
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698