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 "base/strings/utf_string_conversions.h" | |
7 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.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" |
16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
17 | 18 |
18 #if !defined(OS_ANDROID) | 19 #if !defined(OS_ANDROID) |
19 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" | 20 #include "chrome/browser/ui/autofill/autofill_dialog_i18n_input.h" |
20 #endif // !defined(OS_ANDROID) | 21 #endif // !defined(OS_ANDROID) |
21 | 22 |
22 namespace autofill { | 23 namespace autofill { |
23 namespace common { | 24 namespace common { |
24 | 25 |
Dan Beam
2014/02/07 01:30:44
namespace {
const char kHardcodedCountryCode[] = "
Evan Stade
2014/02/07 01:52:43
why?
Dan Beam
2014/02/07 03:33:23
because of all the other comments in this file. a
Evan Stade
2014/02/07 21:20:48
ah, I missed the last one. I don't think we need t
| |
25 // Returns true if |input| should be shown when |field_type| has been requested. | 26 // Returns true if |input| should be shown when |field_type| has been requested. |
26 bool ServerTypeMatchesFieldType(ServerFieldType type, | 27 bool ServerTypeMatchesFieldType(ServerFieldType type, |
27 const AutofillType& field_type) { | 28 const AutofillType& field_type) { |
28 // If any credit card expiration info is asked for, show both month and year | 29 // If any credit card expiration info is asked for, show both month and year |
29 // inputs. | 30 // inputs. |
30 ServerFieldType server_type = field_type.GetStorableType(); | 31 ServerFieldType server_type = field_type.GetStorableType(); |
31 if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | 32 if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
32 server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || | 33 server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || |
33 server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || | 34 server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || |
34 server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || | 35 server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 case SECTION_BILLING: | 194 case SECTION_BILLING: |
194 if (IsI18nInputEnabled()) | 195 if (IsI18nInputEnabled()) |
195 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, country_code, inputs); | 196 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, country_code, inputs); |
196 else | 197 else |
197 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 198 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
198 | 199 |
199 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); | 200 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
200 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); | 201 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); |
201 break; | 202 break; |
202 | 203 |
203 case SECTION_CC_BILLING: | 204 case SECTION_CC_BILLING: |
Dan Beam
2014/02/07 01:30:44
^ in general I'd prefer to minimize the amount of
Evan Stade
2014/02/07 01:52:43
Wallet is the only reason SECTION_CC_BILLING even
Dan Beam
2014/02/07 03:33:23
it's not a big deal until we encounter another dat
| |
204 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 205 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
205 | 206 |
206 if (IsI18nInputEnabled()) | 207 if (IsI18nInputEnabled()) { |
207 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, country_code, inputs); | 208 // Wallet only supports US billing addresses. |
208 else | 209 const std::string hardcoded_country_code = "US"; |
210 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, | |
211 hardcoded_country_code, | |
212 inputs); | |
213 DCHECK_EQ(inputs->back().type, ADDRESS_HOME_COUNTRY); | |
214 inputs->back().length = DetailInput::NONE; | |
215 inputs->back().initial_value = | |
216 base::ASCIIToUTF16(hardcoded_country_code); | |
Dan Beam
2014/02/07 01:30:44
s/hardcoded_country_code/kHardcodedCountryCode/g
| |
217 } else { | |
209 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 218 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
219 } | |
210 | 220 |
211 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); | 221 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
212 break; | 222 break; |
213 | 223 |
214 case SECTION_SHIPPING: | 224 case SECTION_SHIPPING: |
215 if (IsI18nInputEnabled()) | 225 if (IsI18nInputEnabled()) |
216 BuildI18nAddressInputs(ADDRESS_TYPE_SHIPPING, country_code, inputs); | 226 BuildI18nAddressInputs(ADDRESS_TYPE_SHIPPING, country_code, inputs); |
217 else | 227 else |
218 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); | 228 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); |
219 | 229 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 case SECTION_CC: | 268 case SECTION_CC: |
259 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; | 269 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; |
260 } | 270 } |
261 | 271 |
262 NOTREACHED(); | 272 NOTREACHED(); |
263 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; | 273 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; |
264 } | 274 } |
265 | 275 |
266 base::string16 GetHardcodedValueForType(ServerFieldType type) { | 276 base::string16 GetHardcodedValueForType(ServerFieldType type) { |
267 // TODO(dbeam): remove this entire function when i18n inputs are the default. | 277 // TODO(dbeam): remove this entire function when i18n inputs are the default. |
268 if (IsI18nInputEnabled()) | 278 DCHECK(!IsI18nInputEnabled()); |
269 return base::string16(); | |
270 | 279 |
271 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { | 280 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { |
272 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); | 281 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); |
Dan Beam
2014/02/07 01:30:44
s/"US"/kHardcodedCountryCode/
| |
273 return country.name(); | 282 return country.name(); |
274 } | 283 } |
275 | 284 |
276 return base::string16(); | 285 return base::string16(); |
277 } | 286 } |
278 | 287 |
279 std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs) { | 288 std::vector<ServerFieldType> TypesFromInputs(const DetailInputs& inputs) { |
280 std::vector<ServerFieldType> types; | 289 std::vector<ServerFieldType> types; |
281 for (size_t i = 0; i < inputs.size(); ++i) { | 290 for (size_t i = 0; i < inputs.size(); ++i) { |
282 types.push_back(inputs[i].type); | 291 types.push_back(inputs[i].type); |
283 } | 292 } |
284 return types; | 293 return types; |
285 } | 294 } |
286 | 295 |
287 } // namespace common | 296 } // namespace common |
288 } // namespace autofill | 297 } // namespace autofill |
OLD | NEW |