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

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: Incorporated review comments. Created 6 years, 4 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::kCardNumberRe); 91 pattern = base::UTF8ToUTF16(autofill::kCardNumberRe);
92 if (!credit_card_field->number_ && 92 const AutofillField* cc_number_field = NULL;
93 ParseField(scanner, pattern, &credit_card_field->number_)) { 93 if (ParseField(scanner, pattern, &cc_number_field)) {
94 int start_index = 0;
95 if (!credit_card_field->numbers_.empty()) {
96 AutofillField* last_number_field =
97 const_cast<AutofillField*>(credit_card_field->numbers_.back());
98 AutofillField::CreditCardNumberInfo* last_number_info =
99 const_cast<AutofillField::CreditCardNumberInfo*>(
Ilya Sherman 2014/08/07 20:57:25 Note: If you find yourself using const_cast, that'
Pritam Nikam 2014/08/08 14:14:34 ParseField() accepts const Autofill**, and hence w
Ilya Sherman 2014/08/12 04:23:41 The correct change is to modify the signature of P
100 last_number_field->credit_card_number_info());
101 start_index =
102 last_number_info->start_index_ + last_number_field->max_length;
Ilya Sherman 2014/08/07 20:57:25 It's possible for this code to assign very large s
Pritam Nikam 2014/08/08 14:14:34 Done.
103 }
104
105 AutofillField* current_number_field =
106 const_cast<AutofillField*>(cc_number_field);
107 AutofillField::CreditCardNumberInfo* number_info =
108 new AutofillField::CreditCardNumberInfo;
Ilya Sherman 2014/08/07 20:57:25 If this is always non-null, why use a pointer, rat
Pritam Nikam 2014/08/08 14:14:34 Done. std::min(std::numeric_limits<size_t>::max(),
109 number_info->part_ = 1 + credit_card_field->numbers_.size();
110 number_info->start_index_ = start_index;
111 current_number_field->set_credit_card_number_info(number_info);
112 credit_card_field->numbers_.push_back(current_number_field);
94 continue; 113 continue;
95 } 114 }
96 115
97 if (LowerCaseEqualsASCII(scanner->Cursor()->form_control_type, "month")) { 116 if (LowerCaseEqualsASCII(scanner->Cursor()->form_control_type, "month")) {
98 credit_card_field->expiration_date_ = scanner->Cursor(); 117 credit_card_field->expiration_date_ = scanner->Cursor();
99 scanner->Advance(); 118 scanner->Advance();
100 } else { 119 } else {
101 // First try to parse split month/year expiration fields. 120 // First try to parse split month/year expiration fields.
102 scanner->SaveCursor(); 121 scanner->SaveCursor();
103 pattern = base::UTF8ToUTF16(autofill::kExpirationMonthRe); 122 pattern = base::UTF8ToUTF16(autofill::kExpirationMonthRe);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (credit_card_field->cardholder_) 179 if (credit_card_field->cardholder_)
161 return credit_card_field.release(); 180 return credit_card_field.release();
162 181
163 // On some pages, the user selects a card type using radio buttons 182 // 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, 183 // (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. 184 // so we treat the card type as optional for now.
166 // The existence of a number or cvc in combination with expiration date is 185 // 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 186 // 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 187 // 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. 188 // the cvc and date were found independently they are returned.
170 if ((credit_card_field->number_ || credit_card_field->verification_) && 189 if ((!credit_card_field->numbers_.empty() ||
190 credit_card_field->verification_) &&
171 (credit_card_field->expiration_date_ || 191 (credit_card_field->expiration_date_ ||
172 (credit_card_field->expiration_month_ && 192 (credit_card_field->expiration_month_ &&
173 credit_card_field->expiration_year_))) { 193 credit_card_field->expiration_year_))) {
174 return credit_card_field.release(); 194 return credit_card_field.release();
175 } 195 }
176 196
177 scanner->RewindTo(saved_cursor); 197 scanner->RewindTo(saved_cursor);
178 return NULL; 198 return NULL;
179 } 199 }
180 200
181 CreditCardField::CreditCardField() 201 CreditCardField::CreditCardField()
182 : cardholder_(NULL), 202 : cardholder_(NULL),
183 cardholder_last_(NULL), 203 cardholder_last_(NULL),
184 type_(NULL), 204 type_(NULL),
185 number_(NULL),
186 verification_(NULL), 205 verification_(NULL),
187 expiration_month_(NULL), 206 expiration_month_(NULL),
188 expiration_year_(NULL), 207 expiration_year_(NULL),
189 expiration_date_(NULL), 208 expiration_date_(NULL),
190 is_two_digit_year_(false) { 209 is_two_digit_year_(false) {
191 } 210 }
192 211
212 CreditCardField::~CreditCardField() {
213 numbers_.clear();
Ilya Sherman 2014/08/07 20:57:25 This is called automatically. Why did you add it
Pritam Nikam 2014/08/08 14:14:34 Done.
214 }
215
193 bool CreditCardField::ClassifyField(ServerFieldTypeMap* map) const { 216 bool CreditCardField::ClassifyField(ServerFieldTypeMap* map) const {
194 bool ok = AddClassification(number_, CREDIT_CARD_NUMBER, map); 217 bool ok = true;
218 for (std::vector<const AutofillField*>::const_iterator it = numbers_.begin();
219 it != numbers_.end();
220 ++it)
221 ok = ok && AddClassification(*it, CREDIT_CARD_NUMBER, map);
222
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 16 matching lines...) Expand all
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 }
226 254
227 return ok; 255 return ok;
228 } 256 }
229 257
230 } // namespace autofill 258 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698