Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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 "components/autofill/core/browser/address_i18n.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "base/strings/string_split.h" | |
| 9 #include "base/strings/utf_string_conversions.h" | |
| 10 #include "components/autofill/core/browser/autofill_type.h" | |
| 11 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre ss_data.h" | |
| 12 | |
| 13 namespace autofill { | |
| 14 namespace i18n { | |
| 15 | |
| 16 using ::i18n::addressinput::AddressData; | |
| 17 | |
| 18 scoped_ptr<AddressData> CreateAddressData( | |
| 19 const base::Callback<base::string16(const AutofillType&)>& get_info) { | |
| 20 scoped_ptr<AddressData> address_data(new AddressData()); | |
| 21 address_data->recipient = UTF16ToUTF8(get_info.Run(AutofillType(NAME_FULL))); | |
| 22 address_data->country_code = UTF16ToUTF8( | |
| 23 get_info.Run(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_SHIPPING))); | |
|
Ilya Sherman
2014/05/07 01:19:19
nit: Why SHIPPING as opposed to NONE?
Evan Stade
2014/05/09 22:14:59
Done.
| |
| 24 DCHECK_EQ(2U, address_data->country_code.size()); | |
|
Ilya Sherman
2014/05/07 01:19:19
What if the country code is unspecified?
Evan Stade
2014/05/09 22:14:59
added a testcase
| |
| 25 address_data->administrative_area = UTF16ToUTF8( | |
| 26 get_info.Run(AutofillType(ADDRESS_HOME_STATE))); | |
| 27 address_data->locality = UTF16ToUTF8( | |
| 28 get_info.Run(AutofillType(ADDRESS_HOME_CITY))); | |
| 29 address_data->dependent_locality = UTF16ToUTF8( | |
| 30 get_info.Run(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY))); | |
| 31 address_data->sorting_code = UTF16ToUTF8( | |
| 32 get_info.Run(AutofillType(ADDRESS_HOME_SORTING_CODE))); | |
| 33 address_data->postal_code = UTF16ToUTF8( | |
| 34 get_info.Run(AutofillType(ADDRESS_HOME_ZIP))); | |
| 35 base::SplitString( | |
| 36 UTF16ToUTF8(get_info.Run(AutofillType(ADDRESS_HOME_STREET_ADDRESS))), | |
| 37 '\n', | |
|
Ilya Sherman
2014/05/07 01:19:19
Not all addresses are joined with newlines, right?
Evan Stade
2014/05/09 22:14:59
Yes, all addresses are joined with newlines in the
| |
| 38 &address_data->address_lines); | |
| 39 return address_data.Pass(); | |
| 40 } | |
| 41 | |
| 42 } // namespace i18n | |
| 43 } // namespace autofill | |
| OLD | NEW |