Index: chrome/browser/ui/webui/options/autofill_options_handler.cc |
diff --git a/chrome/browser/ui/webui/options/autofill_options_handler.cc b/chrome/browser/ui/webui/options/autofill_options_handler.cc |
index 4b83a007a168bb62de30a8621ba06faa83888676..81fed3e7a70914126acffd87cf33f4b2125f1713 100644 |
--- a/chrome/browser/ui/webui/options/autofill_options_handler.cc |
+++ b/chrome/browser/ui/webui/options/autofill_options_handler.cc |
@@ -1,5 +1,5 @@ |
// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
-// Use of this source code is governed by a BSD-style license that can be |
+// Use of this soutaxrce code is governed by a BSD-style license that can be |
Ilya Sherman
2013/02/26 09:57:07
nit: soutaxrce, huh? ;)
Evan Stade
2013/02/26 19:01:40
Done.
|
// found in the LICENSE file. |
#include "chrome/browser/ui/webui/options/autofill_options_handler.h" |
@@ -29,27 +29,6 @@ |
namespace { |
-// Returns a dictionary that maps country codes to data for the country. |
-DictionaryValue* GetCountryData() { |
- std::string app_locale = AutofillCountry::ApplicationLocale(); |
- std::vector<std::string> country_codes; |
- AutofillCountry::GetAvailableCountries(&country_codes); |
- |
- DictionaryValue* country_data = new DictionaryValue(); |
- for (size_t i = 0; i < country_codes.size(); ++i) { |
- const AutofillCountry country(country_codes[i], app_locale); |
- |
- DictionaryValue* details = new DictionaryValue(); |
- details->SetString("name", country.name()); |
- details->SetString("postalCodeLabel", country.postal_code_label()); |
- details->SetString("stateLabel", country.state_label()); |
- |
- country_data->Set(country.country_code(), details); |
- } |
- |
- return country_data; |
-} |
- |
// Get the multi-valued element for |type| and return it in |ListValue| form. |
void GetValueList(const AutofillProfile& profile, |
AutofillFieldType type, |
@@ -335,12 +314,7 @@ void AutofillOptionsHandler::SetAddressOverlayStrings( |
l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); |
localized_strings->SetString("autofillAddEmailPlaceholder", |
l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); |
- |
- std::string app_locale = AutofillCountry::ApplicationLocale(); |
- std::string default_country_code = |
- AutofillCountry::CountryCodeForLocale(app_locale); |
- localized_strings->SetString("defaultCountryCode", default_country_code); |
- localized_strings->Set("autofillCountryData", GetCountryData()); |
+ SetCountryData(localized_strings); |
} |
void AutofillOptionsHandler::SetCreditCardOverlayStrings( |
@@ -355,6 +329,43 @@ void AutofillOptionsHandler::SetCreditCardOverlayStrings( |
l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_DATE)); |
} |
+void AutofillOptionsHandler::SetCountryData( |
+ DictionaryValue* localized_strings) { |
+ std::string app_locale = AutofillCountry::ApplicationLocale(); |
+ std::string default_country_code = |
+ AutofillCountry::CountryCodeForLocale(app_locale); |
+ localized_strings->SetString("defaultCountryCode", default_country_code); |
+ |
+ autofill::CountryComboboxModel model; |
+ const std::vector<AutofillCountry*>& countries = model.countries(); |
+ |
+ // An ordered list of options to show in the <select>. |
+ ListValue* country_list = new ListValue(); |
Ilya Sherman
2013/02/26 09:57:07
nit: I'd prefer you use a scoped_ptr here, and rel
Evan Stade
2013/02/26 19:01:40
Done.
|
+ // A dictionary of postal code and state info, keyed on country code. |
+ DictionaryValue* country_data = new DictionaryValue(); |
+ for (size_t i = 0; i < countries.size(); ++i) { |
+ DictionaryValue* option_details = new DictionaryValue(); |
+ option_details->SetString("name", model.GetItemAt(i)); |
+ option_details->SetString( |
+ "value", |
+ countries[i] ? countries[i]->country_code() : |
+ model.GetItemAt(i).empty() ? "" : "separator"); |
+ country_list->Append(option_details); |
+ |
+ if (!countries[i]) |
+ continue; |
+ |
+ DictionaryValue* details = new DictionaryValue(); |
+ details->SetString("postalCodeLabel", countries[i]->postal_code_label()); |
+ details->SetString("stateLabel", countries[i]->state_label()); |
+ |
+ country_data->Set(countries[i]->country_code(), details); |
+ |
+ } |
+ localized_strings->Set("autofillCountrySelectList", country_list); |
+ localized_strings->Set("autofillCountryData", country_data); |
+} |
+ |
void AutofillOptionsHandler::LoadAutofillData() { |
if (!IsPersonalDataLoaded()) |
return; |