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 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.
| |
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/common/url_constants.h" | 24 #include "chrome/common/url_constants.h" |
25 #include "content/public/browser/web_ui.h" | 25 #include "content/public/browser/web_ui.h" |
26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
27 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/webui/web_ui_util.h" | 28 #include "ui/webui/web_ui_util.h" |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 // Returns a dictionary that maps country codes to data for the country. | |
33 DictionaryValue* GetCountryData() { | |
34 std::string app_locale = AutofillCountry::ApplicationLocale(); | |
35 std::vector<std::string> country_codes; | |
36 AutofillCountry::GetAvailableCountries(&country_codes); | |
37 | |
38 DictionaryValue* country_data = new DictionaryValue(); | |
39 for (size_t i = 0; i < country_codes.size(); ++i) { | |
40 const AutofillCountry country(country_codes[i], app_locale); | |
41 | |
42 DictionaryValue* details = new DictionaryValue(); | |
43 details->SetString("name", country.name()); | |
44 details->SetString("postalCodeLabel", country.postal_code_label()); | |
45 details->SetString("stateLabel", country.state_label()); | |
46 | |
47 country_data->Set(country.country_code(), details); | |
48 } | |
49 | |
50 return country_data; | |
51 } | |
52 | |
53 // Get the multi-valued element for |type| and return it in |ListValue| form. | 32 // Get the multi-valued element for |type| and return it in |ListValue| form. |
54 void GetValueList(const AutofillProfile& profile, | 33 void GetValueList(const AutofillProfile& profile, |
55 AutofillFieldType type, | 34 AutofillFieldType type, |
56 scoped_ptr<ListValue>* list) { | 35 scoped_ptr<ListValue>* list) { |
57 list->reset(new ListValue); | 36 list->reset(new ListValue); |
58 | 37 |
59 std::vector<string16> values; | 38 std::vector<string16> values; |
60 profile.GetRawMultiInfo(type, &values); | 39 profile.GetRawMultiInfo(type, &values); |
61 | 40 |
62 // |GetRawMultiInfo()| always returns at least one, potentially empty, item. | 41 // |GetRawMultiInfo()| always returns at least one, potentially empty, item. |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
328 localized_strings->SetString("autofillAddFirstNamePlaceholder", | 307 localized_strings->SetString("autofillAddFirstNamePlaceholder", |
329 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_FIRST_NAME)); | 308 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_FIRST_NAME)); |
330 localized_strings->SetString("autofillAddMiddleNamePlaceholder", | 309 localized_strings->SetString("autofillAddMiddleNamePlaceholder", |
331 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_MIDDLE_NAME)); | 310 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_MIDDLE_NAME)); |
332 localized_strings->SetString("autofillAddLastNamePlaceholder", | 311 localized_strings->SetString("autofillAddLastNamePlaceholder", |
333 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_LAST_NAME)); | 312 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_LAST_NAME)); |
334 localized_strings->SetString("autofillAddPhonePlaceholder", | 313 localized_strings->SetString("autofillAddPhonePlaceholder", |
335 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); | 314 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); |
336 localized_strings->SetString("autofillAddEmailPlaceholder", | 315 localized_strings->SetString("autofillAddEmailPlaceholder", |
337 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); | 316 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); |
338 | 317 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 } | 318 } |
345 | 319 |
346 void AutofillOptionsHandler::SetCreditCardOverlayStrings( | 320 void AutofillOptionsHandler::SetCreditCardOverlayStrings( |
347 DictionaryValue* localized_strings) { | 321 DictionaryValue* localized_strings) { |
348 localized_strings->SetString("autofillEditCreditCardTitle", | 322 localized_strings->SetString("autofillEditCreditCardTitle", |
349 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); | 323 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_CREDITCARD_CAPTION)); |
350 localized_strings->SetString("nameOnCardLabel", | 324 localized_strings->SetString("nameOnCardLabel", |
351 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD)); | 325 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD)); |
352 localized_strings->SetString("creditCardNumberLabel", | 326 localized_strings->SetString("creditCardNumberLabel", |
353 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER)); | 327 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER)); |
354 localized_strings->SetString("creditCardExpirationDateLabel", | 328 localized_strings->SetString("creditCardExpirationDateLabel", |
355 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_DATE)); | 329 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_DATE)); |
356 } | 330 } |
357 | 331 |
332 void AutofillOptionsHandler::SetCountryData( | |
333 DictionaryValue* localized_strings) { | |
334 std::string app_locale = AutofillCountry::ApplicationLocale(); | |
335 std::string default_country_code = | |
336 AutofillCountry::CountryCodeForLocale(app_locale); | |
337 localized_strings->SetString("defaultCountryCode", default_country_code); | |
338 | |
339 autofill::CountryComboboxModel model; | |
340 const std::vector<AutofillCountry*>& countries = model.countries(); | |
341 | |
342 // An ordered list of options to show in the <select>. | |
343 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.
| |
344 // A dictionary of postal code and state info, keyed on country code. | |
345 DictionaryValue* country_data = new DictionaryValue(); | |
346 for (size_t i = 0; i < countries.size(); ++i) { | |
347 DictionaryValue* option_details = new DictionaryValue(); | |
348 option_details->SetString("name", model.GetItemAt(i)); | |
349 option_details->SetString( | |
350 "value", | |
351 countries[i] ? countries[i]->country_code() : | |
352 model.GetItemAt(i).empty() ? "" : "separator"); | |
353 country_list->Append(option_details); | |
354 | |
355 if (!countries[i]) | |
356 continue; | |
357 | |
358 DictionaryValue* details = new DictionaryValue(); | |
359 details->SetString("postalCodeLabel", countries[i]->postal_code_label()); | |
360 details->SetString("stateLabel", countries[i]->state_label()); | |
361 | |
362 country_data->Set(countries[i]->country_code(), details); | |
363 | |
364 } | |
365 localized_strings->Set("autofillCountrySelectList", country_list); | |
366 localized_strings->Set("autofillCountryData", country_data); | |
367 } | |
368 | |
358 void AutofillOptionsHandler::LoadAutofillData() { | 369 void AutofillOptionsHandler::LoadAutofillData() { |
359 if (!IsPersonalDataLoaded()) | 370 if (!IsPersonalDataLoaded()) |
360 return; | 371 return; |
361 | 372 |
362 ListValue addresses; | 373 ListValue addresses; |
363 for (std::vector<AutofillProfile*>::const_iterator i = | 374 for (std::vector<AutofillProfile*>::const_iterator i = |
364 personal_data_->web_profiles().begin(); | 375 personal_data_->web_profiles().begin(); |
365 i != personal_data_->web_profiles().end(); ++i) { | 376 i != personal_data_->web_profiles().end(); ++i) { |
366 ListValue* entry = new ListValue(); | 377 ListValue* entry = new ListValue(); |
367 entry->Append(new StringValue((*i)->guid())); | 378 entry->Append(new StringValue((*i)->guid())); |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
570 | 581 |
571 web_ui()->CallJavascriptFunction( | 582 web_ui()->CallJavascriptFunction( |
572 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 583 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
573 } | 584 } |
574 | 585 |
575 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 586 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
576 return personal_data_ && personal_data_->IsDataLoaded(); | 587 return personal_data_ && personal_data_->IsDataLoaded(); |
577 } | 588 } |
578 | 589 |
579 } // namespace options | 590 } // namespace options |
OLD | NEW |