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 <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/guid.h" | 11 #include "base/guid.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/autofill/autofill_country.h" | 17 #include "chrome/browser/autofill/autofill_country.h" |
18 #include "chrome/browser/autofill/autofill_profile.h" | 18 #include "chrome/browser/autofill/autofill_profile.h" |
19 #include "chrome/browser/autofill/credit_card.h" | 19 #include "chrome/browser/autofill/credit_card.h" |
20 #include "chrome/browser/autofill/personal_data_manager.h" | 20 #include "chrome/browser/autofill/personal_data_manager.h" |
21 #include "chrome/browser/autofill/personal_data_manager_factory.h" | 21 #include "chrome/browser/autofill/personal_data_manager_factory.h" |
22 #include "chrome/browser/autofill/phone_number_i18n.h" | 22 #include "chrome/browser/autofill/phone_number_i18n.h" |
23 #include "chrome/browser/profiles/profile.h" | 23 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/ui/autofill/country_combobox_model.h" |
24 #include "chrome/common/url_constants.h" | 25 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/web_ui.h" | 26 #include "content/public/browser/web_ui.h" |
26 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/webui/web_ui_util.h" | 29 #include "ui/webui/web_ui_util.h" |
29 | 30 |
30 namespace { | 31 namespace { |
31 | 32 |
32 // Returns a dictionary that maps country codes to data for the country. | 33 // Sets data related to the country <select>. |
33 DictionaryValue* GetCountryData() { | 34 void SetCountryData(DictionaryValue* localized_strings) { |
34 std::string app_locale = AutofillCountry::ApplicationLocale(); | 35 std::string app_locale = AutofillCountry::ApplicationLocale(); |
35 std::vector<std::string> country_codes; | 36 std::string default_country_code = |
36 AutofillCountry::GetAvailableCountries(&country_codes); | 37 AutofillCountry::CountryCodeForLocale(app_locale); |
| 38 localized_strings->SetString("defaultCountryCode", default_country_code); |
37 | 39 |
38 DictionaryValue* country_data = new DictionaryValue(); | 40 autofill::CountryComboboxModel model; |
39 for (size_t i = 0; i < country_codes.size(); ++i) { | 41 const std::vector<AutofillCountry*>& countries = model.countries(); |
40 const AutofillCountry country(country_codes[i], app_locale); | |
41 | 42 |
42 DictionaryValue* details = new DictionaryValue(); | 43 // An ordered list of options to show in the <select>. |
43 details->SetString("name", country.name()); | 44 scoped_ptr<ListValue> country_list(new ListValue()); |
44 details->SetString("postalCodeLabel", country.postal_code_label()); | 45 // A dictionary of postal code and state info, keyed on country code. |
45 details->SetString("stateLabel", country.state_label()); | 46 scoped_ptr<DictionaryValue> country_data(new DictionaryValue()); |
| 47 for (size_t i = 0; i < countries.size(); ++i) { |
| 48 scoped_ptr<DictionaryValue> option_details(new DictionaryValue()); |
| 49 option_details->SetString("name", model.GetItemAt(i)); |
| 50 option_details->SetString( |
| 51 "value", |
| 52 countries[i] ? countries[i]->country_code() : "separator"); |
| 53 country_list->Append(option_details.release()); |
46 | 54 |
47 country_data->Set(country.country_code(), details); | 55 if (!countries[i]) |
| 56 continue; |
| 57 |
| 58 scoped_ptr<DictionaryValue> details(new DictionaryValue()); |
| 59 details->SetString("postalCodeLabel", countries[i]->postal_code_label()); |
| 60 details->SetString("stateLabel", countries[i]->state_label()); |
| 61 country_data->Set(countries[i]->country_code(), details.release()); |
| 62 |
48 } | 63 } |
49 | 64 localized_strings->Set("autofillCountrySelectList", country_list.release()); |
50 return country_data; | 65 localized_strings->Set("autofillCountryData", country_data.release()); |
51 } | 66 } |
52 | 67 |
53 // Get the multi-valued element for |type| and return it in |ListValue| form. | 68 // Get the multi-valued element for |type| and return it in |ListValue| form. |
54 void GetValueList(const AutofillProfile& profile, | 69 void GetValueList(const AutofillProfile& profile, |
55 AutofillFieldType type, | 70 AutofillFieldType type, |
56 scoped_ptr<ListValue>* list) { | 71 scoped_ptr<ListValue>* list) { |
57 list->reset(new ListValue); | 72 list->reset(new ListValue); |
58 | 73 |
59 std::vector<string16> values; | 74 std::vector<string16> values; |
60 profile.GetRawMultiInfo(type, &values); | 75 profile.GetRawMultiInfo(type, &values); |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 localized_strings->SetString("autofillAddFirstNamePlaceholder", | 343 localized_strings->SetString("autofillAddFirstNamePlaceholder", |
329 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_FIRST_NAME)); | 344 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_FIRST_NAME)); |
330 localized_strings->SetString("autofillAddMiddleNamePlaceholder", | 345 localized_strings->SetString("autofillAddMiddleNamePlaceholder", |
331 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_MIDDLE_NAME)); | 346 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_MIDDLE_NAME)); |
332 localized_strings->SetString("autofillAddLastNamePlaceholder", | 347 localized_strings->SetString("autofillAddLastNamePlaceholder", |
333 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_LAST_NAME)); | 348 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_LAST_NAME)); |
334 localized_strings->SetString("autofillAddPhonePlaceholder", | 349 localized_strings->SetString("autofillAddPhonePlaceholder", |
335 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); | 350 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); |
336 localized_strings->SetString("autofillAddEmailPlaceholder", | 351 localized_strings->SetString("autofillAddEmailPlaceholder", |
337 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); | 352 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); |
338 | 353 SetCountryData(localized_strings); |
339 std::string app_locale = AutofillCountry::ApplicationLocale(); | |
340 std::string default_country_code = | |
341 AutofillCountry::CountryCodeForLocale(app_locale); | |
342 localized_strings->SetString("defaultCountryCode", default_country_code); | |
343 localized_strings->Set("autofillCountryData", GetCountryData()); | |
344 } | 354 } |
345 | 355 |
346 void AutofillOptionsHandler::SetCreditCardOverlayStrings( | 356 void AutofillOptionsHandler::SetCreditCardOverlayStrings( |
347 DictionaryValue* localized_strings) { | 357 DictionaryValue* localized_strings) { |
348 localized_strings->SetString("autofillEditCreditCardTitle", | 358 localized_strings->SetString("autofillEditCreditCardTitle", |
349 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); | 359 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); |
350 localized_strings->SetString("nameOnCardLabel", | 360 localized_strings->SetString("nameOnCardLabel", |
351 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD)); | 361 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD)); |
352 localized_strings->SetString("creditCardNumberLabel", | 362 localized_strings->SetString("creditCardNumberLabel", |
353 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER)); | 363 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER)); |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 | 580 |
571 web_ui()->CallJavascriptFunction( | 581 web_ui()->CallJavascriptFunction( |
572 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 582 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
573 } | 583 } |
574 | 584 |
575 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 585 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
576 return personal_data_ && personal_data_->IsDataLoaded(); | 586 return personal_data_ && personal_data_->IsDataLoaded(); |
577 } | 587 } |
578 | 588 |
579 } // namespace options | 589 } // namespace options |
OLD | NEW |