OLD | NEW |
---|---|
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 "components/autofill/core/browser/autofill_country.h" | 8 #include "components/autofill/core/browser/autofill_country.h" |
9 #include "components/autofill/core/browser/autofill_field.h" | 9 #include "components/autofill/core/browser/autofill_field.h" |
10 #include "components/autofill/core/browser/autofill_type.h" | 10 #include "components/autofill/core/browser/autofill_type.h" |
11 #include "grit/chromium_strings.h" | 11 #include "grit/chromium_strings.h" |
12 #include "grit/component_strings.h" | 12 #include "grit/component_strings.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
15 #include "grit/webkit_resources.h" | 15 #include "grit/webkit_resources.h" |
16 #include "ui/base/l10n/l10n_util.h" | |
17 | |
18 #if !defined(OS_ANDROID) | |
19 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | |
20 #endif // !defined(OS_ANDROID) | |
16 | 21 |
17 namespace autofill { | 22 namespace autofill { |
18 namespace common { | 23 namespace common { |
19 | 24 |
20 // Returns true if |input| should be shown when |field_type| has been requested. | 25 // Returns true if |input| should be shown when |field_type| has been requested. |
21 bool InputTypeMatchesFieldType(const DetailInput& input, | 26 bool InputTypeMatchesFieldType(const DetailInput& input, |
22 const AutofillType& field_type) { | 27 const AutofillType& field_type) { |
23 // If any credit card expiration info is asked for, show both month and year | 28 // If any credit card expiration info is asked for, show both month and year |
24 // inputs. | 29 // inputs. |
25 ServerFieldType server_type = field_type.GetStorableType(); | 30 ServerFieldType server_type = field_type.GetStorableType(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 // Constructs |inputs| from template data. | 69 // Constructs |inputs| from template data. |
65 void BuildInputs(const DetailInput* input_template, | 70 void BuildInputs(const DetailInput* input_template, |
66 size_t template_size, | 71 size_t template_size, |
67 DetailInputs* inputs) { | 72 DetailInputs* inputs) { |
68 for (size_t i = 0; i < template_size; ++i) { | 73 for (size_t i = 0; i < template_size; ++i) { |
69 const DetailInput* input = &input_template[i]; | 74 const DetailInput* input = &input_template[i]; |
70 inputs->push_back(*input); | 75 inputs->push_back(*input); |
71 } | 76 } |
72 } | 77 } |
73 | 78 |
79 bool IsI18nAddressInputEnabledForPlatform() { | |
80 #if defined(OS_ANDROID) | |
81 return false; | |
82 #else | |
83 return i18ninput::IsI18nAddressInputEnabled(); | |
84 #endif | |
85 } | |
86 | |
87 void BuildI18nInputs(i18ninput::AddressType address_type, | |
88 const std::string& country_code, | |
89 DetailInputs* inputs) { | |
90 #if defined(OS_ANDROID) | |
91 NOTREACHED(); | |
92 #else | |
93 i18ninput::BuildI18nInputsForCountry(address_type, country_code, inputs); | |
94 #endif | |
95 } | |
96 | |
74 // Constructs |inputs| from template data for a given |dialog_section|. | 97 // Constructs |inputs| from template data for a given |dialog_section|. |
75 void BuildInputsForSection(DialogSection dialog_section, | 98 void BuildInputsForSection(DialogSection dialog_section, |
76 DetailInputs* inputs) { | 99 DetailInputs* inputs, |
100 const std::string& country_code) { | |
101 using l10n_util::GetStringUTF16; | |
102 | |
103 // Row ids are segmented as follows: | |
104 // <= 0: invisible fields (e.g. country when i18n is off) | |
105 // 0-99: visible fields before address inputs (e.g. credit card) | |
106 // 100-199: visible address inputs (e.g. street, country) | |
107 // >= 200: visible fields after address inputs (e.g. email, phone number) | |
Evan Stade
2013/12/03 02:32:49
no magic numbers
Dan Beam
2013/12/03 07:38:07
Done.
| |
108 | |
77 const DetailInput kCCInputs[] = { | 109 const DetailInput kCCInputs[] = { |
78 { 1, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, | 110 { 1, CREDIT_CARD_NUMBER, |
79 { 2, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, | 111 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER) }, |
112 { 2, CREDIT_CARD_EXP_MONTH, | |
113 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH) }, | |
80 { 2, CREDIT_CARD_EXP_4_DIGIT_YEAR, | 114 { 2, CREDIT_CARD_EXP_4_DIGIT_YEAR, |
81 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, | 115 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR) }, |
82 { 2, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, | 116 { 2, CREDIT_CARD_VERIFICATION_CODE, |
117 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC), | |
83 1.5 }, | 118 1.5 }, |
84 }; | 119 }; |
85 | 120 |
86 const DetailInput kBillingInputs[] = { | 121 const DetailInput kBillingInputs[] = { |
87 { 3, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, | 122 { 101, NAME_BILLING_FULL, |
88 { 4, ADDRESS_BILLING_LINE1, | 123 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME) }, |
89 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | 124 { 102, ADDRESS_BILLING_LINE1, |
90 { 5, ADDRESS_BILLING_LINE2, | 125 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) }, |
91 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | 126 { 103, ADDRESS_BILLING_LINE2, |
92 { 6, ADDRESS_BILLING_CITY, | 127 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) }, |
93 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | 128 { 104, ADDRESS_BILLING_CITY, |
94 // TODO(estade): state placeholder should depend on locale. | 129 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) }, |
95 { 7, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | 130 { 105, ADDRESS_BILLING_STATE, |
96 { 7, ADDRESS_BILLING_ZIP, | 131 GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) }, |
97 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | 132 { 105, ADDRESS_BILLING_ZIP, |
133 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) }, | |
98 // We don't allow the user to change the country: http://crbug.com/247518 | 134 // We don't allow the user to change the country: http://crbug.com/247518 |
99 { -1, ADDRESS_BILLING_COUNTRY, 0 }, | 135 { -1, ADDRESS_BILLING_COUNTRY, base::string16() }, |
100 { 9, PHONE_BILLING_WHOLE_NUMBER, | 136 }; |
101 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | 137 |
138 const DetailInput kBillingPhoneInputs[] = { | |
139 { 201, PHONE_BILLING_WHOLE_NUMBER, | |
140 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) }, | |
102 }; | 141 }; |
103 | 142 |
104 const DetailInput kEmailInputs[] = { | 143 const DetailInput kEmailInputs[] = { |
105 { 10, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 144 { 202, EMAIL_ADDRESS, |
145 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL) }, | |
106 }; | 146 }; |
107 | 147 |
108 const DetailInput kShippingInputs[] = { | 148 const DetailInput kShippingInputs[] = { |
109 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, | 149 { 101, NAME_FULL, |
110 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | 150 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME) }, |
111 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | 151 { 102, ADDRESS_HOME_LINE1, |
112 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | 152 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) }, |
113 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | 153 { 103, ADDRESS_HOME_LINE2, |
114 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | 154 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) }, |
115 { -1, ADDRESS_HOME_COUNTRY, 0 }, | 155 { 104, ADDRESS_HOME_CITY, |
116 { 17, PHONE_HOME_WHOLE_NUMBER, | 156 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) }, |
117 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | 157 { 105, ADDRESS_HOME_STATE, |
158 GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) }, | |
159 { 106, ADDRESS_HOME_ZIP, | |
160 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) }, | |
161 { -1, ADDRESS_HOME_COUNTRY, base::string16() }, | |
162 }; | |
163 | |
164 const DetailInput kShippingPhoneInputs[] = { | |
165 { 201, PHONE_HOME_WHOLE_NUMBER, | |
166 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) }, | |
118 }; | 167 }; |
119 | 168 |
120 switch (dialog_section) { | 169 switch (dialog_section) { |
121 case SECTION_CC: | 170 case SECTION_CC: |
122 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 171 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
123 break; | 172 break; |
124 | 173 |
125 case SECTION_BILLING: | 174 case SECTION_BILLING: |
126 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 175 if (IsI18nAddressInputEnabledForPlatform()) |
176 BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING, country_code, inputs); | |
177 else | |
178 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | |
179 | |
180 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); | |
127 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); | 181 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); |
128 break; | 182 break; |
129 | 183 |
130 case SECTION_CC_BILLING: | 184 case SECTION_CC_BILLING: |
131 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 185 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
132 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 186 |
187 if (IsI18nAddressInputEnabledForPlatform()) | |
188 BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING, country_code, inputs); | |
189 else | |
190 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | |
191 | |
192 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); | |
133 break; | 193 break; |
134 | 194 |
135 case SECTION_SHIPPING: | 195 case SECTION_SHIPPING: |
136 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); | 196 if (IsI18nAddressInputEnabledForPlatform()) |
197 BuildI18nInputs(i18ninput::ADDRESS_TYPE_SHIPPING, country_code, inputs); | |
198 else | |
199 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); | |
200 | |
201 BuildInputs( | |
202 kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs); | |
137 break; | 203 break; |
138 } | 204 } |
139 } | 205 } |
140 | 206 |
141 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( | 207 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( |
142 DialogSection section) { | 208 DialogSection section) { |
143 switch (section) { | 209 switch (section) { |
144 case SECTION_BILLING: | 210 case SECTION_BILLING: |
145 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; | 211 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; |
146 | 212 |
(...skipping 24 matching lines...) Expand all Loading... | |
171 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED; | 237 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED; |
172 | 238 |
173 case SECTION_CC: | 239 case SECTION_CC: |
174 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; | 240 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; |
175 } | 241 } |
176 | 242 |
177 NOTREACHED(); | 243 NOTREACHED(); |
178 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; | 244 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; |
179 } | 245 } |
180 | 246 |
181 string16 GetHardcodedValueForType(ServerFieldType type) { | 247 base::string16 GetInitialValueForType(ServerFieldType type, |
248 const std::string& country_code) { | |
182 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { | 249 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { |
183 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); | 250 const std::string& ui_locale = g_browser_process->GetApplicationLocale(); |
184 return country.name(); | 251 return AutofillCountry(country_code, ui_locale).name(); |
185 } | 252 } |
186 | 253 return base::string16(); |
187 return string16(); | |
188 } | 254 } |
189 | 255 |
190 } // namespace common | 256 } // namespace common |
191 } // namespace autofill | 257 } // namespace autofill |
OLD | NEW |