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

Unified Diff: components/autofill/core/browser/autofill_field.cc

Issue 1030073003: Autofill: Better recognize credit card type fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: after 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/autofill/core/browser/autofill_field.cc
diff --git a/components/autofill/core/browser/autofill_field.cc b/components/autofill/core/browser/autofill_field.cc
index 75a0d0a4220a61e4f8f9c92a523bbb12363974cf..aafd72013e2f7f51504f938c4be476dec23aa55b 100644
--- a/components/autofill/core/browser/autofill_field.cc
+++ b/components/autofill/core/browser/autofill_field.cc
@@ -248,26 +248,10 @@ bool FillYearSelectControl(const base::string16& value,
// given |field|.
bool FillCreditCardTypeSelectControl(const base::string16& value,
FormFieldData* field) {
- // Try stripping off spaces.
- base::string16 value_stripped;
- base::RemoveChars(base::StringToLowerASCII(value), base::kWhitespaceUTF16,
- &value_stripped);
-
- for (size_t i = 0; i < field->option_values.size(); ++i) {
- base::string16 option_value_lowercase;
- base::RemoveChars(base::StringToLowerASCII(field->option_values[i]),
- base::kWhitespaceUTF16, &option_value_lowercase);
- base::string16 option_contents_lowercase;
- base::RemoveChars(base::StringToLowerASCII(field->option_contents[i]),
- base::kWhitespaceUTF16, &option_contents_lowercase);
-
- // Perform a case-insensitive comparison; but fill the form with the
- // original text, not the lowercased version.
- if (value_stripped == option_value_lowercase ||
- value_stripped == option_contents_lowercase) {
- field->value = field->option_values[i];
- return true;
- }
+ size_t idx;
+ if (AutofillField::FindValueInCreditTypeSelectControl(*field, value, &idx)) {
+ field->value = field->option_values[idx];
+ return true;
}
// For American Express, also try filling as "AmEx".
@@ -541,4 +525,32 @@ base::string16 AutofillField::GetPhoneNumberValue(
return number;
}
+// static
+bool AutofillField::FindValueInCreditTypeSelectControl(
Evan Stade 2015/03/25 21:25:51 nothing about this looks credit card specific (?)
Lei Zhang 2015/03/25 22:18:48 Done.
+ const FormFieldData& field,
+ const base::string16& value,
+ size_t* index) {
+ // Try stripping off spaces.
+ base::string16 value_stripped;
+ base::RemoveChars(base::StringToLowerASCII(value), base::kWhitespaceUTF16,
+ &value_stripped);
+ for (size_t i = 0; i < field.option_values.size(); ++i) {
+ base::string16 option_value_lowercase;
+ base::RemoveChars(base::StringToLowerASCII(field.option_values[i]),
+ base::kWhitespaceUTF16, &option_value_lowercase);
+ base::string16 option_contents_lowercase;
+ base::RemoveChars(base::StringToLowerASCII(field.option_contents[i]),
Evan Stade 2015/03/25 21:25:51 I don't think assuming this is ASCII and failing o
Lei Zhang 2015/03/25 22:18:48 base::StringToLowerASCII() doesn't fail if it enco
Evan Stade 2015/03/25 22:23:08 my point is that upper case accented character won
Lei Zhang 2015/03/25 22:39:03 Sure, that's a valid point, but I just want to mov
Evan Stade 2015/03/25 22:39:53 seems like it would only take about 5 minutes of e
+ base::kWhitespaceUTF16, &option_contents_lowercase);
+
+ // Perform a case-insensitive comparison.
+ if (value_stripped == option_value_lowercase ||
+ value_stripped == option_contents_lowercase) {
+ if (index)
+ *index = i;
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698