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" |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
43 string16 name_pattern; | 43 string16 name_pattern; |
44 if (is_ecml) { | 44 if (is_ecml) { |
45 name_pattern = GetEcmlPattern(kEcmlCardHolder); | 45 name_pattern = GetEcmlPattern(kEcmlCardHolder); |
46 } else { | 46 } else { |
47 if (fields == 0 || credit_card_field->expiration_month_) { | 47 if (fields == 0 || credit_card_field->expiration_month_) { |
48 // at beginning or end | 48 // at beginning or end |
49 name_pattern = l10n_util::GetStringUTF16( | 49 name_pattern = l10n_util::GetStringUTF16( |
50 IDS_AUTOFILL_NAME_ON_CARD_RE); | 50 IDS_AUTOFILL_NAME_ON_CARD_RE); |
51 } else { | 51 } else { |
52 name_pattern = l10n_util::GetStringUTF16( | 52 name_pattern = l10n_util::GetStringUTF16( |
53 IDS_AUTOFILL_NAME_ON_CARD_CONTEXTUAL_RE); | 53 IDS_AUTOFILL_NAME_ON_CARD_CONTEXTUAL_RE); |
dhollowa
2011/08/01 17:02:27
This is the source of the problem. This essential
| |
54 } | 54 } |
55 } | 55 } |
56 | 56 |
57 if (ParseField(scanner, name_pattern, &credit_card_field->cardholder_)) | 57 if (ParseField(scanner, name_pattern, &credit_card_field->cardholder_)) |
58 continue; | 58 continue; |
59 | 59 |
60 // As a hard-coded hack for Expedia's billing pages (expedia_checkout.html | 60 // As a hard-coded hack for Expedia's billing pages (expedia_checkout.html |
61 // and ExpediaBilling.html in our test suite), recognize separate fields | 61 // and ExpediaBilling.html in our test suite), recognize separate fields |
62 // for the cardholder's first and last name if they have the labels "cfnm" | 62 // for the cardholder's first and last name if they have the labels "cfnm" |
63 // and "clnm". | 63 // and "clnm". |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
150 // the credit card section being processed but are uninteresting to us. | 150 // the credit card section being processed but are uninteresting to us. |
151 if (ParseField(scanner, | 151 if (ParseField(scanner, |
152 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_IGNORED_RE), | 152 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_IGNORED_RE), |
153 NULL)) { | 153 NULL)) { |
154 continue; | 154 continue; |
155 } | 155 } |
156 | 156 |
157 break; | 157 break; |
158 } | 158 } |
159 | 159 |
160 bool has_expiration_year_month = credit_card_field->expiration_month_ && | |
161 (credit_card_field->expiration_year_ || | |
162 LowerCaseEqualsASCII( | |
163 credit_card_field->expiration_month_->form_control_type, "month")); | |
164 | |
160 // Some pages have a billing address field after the cardholder name field. | 165 // Some pages have a billing address field after the cardholder name field. |
161 // For that case, allow only just the cardholder name field. The remaining | 166 // For that case, allow only just the cardholder name field. The remaining |
162 // CC fields will be picked up in a following CreditCardField. | 167 // CC fields will be picked up in a following CreditCardField. |
163 if (credit_card_field->cardholder_) | 168 // But credit card number is strongly tied with expiration year/month, so |
169 // we should eliminate the case when we found only card number without | |
170 // expiration year/month. | |
171 if (credit_card_field->cardholder_ && | |
172 !(credit_card_field->number_ && !has_expiration_year_month)) { | |
164 return credit_card_field.release(); | 173 return credit_card_field.release(); |
174 } | |
165 | 175 |
166 // On some pages, the user selects a card type using radio buttons | 176 // On some pages, the user selects a card type using radio buttons |
167 // (e.g. test page Apple Store Billing.html). We can't handle that yet, | 177 // (e.g. test page Apple Store Billing.html). We can't handle that yet, |
168 // so we treat the card type as optional for now. | 178 // so we treat the card type as optional for now. |
169 // The existence of a number or cvc in combination with expiration date is | 179 // The existence of a number or cvc in combination with expiration date is |
170 // a strong enough signal that this is a credit card. It is possible that | 180 // a strong enough signal that this is a credit card. It is possible that |
171 // the number and name were parsed in a separate part of the form. So if | 181 // the number and name were parsed in a separate part of the form. So if |
172 // the cvc and date were found independently they are returned. | 182 // the cvc and date were found independently they are returned. |
173 if ((credit_card_field->number_ || credit_card_field->verification_) && | 183 if ((credit_card_field->number_ || credit_card_field->verification_) && |
174 credit_card_field->expiration_month_ && | 184 has_expiration_year_month) { |
175 (credit_card_field->expiration_year_ || | |
176 (LowerCaseEqualsASCII( | |
177 credit_card_field->expiration_month_->form_control_type, | |
178 "month")))) { | |
179 return credit_card_field.release(); | 185 return credit_card_field.release(); |
180 } | 186 } |
181 | 187 |
182 scanner->RewindTo(saved_cursor); | 188 scanner->RewindTo(saved_cursor); |
183 return NULL; | 189 return NULL; |
184 } | 190 } |
185 | 191 |
186 CreditCardField::CreditCardField() | 192 CreditCardField::CreditCardField() |
187 : cardholder_(NULL), | 193 : cardholder_(NULL), |
188 cardholder_last_(NULL), | 194 cardholder_last_(NULL), |
(...skipping 14 matching lines...) Expand all Loading... | |
203 if (cardholder_last_ == NULL) | 209 if (cardholder_last_ == NULL) |
204 ok = ok && AddClassification(cardholder_, CREDIT_CARD_NAME, map); | 210 ok = ok && AddClassification(cardholder_, CREDIT_CARD_NAME, map); |
205 | 211 |
206 ok = ok && AddClassification(type_, CREDIT_CARD_TYPE, map); | 212 ok = ok && AddClassification(type_, CREDIT_CARD_TYPE, map); |
207 ok = ok && AddClassification(expiration_month_, CREDIT_CARD_EXP_MONTH, map); | 213 ok = ok && AddClassification(expiration_month_, CREDIT_CARD_EXP_MONTH, map); |
208 ok = ok && AddClassification(expiration_year_, | 214 ok = ok && AddClassification(expiration_year_, |
209 CREDIT_CARD_EXP_4_DIGIT_YEAR, | 215 CREDIT_CARD_EXP_4_DIGIT_YEAR, |
210 map); | 216 map); |
211 return ok; | 217 return ok; |
212 } | 218 } |
OLD | NEW |