OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "components/autofill/core/browser/address_i18n.h" | 5 #include "components/autofill/core/browser/address_i18n.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
12 #include "components/autofill/core/browser/autofill_profile.h" | 12 #include "components/autofill/core/browser/autofill_profile.h" |
13 #include "components/autofill/core/browser/autofill_type.h" | 13 #include "components/autofill/core/browser/autofill_type.h" |
14 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_data.h" | 14 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_da
ta.h" |
15 | 15 |
16 namespace autofill { | 16 namespace autofill { |
17 namespace i18n { | 17 namespace i18n { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 base::string16 GetInfoHelper(const AutofillProfile& profile, | 21 base::string16 GetInfoHelper(const AutofillProfile& profile, |
22 const std::string& app_locale, | 22 const std::string& app_locale, |
23 const AutofillType& type) { | 23 const AutofillType& type) { |
24 return profile.GetInfo(type, app_locale); | 24 return profile.GetInfo(type, app_locale); |
25 } | 25 } |
26 | 26 |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 using ::i18n::addressinput::AddressData; | 29 using ::i18n::addressinput::AddressData; |
30 | 30 |
31 scoped_ptr<AddressData> CreateAddressData( | 31 scoped_ptr<AddressData> CreateAddressData( |
32 const base::Callback<base::string16(const AutofillType&)>& get_info) { | 32 const base::Callback<base::string16(const AutofillType&)>& get_info) { |
33 scoped_ptr<AddressData> address_data(new AddressData()); | 33 scoped_ptr<AddressData> address_data(new AddressData()); |
34 address_data->recipient = base::UTF16ToUTF8( | 34 address_data->recipient = base::UTF16ToUTF8( |
35 get_info.Run(AutofillType(NAME_FULL))); | 35 get_info.Run(AutofillType(NAME_FULL))); |
36 address_data->country_code = base::UTF16ToUTF8( | 36 address_data->region_code = base::UTF16ToUTF8( |
37 get_info.Run(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); | 37 get_info.Run(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); |
38 address_data->administrative_area = base::UTF16ToUTF8( | 38 address_data->administrative_area = base::UTF16ToUTF8( |
39 get_info.Run(AutofillType(ADDRESS_HOME_STATE))); | 39 get_info.Run(AutofillType(ADDRESS_HOME_STATE))); |
40 address_data->locality = base::UTF16ToUTF8( | 40 address_data->locality = base::UTF16ToUTF8( |
41 get_info.Run(AutofillType(ADDRESS_HOME_CITY))); | 41 get_info.Run(AutofillType(ADDRESS_HOME_CITY))); |
42 address_data->dependent_locality = base::UTF16ToUTF8( | 42 address_data->dependent_locality = base::UTF16ToUTF8( |
43 get_info.Run(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY))); | 43 get_info.Run(AutofillType(ADDRESS_HOME_DEPENDENT_LOCALITY))); |
44 address_data->sorting_code = base::UTF16ToUTF8( | 44 address_data->sorting_code = base::UTF16ToUTF8( |
45 get_info.Run(AutofillType(ADDRESS_HOME_SORTING_CODE))); | 45 get_info.Run(AutofillType(ADDRESS_HOME_SORTING_CODE))); |
46 address_data->postal_code = base::UTF16ToUTF8( | 46 address_data->postal_code = base::UTF16ToUTF8( |
47 get_info.Run(AutofillType(ADDRESS_HOME_ZIP))); | 47 get_info.Run(AutofillType(ADDRESS_HOME_ZIP))); |
48 base::SplitString( | 48 base::SplitString( |
49 base::UTF16ToUTF8( | 49 base::UTF16ToUTF8( |
50 get_info.Run(AutofillType(ADDRESS_HOME_STREET_ADDRESS))), | 50 get_info.Run(AutofillType(ADDRESS_HOME_STREET_ADDRESS))), |
51 '\n', | 51 '\n', |
52 &address_data->address_lines); | 52 &address_data->address_line); |
53 return address_data.Pass(); | 53 return address_data.Pass(); |
54 } | 54 } |
55 | 55 |
56 scoped_ptr< ::i18n::addressinput::AddressData> | 56 scoped_ptr< ::i18n::addressinput::AddressData> |
57 CreateAddressDataFromAutofillProfile(const AutofillProfile& profile, | 57 CreateAddressDataFromAutofillProfile(const AutofillProfile& profile, |
58 const std::string& app_locale) { | 58 const std::string& app_locale) { |
59 scoped_ptr< ::i18n::addressinput::AddressData> address_data = | 59 scoped_ptr< ::i18n::addressinput::AddressData> address_data = |
60 i18n::CreateAddressData(base::Bind(&GetInfoHelper, profile, app_locale)); | 60 i18n::CreateAddressData(base::Bind(&GetInfoHelper, profile, app_locale)); |
61 address_data->language_code = profile.language_code(); | 61 address_data->language_code = profile.language_code(); |
62 return address_data.Pass(); | 62 return address_data.Pass(); |
63 } | 63 } |
64 | 64 |
65 } // namespace i18n | 65 } // namespace i18n |
66 } // namespace autofill | 66 } // namespace autofill |
OLD | NEW |