OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/autofill/autofill_dialog_common.h" | 5 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
9 #include "components/autofill/core/browser/autofill_country.h" | 9 #include "components/autofill/core/browser/autofill_country.h" |
10 #include "components/autofill/core/browser/autofill_field.h" | 10 #include "components/autofill/core/browser/autofill_field.h" |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 bool IsI18nInputEnabled() { | 89 bool IsI18nInputEnabled() { |
90 #if defined(OS_ANDROID) | 90 #if defined(OS_ANDROID) |
91 return false; | 91 return false; |
92 #else | 92 #else |
93 return true; | 93 return true; |
94 #endif | 94 #endif |
95 } | 95 } |
96 | 96 |
97 void BuildI18nAddressInputs(AddressType address_type, | 97 void BuildI18nAddressInputs(AddressType address_type, |
98 const std::string& country_code, | 98 const std::string& country_code, |
99 DetailInputs* inputs) { | 99 DetailInputs* inputs, |
| 100 std::string* language_code) { |
100 #if defined(OS_ANDROID) | 101 #if defined(OS_ANDROID) |
101 NOTREACHED(); | 102 NOTREACHED(); |
102 #else | 103 #else |
103 i18ninput::BuildAddressInputs(address_type, country_code, inputs); | 104 i18ninput::BuildAddressInputs(address_type, country_code, inputs, |
| 105 language_code); |
104 #endif | 106 #endif |
105 } | 107 } |
106 | 108 |
107 // Constructs |inputs| from template data for a given |dialog_section|. | 109 // Constructs |inputs| from template data for a given |dialog_section|. |
108 void BuildInputsForSection(DialogSection dialog_section, | 110 void BuildInputsForSection(DialogSection dialog_section, |
109 const std::string& country_code, | 111 const std::string& country_code, |
110 DetailInputs* inputs) { | 112 DetailInputs* inputs, |
| 113 std::string* language_code) { |
111 using l10n_util::GetStringUTF16; | 114 using l10n_util::GetStringUTF16; |
112 | 115 |
113 const DetailInput kCCInputs[] = { | 116 const DetailInput kCCInputs[] = { |
114 { DetailInput::LONG, | 117 { DetailInput::LONG, |
115 CREDIT_CARD_NUMBER, | 118 CREDIT_CARD_NUMBER, |
116 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER) }, | 119 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER) }, |
117 { DetailInput::SHORT, | 120 { DetailInput::SHORT, |
118 CREDIT_CARD_EXP_MONTH, | 121 CREDIT_CARD_EXP_MONTH, |
119 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH) }, | 122 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH) }, |
120 { DetailInput::SHORT, | 123 { DetailInput::SHORT, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 PHONE_HOME_WHOLE_NUMBER, | 191 PHONE_HOME_WHOLE_NUMBER, |
189 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) }, | 192 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) }, |
190 }; | 193 }; |
191 | 194 |
192 switch (dialog_section) { | 195 switch (dialog_section) { |
193 case SECTION_CC: | 196 case SECTION_CC: |
194 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 197 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
195 break; | 198 break; |
196 | 199 |
197 case SECTION_BILLING: | 200 case SECTION_BILLING: |
198 if (IsI18nInputEnabled()) | 201 if (IsI18nInputEnabled()) { |
199 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, country_code, inputs); | 202 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, country_code, inputs, |
200 else | 203 language_code); |
| 204 } else { |
201 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 205 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
| 206 } |
202 | 207 |
203 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); | 208 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
204 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); | 209 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); |
205 break; | 210 break; |
206 | 211 |
207 case SECTION_CC_BILLING: | 212 case SECTION_CC_BILLING: |
208 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 213 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
209 | 214 |
210 if (IsI18nInputEnabled()) { | 215 if (IsI18nInputEnabled()) { |
211 // Wallet only supports US billing addresses. | 216 // Wallet only supports US billing addresses. |
212 const std::string hardcoded_country_code = "US"; | 217 const std::string hardcoded_country_code = "US"; |
213 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, | 218 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, |
214 hardcoded_country_code, | 219 hardcoded_country_code, |
215 inputs); | 220 inputs, |
| 221 language_code); |
216 DCHECK_EQ(inputs->back().type, ADDRESS_BILLING_COUNTRY); | 222 DCHECK_EQ(inputs->back().type, ADDRESS_BILLING_COUNTRY); |
217 inputs->back().length = DetailInput::NONE; | 223 inputs->back().length = DetailInput::NONE; |
218 const std::string& app_locale = | 224 const std::string& app_locale = |
219 g_browser_process->GetApplicationLocale(); | 225 g_browser_process->GetApplicationLocale(); |
220 inputs->back().initial_value = | 226 inputs->back().initial_value = |
221 AutofillCountry(hardcoded_country_code, app_locale).name(); | 227 AutofillCountry(hardcoded_country_code, app_locale).name(); |
222 } else { | 228 } else { |
223 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 229 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
224 } | 230 } |
225 | 231 |
226 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); | 232 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
227 break; | 233 break; |
228 | 234 |
229 case SECTION_SHIPPING: | 235 case SECTION_SHIPPING: |
230 if (IsI18nInputEnabled()) | 236 if (IsI18nInputEnabled()) { |
231 BuildI18nAddressInputs(ADDRESS_TYPE_SHIPPING, country_code, inputs); | 237 BuildI18nAddressInputs(ADDRESS_TYPE_SHIPPING, country_code, inputs, |
232 else | 238 language_code); |
| 239 } else { |
233 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); | 240 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); |
| 241 } |
234 | 242 |
235 BuildInputs( | 243 BuildInputs( |
236 kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs); | 244 kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs); |
237 break; | 245 break; |
238 } | 246 } |
239 } | 247 } |
240 | 248 |
241 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( | 249 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( |
242 DialogSection section) { | 250 DialogSection section) { |
243 switch (section) { | 251 switch (section) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs) { | 289 std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs) { |
282 std::vector<ServerFieldType> types; | 290 std::vector<ServerFieldType> types; |
283 for (size_t i = 0; i < inputs.size(); ++i) { | 291 for (size_t i = 0; i < inputs.size(); ++i) { |
284 types.push_back(inputs[i].type); | 292 types.push_back(inputs[i].type); |
285 } | 293 } |
286 return types; | 294 return types; |
287 } | 295 } |
288 | 296 |
289 } // namespace common | 297 } // namespace common |
290 } // namespace autofill | 298 } // namespace autofill |
OLD | NEW |