Index: components/autofill/core/browser/credit_card_field.cc |
diff --git a/components/autofill/core/browser/credit_card_field.cc b/components/autofill/core/browser/credit_card_field.cc |
index a9fe79e7c85bc5fd840c2761c053133b68a2d5c4..d97d54ec2e39902fd243309778a21950d6916366 100644 |
--- a/components/autofill/core/browser/credit_card_field.cc |
+++ b/components/autofill/core/browser/credit_card_field.cc |
@@ -60,7 +60,7 @@ scoped_ptr<FormField> CreditCardField::Parse(AutofillScanner* scanner) { |
// Credit card fields can appear in many different orders. |
// We loop until no more credit card related fields are found, see |break| at |
- // bottom of the loop. |
+ // the bottom of the loop. |
for (int fields = 0; !scanner->IsEnd(); ++fields) { |
// Ignore gift card fields. |
if (ParseField(scanner, base::UTF8ToUTF16(kGiftCardRe), nullptr)) |
@@ -89,11 +89,9 @@ scoped_ptr<FormField> CreditCardField::Parse(AutofillScanner* scanner) { |
} |
// Check for a credit card type (Visa, MasterCard, etc.) field. |
- if (!credit_card_field->type_ && |
- ParseFieldSpecifics(scanner, |
- base::UTF8ToUTF16(kCardTypeRe), |
- MATCH_DEFAULT | MATCH_SELECT, |
Evan Stade
2015/03/25 21:25:51
so we'll no longer fill text inputs?
Lei Zhang
2015/03/25 22:18:48
Correct. None of the websites in our heuristics te
Evan Stade
2015/03/25 22:23:08
k, seems fine. Can you put a comment to that effec
Lei Zhang
2015/03/25 22:39:03
Done.
|
- &credit_card_field->type_)) { |
+ if (!credit_card_field->type_ && LikelyCardTypeSelectField(scanner)) { |
+ credit_card_field->type_ = scanner->Cursor(); |
+ scanner->Advance(); |
continue; |
} |
@@ -150,14 +148,6 @@ scoped_ptr<FormField> CreditCardField::Parse(AutofillScanner* scanner) { |
return nullptr; |
} |
- // Some pages (e.g. ExpediaBilling.html) have a "card description" |
- // field; we parse this field but ignore it. |
- // We also ignore any other fields within a credit card block that |
- // start with "card", under the assumption that they are related to |
- // the credit card section being processed but are uninteresting to us. |
- if (ParseField(scanner, base::UTF8ToUTF16(kCardIgnoredRe), nullptr)) |
- continue; |
- |
break; |
} |
@@ -247,6 +237,30 @@ bool CreditCardField::LikelyCardYearSelectField(AutofillScanner* scanner) { |
FindConsecutiveStrings(years_to_check, field->option_contents)); |
} |
+// static |
+bool CreditCardField::LikelyCardTypeSelectField(AutofillScanner* scanner) { |
+ if (scanner->IsEnd()) |
+ return false; |
+ |
+ AutofillField* field = scanner->Cursor(); |
+ if (!MatchesFormControlType(field->form_control_type, MATCH_SELECT)) |
+ return false; |
+ |
+ // VISA and Mastercard are oftentimes branded as is in other countries, so |
+ // translations are probably not needed. |
+ const char* const kCardBrands[] = { |
Evan Stade
2015/03/25 21:25:51
nit: this is a little over-engineered imo. You can
Lei Zhang
2015/03/25 22:18:48
I'm just going to use IDS_AUTOFILL_CC_FOO since Ty
Evan Stade
2015/03/25 22:23:08
sgtm
|
+ "visa", |
+ "mastercard", |
+ }; |
+ for (const char* brand : kCardBrands) { |
+ if (AutofillField::FindValueInCreditTypeSelectControl( |
+ *field, base::ASCIIToUTF16(brand), nullptr)) { |
+ return true; |
+ } |
+ } |
+ return false; |
+} |
+ |
CreditCardField::CreditCardField() |
: cardholder_(nullptr), |
cardholder_last_(nullptr), |