OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/core/browser/credit_card_field.h" | 5 #include "components/autofill/core/browser/credit_card_field.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 // execute it only after we have found a valid credit card (first) name | 119 // execute it only after we have found a valid credit card (first) name |
120 // and haven't yet parsed the expiration date (which usually appears at | 120 // and haven't yet parsed the expiration date (which usually appears at |
121 // the end). | 121 // the end). |
122 if (!credit_card_field->expiration_month_ && | 122 if (!credit_card_field->expiration_month_ && |
123 ParseField(scanner, base::UTF8ToUTF16(kLastNameRe), | 123 ParseField(scanner, base::UTF8ToUTF16(kLastNameRe), |
124 &credit_card_field->cardholder_last_)) { | 124 &credit_card_field->cardholder_last_)) { |
125 continue; | 125 continue; |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 // Check for a credit card type (Visa, MasterCard, etc.) field. | 129 // Check for a credit card type (Visa, Mastercard, etc.) field. |
130 // All CC type fields encountered so far have been of type select. | 130 // All CC type fields encountered so far have been of type select. |
131 if (!credit_card_field->type_ && LikelyCardTypeSelectField(scanner)) { | 131 if (!credit_card_field->type_ && LikelyCardTypeSelectField(scanner)) { |
132 credit_card_field->type_ = scanner->Cursor(); | 132 credit_card_field->type_ = scanner->Cursor(); |
133 scanner->Advance(); | 133 scanner->Advance(); |
134 continue; | 134 continue; |
135 } | 135 } |
136 | 136 |
137 // We look for a card security code before we look for a credit card number | 137 // We look for a card security code before we look for a credit card number |
138 // and match the general term "number". The security code has a plethora of | 138 // and match the general term "number". The security code has a plethora of |
139 // names; we've seen "verification #", "verification number", "card | 139 // names; we've seen "verification #", "verification number", "card |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
305 bool CreditCardField::LikelyCardTypeSelectField(AutofillScanner* scanner) { | 305 bool CreditCardField::LikelyCardTypeSelectField(AutofillScanner* scanner) { |
306 if (scanner->IsEnd()) | 306 if (scanner->IsEnd()) |
307 return false; | 307 return false; |
308 | 308 |
309 AutofillField* field = scanner->Cursor(); | 309 AutofillField* field = scanner->Cursor(); |
310 | 310 |
311 if (!MatchesFormControlType(field->form_control_type, MATCH_SELECT)) | 311 if (!MatchesFormControlType(field->form_control_type, MATCH_SELECT)) |
312 return false; | 312 return false; |
313 | 313 |
314 // We set |ignore_whitespace| to true on these calls because this is actually | 314 // We set |ignore_whitespace| to true on these calls because this is actually |
315 // a pretty common mistake; e.g., "Master Card" instead of "MasterCard". | 315 // a pretty common mistake; e.g., "Master Card" instead of "Mastercard". |
Jared Saul
2017/04/18 01:21:57
Missed a "Master Card" even though it looks like y
jiahuiguo
2017/04/18 17:58:04
Done.
| |
316 bool isSelect = (AutofillField::FindShortestSubstringMatchInSelect( | 316 bool isSelect = (AutofillField::FindShortestSubstringMatchInSelect( |
317 l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA), true, | 317 l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA), true, |
318 field) >= 0) || | 318 field) >= 0) || |
319 (AutofillField::FindShortestSubstringMatchInSelect( | 319 (AutofillField::FindShortestSubstringMatchInSelect( |
320 l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD), | 320 l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD), |
321 true, field) >= 0); | 321 true, field) >= 0); |
322 return isSelect; | 322 return isSelect; |
323 } | 323 } |
324 | 324 |
325 // static | 325 // static |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
507 : ((expiration_year_ && expiration_year_->max_length == 2) | 507 : ((expiration_year_ && expiration_year_->max_length == 2) |
508 ? CREDIT_CARD_EXP_2_DIGIT_YEAR | 508 ? CREDIT_CARD_EXP_2_DIGIT_YEAR |
509 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 509 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
510 } | 510 } |
511 | 511 |
512 bool CreditCardField::HasExpiration() const { | 512 bool CreditCardField::HasExpiration() const { |
513 return expiration_date_ || (expiration_month_ && expiration_year_); | 513 return expiration_date_ || (expiration_month_ && expiration_year_); |
514 } | 514 } |
515 | 515 |
516 } // namespace autofill | 516 } // namespace autofill |
OLD | NEW |