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

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: let's try this again, android 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
94 const int kBillingInputsStartRow = 3;
86 const DetailInput kBillingInputs[] = { 95 const DetailInput kBillingInputs[] = {
87 { 3, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, 96 { 3, NAME_BILLING_FULL,
97 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME) },
88 { 4, ADDRESS_BILLING_LINE1, 98 { 4, ADDRESS_BILLING_LINE1,
89 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, 99 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) },
90 { 5, ADDRESS_BILLING_LINE2, 100 { 5, ADDRESS_BILLING_LINE2,
91 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, 101 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) },
92 { 6, ADDRESS_BILLING_CITY, 102 { 6, ADDRESS_BILLING_CITY,
93 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, 103 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) },
94 // TODO(estade): state placeholder should depend on locale. 104 { 7, ADDRESS_BILLING_STATE,
95 { 7, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, 105 GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) },
96 { 7, ADDRESS_BILLING_ZIP, 106 { 7, ADDRESS_BILLING_ZIP,
97 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, 107 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) },
98 // We don't allow the user to change the country: http://crbug.com/247518 108 { -1, ADDRESS_BILLING_COUNTRY, base::string16() },
Evan Stade 2013/12/02 17:57:33 leave this comment
Dan Beam 2013/12/02 22:37:54 Done.
99 { -1, ADDRESS_BILLING_COUNTRY, 0 }, 109 };
100 { 9, PHONE_BILLING_WHOLE_NUMBER, 110
101 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, 111 const DetailInput kBillingPhoneInputs[] = {
112 { 19, 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 { 20, EMAIL_ADDRESS,
118 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL) },
106 }; 119 };
107 120
121 const int kShippingInputsStartRow = 21;
108 const DetailInput kShippingInputs[] = { 122 const DetailInput kShippingInputs[] = {
109 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, 123 { 21, NAME_FULL,
110 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, 124 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME) },
111 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, 125 { 22, ADDRESS_HOME_LINE1,
112 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, 126 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) },
113 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, 127 { 23, ADDRESS_HOME_LINE2,
114 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, 128 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) },
115 { -1, ADDRESS_HOME_COUNTRY, 0 }, 129 { 24, ADDRESS_HOME_CITY,
116 { 17, PHONE_HOME_WHOLE_NUMBER, 130 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) },
117 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, 131 { 25, ADDRESS_HOME_STATE,
132 GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) },
133 { 25, ADDRESS_HOME_ZIP,
134 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) },
135 { -1, ADDRESS_HOME_COUNTRY, base::string16() },
136 };
137
138 const DetailInput kShippingPhoneInputs[] = {
Evan Stade 2013/12/02 17:57:33 Might as well just have one phone input struct arr
Dan Beam 2013/12/02 22:37:54 the ServerFieldType differs
139 { 37, PHONE_HOME_WHOLE_NUMBER,
140 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) },
118 }; 141 };
119 142
120 switch (dialog_section) { 143 switch (dialog_section) {
121 case SECTION_CC: 144 case SECTION_CC:
122 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); 145 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs);
123 break; 146 break;
124 147
125 case SECTION_BILLING: 148 case SECTION_BILLING:
126 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); 149 if (i18ninput::IsI18nAddressInputEnabled()) {
150 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING,
151 country_region,
152 kBillingInputsStartRow,
153 inputs);
154 } else {
155 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs);
156 }
157 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs);
127 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); 158 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs);
128 break; 159 break;
129 160
130 case SECTION_CC_BILLING: 161 case SECTION_CC_BILLING:
131 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); 162 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs);
132 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); 163 if (i18ninput::IsI18nAddressInputEnabled()) {
164 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING,
165 country_region,
166 kBillingInputsStartRow,
167 inputs);
168 } else {
169 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs);
170 }
171 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs);
133 break; 172 break;
134 173
135 case SECTION_SHIPPING: 174 case SECTION_SHIPPING:
136 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); 175 if (i18ninput::IsI18nAddressInputEnabled()) {
176 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_SHIPPING,
177 country_region,
178 kShippingInputsStartRow,
179 inputs);
180 } else {
181 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs);
182 }
183 BuildInputs(
184 kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs);
137 break; 185 break;
138 } 186 }
139 } 187 }
140 188
141 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( 189 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent(
142 DialogSection section) { 190 DialogSection section) {
143 switch (section) { 191 switch (section) {
144 case SECTION_BILLING: 192 case SECTION_BILLING:
145 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; 193 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED;
146 194
(...skipping 24 matching lines...) Expand all
171 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED; 219 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED;
172 220
173 case SECTION_CC: 221 case SECTION_CC:
174 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; 222 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED;
175 } 223 }
176 224
177 NOTREACHED(); 225 NOTREACHED();
178 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; 226 return AutofillMetrics::NUM_DIALOG_UI_EVENTS;
179 } 227 }
180 228
181 string16 GetHardcodedValueForType(ServerFieldType type) { 229 base::string16 GetInitialValueForType(ServerFieldType type,
230 const std::string& country_code) {
182 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { 231 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) {
183 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); 232 const std::string& ui_locale = g_browser_process->GetApplicationLocale();
184 return country.name(); 233 return AutofillCountry(country_code, ui_locale).name();
185 } 234 }
186 235 return base::string16();
187 return string16();
188 } 236 }
189 237
190 } // namespace common 238 } // namespace common
191 } // namespace autofill 239 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698