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

Unified 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: Added unittests. Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
Index: components/password_manager/core/browser/password_autofill_manager.cc
diff --git a/components/password_manager/core/browser/password_autofill_manager.cc b/components/password_manager/core/browser/password_autofill_manager.cc
index 15d5f7e3c8da005d4853f4dc3a8e78098bcaaebb..6f4214e10b3272944f99dcdfe4edd9f1bf6db9e4 100644
--- a/components/password_manager/core/browser/password_autofill_manager.cc
+++ b/components/password_manager/core/browser/password_autofill_manager.cc
@@ -15,6 +15,7 @@
#include "components/autofill/core/browser/suggestion.h"
#include "components/autofill/core/common/autofill_constants.h"
#include "components/autofill/core/common/autofill_data_validation.h"
+#include "components/autofill/core/common/autofill_util.h"
#include "components/password_manager/core/browser/affiliation_utils.h"
#include "components/password_manager/core/browser/password_manager_driver.h"
#include "components/strings/grit/components_strings.h"
@@ -57,13 +58,24 @@ base::string16 GetHumanReadableRealm(const std::string& signon_realm) {
return base::UTF8ToUTF16(signon_realm);
}
+// Returns |true| if |kEnableSuggestionsWithSubStringMatch| command line switch
+// is on and |field_contents| matches the sub-string within |field_suggestion|;
vabr (Chromium) 2015/03/23 14:17:33 What does "the sub-string within" mean? This comme
Pritam Nikam 2015/03/24 11:39:37 Done. Rephrased to "Returns |true| if |kEnableSug
+// otherwise |false|.
+bool DoesSuggestionsSubStringMatchContents(
+ const base::string16& field_suggestion,
+ const base::string16& field_contents) {
+ return autofill::IsFeatureSubStringMatchEnabled() &&
+ autofill::HasTokoneStartsWith(field_suggestion, field_contents);
vabr (Chromium) 2015/03/23 14:17:33 typo: Tokone
Pritam Nikam 2015/03/24 11:39:37 Done.
+}
+
// This function attempts to fill |suggestions| and |realms| form |fill_data|
// based on |current_username|. Unless |show_all| is true, it only picks
-// suggestions where the username has |current_username| as a prefix.
+// suggestions where the username has |current_username| as a sub-string.
void GetSuggestions(const autofill::PasswordFormFillData& fill_data,
const base::string16& current_username,
std::vector<autofill::Suggestion>* suggestions,
bool show_all) {
+ std::vector<autofill::Suggestion> substring_matched_suggestions;
vabr (Chromium) 2015/03/23 14:17:33 Why do you separate the substring matched suggesti
Pritam Nikam 2015/03/24 11:39:37 Yes. Just to keep prefix matched suggestions up in
vabr (Chromium) 2015/03/24 13:32:28 First of all -- this is a significant UI decision.
Pritam Nikam 2015/03/25 14:25:26 Sure! I'll wait for UX approval from ainslie@ rega
if (show_all ||
StartsWith(fill_data.username_field.value, current_username, false)) {
autofill::Suggestion suggestion(
@@ -71,6 +83,13 @@ void GetSuggestions(const autofill::PasswordFormFillData& fill_data,
suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm);
suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
suggestions->push_back(suggestion);
+ } else if (DoesSuggestionsSubStringMatchContents(
+ fill_data.username_field.value, current_username)) {
+ autofill::Suggestion suggestion(
+ ReplaceEmptyUsername(fill_data.username_field.value));
+ suggestion.label = GetHumanReadableRealm(fill_data.preferred_realm);
+ suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
+ substring_matched_suggestions.push_back(suggestion);
}
for (const auto& login : fill_data.additional_logins) {
@@ -79,6 +98,12 @@ void GetSuggestions(const autofill::PasswordFormFillData& fill_data,
suggestion.label = GetHumanReadableRealm(login.second.realm);
suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
suggestions->push_back(suggestion);
+ } else if (DoesSuggestionsSubStringMatchContents(login.first,
+ current_username)) {
+ autofill::Suggestion suggestion(ReplaceEmptyUsername(login.first));
+ suggestion.label = GetHumanReadableRealm(login.second.realm);
+ suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
+ substring_matched_suggestions.push_back(suggestion);
}
}
@@ -91,9 +116,21 @@ void GetSuggestions(const autofill::PasswordFormFillData& fill_data,
suggestion.label = GetHumanReadableRealm(usernames.first.realm);
suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
suggestions->push_back(suggestion);
+ } else if (DoesSuggestionsSubStringMatchContents(usernames.second[i],
+ current_username)) {
+ autofill::Suggestion suggestion(
+ ReplaceEmptyUsername(usernames.second[i]));
+ suggestion.label = GetHumanReadableRealm(usernames.first.realm);
+ suggestion.frontend_id = autofill::POPUP_ITEM_ID_PASSWORD_ENTRY;
+ substring_matched_suggestions.push_back(suggestion);
}
}
}
+
+ // Now append usernames having sub-string matching.
+ for (const auto& suggestion : substring_matched_suggestions) {
+ suggestions->push_back(suggestion);
vabr (Chromium) 2015/03/23 14:17:33 optional nit: What about using std::insert instead
Pritam Nikam 2015/03/24 11:39:37 With std::insert we have to pass position as well,
vabr (Chromium) 2015/03/24 13:32:28 Having looked more deeply into this: There are ple
Pritam Nikam 2015/03/25 14:25:26 Done. Got rid of |substring_matched_suggestions| a
+ }
}
} // namespace

Powered by Google App Engine
This is Rietveld 408576698