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

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

Issue 1753253003: [Autofill] Fix heuristics to detect consecutive CVCs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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/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 871dcbb046b563683497295dc3f435e8af71c116..0c54e6f268bdea3e1b7c0aa7cfd3017fc57f9c39 100644
--- a/components/autofill/core/browser/credit_card_field.cc
+++ b/components/autofill/core/browser/credit_card_field.cc
@@ -72,7 +72,6 @@ bool FieldCanFitDataForFieldType(int max_length, ServerFieldType type) {
}
}
-
} // namespace
// static
@@ -143,6 +142,31 @@ scoped_ptr<FormField> CreditCardField::Parse(AutofillScanner* scanner) {
base::UTF8ToUTF16(kCardCvcRe),
kMatchNumAndTel | MATCH_PASSWORD,
Mathieu 2016/03/04 18:54:38 note: add MATCH_PASSWORD to the constant above.
Toyama 2016/03/04 19:29:40 I think that makes sense, but it might introduce d
sebsg 2016/03/09 16:38:35 Once I rebase the other will use password also, so
sebsg 2016/03/09 16:38:36 Done.
&credit_card_field->verification_)) {
+ // A couple of sites have multiple verification codes right after an
Toyama 2016/03/04 19:08:49 s/an another/another/
sebsg 2016/03/09 16:38:35 Done.
+ // other. Allow the classification of these codes one by one.
+ AutofillField* cvv = credit_card_field->verification_;
Mathieu 2016/03/04 18:54:38 rename to |saved_cvv|?
Toyama 2016/03/04 19:08:50 const
sebsg 2016/03/09 16:38:35 Done.
sebsg 2016/03/09 16:38:35 Done.
+
+ // Make sure that only a verification code was found.
Mathieu 2016/03/04 18:54:38 Combine the previous comment with this: // If the
Toyama 2016/03/04 19:08:49 s/a/one/
sebsg 2016/03/09 16:38:35 Done.
sebsg 2016/03/09 16:38:35 Done.
+ if (credit_card_field->numbers_.empty() &&
+ !credit_card_field->HasExpiration() &&
+ !credit_card_field->cardholder_) {
+ // Check if the previous field was a verification code.
+ scanner->RewindTo(scanner->SaveCursor() - 2);
+ if (ParseFieldSpecifics(scanner, base::UTF8ToUTF16(kCardCvcRe),
+ kMatchNumAndTel | MATCH_PASSWORD,
+ &credit_card_field->verification_)) {
+ // Reset the current cvv (The verification parse overwrote it).
+ credit_card_field->verification_ = cvv;
+ // Put the scanner back to the field right after the current cvv.
+ scanner->Advance();
+ return std::move(credit_card_field);
Mathieu 2016/03/04 18:54:38 wait, isn't |credit_card_field| mostly empty here?
sebsg 2016/03/09 16:38:35 At this point it contains only a CVV. The effect o
+ } else {
+ // Put the scanner back to the field right after the current cvv.
+ scanner->Advance();
+ scanner->Advance();
+ }
+ }
+
continue;
}
@@ -202,10 +226,7 @@ scoped_ptr<FormField> CreditCardField::Parse(AutofillScanner* scanner) {
// the cvc and date were found independently they are returned.
bool has_cc_number_or_verification = (credit_card_field->verification_ ||
Toyama 2016/03/04 19:29:40 This is not your change, but this should be const.
sebsg 2016/03/09 16:38:35 Done.
!credit_card_field->numbers_.empty());
- bool has_date_or_mm_yy = (credit_card_field->expiration_date_ ||
- (credit_card_field->expiration_month_ &&
- credit_card_field->expiration_year_));
- if (has_cc_number_or_verification && has_date_or_mm_yy)
+ if (has_cc_number_or_verification && credit_card_field->HasExpiration())
return std::move(credit_card_field);
scanner->RewindTo(saved_cursor);
@@ -477,4 +498,8 @@ ServerFieldType CreditCardField::GetExpirationYearType() const {
: CREDIT_CARD_EXP_4_DIGIT_YEAR));
}
+bool CreditCardField::HasExpiration() const {
+ return expiration_date_ || (expiration_month_ && expiration_year_);
+}
+
} // namespace autofill
« no previous file with comments | « components/autofill/core/browser/credit_card_field.h ('k') | components/autofill/core/browser/credit_card_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698