| 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 "components/autofill/browser/credit_card_field.h" | 5 #include "components/autofill/browser/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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 if (ParseField(scanner, UTF8ToUTF16(autofill::kGiftCardRe), NULL)) | 33 if (ParseField(scanner, UTF8ToUTF16(autofill::kGiftCardRe), NULL)) |
| 34 break; | 34 break; |
| 35 | 35 |
| 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 |
| 41 // usually appears at the end). | 41 // usually appears at the end). |
| 42 if (credit_card_field->cardholder_ == NULL) { | 42 if (credit_card_field->cardholder_ == NULL) { |
| 43 string16 name_pattern; | 43 base::string16 name_pattern; |
| 44 if (fields == 0 || credit_card_field->expiration_month_) { | 44 if (fields == 0 || credit_card_field->expiration_month_) { |
| 45 // at beginning or end | 45 // at beginning or end |
| 46 name_pattern = UTF8ToUTF16(autofill::kNameOnCardRe); | 46 name_pattern = UTF8ToUTF16(autofill::kNameOnCardRe); |
| 47 } else { | 47 } else { |
| 48 name_pattern = UTF8ToUTF16(autofill::kNameOnCardContextualRe); | 48 name_pattern = UTF8ToUTF16(autofill::kNameOnCardContextualRe); |
| 49 } | 49 } |
| 50 | 50 |
| 51 if (ParseField(scanner, name_pattern, &credit_card_field->cardholder_)) | 51 if (ParseField(scanner, name_pattern, &credit_card_field->cardholder_)) |
| 52 continue; | 52 continue; |
| 53 | 53 |
| 54 // As a hard-coded hack for Expedia's billing pages (expedia_checkout.html | 54 // As a hard-coded hack for Expedia's billing pages (expedia_checkout.html |
| 55 // and ExpediaBilling.html in our test suite), recognize separate fields | 55 // and ExpediaBilling.html in our test suite), recognize separate fields |
| 56 // for the cardholder's first and last name if they have the labels "cfnm" | 56 // for the cardholder's first and last name if they have the labels "cfnm" |
| 57 // and "clnm". | 57 // and "clnm". |
| 58 scanner->SaveCursor(); | 58 scanner->SaveCursor(); |
| 59 const AutofillField* first; | 59 const AutofillField* first; |
| 60 if (ParseField(scanner, ASCIIToUTF16("^cfnm"), &first) && | 60 if (ParseField(scanner, ASCIIToUTF16("^cfnm"), &first) && |
| 61 ParseField(scanner, ASCIIToUTF16("^clnm"), | 61 ParseField(scanner, ASCIIToUTF16("^clnm"), |
| 62 &credit_card_field->cardholder_last_)) { | 62 &credit_card_field->cardholder_last_)) { |
| 63 credit_card_field->cardholder_ = first; | 63 credit_card_field->cardholder_ = first; |
| 64 continue; | 64 continue; |
| 65 } | 65 } |
| 66 scanner->Rewind(); | 66 scanner->Rewind(); |
| 67 } | 67 } |
| 68 | 68 |
| 69 // Check for a credit card type (Visa, MasterCard, etc.) field. | 69 // Check for a credit card type (Visa, MasterCard, etc.) field. |
| 70 string16 type_pattern = UTF8ToUTF16(autofill::kCardTypeRe); | 70 base::string16 type_pattern = UTF8ToUTF16(autofill::kCardTypeRe); |
| 71 if (!credit_card_field->type_ && | 71 if (!credit_card_field->type_ && |
| 72 ParseFieldSpecifics(scanner, type_pattern, | 72 ParseFieldSpecifics(scanner, type_pattern, |
| 73 MATCH_DEFAULT | MATCH_SELECT, | 73 MATCH_DEFAULT | MATCH_SELECT, |
| 74 &credit_card_field->type_)) { | 74 &credit_card_field->type_)) { |
| 75 continue; | 75 continue; |
| 76 } | 76 } |
| 77 | 77 |
| 78 // We look for a card security code before we look for a credit | 78 // We look for a card security code before we look for a credit |
| 79 // card number and match the general term "number". The security code | 79 // card number and match the general term "number". The security code |
| 80 // has a plethora of names; we've seen "verification #", | 80 // has a plethora of names; we've seen "verification #", |
| 81 // "verification number", "card identification number" and others listed | 81 // "verification number", "card identification number" and others listed |
| 82 // in the |pattern| below. | 82 // in the |pattern| below. |
| 83 string16 pattern = UTF8ToUTF16(autofill::kCardCvcRe); | 83 base::string16 pattern = UTF8ToUTF16(autofill::kCardCvcRe); |
| 84 if (!credit_card_field->verification_ && | 84 if (!credit_card_field->verification_ && |
| 85 ParseField(scanner, pattern, &credit_card_field->verification_)) { | 85 ParseField(scanner, pattern, &credit_card_field->verification_)) { |
| 86 continue; | 86 continue; |
| 87 } | 87 } |
| 88 | 88 |
| 89 pattern = UTF8ToUTF16(autofill::kCardNumberRe); | 89 pattern = UTF8ToUTF16(autofill::kCardNumberRe); |
| 90 if (!credit_card_field->number_ && | 90 if (!credit_card_field->number_ && |
| 91 ParseField(scanner, pattern, &credit_card_field->number_)) { | 91 ParseField(scanner, pattern, &credit_card_field->number_)) { |
| 92 continue; | 92 continue; |
| 93 } | 93 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 map); | 220 map); |
| 221 } else { | 221 } else { |
| 222 ok = ok && AddClassification(expiration_year_, | 222 ok = ok && AddClassification(expiration_year_, |
| 223 CREDIT_CARD_EXP_4_DIGIT_YEAR, | 223 CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 224 map); | 224 map); |
| 225 } | 225 } |
| 226 } | 226 } |
| 227 | 227 |
| 228 return ok; | 228 return ok; |
| 229 } | 229 } |
| OLD | NEW |