Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/payments/core/payment_request_data_util.h" | 5 #include "components/payments/core/payment_request_data_util.h" |
| 6 | 6 |
| 7 #include "base/strings/string16.h" | 7 #include "base/strings/string16.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_util.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 10 #include "components/autofill/core/browser/autofill_country.h" | 11 #include "components/autofill/core/browser/autofill_country.h" |
| 11 #include "components/autofill/core/browser/autofill_data_util.h" | 12 #include "components/autofill/core/browser/autofill_data_util.h" |
| 12 #include "components/autofill/core/browser/autofill_profile.h" | 13 #include "components/autofill/core/browser/autofill_profile.h" |
| 13 #include "components/autofill/core/browser/credit_card.h" | 14 #include "components/autofill/core/browser/credit_card.h" |
| 14 #include "components/autofill/core/browser/field_types.h" | 15 #include "components/autofill/core/browser/field_types.h" |
| 15 #include "components/autofill/core/browser/personal_data_manager.h" | 16 #include "components/autofill/core/browser/personal_data_manager.h" |
| 16 #include "components/autofill/core/browser/validation.h" | 17 #include "components/autofill/core/browser/validation.h" |
| 17 #include "components/payments/core/basic_card_response.h" | 18 #include "components/payments/core/basic_card_response.h" |
| 18 #include "components/payments/core/payment_address.h" | 19 #include "components/payments/core/payment_address.h" |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 184 return FormatPhoneNumber(phone_number, country_code, | 185 return FormatPhoneNumber(phone_number, country_code, |
| 185 PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL); | 186 PhoneNumberUtil::PhoneNumberFormat::INTERNATIONAL); |
| 186 } | 187 } |
| 187 | 188 |
| 188 std::string FormatPhoneForResponse(const std::string& phone_number, | 189 std::string FormatPhoneForResponse(const std::string& phone_number, |
| 189 const std::string& country_code) { | 190 const std::string& country_code) { |
| 190 return FormatPhoneNumber(phone_number, country_code, | 191 return FormatPhoneNumber(phone_number, country_code, |
| 191 PhoneNumberUtil::PhoneNumberFormat::E164); | 192 PhoneNumberUtil::PhoneNumberFormat::E164); |
| 192 } | 193 } |
| 193 | 194 |
| 195 base::string16 FormatCardNumberForDisplay(const base::string16& card_number) { | |
| 196 // Do not format masked card numbers, which start with a letter. | |
|
please use gerrit instead
2017/06/20 16:27:04
Move this comment into the header file.
Moe
2017/06/20 18:00:59
Done.
| |
| 197 base::string16 number = autofill::CreditCard::StripSeparators(card_number); | |
| 198 if (number.empty() || !base::IsAsciiDigit(number[0])) | |
| 199 return card_number; | |
| 200 | |
| 201 std::vector<size_t> positions = {4U, 9U, 14U}; | |
| 202 if (autofill::CreditCard::GetCardNetwork(number) == | |
| 203 autofill::kAmericanExpressCard) { | |
| 204 positions = {4U, 11U}; | |
| 205 } | |
| 206 | |
| 207 static const base::char16 kSeparator = base::ASCIIToUTF16(" ")[0]; | |
| 208 for (size_t i : positions) { | |
| 209 if (number.size() > i) | |
| 210 number.insert(i, 1U, kSeparator); | |
| 211 } | |
| 212 | |
| 213 return number; | |
| 214 } | |
| 215 | |
| 194 std::string GetCountryCodeWithFallback(const autofill::AutofillProfile* profile, | 216 std::string GetCountryCodeWithFallback(const autofill::AutofillProfile* profile, |
| 195 const std::string& app_locale) { | 217 const std::string& app_locale) { |
| 196 std::string country_code = | 218 std::string country_code = |
| 197 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | 219 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |
| 198 if (!autofill::data_util::IsValidCountryCode(country_code)) | 220 if (!autofill::data_util::IsValidCountryCode(country_code)) |
| 199 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale); | 221 country_code = autofill::AutofillCountry::CountryCodeForLocale(app_locale); |
| 200 return country_code; | 222 return country_code; |
| 201 } | 223 } |
| 202 | 224 |
| 203 } // namespace data_util | 225 } // namespace data_util |
| 204 } // namespace payments | 226 } // namespace payments |
| OLD | NEW |