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

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: Rebase 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 a last name. Since this is a dangerously generic search, we
116 // execute it only after we have found a valid credit card (first) name
117 // and haven't yet parsed the expiration date (which usually appears at
118 // 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 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 331
322 AddClassification(type_, CREDIT_CARD_TYPE, kBaseCreditCardParserScore, 332 AddClassification(type_, CREDIT_CARD_TYPE, kBaseCreditCardParserScore,
323 field_candidates); 333 field_candidates);
324 AddClassification(verification_, CREDIT_CARD_VERIFICATION_CODE, 334 AddClassification(verification_, CREDIT_CARD_VERIFICATION_CODE,
325 kBaseCreditCardParserScore, field_candidates); 335 kBaseCreditCardParserScore, field_candidates);
326 336
327 // If the heuristics detected first and last name in separate fields, 337 // If the heuristics detected first and last name in separate fields,
328 // then ignore both fields. Putting them into separate fields is probably 338 // then ignore both fields. Putting them into separate fields is probably
329 // wrong, because the credit card can also contain a middle name or middle 339 // wrong, because the credit card can also contain a middle name or middle
330 // initial. 340 // initial.
331 if (cardholder_last_ == nullptr) 341 if (cardholder_last_ == nullptr) {
332 AddClassification(cardholder_, CREDIT_CARD_NAME, kBaseCreditCardParserScore, 342 AddClassification(cardholder_, CREDIT_CARD_NAME_FULL,
333 field_candidates); 343 kBaseCreditCardParserScore, field_candidates);
344 } else {
345 AddClassification(cardholder_, CREDIT_CARD_NAME_FIRST,
346 kBaseCreditCardParserScore, field_candidates);
347 AddClassification(cardholder_last_, CREDIT_CARD_NAME_LAST,
348 kBaseCreditCardParserScore, field_candidates);
349 }
334 350
335 if (expiration_date_) { 351 if (expiration_date_) {
336 DCHECK(!expiration_month_); 352 DCHECK(!expiration_month_);
337 DCHECK(!expiration_year_); 353 DCHECK(!expiration_year_);
338 AddClassification(expiration_date_, GetExpirationYearType(), 354 AddClassification(expiration_date_, GetExpirationYearType(),
339 kBaseCreditCardParserScore, field_candidates); 355 kBaseCreditCardParserScore, field_candidates);
340 } else { 356 } else {
341 AddClassification(expiration_month_, CREDIT_CARD_EXP_MONTH, 357 AddClassification(expiration_month_, CREDIT_CARD_EXP_MONTH,
342 kBaseCreditCardParserScore, field_candidates); 358 kBaseCreditCardParserScore, field_candidates);
343 AddClassification(expiration_year_, GetExpirationYearType(), 359 AddClassification(expiration_year_, GetExpirationYearType(),
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 471
456 ServerFieldType CreditCardField::GetExpirationYearType() const { 472 ServerFieldType CreditCardField::GetExpirationYearType() const {
457 return (expiration_date_ 473 return (expiration_date_
458 ? exp_year_type_ 474 ? exp_year_type_
459 : ((expiration_year_ && expiration_year_->max_length == 2) 475 : ((expiration_year_ && expiration_year_->max_length == 2)
460 ? CREDIT_CARD_EXP_2_DIGIT_YEAR 476 ? CREDIT_CARD_EXP_2_DIGIT_YEAR
461 : CREDIT_CARD_EXP_4_DIGIT_YEAR)); 477 : CREDIT_CARD_EXP_4_DIGIT_YEAR));
462 } 478 }
463 479
464 } // namespace autofill 480 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/credit_card.cc ('k') | components/autofill/core/browser/credit_card_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698