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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/autofill/core/common/autofill_util.h" 5 #include "components/autofill/core/common/autofill_util.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/feature_list.h" 10 #include "base/feature_list.h"
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 case_sensitive 108 case_sensitive
109 ? base::CompareCase::SENSITIVE 109 ? base::CompareCase::SENSITIVE
110 : base::CompareCase::INSENSITIVE_ASCII); 110 : base::CompareCase::INSENSITIVE_ASCII);
111 } 111 }
112 112
113 return suggestion.length() >= field_contents.length() && 113 return suggestion.length() >= field_contents.length() &&
114 GetTextSelectionStart(suggestion, field_contents, case_sensitive) != 114 GetTextSelectionStart(suggestion, field_contents, case_sensitive) !=
115 base::string16::npos; 115 base::string16::npos;
116 } 116 }
117 117
118 bool IsPrefixOfEmailEndingAtSign(const base::string16& full_string,
119 const base::string16& prefix) {
120 auto at_sign = std::find(full_string.begin(), full_string.end(), '@');
121 auto e = full_string.end();
122 // 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.
123 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
124 (at_sign != e // there is @
125 && std::find(at_sign, e, '.') != e // there is . and it's after @
126 && std::find(++at_sign, e, '@') == e); // there is at most 1 @
127 if (is_email &&
128 base::StartsWith(full_string, prefix, base::CompareCase::SENSITIVE)) {
129 return (full_string.size() > prefix.size() &&
130 full_string[prefix.size()] == '@');
131 }
132 return false;
133 }
134
118 size_t GetTextSelectionStart(const base::string16& suggestion, 135 size_t GetTextSelectionStart(const base::string16& suggestion,
119 const base::string16& field_contents, 136 const base::string16& field_contents,
120 bool case_sensitive) { 137 bool case_sensitive) {
121 const base::string16 kSplitChars = base::ASCIIToUTF16(kSplitCharacters); 138 const base::string16 kSplitChars = base::ASCIIToUTF16(kSplitCharacters);
122 139
123 // Loop until we find either the |field_contents| is a prefix of |suggestion| 140 // Loop until we find either the |field_contents| is a prefix of |suggestion|
124 // or character right before the match is one of the splitting characters. 141 // or character right before the match is one of the splitting characters.
125 for (base::string16::const_iterator it = suggestion.begin(); 142 for (base::string16::const_iterator it = suggestion.begin();
126 (it = std::search( 143 (it = std::search(
127 it, suggestion.end(), field_contents.begin(), field_contents.end(), 144 it, suggestion.end(), field_contents.begin(), field_contents.end(),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 193 }
177 194
178 std::vector<std::string> LowercaseAndTokenizeAttributeString( 195 std::vector<std::string> LowercaseAndTokenizeAttributeString(
179 const std::string& attribute) { 196 const std::string& attribute) {
180 return base::SplitString(base::ToLowerASCII(attribute), 197 return base::SplitString(base::ToLowerASCII(attribute),
181 base::kWhitespaceASCII, base::TRIM_WHITESPACE, 198 base::kWhitespaceASCII, base::TRIM_WHITESPACE,
182 base::SPLIT_WANT_NONEMPTY); 199 base::SPLIT_WANT_NONEMPTY);
183 } 200 }
184 201
185 } // namespace autofill 202 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698