Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Side by Side Diff: ios/chrome/browser/payments/payment_request_util.mm

Issue 2712053003: [Payment Request] Displays Contact Info in the payment summary view (Closed)
Patch Set: Addressed comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_util.h" 5 #import "ios/chrome/browser/payments/payment_request_util.h"
6 6
7 #include "base/strings/string16.h"
7 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
8 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/browser/autofill_profile.h" 10 #include "components/autofill/core/browser/autofill_profile.h"
10 #include "components/autofill/core/browser/field_types.h" 11 #include "components/autofill/core/browser/field_types.h"
11 #include "components/strings/grit/components_strings.h" 12 #include "components/strings/grit/components_strings.h"
12 #include "ios/chrome/browser/application_context.h" 13 #include "ios/chrome/browser/application_context.h"
13 #include "ios/chrome/browser/payments/payment_request.h" 14 #include "ios/chrome/browser/payments/payment_request.h"
14 #include "ui/base/l10n/l10n_util.h" 15 #include "ui/base/l10n/l10n_util.h"
15 16
16 #if !defined(__has_feature) || !__has_feature(objc_arc) 17 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support." 18 #error "This file requires ARC support."
18 #endif 19 #endif
19 20
20 namespace payment_request_util { 21 namespace payment_request_util {
21 22
22 NSString* NameLabelFromAutofillProfile(autofill::AutofillProfile* profile) { 23 NSString* GetNameLabelFromAutofillProfile(autofill::AutofillProfile* profile) {
23 return base::SysUTF16ToNSString( 24 return base::SysUTF16ToNSString(
24 profile->GetInfo(autofill::AutofillType(autofill::NAME_FULL), 25 profile->GetInfo(autofill::AutofillType(autofill::NAME_FULL),
25 GetApplicationContext()->GetApplicationLocale())); 26 GetApplicationContext()->GetApplicationLocale()));
26 } 27 }
27 28
28 NSString* AddressLabelFromAutofillProfile(autofill::AutofillProfile* profile) { 29 NSString* GetAddressLabelFromAutofillProfile(
30 autofill::AutofillProfile* profile) {
29 // Name, company, and country are not included in the shipping address label. 31 // Name, company, and country are not included in the shipping address label.
30 std::vector<autofill::ServerFieldType> label_fields; 32 std::vector<autofill::ServerFieldType> label_fields;
33 label_fields.push_back(autofill::COMPANY_NAME);
lpromero 2017/02/27 17:52:10 This is in conflict with the comment.
Moe 2017/02/27 20:49:42 Good catch! Updated comment.
31 label_fields.push_back(autofill::ADDRESS_HOME_LINE1); 34 label_fields.push_back(autofill::ADDRESS_HOME_LINE1);
32 label_fields.push_back(autofill::ADDRESS_HOME_LINE2); 35 label_fields.push_back(autofill::ADDRESS_HOME_LINE2);
33 label_fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); 36 label_fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
34 label_fields.push_back(autofill::ADDRESS_HOME_CITY); 37 label_fields.push_back(autofill::ADDRESS_HOME_CITY);
35 label_fields.push_back(autofill::ADDRESS_HOME_STATE); 38 label_fields.push_back(autofill::ADDRESS_HOME_STATE);
36 label_fields.push_back(autofill::ADDRESS_HOME_ZIP); 39 label_fields.push_back(autofill::ADDRESS_HOME_ZIP);
37 label_fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); 40 label_fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE);
38 41
39 return base::SysUTF16ToNSString(profile->ConstructInferredLabel( 42 base::string16 label = profile->ConstructInferredLabel(
40 label_fields, label_fields.size(), 43 label_fields, label_fields.size(),
41 GetApplicationContext()->GetApplicationLocale())); 44 GetApplicationContext()->GetApplicationLocale());
45 return !label.empty() ? base::SysUTF16ToNSString(label) : nil;
42 } 46 }
43 47
44 NSString* PhoneNumberLabelFromAutofillProfile( 48 NSString* GetPhoneNumberLabelFromAutofillProfile(
45 autofill::AutofillProfile* profile) { 49 autofill::AutofillProfile* profile) {
46 return base::SysUTF16ToNSString(profile->GetInfo( 50 base::string16 label = profile->GetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER);
47 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), 51 return !label.empty() ? base::SysUTF16ToNSString(label) : nil;
48 GetApplicationContext()->GetApplicationLocale()));
49 } 52 }
50 53
51 web::PaymentAddress PaymentAddressFromAutofillProfile( 54 NSString* GetEmailLabelFromAutofillProfile(autofill::AutofillProfile* profile) {
55 base::string16 label = profile->GetRawInfo(autofill::EMAIL_ADDRESS);
56 return !label.empty() ? base::SysUTF16ToNSString(label) : nil;
57 }
58
59 web::PaymentAddress GetPaymentAddressFromAutofillProfile(
52 autofill::AutofillProfile* profile) { 60 autofill::AutofillProfile* profile) {
53 web::PaymentAddress address; 61 web::PaymentAddress address;
54 address.country = profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY); 62 address.country = profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY);
55 address.address_line.push_back( 63 address.address_line.push_back(
56 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE1)); 64 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE1));
57 address.address_line.push_back( 65 address.address_line.push_back(
58 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE2)); 66 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE2));
59 address.address_line.push_back( 67 address.address_line.push_back(
60 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE3)); 68 profile->GetRawInfo(autofill::ADDRESS_HOME_LINE3));
61 address.region = profile->GetRawInfo(autofill::ADDRESS_HOME_STATE); 69 address.region = profile->GetRawInfo(autofill::ADDRESS_HOME_STATE);
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_DELIVERY_OPTION); 173 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_DELIVERY_OPTION);
166 case web::PaymentShippingType::PICKUP: 174 case web::PaymentShippingType::PICKUP:
167 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_PICKUP_OPTION); 175 return l10n_util::GetNSString(IDS_PAYMENTS_UNSUPPORTED_PICKUP_OPTION);
168 default: 176 default:
169 NOTREACHED(); 177 NOTREACHED();
170 return @""; 178 return @"";
171 } 179 }
172 } 180 }
173 181
174 } // namespace payment_request_util 182 } // namespace payment_request_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698