| 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 IsI18nInputEnabled() { |
| 80 #if defined(OS_ANDROID) |
| 81 return false; |
| 82 #else |
| 83 return i18ninput::Enabled(); |
| 84 #endif |
| 85 } |
| 86 |
| 87 void BuildI18nAddressInputs(AddressType address_type, |
| 88 const std::string& country_code, |
| 89 DetailInputs* inputs) { |
| 90 #if defined(OS_ANDROID) |
| 91 NOTREACHED(); |
| 92 #else |
| 93 i18ninput::BuildAddressInputs(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, |
| 99 const std::string& country_code, |
| 76 DetailInputs* inputs) { | 100 DetailInputs* inputs) { |
| 101 using l10n_util::GetStringUTF16; |
| 102 |
| 77 const DetailInput kCCInputs[] = { | 103 const DetailInput kCCInputs[] = { |
| 78 { DetailInput::LONG, | 104 { DetailInput::LONG, |
| 79 CREDIT_CARD_NUMBER, | 105 CREDIT_CARD_NUMBER, |
| 80 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, | 106 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER) }, |
| 81 { DetailInput::SHORT, | 107 { DetailInput::SHORT, |
| 82 CREDIT_CARD_EXP_MONTH, | 108 CREDIT_CARD_EXP_MONTH, |
| 83 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, | 109 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH) }, |
| 84 { DetailInput::SHORT, | 110 { DetailInput::SHORT, |
| 85 CREDIT_CARD_EXP_4_DIGIT_YEAR, | 111 CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 86 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, | 112 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR) }, |
| 87 { DetailInput::SHORT, | 113 { DetailInput::SHORT_EOL, |
| 88 CREDIT_CARD_VERIFICATION_CODE, | 114 CREDIT_CARD_VERIFICATION_CODE, |
| 89 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, | 115 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC), |
| 90 1.5 }, | 116 1.5 }, |
| 91 }; | 117 }; |
| 92 | 118 |
| 93 const DetailInput kBillingInputs[] = { | 119 const DetailInput kBillingInputs[] = { |
| 94 { DetailInput::LONG, | 120 { DetailInput::LONG, |
| 95 NAME_BILLING_FULL, | 121 NAME_BILLING_FULL, |
| 96 IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, | 122 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME) }, |
| 97 { DetailInput::LONG, | 123 { DetailInput::LONG, |
| 98 ADDRESS_BILLING_LINE1, | 124 ADDRESS_BILLING_LINE1, |
| 99 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | 125 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) }, |
| 100 { DetailInput::LONG, | 126 { DetailInput::LONG, |
| 101 ADDRESS_BILLING_LINE2, | 127 ADDRESS_BILLING_LINE2, |
| 102 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | 128 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) }, |
| 103 { DetailInput::LONG, | 129 { DetailInput::LONG, |
| 104 ADDRESS_BILLING_CITY, | 130 ADDRESS_BILLING_CITY, |
| 105 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | 131 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) }, |
| 106 // TODO(estade): state placeholder should depend on locale. | |
| 107 { DetailInput::SHORT, | 132 { DetailInput::SHORT, |
| 108 ADDRESS_BILLING_STATE, | 133 ADDRESS_BILLING_STATE, |
| 109 IDS_AUTOFILL_FIELD_LABEL_STATE }, | 134 GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) }, |
| 110 { DetailInput::SHORT, | 135 { DetailInput::SHORT_EOL, |
| 111 ADDRESS_BILLING_ZIP, | 136 ADDRESS_BILLING_ZIP, |
| 112 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | 137 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) }, |
| 113 // We don't allow the user to change the country: http://crbug.com/247518 | 138 // We don't allow the user to change the country: http://crbug.com/247518 |
| 114 { DetailInput::NONE, ADDRESS_BILLING_COUNTRY, 0 }, | 139 { DetailInput::NONE, ADDRESS_BILLING_COUNTRY }, |
| 140 }; |
| 141 |
| 142 const DetailInput kBillingPhoneInputs[] = { |
| 115 { DetailInput::LONG, | 143 { DetailInput::LONG, |
| 116 PHONE_BILLING_WHOLE_NUMBER, | 144 PHONE_BILLING_WHOLE_NUMBER, |
| 117 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | 145 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) }, |
| 118 }; | 146 }; |
| 119 | 147 |
| 120 const DetailInput kEmailInputs[] = { | 148 const DetailInput kEmailInputs[] = { |
| 121 { DetailInput::LONG, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 149 { DetailInput::LONG, |
| 150 EMAIL_ADDRESS, |
| 151 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL) }, |
| 122 }; | 152 }; |
| 123 | 153 |
| 124 const DetailInput kShippingInputs[] = { | 154 const DetailInput kShippingInputs[] = { |
| 125 { DetailInput::LONG, | 155 { DetailInput::LONG, |
| 126 NAME_FULL, | 156 NAME_FULL, |
| 127 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, | 157 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME) }, |
| 128 { DetailInput::LONG, | 158 { DetailInput::LONG, |
| 129 ADDRESS_HOME_LINE1, | 159 ADDRESS_HOME_LINE1, |
| 130 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | 160 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1) }, |
| 131 { DetailInput::LONG, | 161 { DetailInput::LONG, |
| 132 ADDRESS_HOME_LINE2, | 162 ADDRESS_HOME_LINE2, |
| 133 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | 163 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2) }, |
| 134 { DetailInput::LONG, | 164 { DetailInput::LONG, |
| 135 ADDRESS_HOME_CITY, | 165 ADDRESS_HOME_CITY, |
| 136 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | 166 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY) }, |
| 137 { DetailInput::SHORT, | 167 { DetailInput::SHORT, |
| 138 ADDRESS_HOME_STATE, | 168 ADDRESS_HOME_STATE, |
| 139 IDS_AUTOFILL_FIELD_LABEL_STATE }, | 169 GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_STATE) }, |
| 140 { DetailInput::SHORT, | 170 { DetailInput::SHORT_EOL, |
| 141 ADDRESS_HOME_ZIP, | 171 ADDRESS_HOME_ZIP, |
| 142 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | 172 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE) }, |
| 143 { DetailInput::NONE, ADDRESS_HOME_COUNTRY, 0 }, | 173 { DetailInput::NONE, ADDRESS_HOME_COUNTRY }, |
| 174 }; |
| 175 |
| 176 const DetailInput kShippingPhoneInputs[] = { |
| 144 { DetailInput::LONG, | 177 { DetailInput::LONG, |
| 145 PHONE_HOME_WHOLE_NUMBER, | 178 PHONE_HOME_WHOLE_NUMBER, |
| 146 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | 179 GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER) }, |
| 147 }; | 180 }; |
| 148 | 181 |
| 149 switch (dialog_section) { | 182 switch (dialog_section) { |
| 150 case SECTION_CC: | 183 case SECTION_CC: |
| 151 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 184 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
| 152 break; | 185 break; |
| 153 | 186 |
| 154 case SECTION_BILLING: | 187 case SECTION_BILLING: |
| 155 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 188 if (IsI18nInputEnabled()) |
| 189 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, country_code, inputs); |
| 190 else |
| 191 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
| 192 |
| 193 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
| 156 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); | 194 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); |
| 157 break; | 195 break; |
| 158 | 196 |
| 159 case SECTION_CC_BILLING: | 197 case SECTION_CC_BILLING: |
| 160 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 198 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
| 161 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 199 |
| 200 if (IsI18nInputEnabled()) |
| 201 BuildI18nAddressInputs(ADDRESS_TYPE_BILLING, country_code, inputs); |
| 202 else |
| 203 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
| 204 |
| 205 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
| 162 break; | 206 break; |
| 163 | 207 |
| 164 case SECTION_SHIPPING: | 208 case SECTION_SHIPPING: |
| 165 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); | 209 if (IsI18nInputEnabled()) |
| 210 BuildI18nAddressInputs(ADDRESS_TYPE_SHIPPING, country_code, inputs); |
| 211 else |
| 212 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); |
| 213 |
| 214 BuildInputs( |
| 215 kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs); |
| 166 break; | 216 break; |
| 167 } | 217 } |
| 168 } | 218 } |
| 169 | 219 |
| 170 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( | 220 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( |
| 171 DialogSection section) { | 221 DialogSection section) { |
| 172 switch (section) { | 222 switch (section) { |
| 173 case SECTION_BILLING: | 223 case SECTION_BILLING: |
| 174 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; | 224 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; |
| 175 | 225 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { | 261 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { |
| 212 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); | 262 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); |
| 213 return country.name(); | 263 return country.name(); |
| 214 } | 264 } |
| 215 | 265 |
| 216 return base::string16(); | 266 return base::string16(); |
| 217 } | 267 } |
| 218 | 268 |
| 219 } // namespace common | 269 } // namespace common |
| 220 } // namespace autofill | 270 } // namespace autofill |
| OLD | NEW |