OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/webui/options/autofill_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/autofill_options_handler.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/guid.h" | 16 #include "base/guid.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/ptr_util.h" | 19 #include "base/memory/ptr_util.h" |
20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
22 #include "base/strings/string_split.h" | 22 #include "base/strings/string_split.h" |
23 #include "base/strings/utf_string_conversions.h" | 23 #include "base/strings/utf_string_conversions.h" |
24 #include "base/values.h" | 24 #include "base/values.h" |
25 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 25 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
26 #include "chrome/browser/browser_process.h" | 26 #include "chrome/browser/browser_process.h" |
27 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
28 #include "chrome/browser/ui/autofill/country_combobox_model.h" | |
29 #include "chrome/common/url_constants.h" | 28 #include "chrome/common/url_constants.h" |
30 #include "chrome/grit/chromium_strings.h" | 29 #include "chrome/grit/chromium_strings.h" |
31 #include "chrome/grit/generated_resources.h" | 30 #include "chrome/grit/generated_resources.h" |
32 #include "components/autofill/core/browser/autofill_country.h" | 31 #include "components/autofill/core/browser/autofill_country.h" |
33 #include "components/autofill/core/browser/autofill_data_util.h" | 32 #include "components/autofill/core/browser/autofill_data_util.h" |
34 #include "components/autofill/core/browser/autofill_profile.h" | 33 #include "components/autofill/core/browser/autofill_profile.h" |
| 34 #include "components/autofill/core/browser/country_combobox_model.h" |
35 #include "components/autofill/core/browser/credit_card.h" | 35 #include "components/autofill/core/browser/credit_card.h" |
36 #include "components/autofill/core/browser/payments/payments_service_url.h" | 36 #include "components/autofill/core/browser/payments/payments_service_url.h" |
37 #include "components/autofill/core/browser/personal_data_manager.h" | 37 #include "components/autofill/core/browser/personal_data_manager.h" |
38 #include "components/autofill/core/browser/phone_number_i18n.h" | 38 #include "components/autofill/core/browser/phone_number_i18n.h" |
39 #include "components/autofill/core/common/autofill_constants.h" | 39 #include "components/autofill/core/common/autofill_constants.h" |
40 #include "components/autofill/core/common/autofill_switches.h" | 40 #include "components/autofill/core/common/autofill_switches.h" |
41 #include "components/strings/grit/components_strings.h" | 41 #include "components/strings/grit/components_strings.h" |
42 #include "content/public/browser/web_ui.h" | 42 #include "content/public/browser/web_ui.h" |
43 #include "third_party/libaddressinput/messages.h" | 43 #include "third_party/libaddressinput/messages.h" |
44 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" | 44 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 component->SetString(kLength, "short"); | 161 component->SetString(kLength, "short"); |
162 break; | 162 break; |
163 } | 163 } |
164 | 164 |
165 line->Append(std::move(component)); | 165 line->Append(std::move(component)); |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 // Sets data related to the country <select>. | 169 // Sets data related to the country <select>. |
170 void SetCountryData(const PersonalDataManager& manager, | 170 void SetCountryData(const PersonalDataManager& manager, |
171 base::DictionaryValue* localized_strings) { | 171 base::DictionaryValue* localized_strings, |
| 172 const std::string& ui_language_code) { |
172 autofill::CountryComboboxModel model; | 173 autofill::CountryComboboxModel model; |
173 model.SetCountries(manager, base::Callback<bool(const std::string&)>()); | 174 model.SetCountries(manager, base::Callback<bool(const std::string&)>(), |
| 175 ui_language_code); |
174 const std::vector<std::unique_ptr<autofill::AutofillCountry>>& countries = | 176 const std::vector<std::unique_ptr<autofill::AutofillCountry>>& countries = |
175 model.countries(); | 177 model.countries(); |
176 localized_strings->SetString("defaultCountryCode", | 178 localized_strings->SetString("defaultCountryCode", |
177 countries.front()->country_code()); | 179 countries.front()->country_code()); |
178 | 180 |
179 // An ordered list of options to show in the <select>. | 181 // An ordered list of options to show in the <select>. |
180 std::unique_ptr<base::ListValue> country_list(new base::ListValue()); | 182 std::unique_ptr<base::ListValue> country_list(new base::ListValue()); |
181 for (size_t i = 0; i < countries.size(); ++i) { | 183 for (size_t i = 0; i < countries.size(); ++i) { |
182 std::unique_ptr<base::DictionaryValue> option_details( | 184 std::unique_ptr<base::DictionaryValue> option_details( |
183 new base::DictionaryValue()); | 185 new base::DictionaryValue()); |
184 option_details->SetString("name", model.GetItemAt(i)); | 186 option_details->SetString("name", model.GetItemAt(i)); |
185 option_details->SetString( | 187 option_details->SetString( |
186 "value", | 188 "value", |
187 countries[i] ? countries[i]->country_code() : "separator"); | 189 countries[i] ? countries[i]->country_code() : "separator"); |
188 country_list->Append(std::move(option_details)); | 190 country_list->Append(std::move(option_details)); |
189 } | 191 } |
190 localized_strings->Set("autofillCountrySelectList", country_list.release()); | 192 localized_strings->Set("autofillCountrySelectList", country_list.release()); |
191 | 193 |
192 std::unique_ptr<base::ListValue> default_country_components( | 194 std::unique_ptr<base::ListValue> default_country_components( |
193 new base::ListValue); | 195 new base::ListValue); |
194 std::string default_country_language_code; | 196 std::string default_country_language_code; |
195 GetAddressComponents(countries.front()->country_code(), | 197 GetAddressComponents(countries.front()->country_code(), ui_language_code, |
196 g_browser_process->GetApplicationLocale(), | |
197 default_country_components.get(), | 198 default_country_components.get(), |
198 &default_country_language_code); | 199 &default_country_language_code); |
199 localized_strings->Set("autofillDefaultCountryComponents", | 200 localized_strings->Set("autofillDefaultCountryComponents", |
200 default_country_components.release()); | 201 default_country_components.release()); |
201 localized_strings->SetString("autofillDefaultCountryLanguageCode", | 202 localized_strings->SetString("autofillDefaultCountryLanguageCode", |
202 default_country_language_code); | 203 default_country_language_code); |
203 } | 204 } |
204 | 205 |
205 } // namespace | 206 } // namespace |
206 | 207 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 void AutofillOptionsHandler::SetAddressOverlayStrings( | 306 void AutofillOptionsHandler::SetAddressOverlayStrings( |
306 base::DictionaryValue* localized_strings) { | 307 base::DictionaryValue* localized_strings) { |
307 localized_strings->SetString("autofillEditAddressTitle", | 308 localized_strings->SetString("autofillEditAddressTitle", |
308 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); | 309 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); |
309 localized_strings->SetString("autofillCountryLabel", | 310 localized_strings->SetString("autofillCountryLabel", |
310 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); | 311 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); |
311 localized_strings->SetString("autofillPhoneLabel", | 312 localized_strings->SetString("autofillPhoneLabel", |
312 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); | 313 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); |
313 localized_strings->SetString("autofillEmailLabel", | 314 localized_strings->SetString("autofillEmailLabel", |
314 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); | 315 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); |
315 SetCountryData(*personal_data_, localized_strings); | 316 SetCountryData(*personal_data_, localized_strings, |
| 317 g_browser_process->GetApplicationLocale()); |
316 } | 318 } |
317 | 319 |
318 void AutofillOptionsHandler::SetCreditCardOverlayStrings( | 320 void AutofillOptionsHandler::SetCreditCardOverlayStrings( |
319 base::DictionaryValue* localized_strings) { | 321 base::DictionaryValue* localized_strings) { |
320 localized_strings->SetString("autofillEditCreditCardTitle", | 322 localized_strings->SetString("autofillEditCreditCardTitle", |
321 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); | 323 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); |
322 localized_strings->SetString("nameOnCardLabel", | 324 localized_strings->SetString("nameOnCardLabel", |
323 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD)); | 325 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD)); |
324 localized_strings->SetString("creditCardNumberLabel", | 326 localized_strings->SetString("creditCardNumberLabel", |
325 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER)); | 327 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER)); |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 address->SetString(kLanguageCode, profile.language_code()); | 633 address->SetString(kLanguageCode, profile.language_code()); |
632 | 634 |
633 std::unique_ptr<base::ListValue> components(new base::ListValue); | 635 std::unique_ptr<base::ListValue> components(new base::ListValue); |
634 GetAddressComponents( | 636 GetAddressComponents( |
635 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), | 637 base::UTF16ToUTF8(profile.GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), |
636 profile.language_code(), components.get(), nullptr); | 638 profile.language_code(), components.get(), nullptr); |
637 address->Set(kComponents, components.release()); | 639 address->Set(kComponents, components.release()); |
638 } | 640 } |
639 | 641 |
640 } // namespace options | 642 } // namespace options |
OLD | NEW |