Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Unified Diff: chrome/browser/ui/webui/options/autofill_options_handler.cc

Issue 12328091: set a default country in the autofill dialog. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Ilya review 2 Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/autofill/country_combobox_model.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..0f5f76011e5c318748122db90db976e1f5ea96b2 100644
--- a/chrome/browser/ui/webui/options/autofill_options_handler.cc
+++ b/chrome/browser/ui/webui/options/autofill_options_handler.cc
@@ -21,6 +21,7 @@
#include "chrome/browser/autofill/personal_data_manager_factory.h"
#include "chrome/browser/autofill/phone_number_i18n.h"
#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/autofill/country_combobox_model.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/web_ui.h"
#include "grit/generated_resources.h"
@@ -29,25 +30,39 @@
namespace {
-// Returns a dictionary that maps country codes to data for the country.
-DictionaryValue* GetCountryData() {
+// Sets data related to the country <select>.
+void SetCountryData(DictionaryValue* localized_strings) {
std::string app_locale = AutofillCountry::ApplicationLocale();
- std::vector<std::string> country_codes;
- AutofillCountry::GetAvailableCountries(&country_codes);
+ std::string default_country_code =
+ AutofillCountry::CountryCodeForLocale(app_locale);
+ localized_strings->SetString("defaultCountryCode", default_country_code);
- DictionaryValue* country_data = new DictionaryValue();
- for (size_t i = 0; i < country_codes.size(); ++i) {
- const AutofillCountry country(country_codes[i], app_locale);
+ autofill::CountryComboboxModel model;
+ const std::vector<AutofillCountry*>& countries = model.countries();
+
+ // An ordered list of options to show in the <select>.
+ scoped_ptr<ListValue> country_list(new ListValue());
+ // A dictionary of postal code and state info, keyed on country code.
+ scoped_ptr<DictionaryValue> country_data(new DictionaryValue());
+ for (size_t i = 0; i < countries.size(); ++i) {
+ scoped_ptr<DictionaryValue> option_details(new DictionaryValue());
+ option_details->SetString("name", model.GetItemAt(i));
+ option_details->SetString(
+ "value",
+ countries[i] ? countries[i]->country_code() : "separator");
+ country_list->Append(option_details.release());
+
+ if (!countries[i])
+ continue;
- DictionaryValue* details = new DictionaryValue();
- details->SetString("name", country.name());
- details->SetString("postalCodeLabel", country.postal_code_label());
- details->SetString("stateLabel", country.state_label());
+ scoped_ptr<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.release());
- country_data->Set(country.country_code(), details);
}
-
- return country_data;
+ localized_strings->Set("autofillCountrySelectList", country_list.release());
+ localized_strings->Set("autofillCountryData", country_data.release());
}
// Get the multi-valued element for |type| and return it in |ListValue| form.
@@ -335,12 +350,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(
« no previous file with comments | « chrome/browser/ui/autofill/country_combobox_model.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698