Chromium Code Reviews| Index: chrome/browser/ui/views/payments/payment_request_address_util.cc |
| diff --git a/chrome/browser/ui/views/payments/payment_request_address_util.cc b/chrome/browser/ui/views/payments/payment_request_address_util.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5339c64dc2e2dd159f7308051947d4a680f1a502 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/payments/payment_request_address_util.cc |
| @@ -0,0 +1,78 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/payments/payment_request_address_util.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "components/autofill/core/browser/autofill_type.h" |
| +#include "components/autofill/core/browser/field_types.h" |
| +#include "ui/views/controls/styled_label.h" |
| +#include "ui/views/view.h" |
| + |
| +namespace { |
| + |
| +// TODO(tmartino): Consider combining this with the Android equivalent in |
| +// PersonalDataManager.java |
| +base::string16 GetAddressFromProfile(autofill::AutofillProfile* profile, |
| + std::string locale) { |
| + std::vector<autofill::ServerFieldType> fields; |
| + fields.push_back(autofill::COMPANY_NAME); |
| + fields.push_back(autofill::ADDRESS_HOME_LINE1); |
| + fields.push_back(autofill::ADDRESS_HOME_LINE2); |
| + fields.push_back(autofill::ADDRESS_HOME_DEPENDENT_LOCALITY); |
| + fields.push_back(autofill::ADDRESS_HOME_CITY); |
| + fields.push_back(autofill::ADDRESS_HOME_STATE); |
| + fields.push_back(autofill::ADDRESS_HOME_ZIP); |
| + fields.push_back(autofill::ADDRESS_HOME_SORTING_CODE); |
| + |
| + return profile->ConstructInferredLabel(fields, fields.size(), locale); |
| +} |
| + |
| +} // namespace |
| + |
| +namespace payments { |
| + |
| +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
|
| + std::unique_ptr<autofill::AutofillProfile> profile = |
| + base::MakeUnique<autofill::AutofillProfile>(); |
| + profile->SetInfo(autofill::AutofillType(autofill::NAME_FULL), |
| + base::ASCIIToUTF16("Test McTest"), ""); |
| + profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_LINE1), |
| + base::ASCIIToUTF16("123 Fake St."), ""); |
| + profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_CITY), |
| + base::ASCIIToUTF16("Minneapolis"), ""); |
| + profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_STATE), |
| + base::ASCIIToUTF16("MN"), ""); |
| + profile->SetInfo(autofill::AutofillType(autofill::ADDRESS_HOME_ZIP), |
| + base::ASCIIToUTF16("55403"), ""); |
| + profile->SetInfo(autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), |
| + base::ASCIIToUTF16("5551234567"), ""); |
| + return profile; |
| +} |
| + |
| +std::unique_ptr<views::View> GetPaymentRequestAddressLabel( |
| + AddressFormatType type, |
| + std::string locale, |
| + autofill::AutofillProfile* profile) { |
| + base::string16 name_value = |
| + profile->GetInfo(autofill::AutofillType(autofill::NAME_FULL), locale); |
| + |
| + base::string16 address_value = GetAddressFromProfile(profile, locale); |
| + |
| + base::string16 phone_value = profile->GetInfo( |
| + autofill::AutofillType(autofill::PHONE_HOME_WHOLE_NUMBER), locale); |
| + |
| + base::string16 label = base::JoinString( |
| + std::vector<base::string16>({name_value, address_value, phone_value}), |
| + base::ASCIIToUTF16("\n")); |
| + |
| + std::unique_ptr<views::StyledLabel> styled_label = |
| + base::MakeUnique<views::StyledLabel>(label, nullptr); |
| + |
| + return styled_label; |
| +} |
| + |
| +} // namespace payments |