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 09dab1e48d796800fda5065ee6cb54075fd5697a..1d0812b7e8675d209eaa98cf146cfbf9c0cf3a77 100644 |
--- a/components/autofill/core/browser/credit_card_field.cc |
+++ b/components/autofill/core/browser/credit_card_field.cc |
@@ -6,6 +6,8 @@ |
#include <stddef.h> |
+#include <algorithm> |
+ |
#include "base/logging.h" |
#include "base/memory/scoped_ptr.h" |
#include "base/strings/string16.h" |
@@ -19,6 +21,8 @@ |
namespace autofill { |
+static const size_t kMaxValidCardNumberSize = 19; |
+ |
// static |
FormField* CreditCardField::Parse(AutofillScanner* scanner) { |
if (scanner->IsEnd()) |
@@ -89,8 +93,26 @@ FormField* CreditCardField::Parse(AutofillScanner* scanner) { |
} |
pattern = base::UTF8ToUTF16(autofill::kCardNumberRe); |
- if (!credit_card_field->number_ && |
- ParseField(scanner, pattern, &credit_card_field->number_)) { |
+ const AutofillField* cc_number_field; |
+ if (ParseField(scanner, pattern, &cc_number_field)) { |
+ // Avoid autofilling any credit card number field having very low or high |
+ // |start_index| on the HTML form. |
+ size_t start_index = 0; |
+ if (!credit_card_field->numbers_.empty()) { |
+ size_t last_number_field_size = |
+ credit_card_field->numbers_.back() |
+ ->credit_card_number_start_index() + |
Evan Stade
2014/08/12 16:05:07
style-wise, a lot of this seems off to me. Could y
Pritam Nikam
2014/08/12 18:39:11
It's after git cl format only :)
|
+ credit_card_field->numbers_.back()->max_length; |
+ if (!last_number_field_size || |
Evan Stade
2014/08/12 16:05:07
please don't implicitly convert size_t to boolean.
Pritam Nikam
2014/08/12 18:39:11
Done.
|
+ last_number_field_size >= kMaxValidCardNumberSize) |
+ return NULL; |
Evan Stade
2014/08/12 16:05:07
\n
Pritam Nikam
2014/08/12 18:39:11
Done.
|
+ start_index = last_number_field_size; |
+ } |
+ |
+ AutofillField* current_number_field = |
+ const_cast<AutofillField*>(cc_number_field); |
Evan Stade
2014/08/12 16:05:07
you still have this const_cast... I agree with Ily
Pritam Nikam
2014/08/12 18:39:11
[Same as my previous comments]
I didn't get any al
Evan Stade
2014/08/12 19:19:55
What is the cursor module?
|
+ current_number_field->set_credit_card_number_start_index(start_index); |
+ credit_card_field->numbers_.push_back(current_number_field); |
continue; |
} |
@@ -167,7 +189,8 @@ FormField* CreditCardField::Parse(AutofillScanner* scanner) { |
// a strong enough signal that this is a credit card. It is possible that |
// the number and name were parsed in a separate part of the form. So if |
// the cvc and date were found independently they are returned. |
- if ((credit_card_field->number_ || credit_card_field->verification_) && |
+ if ((!credit_card_field->numbers_.empty() || |
+ credit_card_field->verification_) && |
(credit_card_field->expiration_date_ || |
(credit_card_field->expiration_month_ && |
credit_card_field->expiration_year_))) { |
@@ -182,7 +205,6 @@ CreditCardField::CreditCardField() |
: cardholder_(NULL), |
cardholder_last_(NULL), |
type_(NULL), |
- number_(NULL), |
verification_(NULL), |
expiration_month_(NULL), |
expiration_year_(NULL), |
@@ -190,8 +212,17 @@ CreditCardField::CreditCardField() |
is_two_digit_year_(false) { |
} |
+CreditCardField::~CreditCardField() { |
+} |
+ |
bool CreditCardField::ClassifyField(ServerFieldTypeMap* map) const { |
- bool ok = AddClassification(number_, CREDIT_CARD_NUMBER, map); |
+ bool ok = true; |
+ for (std::vector<const AutofillField*>::const_iterator it = numbers_.begin(); |
+ it != numbers_.end(); |
+ ++it) { |
+ ok = ok && AddClassification(*it, CREDIT_CARD_NUMBER, map); |
+ } |
+ |
ok = ok && AddClassification(type_, CREDIT_CARD_TYPE, map); |
ok = ok && AddClassification(verification_, CREDIT_CARD_VERIFICATION_CODE, |
map); |