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

Unified Diff: components/autofill/core/common/autofill_util.cc

Issue 2906383003: Teach PasswordAutofillAgent sometimes match prefixes of usernames (Closed)
Patch Set: . Created 3 years, 7 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/autofill/core/common/autofill_util.cc
diff --git a/components/autofill/core/common/autofill_util.cc b/components/autofill/core/common/autofill_util.cc
index 50e50176d8c336e700bef8af1c7e6bfd865250fd..c0d1064edb4765be235ca71b143ec126710052b0 100644
--- a/components/autofill/core/common/autofill_util.cc
+++ b/components/autofill/core/common/autofill_util.cc
@@ -34,6 +34,8 @@ namespace {
const char kSplitCharacters[] = " .,-_@";
+const char kPrefixMatchTockens[] = "@";
+
template <typename Char>
struct Compare : base::CaseInsensitiveCompareASCII<Char> {
explicit Compare(bool case_sensitive) : case_sensitive_(case_sensitive) {}
@@ -99,10 +101,9 @@ bool IsHintEnabledInKeyboardAccessory() {
#endif
}
-bool FieldIsSuggestionSubstringStartingOnTokenBoundary(
- const base::string16& suggestion,
- const base::string16& field_contents,
- bool case_sensitive) {
+bool IsSubstringStartingOnTokenBoundary(const base::string16& suggestion,
+ const base::string16& field_contents,
+ bool case_sensitive) {
if (!IsFeatureSubstringMatchEnabled()) {
return base::StartsWith(suggestion, field_contents,
case_sensitive
@@ -115,6 +116,22 @@ bool FieldIsSuggestionSubstringStartingOnTokenBoundary(
base::string16::npos;
}
+bool IsPrefixStartingOnTokenBoundary(const base::string16& full_string,
+ const base::string16& prefix,
+ bool case_sensitive) {
+ if (base::StartsWith(full_string, prefix,
+ case_sensitive ? base::CompareCase::SENSITIVE
+ : base::CompareCase::INSENSITIVE_ASCII)) {
+ if (full_string.size() > prefix.size()) {
+ char token = full_string[prefix.size()];
+
+ const std::string tokens(kPrefixMatchTockens);
dvadym 2017/06/01 12:15:56 Since kPrefixMatchTockens is array only with 1 ele
+ return tokens.find(token) != std::string::npos;
+ }
+ }
+ return false;
+}
+
size_t GetTextSelectionStart(const base::string16& suggestion,
const base::string16& field_contents,
bool case_sensitive) {

Powered by Google App Engine
This is Rietveld 408576698