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" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
22 #include "components/autofill/core/browser/autofill_country.h" | 22 #include "components/autofill/core/browser/autofill_country.h" |
23 #include "components/autofill/core/browser/autofill_profile.h" | 23 #include "components/autofill/core/browser/autofill_profile.h" |
24 #include "components/autofill/core/browser/credit_card.h" | 24 #include "components/autofill/core/browser/credit_card.h" |
25 #include "components/autofill/core/browser/personal_data_manager.h" | 25 #include "components/autofill/core/browser/personal_data_manager.h" |
26 #include "components/autofill/core/browser/phone_number_i18n.h" | 26 #include "components/autofill/core/browser/phone_number_i18n.h" |
27 #include "components/autofill/core/common/autofill_constants.h" | 27 #include "components/autofill/core/common/autofill_constants.h" |
28 #include "content/public/browser/web_ui.h" | 28 #include "content/public/browser/web_ui.h" |
29 #include "grit/components_strings.h" | 29 #include "grit/components_strings.h" |
30 #include "grit/generated_resources.h" | 30 #include "grit/generated_resources.h" |
31 #include "grit/libaddressinput_strings.h" | 31 #include "grit/libaddressinput/messages.h" |
32 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" | 32 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" |
33 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui_component.h" | 33 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" |
| 34 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" |
34 #include "ui/base/l10n/l10n_util.h" | 35 #include "ui/base/l10n/l10n_util.h" |
35 #include "ui/base/webui/web_ui_util.h" | 36 #include "ui/base/webui/web_ui_util.h" |
36 | 37 |
37 using autofill::AutofillCountry; | 38 using autofill::AutofillCountry; |
38 using autofill::ServerFieldType; | 39 using autofill::ServerFieldType; |
39 using autofill::AutofillProfile; | 40 using autofill::AutofillProfile; |
40 using autofill::CreditCard; | 41 using autofill::CreditCard; |
41 using autofill::PersonalDataManager; | 42 using autofill::PersonalDataManager; |
42 using i18n::addressinput::AddressUiComponent; | 43 using i18n::addressinput::AddressUiComponent; |
43 | 44 |
(...skipping 17 matching lines...) Expand all Loading... |
61 // Fills |components| with the address UI components that should be used to | 62 // Fills |components| with the address UI components that should be used to |
62 // input an address for |country_code| when UI BCP 47 language code is | 63 // input an address for |country_code| when UI BCP 47 language code is |
63 // |ui_language_code|. If |components_language_code| is not NULL, then sets it | 64 // |ui_language_code|. If |components_language_code| is not NULL, then sets it |
64 // to the BCP 47 language code that should be used to format the address for | 65 // to the BCP 47 language code that should be used to format the address for |
65 // display. | 66 // display. |
66 void GetAddressComponents(const std::string& country_code, | 67 void GetAddressComponents(const std::string& country_code, |
67 const std::string& ui_language_code, | 68 const std::string& ui_language_code, |
68 base::ListValue* address_components, | 69 base::ListValue* address_components, |
69 std::string* components_language_code) { | 70 std::string* components_language_code) { |
70 DCHECK(address_components); | 71 DCHECK(address_components); |
| 72 DCHECK(components_language_code); |
71 | 73 |
| 74 i18n::addressinput::Localization localization; |
| 75 localization.SetGetter(l10n_util::GetStringUTF8, ui_language_code); |
72 std::vector<AddressUiComponent> components = | 76 std::vector<AddressUiComponent> components = |
73 i18n::addressinput::BuildComponents( | 77 i18n::addressinput::BuildComponents( |
74 country_code, ui_language_code, components_language_code); | 78 country_code, localization, components_language_code); |
75 if (components.empty()) { | 79 if (components.empty()) { |
76 static const char kDefaultCountryCode[] = "US"; | 80 static const char kDefaultCountryCode[] = "US"; |
77 components = i18n::addressinput::BuildComponents( | 81 components = i18n::addressinput::BuildComponents( |
78 kDefaultCountryCode, ui_language_code, components_language_code); | 82 kDefaultCountryCode, localization, components_language_code); |
79 } | 83 } |
80 DCHECK(!components.empty()); | 84 DCHECK(!components.empty()); |
81 | 85 |
82 base::ListValue* line = NULL; | 86 base::ListValue* line = NULL; |
83 static const char kField[] = "field"; | 87 static const char kField[] = "field"; |
84 static const char kLength[] = "length"; | 88 static const char kLength[] = "length"; |
85 for (size_t i = 0; i < components.size(); ++i) { | 89 for (size_t i = 0; i < components.size(); ++i) { |
86 if (i == 0 || | 90 if (i == 0 || |
87 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || | 91 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || |
88 components[i].length_hint == AddressUiComponent::HINT_LONG) { | 92 components[i].length_hint == AddressUiComponent::HINT_LONG) { |
89 line = new base::ListValue; | 93 line = new base::ListValue; |
90 address_components->Append(line); | 94 address_components->Append(line); |
91 } | 95 } |
92 | 96 |
93 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue); | 97 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue); |
94 component->SetString( | 98 component->SetString("name", components[i].name); |
95 "name", l10n_util::GetStringUTF16(components[i].name_id)); | |
96 | 99 |
97 switch (components[i].field) { | 100 switch (components[i].field) { |
98 case i18n::addressinput::COUNTRY: | 101 case i18n::addressinput::COUNTRY: |
99 component->SetString(kField, kCountryField); | 102 component->SetString(kField, kCountryField); |
100 break; | 103 break; |
101 case i18n::addressinput::ADMIN_AREA: | 104 case i18n::addressinput::ADMIN_AREA: |
102 component->SetString(kField, kStateField); | 105 component->SetString(kField, kStateField); |
103 break; | 106 break; |
104 case i18n::addressinput::LOCALITY: | 107 case i18n::addressinput::LOCALITY: |
105 component->SetString(kField, kCityField); | 108 component->SetString(kField, kCityField); |
106 break; | 109 break; |
107 case i18n::addressinput::DEPENDENT_LOCALITY: | 110 case i18n::addressinput::DEPENDENT_LOCALITY: |
108 component->SetString(kField, kDependentLocalityField); | 111 component->SetString(kField, kDependentLocalityField); |
109 break; | 112 break; |
110 case i18n::addressinput::SORTING_CODE: | 113 case i18n::addressinput::SORTING_CODE: |
111 component->SetString(kField, kSortingCodeField); | 114 component->SetString(kField, kSortingCodeField); |
112 break; | 115 break; |
113 case i18n::addressinput::POSTAL_CODE: | 116 case i18n::addressinput::POSTAL_CODE: |
114 component->SetString(kField, kPostalCodeField); | 117 component->SetString(kField, kPostalCodeField); |
115 break; | 118 break; |
116 case i18n::addressinput::STREET_ADDRESS: | 119 case i18n::addressinput::STREET_ADDRESS: |
117 component->SetString(kField, kAddressLineField); | 120 component->SetString(kField, kAddressLineField); |
118 break; | 121 break; |
119 case i18n::addressinput::ORGANIZATION: | |
120 component->SetString(kField, kCompanyNameField); | |
121 break; | |
122 case i18n::addressinput::RECIPIENT: | 122 case i18n::addressinput::RECIPIENT: |
123 component->SetString(kField, kFullNameField); | 123 component->SetString(kField, kFullNameField); |
124 component->SetString( | 124 component->SetString( |
125 "placeholder", | 125 "placeholder", |
126 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_NAME)); | 126 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_NAME)); |
127 break; | 127 break; |
128 } | 128 } |
129 | 129 |
130 switch (components[i].length_hint) { | 130 switch (components[i].length_hint) { |
131 case AddressUiComponent::HINT_LONG: | 131 case AddressUiComponent::HINT_LONG: |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 // PersonalDataManagerObserver implementation: | 366 // PersonalDataManagerObserver implementation: |
367 void AutofillOptionsHandler::OnPersonalDataChanged() { | 367 void AutofillOptionsHandler::OnPersonalDataChanged() { |
368 LoadAutofillData(); | 368 LoadAutofillData(); |
369 } | 369 } |
370 | 370 |
371 void AutofillOptionsHandler::SetAddressOverlayStrings( | 371 void AutofillOptionsHandler::SetAddressOverlayStrings( |
372 base::DictionaryValue* localized_strings) { | 372 base::DictionaryValue* localized_strings) { |
373 localized_strings->SetString("autofillEditAddressTitle", | 373 localized_strings->SetString("autofillEditAddressTitle", |
374 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); | 374 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); |
375 localized_strings->SetString("autofillCountryLabel", | 375 localized_strings->SetString("autofillCountryLabel", |
376 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL)); | 376 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); |
377 localized_strings->SetString("autofillPhoneLabel", | 377 localized_strings->SetString("autofillPhoneLabel", |
378 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); | 378 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); |
379 localized_strings->SetString("autofillEmailLabel", | 379 localized_strings->SetString("autofillEmailLabel", |
380 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); | 380 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); |
381 localized_strings->SetString("autofillAddPhonePlaceholder", | 381 localized_strings->SetString("autofillAddPhonePlaceholder", |
382 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); | 382 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); |
383 localized_strings->SetString("autofillAddEmailPlaceholder", | 383 localized_strings->SetString("autofillAddEmailPlaceholder", |
384 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); | 384 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); |
385 SetCountryData(*personal_data_, localized_strings); | 385 SetCountryData(*personal_data_, localized_strings); |
386 } | 386 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP)); | 490 profile->GetRawInfo(autofill::ADDRESS_HOME_ZIP)); |
491 address.SetString(kCountryField, | 491 address.SetString(kCountryField, |
492 profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); | 492 profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)); |
493 GetValueList(*profile, autofill::PHONE_HOME_WHOLE_NUMBER, &list); | 493 GetValueList(*profile, autofill::PHONE_HOME_WHOLE_NUMBER, &list); |
494 address.Set("phone", list.release()); | 494 address.Set("phone", list.release()); |
495 GetValueList(*profile, autofill::EMAIL_ADDRESS, &list); | 495 GetValueList(*profile, autofill::EMAIL_ADDRESS, &list); |
496 address.Set("email", list.release()); | 496 address.Set("email", list.release()); |
497 address.SetString(kLanguageCode, profile->language_code()); | 497 address.SetString(kLanguageCode, profile->language_code()); |
498 | 498 |
499 scoped_ptr<base::ListValue> components(new base::ListValue); | 499 scoped_ptr<base::ListValue> components(new base::ListValue); |
| 500 std::string best_address_language; |
500 GetAddressComponents( | 501 GetAddressComponents( |
501 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), | 502 base::UTF16ToUTF8(profile->GetRawInfo(autofill::ADDRESS_HOME_COUNTRY)), |
502 profile->language_code(), components.get(), NULL); | 503 profile->language_code(), components.get(), &best_address_language); |
503 address.Set(kComponents, components.release()); | 504 address.Set(kComponents, components.release()); |
504 | 505 |
505 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); | 506 web_ui()->CallJavascriptFunction("AutofillOptions.editAddress", address); |
506 } | 507 } |
507 | 508 |
508 void AutofillOptionsHandler::LoadAddressEditorComponents( | 509 void AutofillOptionsHandler::LoadAddressEditorComponents( |
509 const base::ListValue* args) { | 510 const base::ListValue* args) { |
510 std::string country_code; | 511 std::string country_code; |
511 if (!args->GetString(0, &country_code)) { | 512 if (!args->GetString(0, &country_code)) { |
512 NOTREACHED(); | 513 NOTREACHED(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
663 | 664 |
664 web_ui()->CallJavascriptFunction( | 665 web_ui()->CallJavascriptFunction( |
665 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 666 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
666 } | 667 } |
667 | 668 |
668 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 669 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
669 return personal_data_ && personal_data_->IsDataLoaded(); | 670 return personal_data_ && personal_data_->IsDataLoaded(); |
670 } | 671 } |
671 | 672 |
672 } // namespace options | 673 } // namespace options |
OLD | NEW |