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

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: rebase 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..db3046ad4ce39634f78885217c070c1827b45497 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::FindValueInSelectControl(*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::FindValueInSelectControl(const FormFieldData& field,
+ const base::string16& value,
+ size_t* index) {
+ // TODO(thestig): Improve this. See http://crbug.com/470726)
+ // 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.
+ if (value_stripped == option_value_lowercase ||
+ value_stripped == option_contents_lowercase) {
+ if (index)
+ *index = i;
+ return true;
+ }
+ }
+ return false;
+}
+
} // namespace autofill
« no previous file with comments | « components/autofill/core/browser/autofill_field.h ('k') | components/autofill/core/browser/autofill_regex_constants.cc.utf8 » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698