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

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

Issue 2906383003: Teach PasswordAutofillAgent sometimes match prefixes of usernames (Closed)
Patch Set: more browser tests Created 3 years, 6 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..251522fe9cd0ab5548debb183d62dbef6db8f69b 100644
--- a/components/autofill/core/common/autofill_util.cc
+++ b/components/autofill/core/common/autofill_util.cc
@@ -115,6 +115,23 @@ bool FieldIsSuggestionSubstringStartingOnTokenBoundary(
base::string16::npos;
}
+bool IsPrefixOfEmailEndingAtSign(const base::string16& full_string,
+ const base::string16& prefix) {
+ auto at_sign = std::find(full_string.begin(), full_string.end(), '@');
+ auto e = full_string.end();
+ // weak check if |full_string| is a valid email address.
vabr (Chromium) 2017/06/19 12:54:15 nit: weak -> A weak Or maybe better "An incomplete
melandory 2017/06/21 12:00:42 Done.
+ bool is_email =
vabr (Chromium) 2017/06/19 12:54:15 Well, actually, hinting at e-mail, but only doing
melandory 2017/06/21 12:00:42 In this case "ab@cd@g", "ab@cd" will result in mat
vabr (Chromium) 2017/06/21 12:28:07 I think it is fine. From usability perspective I d
+ (at_sign != e // there is @
+ && std::find(at_sign, e, '.') != e // there is . and it's after @
+ && std::find(++at_sign, e, '@') == e); // there is at most 1 @
+ if (is_email &&
+ base::StartsWith(full_string, prefix, base::CompareCase::SENSITIVE)) {
+ return (full_string.size() > prefix.size() &&
+ full_string[prefix.size()] == '@');
+ }
+ 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