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

Side by Side Diff: chrome/browser/autofill/credit_card.cc

Issue 12052059: requestAutocomplete - more elaborate suggestion labels (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: isherman review Created 7 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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.h" 5 #include "chrome/browser/autofill/credit_card.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <ostream> 9 #include <ostream>
10 #include <string> 10 #include <string>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/guid.h" 13 #include "base/guid.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/string16.h" 15 #include "base/string16.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/string_split.h" 17 #include "base/string_split.h"
18 #include "base/string_util.h" 18 #include "base/string_util.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/autofill/autofill_country.h" 20 #include "chrome/browser/autofill/autofill_country.h"
21 #include "chrome/browser/autofill/autofill_field.h" 21 #include "chrome/browser/autofill/autofill_field.h"
22 #include "chrome/browser/autofill/autofill_regexes.h" 22 #include "chrome/browser/autofill/autofill_regexes.h"
23 #include "chrome/browser/autofill/autofill_type.h" 23 #include "chrome/browser/autofill/autofill_type.h"
24 #include "chrome/browser/autofill/field_types.h" 24 #include "chrome/browser/autofill/field_types.h"
25 #include "chrome/browser/autofill/validation.h" 25 #include "chrome/browser/autofill/validation.h"
26 #include "chrome/common/form_field_data.h" 26 #include "chrome/common/form_field_data.h"
27 #include "grit/generated_resources.h" 27 #include "grit/generated_resources.h"
28 #include "grit/webkit_resources.h"
28 #include "third_party/icu/public/common/unicode/uloc.h" 29 #include "third_party/icu/public/common/unicode/uloc.h"
29 #include "third_party/icu/public/i18n/unicode/dtfmtsym.h" 30 #include "third_party/icu/public/i18n/unicode/dtfmtsym.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 32
32 namespace { 33 namespace {
33 34
34 const char16 kCreditCardObfuscationSymbol = '*'; 35 const char16 kCreditCardObfuscationSymbol = '*';
35 36
36 std::string GetCreditCardType(const string16& number) { 37 std::string GetCreditCardType(const string16& number) {
37 // Don't check for a specific type if this is not a credit card number. 38 // Don't check for a specific type if this is not a credit card number.
(...skipping 26 matching lines...) Expand all
64 int first_two_digits = first_three_digits / 10; 65 int first_two_digits = first_three_digits / 10;
65 int first_digit = first_two_digits / 10; 66 int first_digit = first_two_digits / 10;
66 67
67 switch (number.length()) { 68 switch (number.length()) {
68 case 13: 69 case 13:
69 if (first_digit == 4) 70 if (first_digit == 4)
70 return kVisaCard; 71 return kVisaCard;
71 72
72 break; 73 break;
73 case 14: 74 case 14:
74 if (first_three_digits >= 300 && first_three_digits <=305) 75 if (first_three_digits >= 300 && first_three_digits <= 305)
75 return kDinersCard; 76 return kDinersCard;
76 77
77 if (first_digit == 36) 78 if (first_digit == 36)
78 return kDinersCard; 79 return kDinersCard;
79 80
80 break; 81 break;
81 case 15: 82 case 15:
82 if (first_two_digits == 34 || first_two_digits == 37) 83 if (first_two_digits == 34 || first_two_digits == 37)
83 return kAmericanExpressCard; 84 return kAmericanExpressCard;
84 85
(...skipping 25 matching lines...) Expand all
110 case 19: 111 case 19:
111 if (first_four_digits == 6334 || first_four_digits == 6767) 112 if (first_four_digits == 6334 || first_four_digits == 6767)
112 return kSoloCard; 113 return kSoloCard;
113 114
114 break; 115 break;
115 } 116 }
116 117
117 return kGenericCard; 118 return kGenericCard;
118 } 119 }
119 120
120 string16 GetCreditCardTypeDisplayName(const std::string& card_type) {
121 if (card_type == kAmericanExpressCard)
122 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX);
123
124 if (card_type == kDinersCard)
125 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS);
126
127 if (card_type == kDiscoverCard)
128 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER);
129
130 if (card_type == kJCBCard)
131 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB);
132
133 if (card_type == kMasterCard)
134 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD);
135
136 if (card_type == kSoloCard)
137 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_SOLO);
138
139 if (card_type == kVisaCard)
140 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA);
141
142 // If you hit this DCHECK, the above list of cases needs to be updated to
143 // include a new card.
144 DCHECK_EQ(kGenericCard, card_type);
145 return string16();
146 }
147
148 bool ConvertYear(const string16& year, int* num) { 121 bool ConvertYear(const string16& year, int* num) {
149 // If the |year| is empty, clear the stored value. 122 // If the |year| is empty, clear the stored value.
150 if (year.empty()) { 123 if (year.empty()) {
151 *num = 0; 124 *num = 0;
152 return true; 125 return true;
153 } 126 }
154 127
155 // Try parsing the |year| as a number. 128 // Try parsing the |year| as a number.
156 if (base::StringToInt(year, num)) 129 if (base::StringToInt(year, num))
157 return true; 130 return true;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 243
271 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { 244 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: {
272 string16 month = ExpirationMonthAsString(); 245 string16 month = ExpirationMonthAsString();
273 string16 year = Expiration4DigitYearAsString(); 246 string16 year = Expiration4DigitYearAsString();
274 if (!month.empty() && !year.empty()) 247 if (!month.empty() && !year.empty())
275 return month + ASCIIToUTF16("/") + year; 248 return month + ASCIIToUTF16("/") + year;
276 return string16(); 249 return string16();
277 } 250 }
278 251
279 case CREDIT_CARD_TYPE: 252 case CREDIT_CARD_TYPE:
280 return GetCreditCardTypeDisplayName(type_); 253 return TypeForDisplay();
281 254
282 case CREDIT_CARD_NUMBER: 255 case CREDIT_CARD_NUMBER:
283 return number_; 256 return number_;
284 257
285 case CREDIT_CARD_VERIFICATION_CODE: 258 case CREDIT_CARD_VERIFICATION_CODE:
286 // Chrome doesn't store credit card verification codes. 259 // Chrome doesn't store credit card verification codes.
287 return string16(); 260 return string16();
288 261
289 default: 262 default:
290 // ComputeDataPresentForArray will hit this repeatedly. 263 // ComputeDataPresentForArray will hit this repeatedly.
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 string16 CreditCard::LastFourDigits() const { 402 string16 CreditCard::LastFourDigits() const {
430 static const size_t kNumLastDigits = 4; 403 static const size_t kNumLastDigits = 4;
431 404
432 string16 number = StripSeparators(number_); 405 string16 number = StripSeparators(number_);
433 if (number.size() < kNumLastDigits) 406 if (number.size() < kNumLastDigits)
434 return string16(); 407 return string16();
435 408
436 return number.substr(number.size() - kNumLastDigits, kNumLastDigits); 409 return number.substr(number.size() - kNumLastDigits, kNumLastDigits);
437 } 410 }
438 411
412 string16 CreditCard::TypeForDisplay() const {
413 if (type_ == kAmericanExpressCard)
414 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX);
415 if (type_ == kDinersCard)
416 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS);
417 if (type_ == kDiscoverCard)
418 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER);
419 if (type_ == kJCBCard)
420 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB);
421 if (type_ == kMasterCard)
422 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD);
423 if (type_ == kSoloCard)
424 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_SOLO);
425 if (type_ == kVisaCard)
426 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA);
427
428 // If you hit this DCHECK, the above list of cases needs to be updated to
429 // include a new card.
430 DCHECK_EQ(kGenericCard, type_);
431 return string16();
432 }
433
434 string16 CreditCard::TypeAndLastFourDigits() const {
435 string16 type = TypeForDisplay();
436 // TODO(estade): type may be empty, we probably want to return
437 // "Card - 1234" or something in that case.
438
439 string16 digits = LastFourDigits();
440 if (digits.empty())
441 return type;
442
443 // TODO(estade): i18n.
444 return type + ASCIIToUTF16(" - ") + digits;
445 }
446
447 int CreditCard::IconResourceId() const {
448 if (type_ == kAmericanExpressCard)
449 return IDR_AUTOFILL_CC_AMEX;
450 if (type_ == kDinersCard)
451 return IDR_AUTOFILL_CC_DINERS;
452 if (type_ == kDiscoverCard)
453 return IDR_AUTOFILL_CC_DISCOVER;
454 if (type_ == kJCBCard)
455 return IDR_AUTOFILL_CC_JCB;
456 if (type_ == kMasterCard)
457 return IDR_AUTOFILL_CC_MASTERCARD;
458 if (type_ == kSoloCard)
459 return IDR_AUTOFILL_CC_SOLO;
460 if (type_ == kVisaCard)
461 return IDR_AUTOFILL_CC_VISA;
462
463 // If you hit this DCHECK, the above list of cases needs to be updated to
464 // include a new card.
465 DCHECK_EQ(kGenericCard, type_);
466 return IDR_AUTOFILL_CC_GENERIC;
467 }
468
439 void CreditCard::operator=(const CreditCard& credit_card) { 469 void CreditCard::operator=(const CreditCard& credit_card) {
440 if (this == &credit_card) 470 if (this == &credit_card)
441 return; 471 return;
442 472
443 number_ = credit_card.number_; 473 number_ = credit_card.number_;
444 name_on_card_ = credit_card.name_on_card_; 474 name_on_card_ = credit_card.name_on_card_;
445 type_ = credit_card.type_; 475 type_ = credit_card.type_;
446 expiration_month_ = credit_card.expiration_month_; 476 expiration_month_ = credit_card.expiration_month_;
447 expiration_year_ = credit_card.expiration_year_; 477 expiration_year_ = credit_card.expiration_year_;
448 guid_ = credit_card.guid_; 478 guid_ = credit_card.guid_;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 // webkit/glue. We send these strings to WebKit, which then asks 663 // webkit/glue. We send these strings to WebKit, which then asks
634 // WebKitPlatformSupportImpl to load the image data. 664 // WebKitPlatformSupportImpl to load the image data.
635 const char* const kAmericanExpressCard = "americanExpressCC"; 665 const char* const kAmericanExpressCard = "americanExpressCC";
636 const char* const kDinersCard = "dinersCC"; 666 const char* const kDinersCard = "dinersCC";
637 const char* const kDiscoverCard = "discoverCC"; 667 const char* const kDiscoverCard = "discoverCC";
638 const char* const kGenericCard = "genericCC"; 668 const char* const kGenericCard = "genericCC";
639 const char* const kJCBCard = "jcbCC"; 669 const char* const kJCBCard = "jcbCC";
640 const char* const kMasterCard = "masterCardCC"; 670 const char* const kMasterCard = "masterCardCC";
641 const char* const kSoloCard = "soloCC"; 671 const char* const kSoloCard = "soloCC";
642 const char* const kVisaCard = "visaCC"; 672 const char* const kVisaCard = "visaCC";
OLDNEW
« no previous file with comments | « chrome/browser/autofill/credit_card.h ('k') | chrome/browser/ui/autofill/autofill_dialog_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698