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 "third_party/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); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 // PersonalDataManagerObserver implementation: | 380 // PersonalDataManagerObserver implementation: |
370 void AutofillOptionsHandler::OnPersonalDataChanged() { | 381 void AutofillOptionsHandler::OnPersonalDataChanged() { |
371 LoadAutofillData(); | 382 LoadAutofillData(); |
372 } | 383 } |
373 | 384 |
374 void AutofillOptionsHandler::SetAddressOverlayStrings( | 385 void AutofillOptionsHandler::SetAddressOverlayStrings( |
375 base::DictionaryValue* localized_strings) { | 386 base::DictionaryValue* localized_strings) { |
376 localized_strings->SetString("autofillEditAddressTitle", | 387 localized_strings->SetString("autofillEditAddressTitle", |
377 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); | 388 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); |
378 localized_strings->SetString("autofillCountryLabel", | 389 localized_strings->SetString("autofillCountryLabel", |
379 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL)); | 390 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); |
380 localized_strings->SetString("autofillPhoneLabel", | 391 localized_strings->SetString("autofillPhoneLabel", |
381 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); | 392 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); |
382 localized_strings->SetString("autofillEmailLabel", | 393 localized_strings->SetString("autofillEmailLabel", |
383 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); | 394 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); |
384 localized_strings->SetString("autofillAddPhonePlaceholder", | 395 localized_strings->SetString("autofillAddPhonePlaceholder", |
385 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); | 396 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); |
386 localized_strings->SetString("autofillAddEmailPlaceholder", | 397 localized_strings->SetString("autofillAddEmailPlaceholder", |
387 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); | 398 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); |
388 SetCountryData(*personal_data_, localized_strings); | 399 SetCountryData(*personal_data_, localized_strings); |
389 } | 400 } |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
672 | 683 |
673 web_ui()->CallJavascriptFunction( | 684 web_ui()->CallJavascriptFunction( |
674 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 685 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
675 } | 686 } |
676 | 687 |
677 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 688 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
678 return personal_data_ && personal_data_->IsDataLoaded(); | 689 return personal_data_ && personal_data_->IsDataLoaded(); |
679 } | 690 } |
680 | 691 |
681 } // namespace options | 692 } // namespace options |
OLD | NEW |