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

Side by Side Diff: components/autofill/core/common/autofill_util.cc

Issue 2906383003: Teach PasswordAutofillAgent sometimes match prefixes of usernames (Closed)
Patch Set: dvadym@ comments 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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 bool IsHintEnabledInKeyboardAccessory() { 92 bool IsHintEnabledInKeyboardAccessory() {
93 #if defined(OS_ANDROID) 93 #if defined(OS_ANDROID)
94 return base::GetFieldTrialParamByFeatureAsBool( 94 return base::GetFieldTrialParamByFeatureAsBool(
95 kAutofillKeyboardAccessory, kAutofillKeyboardAccessoryHintKey, false); 95 kAutofillKeyboardAccessory, kAutofillKeyboardAccessoryHintKey, false);
96 #else // !defined(OS_ANDROID) 96 #else // !defined(OS_ANDROID)
97 NOTREACHED(); 97 NOTREACHED();
98 return false; 98 return false;
99 #endif 99 #endif
100 } 100 }
101 101
102 bool FieldIsSuggestionSubstringStartingOnTokenBoundary( 102 bool IsSubstringStartingOnTokenBoundary(const base::string16& suggestion,
103 const base::string16& suggestion, 103 const base::string16& field_contents,
104 const base::string16& field_contents, 104 bool case_sensitive) {
105 bool case_sensitive) {
106 if (!IsFeatureSubstringMatchEnabled()) { 105 if (!IsFeatureSubstringMatchEnabled()) {
107 return base::StartsWith(suggestion, field_contents, 106 return base::StartsWith(suggestion, field_contents,
108 case_sensitive 107 case_sensitive
109 ? base::CompareCase::SENSITIVE 108 ? base::CompareCase::SENSITIVE
110 : base::CompareCase::INSENSITIVE_ASCII); 109 : base::CompareCase::INSENSITIVE_ASCII);
111 } 110 }
112 111
113 return suggestion.length() >= field_contents.length() && 112 return suggestion.length() >= field_contents.length() &&
114 GetTextSelectionStart(suggestion, field_contents, case_sensitive) != 113 GetTextSelectionStart(suggestion, field_contents, case_sensitive) !=
115 base::string16::npos; 114 base::string16::npos;
116 } 115 }
117 116
117 bool IsPrefixEndingOnTokenBoundary(const base::string16& full_string,
118 const base::string16& prefix) {
119 if (base::StartsWith(full_string, prefix, base::CompareCase::SENSITIVE)) {
120 return (full_string.size() > prefix.size() &&
121 full_string[prefix.size()] == '@');
122 }
123 return false;
124 }
125
118 size_t GetTextSelectionStart(const base::string16& suggestion, 126 size_t GetTextSelectionStart(const base::string16& suggestion,
119 const base::string16& field_contents, 127 const base::string16& field_contents,
120 bool case_sensitive) { 128 bool case_sensitive) {
121 const base::string16 kSplitChars = base::ASCIIToUTF16(kSplitCharacters); 129 const base::string16 kSplitChars = base::ASCIIToUTF16(kSplitCharacters);
122 130
123 // Loop until we find either the |field_contents| is a prefix of |suggestion| 131 // 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. 132 // or character right before the match is one of the splitting characters.
125 for (base::string16::const_iterator it = suggestion.begin(); 133 for (base::string16::const_iterator it = suggestion.begin();
126 (it = std::search( 134 (it = std::search(
127 it, suggestion.end(), field_contents.begin(), field_contents.end(), 135 it, suggestion.end(), field_contents.begin(), field_contents.end(),
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 } 184 }
177 185
178 std::vector<std::string> LowercaseAndTokenizeAttributeString( 186 std::vector<std::string> LowercaseAndTokenizeAttributeString(
179 const std::string& attribute) { 187 const std::string& attribute) {
180 return base::SplitString(base::ToLowerASCII(attribute), 188 return base::SplitString(base::ToLowerASCII(attribute),
181 base::kWhitespaceASCII, base::TRIM_WHITESPACE, 189 base::kWhitespaceASCII, base::TRIM_WHITESPACE,
182 base::SPLIT_WANT_NONEMPTY); 190 base::SPLIT_WANT_NONEMPTY);
183 } 191 }
184 192
185 } // namespace autofill 193 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698