Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/autofill/autofill_dialog_input_i18n.h" | |
| 6 | |
| 7 #include "chrome/browser/browser_process.h" | |
| 8 #include "chrome/browser/ui/autofill/autofill_dialog_common.h" | |
| 9 #include "grit/component_strings.h" | |
| 10 #include "grit/generated_resources.h" | |
| 11 | |
| 12 namespace autofill { | |
| 13 namespace common { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 void GetLanguageAndCountryRegionFromApplicationLocale( | |
| 18 std::string* language, | |
| 19 std::string* country_region) { | |
| 20 DCHECK(g_browser_process); | |
| 21 const std::string& locale = g_browser_process->GetApplicationLocale(); | |
| 22 *language = locale.substr(0, locale.find('-')); | |
| 23 if (!country_region) | |
| 24 return; | |
| 25 const size_t country_region_pos = language->length() + 1; | |
| 26 if (locale.length() <= country_region_pos) { | |
| 27 *country_region = "US"; | |
| 28 return; | |
| 29 } | |
| 30 *country_region = locale.substr(country_region_pos); | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 AutofillDialogInputI18n::AutofillDialogInputI18n() {} | |
| 36 | |
| 37 AutofillDialogInputI18n::~AutofillDialogInputI18n() {} | |
| 38 | |
| 39 void AutofillDialogInputI18n::BuildInputsForSection( | |
| 40 DialogSection dialog_section, | |
| 41 DetailInputs* inputs) { | |
| 42 std::string language; | |
| 43 std::string country_region; | |
| 44 GetLanguageAndCountryRegionFromApplicationLocale(&language, &country_region); | |
| 45 BuildLocalizedInputs(dialog_section, language, country_region, inputs); | |
| 46 } | |
| 47 | |
| 48 void AutofillDialogInputI18n::BuildInputsForSection( | |
| 49 DialogSection dialog_section, | |
| 50 const std::string& selected_country_region, | |
| 51 DetailInputs* inputs) { | |
| 52 std::string language; | |
| 53 GetLanguageAndCountryRegionFromApplicationLocale(&language, NULL); | |
| 54 BuildLocalizedInputs( | |
| 55 dialog_section, language, selected_country_region, inputs); | |
| 56 } | |
| 57 | |
| 58 // static | |
| 59 ServerFieldType AutofillDialogInputI18n::GetFieldType( | |
|
Evan Stade
2013/10/02 00:57:19
AutofillType::GetEquivalentBillingFieldType
| |
| 60 AddressType address_type, | |
| 61 ServerFieldType field_type) { | |
| 62 switch (field_type) { | |
| 63 case ADDRESS_HOME_LINE1: | |
| 64 return address_type == ADDRESS_TYPE_SHIPPING ? field_type | |
| 65 : ADDRESS_BILLING_LINE1; | |
| 66 case ADDRESS_HOME_LINE2: | |
| 67 return address_type == ADDRESS_TYPE_SHIPPING ? field_type | |
| 68 : ADDRESS_BILLING_LINE2; | |
| 69 case ADDRESS_HOME_CITY: | |
| 70 return address_type == ADDRESS_TYPE_SHIPPING ? field_type | |
| 71 : ADDRESS_BILLING_CITY; | |
| 72 case ADDRESS_HOME_STATE: | |
| 73 return address_type == ADDRESS_TYPE_SHIPPING ? field_type | |
| 74 : ADDRESS_BILLING_STATE; | |
| 75 case ADDRESS_HOME_ZIP: | |
| 76 return address_type == ADDRESS_TYPE_SHIPPING ? field_type | |
| 77 : ADDRESS_BILLING_ZIP; | |
| 78 case ADDRESS_HOME_COUNTRY: | |
| 79 return address_type == ADDRESS_TYPE_SHIPPING ? field_type | |
| 80 : ADDRESS_BILLING_COUNTRY; | |
| 81 default: | |
| 82 NOTREACHED(); | |
| 83 return field_type; | |
| 84 } | |
| 85 } | |
| 86 | |
| 87 void AutofillDialogInputI18n::BuildLocalizedInputs( | |
| 88 DialogSection dialog_section, | |
| 89 const std::string& language, | |
| 90 const std::string& country_region, | |
| 91 DetailInputs* inputs) { | |
| 92 if (dialog_section == SECTION_CC || dialog_section == SECTION_CC_BILLING) | |
| 93 ::autofill::common::BuildInputsForSection(SECTION_CC, inputs); | |
| 94 | |
| 95 int field_row = 3; | |
| 96 if (dialog_section == SECTION_BILLING || | |
| 97 dialog_section == SECTION_CC_BILLING) { | |
| 98 inputs->push_back({field_row++, NAME_BILLING_FULL, | |
| 99 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME}); | |
| 100 field_row = BuildAddressInputs( | |
| 101 ADDRESS_TYPE_BILLING, field_row, language, country_region, inputs); | |
| 102 inputs->push_back({field_row++, PHONE_BILLING_WHOLE_NUMBER, | |
| 103 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER}); | |
| 104 inputs->push_back( | |
| 105 {field_row++, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL}); | |
| 106 } | |
| 107 | |
| 108 if (dialog_section == SECTION_SHIPPING) { | |
| 109 inputs->push_back({field_row++, NAME_FULL, | |
| 110 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME}); | |
| 111 field_row = BuildAddressInputs( | |
| 112 ADDRESS_TYPE_SHIPPING, field_row, language, country_region, inputs); | |
| 113 inputs->push_back({field_row++, PHONE_HOME_WHOLE_NUMBER, | |
| 114 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER}); | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 int AutofillDialogInputI18n::BuildAddressInputs( | |
| 119 AddressType type, | |
| 120 int field_row, | |
| 121 const std::string& language, | |
| 122 const std::string& country_region, | |
| 123 DetailInputs* inputs) { | |
| 124 // Language and country/region parameters are ignored until libaddressinput is | |
| 125 // integrated. | |
| 126 inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_LINE1), | |
| 127 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1}); | |
| 128 inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_LINE2), | |
| 129 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2}); | |
| 130 inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_CITY), | |
| 131 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY}); | |
| 132 inputs->push_back({field_row, GetFieldType(type, ADDRESS_HOME_STATE), | |
| 133 IDS_AUTOFILL_FIELD_LABEL_STATE}); | |
| 134 inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_ZIP), | |
| 135 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE}); | |
| 136 inputs->push_back({field_row++, GetFieldType(type, ADDRESS_HOME_COUNTRY)}); | |
| 137 return field_row; | |
| 138 } | |
| 139 | |
| 140 } // namespace common | |
| 141 } // namespace autofill | |
| OLD | NEW |