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 18 matching lines...) Expand all Loading... |
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); |
71 | 72 |
| 73 i18n::addressinput::Localization localization; |
| 74 localization.SetGetter(l10n_util::GetStringUTF8); |
| 75 std::string not_used; |
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, |
| 79 localization, |
| 80 ui_language_code, |
| 81 components_language_code == NULL ? |
| 82 ¬_used : components_language_code); |
75 if (components.empty()) { | 83 if (components.empty()) { |
76 static const char kDefaultCountryCode[] = "US"; | 84 static const char kDefaultCountryCode[] = "US"; |
77 components = i18n::addressinput::BuildComponents( | 85 components = i18n::addressinput::BuildComponents( |
78 kDefaultCountryCode, ui_language_code, components_language_code); | 86 kDefaultCountryCode, |
| 87 localization, |
| 88 ui_language_code, |
| 89 components_language_code == NULL ? |
| 90 ¬_used : components_language_code); |
79 } | 91 } |
80 DCHECK(!components.empty()); | 92 DCHECK(!components.empty()); |
81 | 93 |
82 base::ListValue* line = NULL; | 94 base::ListValue* line = NULL; |
83 static const char kField[] = "field"; | 95 static const char kField[] = "field"; |
84 static const char kLength[] = "length"; | 96 static const char kLength[] = "length"; |
85 for (size_t i = 0; i < components.size(); ++i) { | 97 for (size_t i = 0; i < components.size(); ++i) { |
86 if (i == 0 || | 98 if (i == 0 || |
87 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || | 99 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || |
88 components[i].length_hint == AddressUiComponent::HINT_LONG) { | 100 components[i].length_hint == AddressUiComponent::HINT_LONG) { |
89 line = new base::ListValue; | 101 line = new base::ListValue; |
90 address_components->Append(line); | 102 address_components->Append(line); |
91 } | 103 } |
92 | 104 |
93 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue); | 105 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue); |
94 component->SetString( | 106 component->SetString("name", components[i].name); |
95 "name", l10n_util::GetStringUTF16(components[i].name_id)); | |
96 | 107 |
97 switch (components[i].field) { | 108 switch (components[i].field) { |
98 case i18n::addressinput::COUNTRY: | 109 case i18n::addressinput::COUNTRY: |
99 component->SetString(kField, kCountryField); | 110 component->SetString(kField, kCountryField); |
100 break; | 111 break; |
101 case i18n::addressinput::ADMIN_AREA: | 112 case i18n::addressinput::ADMIN_AREA: |
102 component->SetString(kField, kStateField); | 113 component->SetString(kField, kStateField); |
103 break; | 114 break; |
104 case i18n::addressinput::LOCALITY: | 115 case i18n::addressinput::LOCALITY: |
105 component->SetString(kField, kCityField); | 116 component->SetString(kField, kCityField); |
106 break; | 117 break; |
107 case i18n::addressinput::DEPENDENT_LOCALITY: | 118 case i18n::addressinput::DEPENDENT_LOCALITY: |
108 component->SetString(kField, kDependentLocalityField); | 119 component->SetString(kField, kDependentLocalityField); |
109 break; | 120 break; |
110 case i18n::addressinput::SORTING_CODE: | 121 case i18n::addressinput::SORTING_CODE: |
111 component->SetString(kField, kSortingCodeField); | 122 component->SetString(kField, kSortingCodeField); |
112 break; | 123 break; |
113 case i18n::addressinput::POSTAL_CODE: | 124 case i18n::addressinput::POSTAL_CODE: |
114 component->SetString(kField, kPostalCodeField); | 125 component->SetString(kField, kPostalCodeField); |
115 break; | 126 break; |
116 case i18n::addressinput::STREET_ADDRESS: | 127 case i18n::addressinput::STREET_ADDRESS: |
117 component->SetString(kField, kAddressLineField); | 128 component->SetString(kField, kAddressLineField); |
118 break; | 129 break; |
119 case i18n::addressinput::ORGANIZATION: | |
120 component->SetString(kField, kCompanyNameField); | |
121 break; | |
122 case i18n::addressinput::RECIPIENT: | 130 case i18n::addressinput::RECIPIENT: |
123 component->SetString(kField, kFullNameField); | 131 component->SetString(kField, kFullNameField); |
124 component->SetString( | 132 component->SetString( |
125 "placeholder", | 133 "placeholder", |
126 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_NAME)); | 134 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_NAME)); |
127 break; | 135 break; |
128 } | 136 } |
129 | 137 |
130 switch (components[i].length_hint) { | 138 switch (components[i].length_hint) { |
131 case AddressUiComponent::HINT_LONG: | 139 case AddressUiComponent::HINT_LONG: |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 // PersonalDataManagerObserver implementation: | 380 // PersonalDataManagerObserver implementation: |
373 void AutofillOptionsHandler::OnPersonalDataChanged() { | 381 void AutofillOptionsHandler::OnPersonalDataChanged() { |
374 LoadAutofillData(); | 382 LoadAutofillData(); |
375 } | 383 } |
376 | 384 |
377 void AutofillOptionsHandler::SetAddressOverlayStrings( | 385 void AutofillOptionsHandler::SetAddressOverlayStrings( |
378 base::DictionaryValue* localized_strings) { | 386 base::DictionaryValue* localized_strings) { |
379 localized_strings->SetString("autofillEditAddressTitle", | 387 localized_strings->SetString("autofillEditAddressTitle", |
380 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); | 388 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); |
381 localized_strings->SetString("autofillCountryLabel", | 389 localized_strings->SetString("autofillCountryLabel", |
382 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL)); | 390 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); |
383 localized_strings->SetString("autofillPhoneLabel", | 391 localized_strings->SetString("autofillPhoneLabel", |
384 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); | 392 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); |
385 localized_strings->SetString("autofillEmailLabel", | 393 localized_strings->SetString("autofillEmailLabel", |
386 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); | 394 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); |
387 localized_strings->SetString("autofillAddPhonePlaceholder", | 395 localized_strings->SetString("autofillAddPhonePlaceholder", |
388 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); | 396 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); |
389 localized_strings->SetString("autofillAddEmailPlaceholder", | 397 localized_strings->SetString("autofillAddEmailPlaceholder", |
390 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); | 398 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); |
391 SetCountryData(*personal_data_, localized_strings); | 399 SetCountryData(*personal_data_, localized_strings); |
392 } | 400 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 | 683 |
676 web_ui()->CallJavascriptFunction( | 684 web_ui()->CallJavascriptFunction( |
677 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 685 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
678 } | 686 } |
679 | 687 |
680 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 688 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
681 return personal_data_ && personal_data_->IsDataLoaded(); | 689 return personal_data_ && personal_data_->IsDataLoaded(); |
682 } | 690 } |
683 | 691 |
684 } // namespace options | 692 } // namespace options |
OLD | NEW |