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

Side by Side Diff: chrome/browser/ui/views/payments/payment_request_address_util.cc

Issue 2625183002: [WebPayments] Adding Shipping Address and Contact Info display to order summary (Closed)
Patch Set: Created 3 years, 11 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/payments/payment_request_address_util.h"
6
7 #include <vector>
8
9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_type.h"
11 #include "components/autofill/core/browser/field_types.h"
12 #include "ui/views/controls/styled_label.h"
13 #include "ui/views/view.h"
14
15 namespace {
16
17 // TODO(tmartino): Consider combining this with the Android equivalent in
18 // PersonalDataManager.java
19 base::string16 GetAddressFromProfile(autofill::AutofillProfile* profile,
20 std::string locale) {
21 std::vector<autofill::ServerFieldType> fields;
22 fields.push_back(autofill::COMPANY_NAME);
23 fields.push_back(autofill::ADDRESS_HOME_LINE1);
24 fields.push_back(autofill::ADDRESS_HOME_LINE2);
25 fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY);
26 fields.push_back(autofill::ADDRESS_HOME_CITY);
27 fields.push_back(autofill::ADDRESS_HOME_STATE);
28 fields.push_back(autofill::ADDRESS_HOME_ZIP);
29 fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE);
30
31 return profile->ConstructInferredLabel(fields, fields.size(), locale);
32 }
33
34 } // namespace
35
36 namespace payments {
37
38 std::unique_ptr<autofill::AutofillProfile> GetDummyProfile() {
anthonyvd 2017/01/12 15:42:11 Since we know the currently selected profile will
tmartino 2017/01/18 17:28:24 Done
39 std::unique_ptr<autofill::AutofillProfile> profile =
40 base::MakeUnique<autofill::AutofillProfile>();
41 profile->SetInfo(autofill::AutofillType(autofill::NAME_FULL),
42 base::ASCIIToUTF16("Test McTest"), "");
43 profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_LINE1),
44 base::ASCIIToUTF16("123 Fake St."), "");
45 profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_CITY),
46 base::ASCIIToUTF16("Minneapolis"), "");
47 profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_STATE),
48 base::ASCIIToUTF16("MN"), "");
49 profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_ZIP),
50 base::ASCIIToUTF16("55403"), "");
51 profile->SetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER),
52 base::ASCIIToUTF16("5551234567"), "");
53 return profile;
54 }
55
56 std::unique_ptr<views::View> GetPaymentRequestAddressLabel(
57 AddressFormatType type,
58 std::string locale,
59 autofill::AutofillProfile* profile) {
60 base::string16 name_value =
61 profile->GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale);
62
63 base::string16 address_value = GetAddressFromProfile(profile, locale);
64
65 base::string16 phone_value = profile->GetInfo(
66 autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale);
67
68 base::string16 label = base::JoinString(
69 std::vector<base::string16>({name_value, address_value, phone_value}),
70 base::ASCIIToUTF16("\n"));
71
72 std::unique_ptr<views::StyledLabel> styled_label =
73 base::MakeUnique<views::StyledLabel>(label, nullptr);
74
75 return styled_label;
76 }
77
78 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698