Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: chrome/browser/ui/webui/options/autofill_options_handler.cc

Issue 298863012: Use upstream libaddressinput in Chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressing comments. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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, ui_language_code);
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 components_language_code == NULL ?
81 &not_used : components_language_code);
75 if (components.empty()) { 82 if (components.empty()) {
76 static const char kDefaultCountryCode[] = "US"; 83 static const char kDefaultCountryCode[] = "US";
77 components = i18n::addressinput::BuildComponents( 84 components = i18n::addressinput::BuildComponents(
78 kDefaultCountryCode, ui_language_code, components_language_code); 85 kDefaultCountryCode,
86 localization,
87 components_language_code == NULL ?
88 &not_used : components_language_code);
79 } 89 }
80 DCHECK(!components.empty()); 90 DCHECK(!components.empty());
81 91
82 base::ListValue* line = NULL; 92 base::ListValue* line = NULL;
83 static const char kField[] = "field"; 93 static const char kField[] = "field";
84 static const char kLength[] = "length"; 94 static const char kLength[] = "length";
85 for (size_t i = 0; i < components.size(); ++i) { 95 for (size_t i = 0; i < components.size(); ++i) {
86 if (i == 0 || 96 if (i == 0 ||
87 components[i - 1].length_hint == AddressUiComponent::HINT_LONG || 97 components[i - 1].length_hint == AddressUiComponent::HINT_LONG ||
88 components[i].length_hint == AddressUiComponent::HINT_LONG) { 98 components[i].length_hint == AddressUiComponent::HINT_LONG) {
89 line = new base::ListValue; 99 line = new base::ListValue;
90 address_components->Append(line); 100 address_components->Append(line);
91 } 101 }
92 102
93 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue); 103 scoped_ptr<base::DictionaryValue> component(new base::DictionaryValue);
94 component->SetString( 104 component->SetString("name", components[i].name);
95 "name", l10n_util::GetStringUTF16(components[i].name_id));
96 105
97 switch (components[i].field) { 106 switch (components[i].field) {
98 case i18n::addressinput::COUNTRY: 107 case i18n::addressinput::COUNTRY:
99 component->SetString(kField, kCountryField); 108 component->SetString(kField, kCountryField);
100 break; 109 break;
101 case i18n::addressinput::ADMIN_AREA: 110 case i18n::addressinput::ADMIN_AREA:
102 component->SetString(kField, kStateField); 111 component->SetString(kField, kStateField);
103 break; 112 break;
104 case i18n::addressinput::LOCALITY: 113 case i18n::addressinput::LOCALITY:
105 component->SetString(kField, kCityField); 114 component->SetString(kField, kCityField);
106 break; 115 break;
107 case i18n::addressinput::DEPENDENT_LOCALITY: 116 case i18n::addressinput::DEPENDENT_LOCALITY:
108 component->SetString(kField, kDependentLocalityField); 117 component->SetString(kField, kDependentLocalityField);
109 break; 118 break;
110 case i18n::addressinput::SORTING_CODE: 119 case i18n::addressinput::SORTING_CODE:
111 component->SetString(kField, kSortingCodeField); 120 component->SetString(kField, kSortingCodeField);
112 break; 121 break;
113 case i18n::addressinput::POSTAL_CODE: 122 case i18n::addressinput::POSTAL_CODE:
114 component->SetString(kField, kPostalCodeField); 123 component->SetString(kField, kPostalCodeField);
115 break; 124 break;
116 case i18n::addressinput::STREET_ADDRESS: 125 case i18n::addressinput::STREET_ADDRESS:
117 component->SetString(kField, kAddressLineField); 126 component->SetString(kField, kAddressLineField);
118 break; 127 break;
119 case i18n::addressinput::ORGANIZATION:
120 component->SetString(kField, kCompanyNameField);
121 break;
122 case i18n::addressinput::RECIPIENT: 128 case i18n::addressinput::RECIPIENT:
123 component->SetString(kField, kFullNameField); 129 component->SetString(kField, kFullNameField);
124 component->SetString( 130 component->SetString(
125 "placeholder", 131 "placeholder",
126 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_NAME)); 132 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_NAME));
127 break; 133 break;
128 } 134 }
129 135
130 switch (components[i].length_hint) { 136 switch (components[i].length_hint) {
131 case AddressUiComponent::HINT_LONG: 137 case AddressUiComponent::HINT_LONG:
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 // PersonalDataManagerObserver implementation: 378 // PersonalDataManagerObserver implementation:
373 void AutofillOptionsHandler::OnPersonalDataChanged() { 379 void AutofillOptionsHandler::OnPersonalDataChanged() {
374 LoadAutofillData(); 380 LoadAutofillData();
375 } 381 }
376 382
377 void AutofillOptionsHandler::SetAddressOverlayStrings( 383 void AutofillOptionsHandler::SetAddressOverlayStrings(
378 base::DictionaryValue* localized_strings) { 384 base::DictionaryValue* localized_strings) {
379 localized_strings->SetString("autofillEditAddressTitle", 385 localized_strings->SetString("autofillEditAddressTitle",
380 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION)); 386 l10n_util::GetStringUTF16(IDS_AUTOFILL_EDIT_ADDRESS_CAPTION));
381 localized_strings->SetString("autofillCountryLabel", 387 localized_strings->SetString("autofillCountryLabel",
382 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_I18N_COUNTRY_LABEL)); 388 l10n_util::GetStringUTF16(IDS_LIBADDRESSINPUT_COUNTRY_OR_REGION_LABEL));
383 localized_strings->SetString("autofillPhoneLabel", 389 localized_strings->SetString("autofillPhoneLabel",
384 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE)); 390 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_PHONE));
385 localized_strings->SetString("autofillEmailLabel", 391 localized_strings->SetString("autofillEmailLabel",
386 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL)); 392 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EMAIL));
387 localized_strings->SetString("autofillAddPhonePlaceholder", 393 localized_strings->SetString("autofillAddPhonePlaceholder",
388 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE)); 394 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_PHONE));
389 localized_strings->SetString("autofillAddEmailPlaceholder", 395 localized_strings->SetString("autofillAddEmailPlaceholder",
390 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL)); 396 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_ADD_EMAIL));
391 SetCountryData(*personal_data_, localized_strings); 397 SetCountryData(*personal_data_, localized_strings);
392 } 398 }
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
675 681
676 web_ui()->CallJavascriptFunction( 682 web_ui()->CallJavascriptFunction(
677 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value); 683 "AutofillEditAddressOverlay.setValidatedPhoneNumbers", *list_value);
678 } 684 }
679 685
680 bool AutofillOptionsHandler::IsPersonalDataLoaded() const { 686 bool AutofillOptionsHandler::IsPersonalDataLoaded() const {
681 return personal_data_ && personal_data_->IsDataLoaded(); 687 return personal_data_ && personal_data_->IsDataLoaded();
682 } 688 }
683 689
684 } // namespace options 690 } // namespace options
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698