| OLD | NEW |
| 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 "components/autofill/browser/credit_card.h" | 5 #include "components/autofill/browser/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> |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 const char16 kCreditCardObfuscationSymbol = '*'; | 34 const char16 kCreditCardObfuscationSymbol = '*'; |
| 35 | 35 |
| 36 // This is the maximum obfuscated symbols displayed. | 36 // This is the maximum obfuscated symbols displayed. |
| 37 // It is introduced to avoid rare cases where the credit card number is | 37 // It is introduced to avoid rare cases where the credit card number is |
| 38 // too large and fills the screen. | 38 // too large and fills the screen. |
| 39 const size_t kMaxObfuscationSize = 20; | 39 const size_t kMaxObfuscationSize = 20; |
| 40 | 40 |
| 41 std::string GetCreditCardType(const string16& number) { | 41 std::string GetCreditCardType(const base::string16& number) { |
| 42 // Don't check for a specific type if this is not a credit card number. | 42 // Don't check for a specific type if this is not a credit card number. |
| 43 if (!autofill::IsValidCreditCardNumber(number)) | 43 if (!autofill::IsValidCreditCardNumber(number)) |
| 44 return kGenericCard; | 44 return kGenericCard; |
| 45 | 45 |
| 46 // Credit card number specifications taken from: | 46 // Credit card number specifications taken from: |
| 47 // http://en.wikipedia.org/wiki/Credit_card_numbers and | 47 // http://en.wikipedia.org/wiki/Credit_card_numbers and |
| 48 // http://www.beachnet.com/~hstiles/cardtype.html | 48 // http://www.beachnet.com/~hstiles/cardtype.html |
| 49 // Card Type Prefix(es) Length | 49 // Card Type Prefix(es) Length |
| 50 // --------------------------------------------------------------- | 50 // --------------------------------------------------------------- |
| 51 // Visa 4 13,16 | 51 // Visa 4 13,16 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 case 19: | 115 case 19: |
| 116 if (first_four_digits == 6334 || first_four_digits == 6767) | 116 if (first_four_digits == 6334 || first_four_digits == 6767) |
| 117 return kSoloCard; | 117 return kSoloCard; |
| 118 | 118 |
| 119 break; | 119 break; |
| 120 } | 120 } |
| 121 | 121 |
| 122 return kGenericCard; | 122 return kGenericCard; |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool ConvertYear(const string16& year, int* num) { | 125 bool ConvertYear(const base::string16& year, int* num) { |
| 126 // If the |year| is empty, clear the stored value. | 126 // If the |year| is empty, clear the stored value. |
| 127 if (year.empty()) { | 127 if (year.empty()) { |
| 128 *num = 0; | 128 *num = 0; |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Try parsing the |year| as a number. | 132 // Try parsing the |year| as a number. |
| 133 if (base::StringToInt(year, num)) | 133 if (base::StringToInt(year, num)) |
| 134 return true; | 134 return true; |
| 135 | 135 |
| 136 *num = 0; | 136 *num = 0; |
| 137 return false; | 137 return false; |
| 138 } | 138 } |
| 139 | 139 |
| 140 bool ConvertMonth(const string16& month, | 140 bool ConvertMonth(const base::string16& month, |
| 141 const std::string& app_locale, | 141 const std::string& app_locale, |
| 142 int* num) { | 142 int* num) { |
| 143 // If the |month| is empty, clear the stored value. | 143 // If the |month| is empty, clear the stored value. |
| 144 if (month.empty()) { | 144 if (month.empty()) { |
| 145 *num = 0; | 145 *num = 0; |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 | 148 |
| 149 // Try parsing the |month| as a number. | 149 // Try parsing the |month| as a number. |
| 150 if (base::StringToInt(month, num)) | 150 if (base::StringToInt(month, num)) |
| 151 return true; | 151 return true; |
| 152 | 152 |
| 153 // If the locale is unknown, give up. | 153 // If the locale is unknown, give up. |
| 154 if (app_locale.empty()) | 154 if (app_locale.empty()) |
| 155 return false; | 155 return false; |
| 156 | 156 |
| 157 // Otherwise, try parsing the |month| as a named month, e.g. "January" or | 157 // Otherwise, try parsing the |month| as a named month, e.g. "January" or |
| 158 // "Jan". | 158 // "Jan". |
| 159 string16 lowercased_month = StringToLowerASCII(month); | 159 base::string16 lowercased_month = StringToLowerASCII(month); |
| 160 | 160 |
| 161 UErrorCode status = U_ZERO_ERROR; | 161 UErrorCode status = U_ZERO_ERROR; |
| 162 icu::Locale locale(app_locale.c_str()); | 162 icu::Locale locale(app_locale.c_str()); |
| 163 icu::DateFormatSymbols date_format_symbols(locale, status); | 163 icu::DateFormatSymbols date_format_symbols(locale, status); |
| 164 DCHECK(status == U_ZERO_ERROR || status == U_USING_FALLBACK_WARNING || | 164 DCHECK(status == U_ZERO_ERROR || status == U_USING_FALLBACK_WARNING || |
| 165 status == U_USING_DEFAULT_WARNING); | 165 status == U_USING_DEFAULT_WARNING); |
| 166 | 166 |
| 167 int32_t num_months; | 167 int32_t num_months; |
| 168 const icu::UnicodeString* months = date_format_symbols.getMonths(num_months); | 168 const icu::UnicodeString* months = date_format_symbols.getMonths(num_months); |
| 169 for (int32_t i = 0; i < num_months; ++i) { | 169 for (int32_t i = 0; i < num_months; ++i) { |
| 170 const string16 icu_month = string16(months[i].getBuffer(), | 170 const base::string16 icu_month = base::string16(months[i].getBuffer(), |
| 171 months[i].length()); | 171 months[i].length()); |
| 172 if (lowercased_month == StringToLowerASCII(icu_month)) { | 172 if (lowercased_month == StringToLowerASCII(icu_month)) { |
| 173 *num = i + 1; // Adjust from 0-indexed to 1-indexed. | 173 *num = i + 1; // Adjust from 0-indexed to 1-indexed. |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 months = date_format_symbols.getShortMonths(num_months); | 178 months = date_format_symbols.getShortMonths(num_months); |
| 179 for (int32_t i = 0; i < num_months; ++i) { | 179 for (int32_t i = 0; i < num_months; ++i) { |
| 180 const string16 icu_month = string16(months[i].getBuffer(), | 180 const base::string16 icu_month = base::string16(months[i].getBuffer(), |
| 181 months[i].length()); | 181 months[i].length()); |
| 182 if (lowercased_month == StringToLowerASCII(icu_month)) { | 182 if (lowercased_month == StringToLowerASCII(icu_month)) { |
| 183 *num = i + 1; // Adjust from 0-indexed to 1-indexed. | 183 *num = i + 1; // Adjust from 0-indexed to 1-indexed. |
| 184 return true; | 184 return true; |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 *num = 0; | 188 *num = 0; |
| 189 return false; | 189 return false; |
| 190 } | 190 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 205 guid_(base::GenerateGUID()) { | 205 guid_(base::GenerateGUID()) { |
| 206 } | 206 } |
| 207 | 207 |
| 208 CreditCard::CreditCard(const CreditCard& credit_card) : FormGroup() { | 208 CreditCard::CreditCard(const CreditCard& credit_card) : FormGroup() { |
| 209 operator=(credit_card); | 209 operator=(credit_card); |
| 210 } | 210 } |
| 211 | 211 |
| 212 CreditCard::~CreditCard() {} | 212 CreditCard::~CreditCard() {} |
| 213 | 213 |
| 214 // static | 214 // static |
| 215 const string16 CreditCard::StripSeparators(const string16& number) { | 215 const base::string16 CreditCard::StripSeparators(const base::string16& number) { |
| 216 const char16 kSeparators[] = {'-', ' ', '\0'}; | 216 const char16 kSeparators[] = {'-', ' ', '\0'}; |
| 217 string16 stripped; | 217 base::string16 stripped; |
| 218 RemoveChars(number, kSeparators, &stripped); | 218 RemoveChars(number, kSeparators, &stripped); |
| 219 return stripped; | 219 return stripped; |
| 220 } | 220 } |
| 221 | 221 |
| 222 // static | 222 // static |
| 223 string16 CreditCard::TypeForDisplay(const std::string& type) { | 223 base::string16 CreditCard::TypeForDisplay(const std::string& type) { |
| 224 if (type == kAmericanExpressCard) | 224 if (type == kAmericanExpressCard) |
| 225 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); | 225 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_AMEX); |
| 226 if (type == kDinersCard) | 226 if (type == kDinersCard) |
| 227 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS); | 227 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DINERS); |
| 228 if (type == kDiscoverCard) | 228 if (type == kDiscoverCard) |
| 229 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER); | 229 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_DISCOVER); |
| 230 if (type == kJCBCard) | 230 if (type == kJCBCard) |
| 231 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB); | 231 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_JCB); |
| 232 if (type == kMasterCard) | 232 if (type == kMasterCard) |
| 233 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD); | 233 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_MASTERCARD); |
| 234 if (type == kSoloCard) | 234 if (type == kSoloCard) |
| 235 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_SOLO); | 235 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_SOLO); |
| 236 if (type == kVisaCard) | 236 if (type == kVisaCard) |
| 237 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); | 237 return l10n_util::GetStringUTF16(IDS_AUTOFILL_CC_VISA); |
| 238 | 238 |
| 239 // If you hit this DCHECK, the above list of cases needs to be updated to | 239 // If you hit this DCHECK, the above list of cases needs to be updated to |
| 240 // include a new card. | 240 // include a new card. |
| 241 DCHECK_EQ(kGenericCard, type); | 241 DCHECK_EQ(kGenericCard, type); |
| 242 return string16(); | 242 return base::string16(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 std::string CreditCard::GetGUID() const { | 245 std::string CreditCard::GetGUID() const { |
| 246 return guid(); | 246 return guid(); |
| 247 } | 247 } |
| 248 | 248 |
| 249 string16 CreditCard::GetRawInfo(AutofillFieldType type) const { | 249 base::string16 CreditCard::GetRawInfo(AutofillFieldType type) const { |
| 250 switch (type) { | 250 switch (type) { |
| 251 case CREDIT_CARD_NAME: | 251 case CREDIT_CARD_NAME: |
| 252 return name_on_card_; | 252 return name_on_card_; |
| 253 | 253 |
| 254 case CREDIT_CARD_EXP_MONTH: | 254 case CREDIT_CARD_EXP_MONTH: |
| 255 return ExpirationMonthAsString(); | 255 return ExpirationMonthAsString(); |
| 256 | 256 |
| 257 case CREDIT_CARD_EXP_2_DIGIT_YEAR: | 257 case CREDIT_CARD_EXP_2_DIGIT_YEAR: |
| 258 return Expiration2DigitYearAsString(); | 258 return Expiration2DigitYearAsString(); |
| 259 | 259 |
| 260 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 260 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
| 261 return Expiration4DigitYearAsString(); | 261 return Expiration4DigitYearAsString(); |
| 262 | 262 |
| 263 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: { | 263 case CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR: { |
| 264 string16 month = ExpirationMonthAsString(); | 264 base::string16 month = ExpirationMonthAsString(); |
| 265 string16 year = Expiration2DigitYearAsString(); | 265 base::string16 year = Expiration2DigitYearAsString(); |
| 266 if (!month.empty() && !year.empty()) | 266 if (!month.empty() && !year.empty()) |
| 267 return month + ASCIIToUTF16("/") + year; | 267 return month + ASCIIToUTF16("/") + year; |
| 268 return string16(); | 268 return base::string16(); |
| 269 } | 269 } |
| 270 | 270 |
| 271 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { | 271 case CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR: { |
| 272 string16 month = ExpirationMonthAsString(); | 272 base::string16 month = ExpirationMonthAsString(); |
| 273 string16 year = Expiration4DigitYearAsString(); | 273 base::string16 year = Expiration4DigitYearAsString(); |
| 274 if (!month.empty() && !year.empty()) | 274 if (!month.empty() && !year.empty()) |
| 275 return month + ASCIIToUTF16("/") + year; | 275 return month + ASCIIToUTF16("/") + year; |
| 276 return string16(); | 276 return base::string16(); |
| 277 } | 277 } |
| 278 | 278 |
| 279 case CREDIT_CARD_TYPE: | 279 case CREDIT_CARD_TYPE: |
| 280 return TypeForDisplay(); | 280 return TypeForDisplay(); |
| 281 | 281 |
| 282 case CREDIT_CARD_NUMBER: | 282 case CREDIT_CARD_NUMBER: |
| 283 return number_; | 283 return number_; |
| 284 | 284 |
| 285 case CREDIT_CARD_VERIFICATION_CODE: | 285 case CREDIT_CARD_VERIFICATION_CODE: |
| 286 // Chrome doesn't store credit card verification codes. | 286 // Chrome doesn't store credit card verification codes. |
| 287 return string16(); | 287 return base::string16(); |
| 288 | 288 |
| 289 default: | 289 default: |
| 290 // ComputeDataPresentForArray will hit this repeatedly. | 290 // ComputeDataPresentForArray will hit this repeatedly. |
| 291 return string16(); | 291 return base::string16(); |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 void CreditCard::SetRawInfo(AutofillFieldType type, const string16& value) { | 295 void CreditCard::SetRawInfo(AutofillFieldType type, |
| 296 const base::string16& value) { |
| 296 switch (type) { | 297 switch (type) { |
| 297 case CREDIT_CARD_NAME: | 298 case CREDIT_CARD_NAME: |
| 298 name_on_card_ = value; | 299 name_on_card_ = value; |
| 299 break; | 300 break; |
| 300 | 301 |
| 301 case CREDIT_CARD_EXP_MONTH: | 302 case CREDIT_CARD_EXP_MONTH: |
| 302 SetExpirationMonthFromString(value, std::string()); | 303 SetExpirationMonthFromString(value, std::string()); |
| 303 break; | 304 break; |
| 304 | 305 |
| 305 case CREDIT_CARD_EXP_2_DIGIT_YEAR: | 306 case CREDIT_CARD_EXP_2_DIGIT_YEAR: |
| (...skipping 26 matching lines...) Expand all Loading... |
| 332 case CREDIT_CARD_VERIFICATION_CODE: | 333 case CREDIT_CARD_VERIFICATION_CODE: |
| 333 // Chrome doesn't store the credit card verification code. | 334 // Chrome doesn't store the credit card verification code. |
| 334 break; | 335 break; |
| 335 | 336 |
| 336 default: | 337 default: |
| 337 NOTREACHED() << "Attempting to set unknown info-type " << type; | 338 NOTREACHED() << "Attempting to set unknown info-type " << type; |
| 338 break; | 339 break; |
| 339 } | 340 } |
| 340 } | 341 } |
| 341 | 342 |
| 342 string16 CreditCard::GetInfo(AutofillFieldType type, | 343 base::string16 CreditCard::GetInfo(AutofillFieldType type, |
| 343 const std::string& app_locale) const { | 344 const std::string& app_locale) const { |
| 344 if (type == CREDIT_CARD_NUMBER) | 345 if (type == CREDIT_CARD_NUMBER) |
| 345 return StripSeparators(number_); | 346 return StripSeparators(number_); |
| 346 | 347 |
| 347 return GetRawInfo(type); | 348 return GetRawInfo(type); |
| 348 } | 349 } |
| 349 | 350 |
| 350 bool CreditCard::SetInfo(AutofillFieldType type, | 351 bool CreditCard::SetInfo(AutofillFieldType type, |
| 351 const string16& value, | 352 const base::string16& value, |
| 352 const std::string& app_locale) { | 353 const std::string& app_locale) { |
| 353 if (type == CREDIT_CARD_NUMBER) | 354 if (type == CREDIT_CARD_NUMBER) |
| 354 SetRawInfo(type, StripSeparators(value)); | 355 SetRawInfo(type, StripSeparators(value)); |
| 355 else if (type == CREDIT_CARD_EXP_MONTH) | 356 else if (type == CREDIT_CARD_EXP_MONTH) |
| 356 SetExpirationMonthFromString(value, app_locale); | 357 SetExpirationMonthFromString(value, app_locale); |
| 357 else | 358 else |
| 358 SetRawInfo(type, value); | 359 SetRawInfo(type, value); |
| 359 | 360 |
| 360 return true; | 361 return true; |
| 361 } | 362 } |
| 362 | 363 |
| 363 void CreditCard::GetMatchingTypes(const string16& text, | 364 void CreditCard::GetMatchingTypes(const base::string16& text, |
| 364 const std::string& app_locale, | 365 const std::string& app_locale, |
| 365 FieldTypeSet* matching_types) const { | 366 FieldTypeSet* matching_types) const { |
| 366 FormGroup::GetMatchingTypes(text, app_locale, matching_types); | 367 FormGroup::GetMatchingTypes(text, app_locale, matching_types); |
| 367 | 368 |
| 368 string16 card_number = GetInfo(CREDIT_CARD_NUMBER, app_locale); | 369 base::string16 card_number = GetInfo(CREDIT_CARD_NUMBER, app_locale); |
| 369 if (!card_number.empty() && StripSeparators(text) == card_number) | 370 if (!card_number.empty() && StripSeparators(text) == card_number) |
| 370 matching_types->insert(CREDIT_CARD_NUMBER); | 371 matching_types->insert(CREDIT_CARD_NUMBER); |
| 371 | 372 |
| 372 int month; | 373 int month; |
| 373 if (ConvertMonth(text, app_locale, &month) && month != 0 && | 374 if (ConvertMonth(text, app_locale, &month) && month != 0 && |
| 374 month == expiration_month_) { | 375 month == expiration_month_) { |
| 375 matching_types->insert(CREDIT_CARD_EXP_MONTH); | 376 matching_types->insert(CREDIT_CARD_EXP_MONTH); |
| 376 } | 377 } |
| 377 } | 378 } |
| 378 | 379 |
| 379 const string16 CreditCard::Label() const { | 380 const base::string16 CreditCard::Label() const { |
| 380 string16 label; | 381 base::string16 label; |
| 381 if (number().empty()) | 382 if (number().empty()) |
| 382 return name_on_card_; // No CC number, return name only. | 383 return name_on_card_; // No CC number, return name only. |
| 383 | 384 |
| 384 string16 obfuscated_cc_number = ObfuscatedNumber(); | 385 base::string16 obfuscated_cc_number = ObfuscatedNumber(); |
| 385 if (!expiration_month_ || !expiration_year_) | 386 if (!expiration_month_ || !expiration_year_) |
| 386 return obfuscated_cc_number; // No expiration date set. | 387 return obfuscated_cc_number; // No expiration date set. |
| 387 | 388 |
| 388 // TODO(georgey): Internationalize date. | 389 // TODO(georgey): Internationalize date. |
| 389 string16 formatted_date(ExpirationMonthAsString()); | 390 base::string16 formatted_date(ExpirationMonthAsString()); |
| 390 formatted_date.append(ASCIIToUTF16("/")); | 391 formatted_date.append(ASCIIToUTF16("/")); |
| 391 formatted_date.append(Expiration4DigitYearAsString()); | 392 formatted_date.append(Expiration4DigitYearAsString()); |
| 392 | 393 |
| 393 label = l10n_util::GetStringFUTF16(IDS_CREDIT_CARD_NUMBER_PREVIEW_FORMAT, | 394 label = l10n_util::GetStringFUTF16(IDS_CREDIT_CARD_NUMBER_PREVIEW_FORMAT, |
| 394 obfuscated_cc_number, | 395 obfuscated_cc_number, |
| 395 formatted_date); | 396 formatted_date); |
| 396 return label; | 397 return label; |
| 397 } | 398 } |
| 398 | 399 |
| 399 void CreditCard::SetInfoForMonthInputType(const string16& value) { | 400 void CreditCard::SetInfoForMonthInputType(const base::string16& value) { |
| 400 // Check if |text| is "yyyy-mm" format first, and check normal month format. | 401 // Check if |text| is "yyyy-mm" format first, and check normal month format. |
| 401 if (!autofill::MatchesPattern(value, UTF8ToUTF16("^[0-9]{4}-[0-9]{1,2}$"))) | 402 if (!autofill::MatchesPattern(value, UTF8ToUTF16("^[0-9]{4}-[0-9]{1,2}$"))) |
| 402 return; | 403 return; |
| 403 | 404 |
| 404 std::vector<string16> year_month; | 405 std::vector<base::string16> year_month; |
| 405 base::SplitString(value, L'-', &year_month); | 406 base::SplitString(value, L'-', &year_month); |
| 406 DCHECK_EQ((int)year_month.size(), 2); | 407 DCHECK_EQ((int)year_month.size(), 2); |
| 407 int num = 0; | 408 int num = 0; |
| 408 bool converted = false; | 409 bool converted = false; |
| 409 converted = base::StringToInt(year_month[0], &num); | 410 converted = base::StringToInt(year_month[0], &num); |
| 410 DCHECK(converted); | 411 DCHECK(converted); |
| 411 SetExpirationYear(num); | 412 SetExpirationYear(num); |
| 412 converted = base::StringToInt(year_month[1], &num); | 413 converted = base::StringToInt(year_month[1], &num); |
| 413 DCHECK(converted); | 414 DCHECK(converted); |
| 414 SetExpirationMonth(num); | 415 SetExpirationMonth(num); |
| 415 } | 416 } |
| 416 | 417 |
| 417 string16 CreditCard::ObfuscatedNumber() const { | 418 base::string16 CreditCard::ObfuscatedNumber() const { |
| 418 // If the number is shorter than four digits, there's no need to obfuscate it. | 419 // If the number is shorter than four digits, there's no need to obfuscate it. |
| 419 if (number_.size() < 4) | 420 if (number_.size() < 4) |
| 420 return number_; | 421 return number_; |
| 421 | 422 |
| 422 string16 number = StripSeparators(number_); | 423 base::string16 number = StripSeparators(number_); |
| 423 | 424 |
| 424 // Avoid making very long obfuscated numbers. | 425 // Avoid making very long obfuscated numbers. |
| 425 size_t obfuscated_digits = std::min(kMaxObfuscationSize, number.size() - 4); | 426 size_t obfuscated_digits = std::min(kMaxObfuscationSize, number.size() - 4); |
| 426 string16 result(obfuscated_digits, kCreditCardObfuscationSymbol); | 427 base::string16 result(obfuscated_digits, kCreditCardObfuscationSymbol); |
| 427 return result.append(LastFourDigits()); | 428 return result.append(LastFourDigits()); |
| 428 } | 429 } |
| 429 | 430 |
| 430 string16 CreditCard::LastFourDigits() const { | 431 base::string16 CreditCard::LastFourDigits() const { |
| 431 static const size_t kNumLastDigits = 4; | 432 static const size_t kNumLastDigits = 4; |
| 432 | 433 |
| 433 string16 number = StripSeparators(number_); | 434 base::string16 number = StripSeparators(number_); |
| 434 if (number.size() < kNumLastDigits) | 435 if (number.size() < kNumLastDigits) |
| 435 return string16(); | 436 return base::string16(); |
| 436 | 437 |
| 437 return number.substr(number.size() - kNumLastDigits, kNumLastDigits); | 438 return number.substr(number.size() - kNumLastDigits, kNumLastDigits); |
| 438 } | 439 } |
| 439 | 440 |
| 440 string16 CreditCard::TypeForDisplay() const { | 441 base::string16 CreditCard::TypeForDisplay() const { |
| 441 return CreditCard::TypeForDisplay(type_); | 442 return CreditCard::TypeForDisplay(type_); |
| 442 } | 443 } |
| 443 | 444 |
| 444 string16 CreditCard::TypeAndLastFourDigits() const { | 445 base::string16 CreditCard::TypeAndLastFourDigits() const { |
| 445 string16 type = TypeForDisplay(); | 446 base::string16 type = TypeForDisplay(); |
| 446 // TODO(estade): type may be empty, we probably want to return | 447 // TODO(estade): type may be empty, we probably want to return |
| 447 // "Card - 1234" or something in that case. | 448 // "Card - 1234" or something in that case. |
| 448 | 449 |
| 449 string16 digits = LastFourDigits(); | 450 base::string16 digits = LastFourDigits(); |
| 450 if (digits.empty()) | 451 if (digits.empty()) |
| 451 return type; | 452 return type; |
| 452 | 453 |
| 453 // TODO(estade): i18n. | 454 // TODO(estade): i18n. |
| 454 return type + ASCIIToUTF16(" - ") + digits; | 455 return type + ASCIIToUTF16(" - ") + digits; |
| 455 } | 456 } |
| 456 | 457 |
| 457 int CreditCard::IconResourceId() const { | 458 int CreditCard::IconResourceId() const { |
| 458 if (type_ == kAmericanExpressCard) | 459 if (type_ == kAmericanExpressCard) |
| 459 return IDR_AUTOFILL_CC_AMEX; | 460 return IDR_AUTOFILL_CC_AMEX; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 size_t /*variant*/, | 514 size_t /*variant*/, |
| 514 const std::string& app_locale, | 515 const std::string& app_locale, |
| 515 FormFieldData* field_data) const { | 516 FormFieldData* field_data) const { |
| 516 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(field.type()).group()); | 517 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(field.type()).group()); |
| 517 DCHECK(field_data); | 518 DCHECK(field_data); |
| 518 | 519 |
| 519 if (field_data->form_control_type == "select-one") { | 520 if (field_data->form_control_type == "select-one") { |
| 520 FillSelectControl(field.type(), app_locale, field_data); | 521 FillSelectControl(field.type(), app_locale, field_data); |
| 521 } else if (field_data->form_control_type == "month") { | 522 } else if (field_data->form_control_type == "month") { |
| 522 // HTML5 input="month" consists of year-month. | 523 // HTML5 input="month" consists of year-month. |
| 523 string16 year = GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, app_locale); | 524 base::string16 year = GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, app_locale); |
| 524 string16 month = GetInfo(CREDIT_CARD_EXP_MONTH, app_locale); | 525 base::string16 month = GetInfo(CREDIT_CARD_EXP_MONTH, app_locale); |
| 525 if (!year.empty() && !month.empty()) { | 526 if (!year.empty() && !month.empty()) { |
| 526 // Fill the value only if |this| includes both year and month | 527 // Fill the value only if |this| includes both year and month |
| 527 // information. | 528 // information. |
| 528 field_data->value = year + ASCIIToUTF16("-") + month; | 529 field_data->value = year + ASCIIToUTF16("-") + month; |
| 529 } | 530 } |
| 530 } else { | 531 } else { |
| 531 field_data->value = GetInfo(field.type(), app_locale); | 532 field_data->value = GetInfo(field.type(), app_locale); |
| 532 } | 533 } |
| 533 } | 534 } |
| 534 | 535 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 supported_types->insert(CREDIT_CARD_NAME); | 579 supported_types->insert(CREDIT_CARD_NAME); |
| 579 supported_types->insert(CREDIT_CARD_NUMBER); | 580 supported_types->insert(CREDIT_CARD_NUMBER); |
| 580 supported_types->insert(CREDIT_CARD_TYPE); | 581 supported_types->insert(CREDIT_CARD_TYPE); |
| 581 supported_types->insert(CREDIT_CARD_EXP_MONTH); | 582 supported_types->insert(CREDIT_CARD_EXP_MONTH); |
| 582 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); | 583 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); |
| 583 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 584 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
| 584 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR); | 585 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR); |
| 585 supported_types->insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR); | 586 supported_types->insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR); |
| 586 } | 587 } |
| 587 | 588 |
| 588 string16 CreditCard::ExpirationMonthAsString() const { | 589 base::string16 CreditCard::ExpirationMonthAsString() const { |
| 589 if (expiration_month_ == 0) | 590 if (expiration_month_ == 0) |
| 590 return string16(); | 591 return base::string16(); |
| 591 | 592 |
| 592 string16 month = base::IntToString16(expiration_month_); | 593 base::string16 month = base::IntToString16(expiration_month_); |
| 593 if (expiration_month_ >= 10) | 594 if (expiration_month_ >= 10) |
| 594 return month; | 595 return month; |
| 595 | 596 |
| 596 string16 zero = ASCIIToUTF16("0"); | 597 base::string16 zero = ASCIIToUTF16("0"); |
| 597 zero.append(month); | 598 zero.append(month); |
| 598 return zero; | 599 return zero; |
| 599 } | 600 } |
| 600 | 601 |
| 601 string16 CreditCard::Expiration4DigitYearAsString() const { | 602 base::string16 CreditCard::Expiration4DigitYearAsString() const { |
| 602 if (expiration_year_ == 0) | 603 if (expiration_year_ == 0) |
| 603 return string16(); | 604 return base::string16(); |
| 604 | 605 |
| 605 return base::IntToString16(Expiration4DigitYear()); | 606 return base::IntToString16(Expiration4DigitYear()); |
| 606 } | 607 } |
| 607 | 608 |
| 608 string16 CreditCard::Expiration2DigitYearAsString() const { | 609 base::string16 CreditCard::Expiration2DigitYearAsString() const { |
| 609 if (expiration_year_ == 0) | 610 if (expiration_year_ == 0) |
| 610 return string16(); | 611 return base::string16(); |
| 611 | 612 |
| 612 return base::IntToString16(Expiration2DigitYear()); | 613 return base::IntToString16(Expiration2DigitYear()); |
| 613 } | 614 } |
| 614 | 615 |
| 615 void CreditCard::SetExpirationMonthFromString(const string16& text, | 616 void CreditCard::SetExpirationMonthFromString(const base::string16& text, |
| 616 const std::string& app_locale) { | 617 const std::string& app_locale) { |
| 617 int month; | 618 int month; |
| 618 if (!ConvertMonth(text, app_locale, &month)) | 619 if (!ConvertMonth(text, app_locale, &month)) |
| 619 return; | 620 return; |
| 620 | 621 |
| 621 SetExpirationMonth(month); | 622 SetExpirationMonth(month); |
| 622 } | 623 } |
| 623 | 624 |
| 624 void CreditCard::SetExpirationYearFromString(const string16& text) { | 625 void CreditCard::SetExpirationYearFromString(const base::string16& text) { |
| 625 int year; | 626 int year; |
| 626 if (!ConvertYear(text, &year)) | 627 if (!ConvertYear(text, &year)) |
| 627 return; | 628 return; |
| 628 | 629 |
| 629 SetExpirationYear(year); | 630 SetExpirationYear(year); |
| 630 } | 631 } |
| 631 | 632 |
| 632 void CreditCard::SetNumber(const string16& number) { | 633 void CreditCard::SetNumber(const base::string16& number) { |
| 633 number_ = number; | 634 number_ = number; |
| 634 type_ = GetCreditCardType(StripSeparators(number_)); | 635 type_ = GetCreditCardType(StripSeparators(number_)); |
| 635 } | 636 } |
| 636 | 637 |
| 637 void CreditCard::SetExpirationMonth(int expiration_month) { | 638 void CreditCard::SetExpirationMonth(int expiration_month) { |
| 638 if (expiration_month < 0 || expiration_month > 12) | 639 if (expiration_month < 0 || expiration_month > 12) |
| 639 return; | 640 return; |
| 640 | 641 |
| 641 expiration_month_ = expiration_month; | 642 expiration_month_ = expiration_month; |
| 642 } | 643 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 672 // webkit/glue. We send these strings to WebKit, which then asks | 673 // webkit/glue. We send these strings to WebKit, which then asks |
| 673 // WebKitPlatformSupportImpl to load the image data. | 674 // WebKitPlatformSupportImpl to load the image data. |
| 674 const char* const kAmericanExpressCard = "americanExpressCC"; | 675 const char* const kAmericanExpressCard = "americanExpressCC"; |
| 675 const char* const kDinersCard = "dinersCC"; | 676 const char* const kDinersCard = "dinersCC"; |
| 676 const char* const kDiscoverCard = "discoverCC"; | 677 const char* const kDiscoverCard = "discoverCC"; |
| 677 const char* const kGenericCard = "genericCC"; | 678 const char* const kGenericCard = "genericCC"; |
| 678 const char* const kJCBCard = "jcbCC"; | 679 const char* const kJCBCard = "jcbCC"; |
| 679 const char* const kMasterCard = "masterCardCC"; | 680 const char* const kMasterCard = "masterCardCC"; |
| 680 const char* const kSoloCard = "soloCC"; | 681 const char* const kSoloCard = "soloCC"; |
| 681 const char* const kVisaCard = "visaCC"; | 682 const char* const kVisaCard = "visaCC"; |
| OLD | NEW |