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/src/cpp/include/libaddressinput/address_da
ta.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 using ::i18n::addressinput::AddressField; |
30 | 31 |
31 scoped_ptr<AddressData> CreateAddressData( | 32 scoped_ptr<AddressData> CreateAddressData( |
32 const base::Callback<base::string16(const AutofillType&)>& get_info) { | 33 const base::Callback<base::string16(const AutofillType&)>& get_info) { |
33 scoped_ptr<AddressData> address_data(new AddressData()); | 34 scoped_ptr<AddressData> address_data(new AddressData()); |
34 address_data->recipient = base::UTF16ToUTF8( | 35 address_data->recipient = base::UTF16ToUTF8( |
35 get_info.Run(AutofillType(NAME_FULL))); | 36 get_info.Run(AutofillType(NAME_FULL))); |
36 address_data->region_code = base::UTF16ToUTF8( | 37 address_data->region_code = base::UTF16ToUTF8( |
37 get_info.Run(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); | 38 get_info.Run(AutofillType(HTML_TYPE_COUNTRY_CODE, HTML_MODE_NONE))); |
38 address_data->administrative_area = base::UTF16ToUTF8( | 39 address_data->administrative_area = base::UTF16ToUTF8( |
39 get_info.Run(AutofillType(ADDRESS_HOME_STATE))); | 40 get_info.Run(AutofillType(ADDRESS_HOME_STATE))); |
(...skipping 15 matching lines...) Expand all Loading... |
55 | 56 |
56 scoped_ptr< ::i18n::addressinput::AddressData> | 57 scoped_ptr< ::i18n::addressinput::AddressData> |
57 CreateAddressDataFromAutofillProfile(const AutofillProfile& profile, | 58 CreateAddressDataFromAutofillProfile(const AutofillProfile& profile, |
58 const std::string& app_locale) { | 59 const std::string& app_locale) { |
59 scoped_ptr< ::i18n::addressinput::AddressData> address_data = | 60 scoped_ptr< ::i18n::addressinput::AddressData> address_data = |
60 i18n::CreateAddressData(base::Bind(&GetInfoHelper, profile, app_locale)); | 61 i18n::CreateAddressData(base::Bind(&GetInfoHelper, profile, app_locale)); |
61 address_data->language_code = profile.language_code(); | 62 address_data->language_code = profile.language_code(); |
62 return address_data.Pass(); | 63 return address_data.Pass(); |
63 } | 64 } |
64 | 65 |
| 66 ServerFieldType TypeForField(AddressField address_field, bool billing) { |
| 67 switch (address_field) { |
| 68 case ::i18n::addressinput::COUNTRY: |
| 69 return billing ? ADDRESS_BILLING_COUNTRY : ADDRESS_HOME_COUNTRY; |
| 70 case ::i18n::addressinput::ADMIN_AREA: |
| 71 return billing ? ADDRESS_BILLING_STATE : ADDRESS_HOME_STATE; |
| 72 case ::i18n::addressinput::LOCALITY: |
| 73 return billing ? ADDRESS_BILLING_CITY : ADDRESS_HOME_CITY; |
| 74 case ::i18n::addressinput::DEPENDENT_LOCALITY: |
| 75 return billing ? ADDRESS_BILLING_DEPENDENT_LOCALITY |
| 76 : ADDRESS_HOME_DEPENDENT_LOCALITY; |
| 77 case ::i18n::addressinput::POSTAL_CODE: |
| 78 return billing ? ADDRESS_BILLING_ZIP : ADDRESS_HOME_ZIP; |
| 79 case ::i18n::addressinput::SORTING_CODE: |
| 80 return billing ? ADDRESS_BILLING_SORTING_CODE : ADDRESS_HOME_SORTING_CODE; |
| 81 case ::i18n::addressinput::STREET_ADDRESS: |
| 82 return billing ? ADDRESS_BILLING_STREET_ADDRESS |
| 83 : ADDRESS_HOME_STREET_ADDRESS; |
| 84 case ::i18n::addressinput::RECIPIENT: |
| 85 return billing ? NAME_BILLING_FULL : NAME_FULL; |
| 86 } |
| 87 NOTREACHED(); |
| 88 return UNKNOWN_TYPE; |
| 89 } |
| 90 |
| 91 bool FieldForType(ServerFieldType server_type, AddressField* field) { |
| 92 switch (server_type) { |
| 93 case ADDRESS_BILLING_COUNTRY: |
| 94 case ADDRESS_HOME_COUNTRY: |
| 95 if (field) |
| 96 *field = ::i18n::addressinput::COUNTRY; |
| 97 return true; |
| 98 case ADDRESS_BILLING_STATE: |
| 99 case ADDRESS_HOME_STATE: |
| 100 if (field) |
| 101 *field = ::i18n::addressinput::ADMIN_AREA; |
| 102 return true; |
| 103 case ADDRESS_BILLING_CITY: |
| 104 case ADDRESS_HOME_CITY: |
| 105 if (field) |
| 106 *field = ::i18n::addressinput::LOCALITY; |
| 107 return true; |
| 108 case ADDRESS_BILLING_DEPENDENT_LOCALITY: |
| 109 case ADDRESS_HOME_DEPENDENT_LOCALITY: |
| 110 if (field) |
| 111 *field = ::i18n::addressinput::DEPENDENT_LOCALITY; |
| 112 return true; |
| 113 case ADDRESS_BILLING_SORTING_CODE: |
| 114 case ADDRESS_HOME_SORTING_CODE: |
| 115 if (field) |
| 116 *field = ::i18n::addressinput::SORTING_CODE; |
| 117 return true; |
| 118 case ADDRESS_BILLING_ZIP: |
| 119 case ADDRESS_HOME_ZIP: |
| 120 if (field) |
| 121 *field = ::i18n::addressinput::POSTAL_CODE; |
| 122 return true; |
| 123 case ADDRESS_BILLING_STREET_ADDRESS: |
| 124 case ADDRESS_BILLING_LINE1: |
| 125 case ADDRESS_BILLING_LINE2: |
| 126 case ADDRESS_HOME_STREET_ADDRESS: |
| 127 case ADDRESS_HOME_LINE1: |
| 128 case ADDRESS_HOME_LINE2: |
| 129 if (field) |
| 130 *field = ::i18n::addressinput::STREET_ADDRESS; |
| 131 return true; |
| 132 case NAME_BILLING_FULL: |
| 133 case NAME_FULL: |
| 134 if (field) |
| 135 *field = ::i18n::addressinput::RECIPIENT; |
| 136 return true; |
| 137 default: |
| 138 return false; |
| 139 } |
| 140 } |
| 141 |
65 } // namespace i18n | 142 } // namespace i18n |
66 } // namespace autofill | 143 } // namespace autofill |
OLD | NEW |