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

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_common.cc

Issue 63053003: Ask libaddressinput for address components to use in requestAutocomplete(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/autofill/autofill_dialog_common.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_common.h"
6 6
7 #include "chrome/browser/browser_process.h" 7 #include "chrome/browser/browser_process.h"
8 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h"
8 #include "components/autofill/core/browser/autofill_country.h" 9 #include "components/autofill/core/browser/autofill_country.h"
9 #include "components/autofill/core/browser/autofill_field.h" 10 #include "components/autofill/core/browser/autofill_field.h"
10 #include "components/autofill/core/browser/autofill_type.h" 11 #include "components/autofill/core/browser/autofill_type.h"
11 #include "grit/chromium_strings.h" 12 #include "grit/chromium_strings.h"
12 #include "grit/component_strings.h" 13 #include "grit/component_strings.h"
13 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
14 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
15 #include "grit/webkit_resources.h" 16 #include "grit/webkit_resources.h"
17 #include "ui/base/l10n/l10n_util.h"
16 18
17 namespace autofill { 19 namespace autofill {
18 namespace common { 20 namespace common {
19 21
20 // Returns true if |input| should be shown when |field_type| has been requested. 22 // Returns true if |input| should be shown when |field_type| has been requested.
21 bool InputTypeMatchesFieldType(const DetailInput& input, 23 bool InputTypeMatchesFieldType(const DetailInput& input,
22 const AutofillType& field_type) { 24 const AutofillType& field_type) {
23 // If any credit card expiration info is asked for, show both month and year 25 // If any credit card expiration info is asked for, show both month and year
24 // inputs. 26 // inputs.
25 ServerFieldType server_type = field_type.GetStorableType(); 27 ServerFieldType server_type = field_type.GetStorableType();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 size_t template_size, 68 size_t template_size,
67 DetailInputs* inputs) { 69 DetailInputs* inputs) {
68 for (size_t i = 0; i < template_size; ++i) { 70 for (size_t i = 0; i < template_size; ++i) {
69 const DetailInput* input = &input_template[i]; 71 const DetailInput* input = &input_template[i];
70 inputs->push_back(*input); 72 inputs->push_back(*input);
71 } 73 }
72 } 74 }
73 75
74 // Constructs |inputs| from template data for a given |dialog_section|. 76 // Constructs |inputs| from template data for a given |dialog_section|.
75 void BuildInputsForSection(DialogSection dialog_section, 77 void BuildInputsForSection(DialogSection dialog_section,
76 DetailInputs* inputs) { 78 DetailInputs* inputs,
79 const std::string& country_region) {
80 using l10n_util::GetStringUTF16;
81
77 const DetailInput kCCInputs[] = { 82 const DetailInput kCCInputs[] = {
78 { 1, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, 83 { 1, CREDIT_CARD_NUMBER,
79 { 2, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, 84 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER) },
85 { 2, CREDIT_CARD_EXP_MONTH,
86 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH) },
80 { 2, CREDIT_CARD_EXP_4_DIGIT_YEAR, 87 { 2, CREDIT_CARD_EXP_4_DIGIT_YEAR,
81 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, 88 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR) },
82 { 2, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, 89 { 2, CREDIT_CARD_VERIFICATION_CODE,
90 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC),
83 1.5 }, 91 1.5 },
84 }; 92 };
85 93
86 const DetailInput kBillingInputs[] = { 94 const DetailInput kBillingInputs[] = {
87 { 3, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, 95 { 3, NAME_BILLING_FULL,
96 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME) },
88 { 4, ADDRESS_BILLING_LINE1, 97 { 4, ADDRESS_BILLING_LINE1,
89 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, 98 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) },
90 { 5, ADDRESS_BILLING_LINE2, 99 { 5, ADDRESS_BILLING_LINE2,
91 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, 100 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) },
92 { 6, ADDRESS_BILLING_CITY, 101 { 6, ADDRESS_BILLING_CITY,
93 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, 102 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) },
94 // TODO(estade): state placeholder should depend on locale. 103 { 7, ADDRESS_BILLING_STATE,
95 { 7, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, 104 GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) },
96 { 7, ADDRESS_BILLING_ZIP, 105 { 7, ADDRESS_BILLING_ZIP,
97 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, 106 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) },
98 // We don't allow the user to change the country: http://crbug.com/247518 107 // We don't allow the user to change the country: http://crbug.com/247518
99 { -1, ADDRESS_BILLING_COUNTRY, 0 }, 108 { -1, ADDRESS_BILLING_COUNTRY, base::string16() },
100 { 9, PHONE_BILLING_WHOLE_NUMBER, 109 };
101 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, 110
111 const DetailInput kBillingPhoneInputs[] = {
112 { 201, PHONE_BILLING_WHOLE_NUMBER,
113 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) },
102 }; 114 };
103 115
104 const DetailInput kEmailInputs[] = { 116 const DetailInput kEmailInputs[] = {
105 { 10, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, 117 { 202, EMAIL_ADDRESS,
118 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL) },
106 }; 119 };
107 120
108 const DetailInput kShippingInputs[] = { 121 const DetailInput kShippingInputs[] = {
109 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, 122 { 1, NAME_FULL,
110 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, 123 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME) },
111 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, 124 { 2, ADDRESS_HOME_LINE1,
112 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, 125 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) },
113 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, 126 { 3, ADDRESS_HOME_LINE2,
114 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, 127 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) },
115 { -1, ADDRESS_HOME_COUNTRY, 0 }, 128 { 4, ADDRESS_HOME_CITY,
116 { 17, PHONE_HOME_WHOLE_NUMBER, 129 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) },
117 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, 130 { 5, ADDRESS_HOME_STATE,
131 GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) },
132 { 6, ADDRESS_HOME_ZIP,
133 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) },
134 { -1, ADDRESS_HOME_COUNTRY, base::string16() },
135 };
136
137 const DetailInput kShippingPhoneInputs[] = {
138 { 201, PHONE_HOME_WHOLE_NUMBER,
139 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) },
118 }; 140 };
119 141
120 switch (dialog_section) { 142 switch (dialog_section) {
121 case SECTION_CC: 143 case SECTION_CC:
122 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); 144 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs);
123 break; 145 break;
124 146
125 case SECTION_BILLING: 147 case SECTION_BILLING:
126 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); 148 if (i18ninput::IsI18nAddressInputEnabled()) {
149 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING,
150 country_region,
151 inputs);
152 } else {
153 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs);
154 }
155 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs);
127 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); 156 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs);
128 break; 157 break;
129 158
130 case SECTION_CC_BILLING: 159 case SECTION_CC_BILLING:
131 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); 160 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs);
132 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); 161 if (i18ninput::IsI18nAddressInputEnabled()) {
162 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING,
163 country_region,
164 inputs);
165 } else {
166 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs);
167 }
168 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs);
133 break; 169 break;
134 170
135 case SECTION_SHIPPING: 171 case SECTION_SHIPPING:
136 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); 172 if (i18ninput::IsI18nAddressInputEnabled()) {
173 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_SHIPPING,
Evan Stade 2013/12/02 23:30:34 this still won't compile on android :/
Dan Beam 2013/12/03 02:11:19 Done.
174 country_region,
175 inputs);
176 } else {
177 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs);
178 }
179 BuildInputs(
180 kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs);
137 break; 181 break;
138 } 182 }
139 } 183 }
140 184
141 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( 185 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent(
142 DialogSection section) { 186 DialogSection section) {
143 switch (section) { 187 switch (section) {
144 case SECTION_BILLING: 188 case SECTION_BILLING:
145 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; 189 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED;
146 190
(...skipping 24 matching lines...) Expand all
171 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED; 215 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED;
172 216
173 case SECTION_CC: 217 case SECTION_CC:
174 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; 218 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED;
175 } 219 }
176 220
177 NOTREACHED(); 221 NOTREACHED();
178 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 222 return AutofillMetrics::NUM_DIALOG_UI_EVENTS;
179 } 223 }
180 224
181 string16 GetHardcodedValueForType(ServerFieldType type) { 225 base::string16 GetInitialValueForType(ServerFieldType type,
226 const std::string& country_code) {
182 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { 227 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) {
183 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); 228 const std::string& ui_locale = g_browser_process->GetApplicationLocale();
184 return country.name(); 229 return AutofillCountry(country_code, ui_locale).name();
185 } 230 }
186 231 return base::string16();
187 return string16();
188 } 232 }
189 233
190 } // namespace common 234 } // namespace common
191 } // namespace autofill 235 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698