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_field.h" | 14 #include "chrome/browser/autofill/autofill_field.h" |
15 #include "chrome/browser/autofill/autofill_regex_constants.h" | 15 #include "chrome/browser/autofill/autofill_regex_constants.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 "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
19 | 19 |
20 // static | 20 // static |
21 FormField* CreditCardField::Parse(AutofillScanner* scanner, | 21 FormField* CreditCardField::Parse(AutofillScanner* scanner) { |
22 bool parse_new_field_types) { | |
23 if (scanner->IsEnd()) | 22 if (scanner->IsEnd()) |
24 return NULL; | 23 return NULL; |
25 | 24 |
26 scoped_ptr<CreditCardField> credit_card_field(new CreditCardField); | 25 scoped_ptr<CreditCardField> credit_card_field(new CreditCardField); |
27 size_t saved_cursor = scanner->SaveCursor(); | 26 size_t saved_cursor = scanner->SaveCursor(); |
28 | 27 |
29 // Credit card fields can appear in many different orders. | 28 // Credit card fields can appear in many different orders. |
30 // We loop until no more credit card related fields are found, see |break| at | 29 // We loop until no more credit card related fields are found, see |break| at |
31 // bottom of the loop. | 30 // bottom of the loop. |
32 for (int fields = 0; !scanner->IsEnd(); ++fields) { | 31 for (int fields = 0; !scanner->IsEnd(); ++fields) { |
(...skipping 28 matching lines...) Expand all Loading... |
61 if (ParseField(scanner, ASCIIToUTF16("^cfnm"), &first) && | 60 if (ParseField(scanner, ASCIIToUTF16("^cfnm"), &first) && |
62 ParseField(scanner, ASCIIToUTF16("^clnm"), | 61 ParseField(scanner, ASCIIToUTF16("^clnm"), |
63 &credit_card_field->cardholder_last_)) { | 62 &credit_card_field->cardholder_last_)) { |
64 credit_card_field->cardholder_ = first; | 63 credit_card_field->cardholder_ = first; |
65 continue; | 64 continue; |
66 } | 65 } |
67 scanner->Rewind(); | 66 scanner->Rewind(); |
68 } | 67 } |
69 | 68 |
70 // Check for a credit card type (Visa, MasterCard, etc.) field. | 69 // Check for a credit card type (Visa, MasterCard, etc.) field. |
71 if (parse_new_field_types) { | 70 string16 type_pattern = UTF8ToUTF16(autofill::kCardTypeRe); |
72 string16 type_pattern = UTF8ToUTF16(autofill::kCardTypeRe); | 71 if (!credit_card_field->type_ && |
73 if (!credit_card_field->type_ && | 72 ParseFieldSpecifics(scanner, type_pattern, |
74 ParseFieldSpecifics(scanner, type_pattern, | 73 MATCH_DEFAULT | MATCH_SELECT, |
75 MATCH_DEFAULT | MATCH_SELECT, | 74 &credit_card_field->type_)) { |
76 &credit_card_field->type_)) { | 75 continue; |
77 continue; | |
78 } | |
79 } | 76 } |
80 | 77 |
81 // 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 |
82 // card number and match the general term "number". The security code | 79 // card number and match the general term "number". The security code |
83 // has a plethora of names; we've seen "verification #", | 80 // has a plethora of names; we've seen "verification #", |
84 // "verification number", "card identification number" and others listed | 81 // "verification number", "card identification number" and others listed |
85 // in the |pattern| below. | 82 // in the |pattern| below. |
86 string16 pattern = UTF8ToUTF16(autofill::kCardCvcRe); | 83 string16 pattern = UTF8ToUTF16(autofill::kCardCvcRe); |
87 if (!credit_card_field->verification_ && | 84 if (!credit_card_field->verification_ && |
88 ParseField(scanner, pattern, &credit_card_field->verification_)) { | 85 ParseField(scanner, pattern, &credit_card_field->verification_)) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 map); | 220 map); |
224 } else { | 221 } else { |
225 ok = ok && AddClassification(expiration_year_, | 222 ok = ok && AddClassification(expiration_year_, |
226 CREDIT_CARD_EXP_4_DIGIT_YEAR, | 223 CREDIT_CARD_EXP_4_DIGIT_YEAR, |
227 map); | 224 map); |
228 } | 225 } |
229 } | 226 } |
230 | 227 |
231 return ok; | 228 return ok; |
232 } | 229 } |
OLD | NEW |