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 "third_party/libaddressinput/messages.h" | 31 #include "grit/libaddressinput_strings.h" |
32 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
.h" | 32 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui.h" |
33 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/address_ui
_component.h" | 33 #include "third_party/libaddressinput/chromium/cpp/include/libaddressinput/addre
ss_ui_component.h" |
34 #include "third_party/libaddressinput/src/cpp/include/libaddressinput/localizati
on.h" | |
35 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
36 #include "ui/base/webui/web_ui_util.h" | 35 #include "ui/base/webui/web_ui_util.h" |
37 | 36 |
38 using autofill::AutofillCountry; | 37 using autofill::AutofillCountry; |
39 using autofill::ServerFieldType; | 38 using autofill::ServerFieldType; |
40 using autofill::AutofillProfile; | 39 using autofill::AutofillProfile; |
41 using autofill::CreditCard; | 40 using autofill::CreditCard; |
42 using autofill::PersonalDataManager; | 41 using autofill::PersonalDataManager; |
43 using i18n::addressinput::AddressUiComponent; | 42 using i18n::addressinput::AddressUiComponent; |
44 | 43 |
(...skipping 18 matching lines...) Expand all Loading... |
63 // input an address for |country_code| when UI BCP 47 language code is | 62 // input an address for |country_code| when UI BCP 47 language code is |
64 // |ui_language_code|. If |components_language_code| is not NULL, then sets it | 63 // |ui_language_code|. If |components_language_code| is not NULL, then sets it |
65 // to the BCP 47 language code that should be used to format the address for | 64 // to the BCP 47 language code that should be used to format the address for |
66 // display. | 65 // display. |
67 void GetAddressComponents(const std::string& country_code, | 66 void GetAddressComponents(const std::string& country_code, |
68 const std::string& ui_language_code, | 67 const std::string& ui_language_code, |
69 base::ListValue* address_components, | 68 base::ListValue* address_components, |
70 std::string* components_language_code) { | 69 std::string* components_language_code) { |
71 DCHECK(address_components); | 70 DCHECK(address_components); |
72 | 71 |
73 i18n::addressinput::Localization localization; | |
74 localization.SetGetter(l10n_util::GetStringUTF8); | |
75 std::string not_used; | |
76 std::vector<AddressUiComponent> components = | 72 std::vector<AddressUiComponent> components = |
77 i18n::addressinput::BuildComponents( | 73 i18n::addressinput::BuildComponents( |
78 country_code, | 74 country_code, ui_language_code, components_language_code); |
79 localization, | |
80 ui_language_code, | |
81 components_language_code == NULL ? | |
82 ¬_used : components_language_code); | |
83 if (components.empty()) { | 75 if (components.empty()) { |
84 static const char kDefaultCountryCode[] = "US"; | 76 static const char kDefaultCountryCode[] = "US"; |
85 components = i18n::addressinput::BuildComponents( | 77 components = i18n::addressinput::BuildComponents( |
86 kDefaultCountryCode, | 78 kDefaultCountryCode, ui_language_code, components_language_code); |
87 localization, | |
88 ui_language_code, | |
89 components_language_code == NULL ? | |
90 ¬_used : components_language_code); | |
91 } | 79 } |
92 DCHECK(!components.empty()); | 80 DCHECK(!components.empty()); |
93 | 81 |
94 base::ListValue* line = NULL; | 82 base::ListValue* line = NULL; |
95 static const char kField[] = "field"; | 83 static const char kField[] = "field"; |
96 static const char kLength[] = "length"; | 84 static const char kLength[] = "length"; |
97 for (size_t i = 0; i < components.size(); ++i) { | 85 for (size_t i = 0; i < components.size(); ++i) { |
98 if (i == 0 || | 86 if (i == 0 || |
99 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || | 87 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || |
100 components[i].length_hint == AddressUiComponent::HINT_LONG) { | 88 components[i].length_hint == AddressUiComponent::HINT_LONG) { |
101 line = new base::ListValue; | 89 line = new base::ListValue; |
102 address_components->Append(line); | 90 address_components->Append(line); |
103 } | 91 } |
104 | 92 |
105 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue); | 93 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue); |
106 component->SetString("name", components[i].name); | 94 component->SetString( |
| 95 "name", l10n_util::GetStringUTF16(components[i].name_id)); |
107 | 96 |
108 switch (components[i].field) { | 97 switch (components[i].field) { |
109 case i18n::addressinput::COUNTRY: | 98 case i18n::addressinput::COUNTRY: |
110 component->SetString(kField, kCountryField); | 99 component->SetString(kField, kCountryField); |
111 break; | 100 break; |
112 case i18n::addressinput::ADMIN_AREA: | 101 case i18n::addressinput::ADMIN_AREA: |
113 component->SetString(kField, kStateField); | 102 component->SetString(kField, kStateField); |
114 break; | 103 break; |
115 case i18n::addressinput::LOCALITY: | 104 case i18n::addressinput::LOCALITY: |
116 component->SetString(kField, kCityField); | 105 component->SetString(kField, kCityField); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 // PersonalDataManagerObserver implementation: | 369 // PersonalDataManagerObserver implementation: |
381 void AutofillOptionsHandler::OnPersonalDataChanged() { | 370 void AutofillOptionsHandler::OnPersonalDataChanged() { |
382 LoadAutofillData(); | 371 LoadAutofillData(); |
383 } | 372 } |
384 | 373 |
385 void AutofillOptionsHandler::SetAddressOverlayStrings( | 374 void AutofillOptionsHandler::SetAddressOverlayStrings( |
386 base::DictionaryValue* localized_strings) { | 375 base::DictionaryValue* localized_strings) { |
387 localized_strings->SetString("autofillEditAddressTitle", | 376 localized_strings->SetString("autofillEditAddressTitle", |
388 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); | 377 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); |
389 localized_strings->SetString("autofillCountryLabel", | 378 localized_strings->SetString("autofillCountryLabel", |
390 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL)); | 379 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL)); |
391 localized_strings->SetString("autofillPhoneLabel", | 380 localized_strings->SetString("autofillPhoneLabel", |
392 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); | 381 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); |
393 localized_strings->SetString("autofillEmailLabel", | 382 localized_strings->SetString("autofillEmailLabel", |
394 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); | 383 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); |
395 localized_strings->SetString("autofillAddPhonePlaceholder", | 384 localized_strings->SetString("autofillAddPhonePlaceholder", |
396 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); | 385 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); |
397 localized_strings->SetString("autofillAddEmailPlaceholder", | 386 localized_strings->SetString("autofillAddEmailPlaceholder", |
398 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); | 387 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); |
399 SetCountryData(*personal_data_, localized_strings); | 388 SetCountryData(*personal_data_, localized_strings); |
400 } | 389 } |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 | 675 |
687 web_ui()->CallJavascriptFunction( | 676 web_ui()->CallJavascriptFunction( |
688 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); | 677 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); |
689 } | 678 } |
690 | 679 |
691 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { | 680 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { |
692 return personal_data_ && personal_data_->IsDataLoaded(); | 681 return personal_data_ && personal_data_->IsDataLoaded(); |
693 } | 682 } |
694 | 683 |
695 } // namespace options | 684 } // namespace options |
OLD | NEW |