| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/autofill/credit_card_field.h" | 5 #include "chrome/browser/autofill/credit_card_field.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/string16.h" | 11 #include "base/string16.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/autofill/autofill_ecml.h" | 14 #include "chrome/browser/autofill/autofill_ecml.h" |
| 15 #include "chrome/browser/autofill/autofill_field.h" | 15 #include "chrome/browser/autofill/autofill_field.h" |
| 16 #include "chrome/browser/autofill/autofill_scanner.h" | 16 #include "chrome/browser/autofill/autofill_scanner.h" |
| 17 #include "chrome/browser/autofill/field_types.h" | 17 #include "chrome/browser/autofill/field_types.h" |
| 18 #include "grit/autofill_resources.h" | 18 #include "grit/autofill_resources.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 20 | 20 |
| 21 using autofill::GetEcmlPattern; | 21 using autofill::GetEcmlPattern; |
| 22 | 22 |
| 23 // static | 23 // static |
| 24 FormField* CreditCardField::Parse(AutofillScanner* scanner, | 24 FormField* CreditCardField::Parse(AutofillScanner* scanner, |
| 25 bool is_ecml) { | 25 bool is_ecml) { |
| 26 if (scanner->IsEnd()) | 26 if (scanner->IsEnd()) |
| 27 return NULL; | 27 return NULL; |
| 28 | 28 |
| 29 scoped_ptr<CreditCardField> credit_card_field(new CreditCardField); | 29 scoped_ptr<CreditCardField> credit_card_field(new CreditCardField); |
| 30 scanner->SaveCursor(); | 30 size_t saved_cursor = scanner->SaveCursor(); |
| 31 | 31 |
| 32 // Credit card fields can appear in many different orders. | 32 // Credit card fields can appear in many different orders. |
| 33 // We loop until no more credit card related fields are found, see |break| at | 33 // We loop until no more credit card related fields are found, see |break| at |
| 34 // bottom of the loop. | 34 // bottom of the loop. |
| 35 for (int fields = 0; !scanner->IsEnd(); ++fields) { | 35 for (int fields = 0; !scanner->IsEnd(); ++fields) { |
| 36 // Sometimes the cardholder field is just labeled "name". Unfortunately this | 36 // Sometimes the cardholder field is just labeled "name". Unfortunately this |
| 37 // is a dangerously generic word to search for, since it will often match a | 37 // is a dangerously generic word to search for, since it will often match a |
| 38 // name (not cardholder name) field before or after credit card fields. So | 38 // name (not cardholder name) field before or after credit card fields. So |
| 39 // we search for "name" only when we've already parsed at least one other | 39 // we search for "name" only when we've already parsed at least one other |
| 40 // credit card field and haven't yet parsed the expiration date (which | 40 // credit card field and haven't yet parsed the expiration date (which |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 credit_card_field->expiration_month_->IsEmpty()) && | 124 credit_card_field->expiration_month_->IsEmpty()) && |
| 125 ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT | MATCH_SELECT, | 125 ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT | MATCH_SELECT, |
| 126 &credit_card_field->expiration_month_)) { | 126 &credit_card_field->expiration_month_)) { |
| 127 if (is_ecml) | 127 if (is_ecml) |
| 128 pattern = GetEcmlPattern(kEcmlCardExpireYear); | 128 pattern = GetEcmlPattern(kEcmlCardExpireYear); |
| 129 else | 129 else |
| 130 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_DATE_RE); | 130 pattern = l10n_util::GetStringUTF16(IDS_AUTOFILL_EXPIRATION_DATE_RE); |
| 131 | 131 |
| 132 if (!ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT | MATCH_SELECT, | 132 if (!ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT | MATCH_SELECT, |
| 133 &credit_card_field->expiration_year_)) { | 133 &credit_card_field->expiration_year_)) { |
| 134 scanner->Rewind(); | 134 scanner->RewindTo(saved_cursor); |
| 135 return NULL; | 135 return NULL; |
| 136 } | 136 } |
| 137 continue; | 137 continue; |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 | 140 |
| 141 if (ParseFieldSpecifics(scanner, GetEcmlPattern(kEcmlCardExpireDay), | 141 if (ParseFieldSpecifics(scanner, GetEcmlPattern(kEcmlCardExpireDay), |
| 142 MATCH_DEFAULT | MATCH_SELECT, NULL)) { | 142 MATCH_DEFAULT | MATCH_SELECT, NULL)) { |
| 143 continue; | 143 continue; |
| 144 } | 144 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 172 // the cvc and date were found independently they are returned. | 172 // the cvc and date were found independently they are returned. |
| 173 if ((credit_card_field->number_ || credit_card_field->verification_) && | 173 if ((credit_card_field->number_ || credit_card_field->verification_) && |
| 174 credit_card_field->expiration_month_ && | 174 credit_card_field->expiration_month_ && |
| 175 (credit_card_field->expiration_year_ || | 175 (credit_card_field->expiration_year_ || |
| 176 (LowerCaseEqualsASCII( | 176 (LowerCaseEqualsASCII( |
| 177 credit_card_field->expiration_month_->form_control_type, | 177 credit_card_field->expiration_month_->form_control_type, |
| 178 "month")))) { | 178 "month")))) { |
| 179 return credit_card_field.release(); | 179 return credit_card_field.release(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 scanner->Rewind(); | 182 scanner->RewindTo(saved_cursor); |
| 183 return NULL; | 183 return NULL; |
| 184 } | 184 } |
| 185 | 185 |
| 186 CreditCardField::CreditCardField() | 186 CreditCardField::CreditCardField() |
| 187 : cardholder_(NULL), | 187 : cardholder_(NULL), |
| 188 cardholder_last_(NULL), | 188 cardholder_last_(NULL), |
| 189 type_(NULL), | 189 type_(NULL), |
| 190 number_(NULL), | 190 number_(NULL), |
| 191 verification_(NULL), | 191 verification_(NULL), |
| 192 expiration_month_(NULL), | 192 expiration_month_(NULL), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 203 if (cardholder_last_ == NULL) | 203 if (cardholder_last_ == NULL) |
| 204 ok = ok && AddClassification(cardholder_, CREDIT_CARD_NAME, map); | 204 ok = ok && AddClassification(cardholder_, CREDIT_CARD_NAME, map); |
| 205 | 205 |
| 206 ok = ok && AddClassification(type_, CREDIT_CARD_TYPE, map); | 206 ok = ok && AddClassification(type_, CREDIT_CARD_TYPE, map); |
| 207 ok = ok && AddClassification(expiration_month_, CREDIT_CARD_EXP_MONTH, map); | 207 ok = ok && AddClassification(expiration_month_, CREDIT_CARD_EXP_MONTH, map); |
| 208 ok = ok && AddClassification(expiration_year_, | 208 ok = ok && AddClassification(expiration_year_, |
| 209 CREDIT_CARD_EXP_4_DIGIT_YEAR, | 209 CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 210 map); | 210 map); |
| 211 return ok; | 211 return ok; |
| 212 } | 212 } |
| OLD | NEW |