OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ios/chrome/browser/payments/payment_request_utils.h" | 5 #import "ios/chrome/browser/payments/payment_request_utils.h" |
6 | 6 |
7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
8 #include "components/autofill/core/browser/autofill_profile.h" | 8 #include "components/autofill/core/browser/autofill_profile.h" |
9 #include "components/autofill/core/browser/field_types.h" | |
10 #include "ios/chrome/browser/application_context.h" | 9 #include "ios/chrome/browser/application_context.h" |
11 | 10 |
12 namespace payment_request_utils { | 11 namespace payment_request_utils { |
13 | 12 |
14 NSString* NameLabelFromAutofillProfile(autofill::AutofillProfile* profile) { | |
15 return base::SysUTF16ToNSString( | |
16 profile->GetInfo(autofill::AutofillType(autofill::NAME_FULL), | |
17 GetApplicationContext()->GetApplicationLocale())); | |
18 } | |
19 | |
20 NSString* AddressLabelFromAutofillProfile(autofill::AutofillProfile* profile) { | 13 NSString* AddressLabelFromAutofillProfile(autofill::AutofillProfile* profile) { |
21 // Name, company, and country are not included in the shipping address label. | 14 // Name, company, and country are not included in the shipping address label. |
22 std::vector<autofill::ServerFieldType> label_fields; | 15 std::vector<autofill::ServerFieldType> label_fields; |
23 label_fields.push_back(autofill::ADDRESS_HOME_LINE1); | 16 label_fields.push_back(autofill::ADDRESS_HOME_LINE1); |
24 label_fields.push_back(autofill::ADDRESS_HOME_LINE2); | 17 label_fields.push_back(autofill::ADDRESS_HOME_LINE2); |
25 label_fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); | 18 label_fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); |
26 label_fields.push_back(autofill::ADDRESS_HOME_CITY); | 19 label_fields.push_back(autofill::ADDRESS_HOME_CITY); |
27 label_fields.push_back(autofill::ADDRESS_HOME_STATE); | 20 label_fields.push_back(autofill::ADDRESS_HOME_STATE); |
28 label_fields.push_back(autofill::ADDRESS_HOME_ZIP); | 21 label_fields.push_back(autofill::ADDRESS_HOME_ZIP); |
29 label_fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); | 22 label_fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); |
30 | 23 |
31 return base::SysUTF16ToNSString(profile->ConstructInferredLabel( | 24 return base::SysUTF16ToNSString(profile->ConstructInferredLabel( |
32 label_fields, label_fields.size(), | 25 label_fields, label_fields.size(), |
33 GetApplicationContext()->GetApplicationLocale())); | 26 GetApplicationContext()->GetApplicationLocale())); |
34 } | 27 } |
35 | 28 |
36 NSString* FormattedCurrencyString(NSDecimalNumber* value, | 29 NSString* FormattedCurrencyString(NSDecimalNumber* value, |
37 NSString* currencyCode) { | 30 NSString* currencyCode) { |
38 NSNumberFormatter* currencyFormatter = | 31 NSNumberFormatter* currencyFormatter = |
39 [[[NSNumberFormatter alloc] init] autorelease]; | 32 [[[NSNumberFormatter alloc] init] autorelease]; |
40 [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; | 33 [currencyFormatter setNumberStyle:NSNumberFormatterCurrencyStyle]; |
41 [currencyFormatter setCurrencyCode:currencyCode]; | 34 [currencyFormatter setCurrencyCode:currencyCode]; |
42 return [currencyFormatter stringFromNumber:value]; | 35 return [currencyFormatter stringFromNumber:value]; |
43 } | 36 } |
44 | 37 |
45 NSString* PhoneNumberLabelFromAutofillProfile( | |
46 autofill::AutofillProfile* profile) { | |
47 return base::SysUTF16ToNSString(profile->GetInfo( | |
48 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), | |
49 GetApplicationContext()->GetApplicationLocale())); | |
50 } | |
51 | |
52 } // namespace payment_request_utils | 38 } // namespace payment_request_utils |
OLD | NEW |