Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: components/autofill/core/browser/credit_card_field.cc

Issue 381613005: [Autofill] Autofill fails to fill credit card number when split across fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // card number and match the general term "number". The security code 81 // card number and match the general term "number". The security code
82 // has a plethora of names; we've seen "verification #", 82 // has a plethora of names; we've seen "verification #",
83 // "verification number", "card identification number" and others listed 83 // "verification number", "card identification number" and others listed
84 // in the |pattern| below. 84 // in the |pattern| below.
85 base::string16 pattern = base::UTF8ToUTF16(autofill::kCardCvcRe); 85 base::string16 pattern = base::UTF8ToUTF16(autofill::kCardCvcRe);
86 if (!credit_card_field->verification_ && 86 if (!credit_card_field->verification_ &&
87 ParseField(scanner, pattern, &credit_card_field->verification_)) { 87 ParseField(scanner, pattern, &credit_card_field->verification_)) {
88 continue; 88 continue;
89 } 89 }
90 90
91 pattern = base::UTF8ToUTF16(autofill::kCardNumberPart1Re);
92 if (!credit_card_field->number_part1_ &&
93 ParseField(scanner, pattern, &credit_card_field->number_part1_)) {
94 continue;
95 }
96
97 pattern = base::UTF8ToUTF16(autofill::kCardNumberPart2Re);
98 if (!credit_card_field->number_part2_ &&
99 ParseField(scanner, pattern, &credit_card_field->number_part2_)) {
100 continue;
101 }
102
103 pattern = base::UTF8ToUTF16(autofill::kCardNumberPart3Re);
104 if (!credit_card_field->number_part3_ &&
105 ParseField(scanner, pattern, &credit_card_field->number_part3_)) {
106 continue;
107 }
108
109 pattern = base::UTF8ToUTF16(autofill::kCardNumberPart4Re);
110 if (!credit_card_field->number_part4_ &&
111 ParseField(scanner, pattern, &credit_card_field->number_part4_)) {
112 continue;
113 }
114
91 pattern = base::UTF8ToUTF16(autofill::kCardNumberRe); 115 pattern = base::UTF8ToUTF16(autofill::kCardNumberRe);
92 if (!credit_card_field->number_ && 116 if (!credit_card_field->number_full_ &&
93 ParseField(scanner, pattern, &credit_card_field->number_)) { 117 ParseField(scanner, pattern, &credit_card_field->number_full_)) {
94 continue; 118 continue;
95 } 119 }
96 120
97 if (LowerCaseEqualsASCII(scanner->Cursor()->form_control_type, "month")) { 121 if (LowerCaseEqualsASCII(scanner->Cursor()->form_control_type, "month")) {
98 credit_card_field->expiration_date_ = scanner->Cursor(); 122 credit_card_field->expiration_date_ = scanner->Cursor();
99 scanner->Advance(); 123 scanner->Advance();
100 } else { 124 } else {
101 // First try to parse split month/year expiration fields. 125 // First try to parse split month/year expiration fields.
102 scanner->SaveCursor(); 126 scanner->SaveCursor();
103 pattern = base::UTF8ToUTF16(autofill::kExpirationMonthRe); 127 pattern = base::UTF8ToUTF16(autofill::kExpirationMonthRe);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (credit_card_field->cardholder_) 184 if (credit_card_field->cardholder_)
161 return credit_card_field.release(); 185 return credit_card_field.release();
162 186
163 // On some pages, the user selects a card type using radio buttons 187 // On some pages, the user selects a card type using radio buttons
164 // (e.g. test page Apple Store Billing.html). We can't handle that yet, 188 // (e.g. test page Apple Store Billing.html). We can't handle that yet,
165 // so we treat the card type as optional for now. 189 // so we treat the card type as optional for now.
166 // The existence of a number or cvc in combination with expiration date is 190 // The existence of a number or cvc in combination with expiration date is
167 // a strong enough signal that this is a credit card. It is possible that 191 // a strong enough signal that this is a credit card. It is possible that
168 // the number and name were parsed in a separate part of the form. So if 192 // the number and name were parsed in a separate part of the form. So if
169 // the cvc and date were found independently they are returned. 193 // the cvc and date were found independently they are returned.
170 if ((credit_card_field->number_ || credit_card_field->verification_) && 194 if ((credit_card_field->number_full_ || credit_card_field->verification_) &&
171 (credit_card_field->expiration_date_ || 195 (credit_card_field->expiration_date_ ||
172 (credit_card_field->expiration_month_ && 196 (credit_card_field->expiration_month_ &&
173 credit_card_field->expiration_year_))) { 197 credit_card_field->expiration_year_))) {
174 return credit_card_field.release(); 198 return credit_card_field.release();
175 } 199 }
176 200
177 scanner->RewindTo(saved_cursor); 201 scanner->RewindTo(saved_cursor);
178 return NULL; 202 return NULL;
179 } 203 }
180 204
181 CreditCardField::CreditCardField() 205 CreditCardField::CreditCardField()
182 : cardholder_(NULL), 206 : cardholder_(NULL),
183 cardholder_last_(NULL), 207 cardholder_last_(NULL),
184 type_(NULL), 208 type_(NULL),
185 number_(NULL), 209 number_full_(NULL),
210 number_part1_(NULL),
211 number_part2_(NULL),
212 number_part3_(NULL),
213 number_part4_(NULL),
186 verification_(NULL), 214 verification_(NULL),
187 expiration_month_(NULL), 215 expiration_month_(NULL),
188 expiration_year_(NULL), 216 expiration_year_(NULL),
189 expiration_date_(NULL), 217 expiration_date_(NULL),
190 is_two_digit_year_(false) { 218 is_two_digit_year_(false) {
191 } 219 }
192 220
193 bool CreditCardField::ClassifyField(ServerFieldTypeMap* map) const { 221 bool CreditCardField::ClassifyField(ServerFieldTypeMap* map) const {
194 bool ok = AddClassification(number_, CREDIT_CARD_NUMBER, map); 222 bool ok = AddClassification(number_full_, CREDIT_CARD_NUMBER, map);
195 ok = ok && AddClassification(type_, CREDIT_CARD_TYPE, map); 223 ok = ok && AddClassification(type_, CREDIT_CARD_TYPE, map);
196 ok = ok && AddClassification(verification_, CREDIT_CARD_VERIFICATION_CODE, 224 ok = ok && AddClassification(verification_, CREDIT_CARD_VERIFICATION_CODE,
197 map); 225 map);
198 226
199 // If the heuristics detected first and last name in separate fields, 227 // If the heuristics detected first and last name in separate fields,
200 // then ignore both fields. Putting them into separate fields is probably 228 // then ignore both fields. Putting them into separate fields is probably
201 // wrong, because the credit card can also contain a middle name or middle 229 // wrong, because the credit card can also contain a middle name or middle
202 // initial. 230 // initial.
203 if (cardholder_last_ == NULL) 231 if (cardholder_last_ == NULL)
204 ok = ok && AddClassification(cardholder_, CREDIT_CARD_NAME, map); 232 ok = ok && AddClassification(cardholder_, CREDIT_CARD_NAME, map);
(...skipping 11 matching lines...) Expand all
216 if (is_two_digit_year_) { 244 if (is_two_digit_year_) {
217 ok = ok && AddClassification(expiration_year_, 245 ok = ok && AddClassification(expiration_year_,
218 CREDIT_CARD_EXP_2_DIGIT_YEAR, 246 CREDIT_CARD_EXP_2_DIGIT_YEAR,
219 map); 247 map);
220 } else { 248 } else {
221 ok = ok && AddClassification(expiration_year_, 249 ok = ok && AddClassification(expiration_year_,
222 CREDIT_CARD_EXP_4_DIGIT_YEAR, 250 CREDIT_CARD_EXP_4_DIGIT_YEAR,
223 map); 251 map);
224 } 252 }
225 } 253 }
254 if (number_full_ == NULL) {
255 ok = ok && AddClassification(number_part1_, CREDIT_CARD_NUMBER_PART1, map);
256 ok = ok && AddClassification(number_part2_, CREDIT_CARD_NUMBER_PART2, map);
257 ok = ok && AddClassification(number_part3_, CREDIT_CARD_NUMBER_PART3, map);
258 ok = ok && AddClassification(number_part4_, CREDIT_CARD_NUMBER_PART4, map);
259 }
226 260
227 return ok; 261 return ok;
228 } 262 }
229 263
230 } // namespace autofill 264 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698