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 "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> |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 supported_types->insert(CREDIT_CARD_NAME); | 236 supported_types->insert(CREDIT_CARD_NAME); |
237 supported_types->insert(CREDIT_CARD_NUMBER); | 237 supported_types->insert(CREDIT_CARD_NUMBER); |
238 supported_types->insert(CREDIT_CARD_TYPE); | 238 supported_types->insert(CREDIT_CARD_TYPE); |
239 supported_types->insert(CREDIT_CARD_EXP_MONTH); | 239 supported_types->insert(CREDIT_CARD_EXP_MONTH); |
240 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); | 240 supported_types->insert(CREDIT_CARD_EXP_2_DIGIT_YEAR); |
241 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); | 241 supported_types->insert(CREDIT_CARD_EXP_4_DIGIT_YEAR); |
242 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR); | 242 supported_types->insert(CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR); |
243 supported_types->insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR); | 243 supported_types->insert(CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR); |
244 } | 244 } |
245 | 245 |
246 string16 CreditCard::GetInfo(AutofillFieldType type) const { | 246 string16 CreditCard::GetRawInfo(AutofillFieldType type) const { |
247 switch (type) { | 247 switch (type) { |
248 case CREDIT_CARD_NAME: | 248 case CREDIT_CARD_NAME: |
249 return name_on_card_; | 249 return name_on_card_; |
250 | 250 |
251 case CREDIT_CARD_EXP_MONTH: | 251 case CREDIT_CARD_EXP_MONTH: |
252 return ExpirationMonthAsString(); | 252 return ExpirationMonthAsString(); |
253 | 253 |
254 case CREDIT_CARD_EXP_2_DIGIT_YEAR: | 254 case CREDIT_CARD_EXP_2_DIGIT_YEAR: |
255 return Expiration2DigitYearAsString(); | 255 return Expiration2DigitYearAsString(); |
256 | 256 |
(...skipping 25 matching lines...) Expand all Loading... |
282 case CREDIT_CARD_VERIFICATION_CODE: | 282 case CREDIT_CARD_VERIFICATION_CODE: |
283 // Chrome doesn't store credit card verification codes. | 283 // Chrome doesn't store credit card verification codes. |
284 return string16(); | 284 return string16(); |
285 | 285 |
286 default: | 286 default: |
287 // ComputeDataPresentForArray will hit this repeatedly. | 287 // ComputeDataPresentForArray will hit this repeatedly. |
288 return string16(); | 288 return string16(); |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 void CreditCard::SetInfo(AutofillFieldType type, const string16& value) { | 292 void CreditCard::SetRawInfo(AutofillFieldType type, const string16& value) { |
293 switch (type) { | 293 switch (type) { |
294 case CREDIT_CARD_NAME: | 294 case CREDIT_CARD_NAME: |
295 name_on_card_ = value; | 295 name_on_card_ = value; |
296 break; | 296 break; |
297 | 297 |
298 case CREDIT_CARD_EXP_MONTH: | 298 case CREDIT_CARD_EXP_MONTH: |
299 SetExpirationMonthFromString(value); | 299 SetExpirationMonthFromString(value); |
300 break; | 300 break; |
301 | 301 |
302 case CREDIT_CARD_EXP_2_DIGIT_YEAR: | 302 case CREDIT_CARD_EXP_2_DIGIT_YEAR: |
(...skipping 30 matching lines...) Expand all Loading... |
333 default: | 333 default: |
334 NOTREACHED() << "Attempting to set unknown info-type " << type; | 334 NOTREACHED() << "Attempting to set unknown info-type " << type; |
335 break; | 335 break; |
336 } | 336 } |
337 } | 337 } |
338 | 338 |
339 string16 CreditCard::GetCanonicalizedInfo(AutofillFieldType type) const { | 339 string16 CreditCard::GetCanonicalizedInfo(AutofillFieldType type) const { |
340 if (type == CREDIT_CARD_NUMBER) | 340 if (type == CREDIT_CARD_NUMBER) |
341 return StripSeparators(number_); | 341 return StripSeparators(number_); |
342 | 342 |
343 return GetInfo(type); | 343 return GetRawInfo(type); |
344 } | 344 } |
345 | 345 |
346 bool CreditCard::SetCanonicalizedInfo(AutofillFieldType type, | 346 bool CreditCard::SetCanonicalizedInfo(AutofillFieldType type, |
347 const string16& value) { | 347 const string16& value) { |
348 if (type == CREDIT_CARD_NUMBER) | 348 if (type == CREDIT_CARD_NUMBER) |
349 SetInfo(type, StripSeparators(value)); | 349 SetRawInfo(type, StripSeparators(value)); |
350 else | 350 else |
351 SetInfo(type, value); | 351 SetRawInfo(type, value); |
352 | 352 |
353 return true; | 353 return true; |
354 } | 354 } |
355 | 355 |
356 void CreditCard::GetMatchingTypes(const string16& text, | 356 void CreditCard::GetMatchingTypes(const string16& text, |
357 FieldTypeSet* matching_types) const { | 357 FieldTypeSet* matching_types) const { |
358 FormGroup::GetMatchingTypes(text, matching_types); | 358 FormGroup::GetMatchingTypes(text, matching_types); |
359 | 359 |
360 string16 card_number = GetCanonicalizedInfo(CREDIT_CARD_NUMBER); | 360 string16 card_number = GetCanonicalizedInfo(CREDIT_CARD_NUMBER); |
361 if (!card_number.empty() && StripSeparators(text) == card_number) | 361 if (!card_number.empty() && StripSeparators(text) == card_number) |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 | 460 |
461 int CreditCard::Compare(const CreditCard& credit_card) const { | 461 int CreditCard::Compare(const CreditCard& credit_card) const { |
462 // The following CreditCard field types are the only types we store in the | 462 // The following CreditCard field types are the only types we store in the |
463 // WebDB so far, so we're only concerned with matching these types in the | 463 // WebDB so far, so we're only concerned with matching these types in the |
464 // credit card. | 464 // credit card. |
465 const AutofillFieldType types[] = { CREDIT_CARD_NAME, | 465 const AutofillFieldType types[] = { CREDIT_CARD_NAME, |
466 CREDIT_CARD_NUMBER, | 466 CREDIT_CARD_NUMBER, |
467 CREDIT_CARD_EXP_MONTH, | 467 CREDIT_CARD_EXP_MONTH, |
468 CREDIT_CARD_EXP_4_DIGIT_YEAR }; | 468 CREDIT_CARD_EXP_4_DIGIT_YEAR }; |
469 for (size_t index = 0; index < arraysize(types); ++index) { | 469 for (size_t index = 0; index < arraysize(types); ++index) { |
470 int comparison = GetInfo(types[index]).compare( | 470 int comparison = GetRawInfo(types[index]).compare( |
471 credit_card.GetInfo(types[index])); | 471 credit_card.GetRawInfo(types[index])); |
472 if (comparison != 0) | 472 if (comparison != 0) |
473 return comparison; | 473 return comparison; |
474 } | 474 } |
475 | 475 |
476 return 0; | 476 return 0; |
477 } | 477 } |
478 | 478 |
479 bool CreditCard::operator==(const CreditCard& credit_card) const { | 479 bool CreditCard::operator==(const CreditCard& credit_card) const { |
480 if (guid_ != credit_card.guid_) | 480 if (guid_ != credit_card.guid_) |
481 return false; | 481 return false; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
600 expiration_year_ = expiration_year; | 600 expiration_year_ = expiration_year; |
601 } | 601 } |
602 | 602 |
603 // So we can compare CreditCards with EXPECT_EQ(). | 603 // So we can compare CreditCards with EXPECT_EQ(). |
604 std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) { | 604 std::ostream& operator<<(std::ostream& os, const CreditCard& credit_card) { |
605 return os | 605 return os |
606 << UTF16ToUTF8(credit_card.Label()) | 606 << UTF16ToUTF8(credit_card.Label()) |
607 << " " | 607 << " " |
608 << credit_card.guid() | 608 << credit_card.guid() |
609 << " " | 609 << " " |
610 << UTF16ToUTF8(credit_card.GetInfo(CREDIT_CARD_NAME)) | 610 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NAME)) |
611 << " " | 611 << " " |
612 << UTF16ToUTF8(credit_card.GetInfo(CREDIT_CARD_TYPE)) | 612 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_TYPE)) |
613 << " " | 613 << " " |
614 << UTF16ToUTF8(credit_card.GetInfo(CREDIT_CARD_NUMBER)) | 614 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_NUMBER)) |
615 << " " | 615 << " " |
616 << UTF16ToUTF8(credit_card.GetInfo(CREDIT_CARD_EXP_MONTH)) | 616 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_EXP_MONTH)) |
617 << " " | 617 << " " |
618 << UTF16ToUTF8(credit_card.GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); | 618 << UTF16ToUTF8(credit_card.GetRawInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR)); |
619 } | 619 } |
620 | 620 |
621 // These values must match the values in WebKitPlatformSupportImpl in | 621 // These values must match the values in WebKitPlatformSupportImpl in |
622 // webkit/glue. We send these strings to WebKit, which then asks | 622 // webkit/glue. We send these strings to WebKit, which then asks |
623 // WebKitPlatformSupportImpl to load the image data. | 623 // WebKitPlatformSupportImpl to load the image data. |
624 const char* const kAmericanExpressCard = "americanExpressCC"; | 624 const char* const kAmericanExpressCard = "americanExpressCC"; |
625 const char* const kDinersCard = "dinersCC"; | 625 const char* const kDinersCard = "dinersCC"; |
626 const char* const kDiscoverCard = "discoverCC"; | 626 const char* const kDiscoverCard = "discoverCC"; |
627 const char* const kGenericCard = "genericCC"; | 627 const char* const kGenericCard = "genericCC"; |
628 const char* const kJCBCard = "jcbCC"; | 628 const char* const kJCBCard = "jcbCC"; |
629 const char* const kMasterCard = "masterCardCC"; | 629 const char* const kMasterCard = "masterCardCC"; |
630 const char* const kSoloCard = "soloCC"; | 630 const char* const kSoloCard = "soloCC"; |
631 const char* const kVisaCard = "visaCC"; | 631 const char* const kVisaCard = "visaCC"; |
OLD | NEW |