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

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

Issue 1694443004: [Autofill] Add credit card first and last name heuristics predictions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch2 Created 4 years, 9 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // fields. So we search for "name" only when we've already parsed at 104 // fields. So we search for "name" only when we've already parsed at
105 // least one other credit card field and haven't yet parsed the 105 // least one other credit card field and haven't yet parsed the
106 // expiration date (which usually appears at the end). 106 // expiration date (which usually appears at the end).
107 if (fields > 0 && 107 if (fields > 0 &&
108 !credit_card_field->expiration_month_ && 108 !credit_card_field->expiration_month_ &&
109 ParseField(scanner, 109 ParseField(scanner,
110 base::UTF8ToUTF16(kNameOnCardContextualRe), 110 base::UTF8ToUTF16(kNameOnCardContextualRe),
111 &credit_card_field->cardholder_)) { 111 &credit_card_field->cardholder_)) {
112 continue; 112 continue;
113 } 113 }
114 } else if (!credit_card_field->cardholder_last_) {
115 // Search for "last.*name" or "name.*last". Since these are dangerously
Mathieu 2016/02/24 21:58:26 we are now using the fuller kLastNameRe so your co
sebsg 2016/03/01 16:32:53 Done.
116 // generic searches, we search for these only after we have found a valid
117 // first name and haven't yet parsed the expiration date (which
118 // usually appears at the end).
119 if (!credit_card_field->expiration_month_ &&
120 ParseField(scanner, base::UTF8ToUTF16(kLastNameRe),
121 &credit_card_field->cardholder_last_)) {
122 continue;
123 }
114 } 124 }
115 125
116 // Check for a credit card type (Visa, MasterCard, etc.) field. 126 // Check for a credit card type (Visa, MasterCard, etc.) field.
117 // All CC type fields encountered so far have been of type select. 127 // All CC type fields encountered so far have been of type select.
118 if (!credit_card_field->type_ && LikelyCardTypeSelectField(scanner)) { 128 if (!credit_card_field->type_ && LikelyCardTypeSelectField(scanner)) {
119 credit_card_field->type_ = scanner->Cursor(); 129 credit_card_field->type_ = scanner->Cursor();
120 scanner->Advance(); 130 scanner->Advance();
121 continue; 131 continue;
122 } 132 }
123 133
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 } 329 }
320 330
321 ok = ok && AddClassification(type_, CREDIT_CARD_TYPE, map); 331 ok = ok && AddClassification(type_, CREDIT_CARD_TYPE, map);
322 ok = ok && 332 ok = ok &&
323 AddClassification(verification_, CREDIT_CARD_VERIFICATION_CODE, map); 333 AddClassification(verification_, CREDIT_CARD_VERIFICATION_CODE, map);
324 334
325 // If the heuristics detected first and last name in separate fields, 335 // If the heuristics detected first and last name in separate fields,
326 // then ignore both fields. Putting them into separate fields is probably 336 // then ignore both fields. Putting them into separate fields is probably
327 // wrong, because the credit card can also contain a middle name or middle 337 // wrong, because the credit card can also contain a middle name or middle
328 // initial. 338 // initial.
329 if (cardholder_last_ == nullptr) 339 if (cardholder_last_ == nullptr) {
330 ok = ok && AddClassification(cardholder_, CREDIT_CARD_NAME, map); 340 ok = ok && AddClassification(cardholder_, CREDIT_CARD_NAME_FULL, map);
341 } else {
342 ok = ok && AddClassification(cardholder_, CREDIT_CARD_NAME_FIRST, map);
343 ok = ok && AddClassification(cardholder_last_, CREDIT_CARD_NAME_LAST, map);
344 }
331 345
332 if (expiration_date_) { 346 if (expiration_date_) {
333 DCHECK(!expiration_month_); 347 DCHECK(!expiration_month_);
334 DCHECK(!expiration_year_); 348 DCHECK(!expiration_year_);
335 ok = 349 ok =
336 ok && AddClassification(expiration_date_, GetExpirationYearType(), map); 350 ok && AddClassification(expiration_date_, GetExpirationYearType(), map);
337 } else { 351 } else {
338 ok = ok && AddClassification(expiration_month_, CREDIT_CARD_EXP_MONTH, map); 352 ok = ok && AddClassification(expiration_month_, CREDIT_CARD_EXP_MONTH, map);
339 ok = 353 ok =
340 ok && AddClassification(expiration_year_, GetExpirationYearType(), map); 354 ok && AddClassification(expiration_year_, GetExpirationYearType(), map);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 467
454 ServerFieldType CreditCardField::GetExpirationYearType() const { 468 ServerFieldType CreditCardField::GetExpirationYearType() const {
455 return (expiration_date_ 469 return (expiration_date_
456 ? exp_year_type_ 470 ? exp_year_type_
457 : ((expiration_year_ && expiration_year_->max_length == 2) 471 : ((expiration_year_ && expiration_year_->max_length == 2)
458 ? CREDIT_CARD_EXP_2_DIGIT_YEAR 472 ? CREDIT_CARD_EXP_2_DIGIT_YEAR
459 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); 473 : CREDIT_CARD_EXP_4_DIGIT_YEAR));
460 } 474 }
461 475
462 } // namespace autofill 476 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698