| 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> |
| 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_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "components/autofill/browser/autofill_country.h" | |
| 21 #include "components/autofill/browser/autofill_field.h" | 20 #include "components/autofill/browser/autofill_field.h" |
| 22 #include "components/autofill/browser/autofill_regexes.h" | 21 #include "components/autofill/browser/autofill_regexes.h" |
| 23 #include "components/autofill/browser/autofill_type.h" | 22 #include "components/autofill/browser/autofill_type.h" |
| 24 #include "components/autofill/browser/field_types.h" | 23 #include "components/autofill/browser/field_types.h" |
| 25 #include "components/autofill/browser/validation.h" | 24 #include "components/autofill/browser/validation.h" |
| 26 #include "components/autofill/common/form_field_data.h" | 25 #include "components/autofill/common/form_field_data.h" |
| 27 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 28 #include "grit/webkit_resources.h" | 27 #include "grit/webkit_resources.h" |
| 29 #include "third_party/icu/public/common/unicode/uloc.h" | 28 #include "third_party/icu/public/common/unicode/uloc.h" |
| 30 #include "third_party/icu/public/i18n/unicode/dtfmtsym.h" | 29 #include "third_party/icu/public/i18n/unicode/dtfmtsym.h" |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 // The expiration date for |imported_card| should always be set. | 504 // The expiration date for |imported_card| should always be set. |
| 506 DCHECK(imported_card.expiration_month_ && imported_card.expiration_year_); | 505 DCHECK(imported_card.expiration_month_ && imported_card.expiration_year_); |
| 507 expiration_month_ = imported_card.expiration_month_; | 506 expiration_month_ = imported_card.expiration_month_; |
| 508 expiration_year_ = imported_card.expiration_year_; | 507 expiration_year_ = imported_card.expiration_year_; |
| 509 | 508 |
| 510 return true; | 509 return true; |
| 511 } | 510 } |
| 512 | 511 |
| 513 void CreditCard::FillFormField(const AutofillField& field, | 512 void CreditCard::FillFormField(const AutofillField& field, |
| 514 size_t /*variant*/, | 513 size_t /*variant*/, |
| 514 const std::string& app_locale, |
| 515 FormFieldData* field_data) const { | 515 FormFieldData* field_data) const { |
| 516 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(field.type()).group()); | 516 DCHECK_EQ(AutofillType::CREDIT_CARD, AutofillType(field.type()).group()); |
| 517 DCHECK(field_data); | 517 DCHECK(field_data); |
| 518 | 518 |
| 519 const std::string app_locale = AutofillCountry::ApplicationLocale(); | |
| 520 | |
| 521 if (field_data->form_control_type == "select-one") { | 519 if (field_data->form_control_type == "select-one") { |
| 522 FillSelectControl(field.type(), field_data); | 520 FillSelectControl(field.type(), app_locale, field_data); |
| 523 } else if (field_data->form_control_type == "month") { | 521 } else if (field_data->form_control_type == "month") { |
| 524 // HTML5 input="month" consists of year-month. | 522 // HTML5 input="month" consists of year-month. |
| 525 string16 year = GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, app_locale); | 523 string16 year = GetInfo(CREDIT_CARD_EXP_4_DIGIT_YEAR, app_locale); |
| 526 string16 month = GetInfo(CREDIT_CARD_EXP_MONTH, app_locale); | 524 string16 month = GetInfo(CREDIT_CARD_EXP_MONTH, app_locale); |
| 527 if (!year.empty() && !month.empty()) { | 525 if (!year.empty() && !month.empty()) { |
| 528 // Fill the value only if |this| includes both year and month | 526 // Fill the value only if |this| includes both year and month |
| 529 // information. | 527 // information. |
| 530 field_data->value = year + ASCIIToUTF16("-") + month; | 528 field_data->value = year + ASCIIToUTF16("-") + month; |
| 531 } | 529 } |
| 532 } else { | 530 } else { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 556 if (guid_ != credit_card.guid_) | 554 if (guid_ != credit_card.guid_) |
| 557 return false; | 555 return false; |
| 558 | 556 |
| 559 return Compare(credit_card) == 0; | 557 return Compare(credit_card) == 0; |
| 560 } | 558 } |
| 561 | 559 |
| 562 bool CreditCard::operator!=(const CreditCard& credit_card) const { | 560 bool CreditCard::operator!=(const CreditCard& credit_card) const { |
| 563 return !operator==(credit_card); | 561 return !operator==(credit_card); |
| 564 } | 562 } |
| 565 | 563 |
| 566 bool CreditCard::IsEmpty() const { | 564 bool CreditCard::IsEmpty(const std::string& app_locale) const { |
| 567 FieldTypeSet types; | 565 FieldTypeSet types; |
| 568 GetNonEmptyTypes(AutofillCountry::ApplicationLocale(), &types); | 566 GetNonEmptyTypes(app_locale, &types); |
| 569 return types.empty(); | 567 return types.empty(); |
| 570 } | 568 } |
| 571 | 569 |
| 572 bool CreditCard::IsComplete() const { | 570 bool CreditCard::IsComplete() const { |
| 573 return | 571 return |
| 574 autofill::IsValidCreditCardNumber(number_) && | 572 autofill::IsValidCreditCardNumber(number_) && |
| 575 expiration_month_ != 0 && | 573 expiration_month_ != 0 && |
| 576 expiration_year_ != 0; | 574 expiration_year_ != 0; |
| 577 } | 575 } |
| 578 | 576 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 // webkit/glue. We send these strings to WebKit, which then asks | 672 // webkit/glue. We send these strings to WebKit, which then asks |
| 675 // WebKitPlatformSupportImpl to load the image data. | 673 // WebKitPlatformSupportImpl to load the image data. |
| 676 const char* const kAmericanExpressCard = "americanExpressCC"; | 674 const char* const kAmericanExpressCard = "americanExpressCC"; |
| 677 const char* const kDinersCard = "dinersCC"; | 675 const char* const kDinersCard = "dinersCC"; |
| 678 const char* const kDiscoverCard = "discoverCC"; | 676 const char* const kDiscoverCard = "discoverCC"; |
| 679 const char* const kGenericCard = "genericCC"; | 677 const char* const kGenericCard = "genericCC"; |
| 680 const char* const kJCBCard = "jcbCC"; | 678 const char* const kJCBCard = "jcbCC"; |
| 681 const char* const kMasterCard = "masterCardCC"; | 679 const char* const kMasterCard = "masterCardCC"; |
| 682 const char* const kSoloCard = "soloCC"; | 680 const char* const kSoloCard = "soloCC"; |
| 683 const char* const kVisaCard = "visaCC"; | 681 const char* const kVisaCard = "visaCC"; |
| OLD | NEW |