| 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 "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" |
| 16 | 17 |
| 17 namespace autofill { | 18 namespace autofill { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 // Constructs |inputs| from template data. | 65 // Constructs |inputs| from template data. |
| 65 void BuildInputs(const DetailInput* input_template, | 66 void BuildInputs(const DetailInput* input_template, |
| 66 size_t template_size, | 67 size_t template_size, |
| 67 DetailInputs* inputs) { | 68 DetailInputs* inputs) { |
| 68 for (size_t i = 0; i < template_size; ++i) { | 69 for (size_t i = 0; i < template_size; ++i) { |
| 69 const DetailInput* input = &input_template[i]; | 70 const DetailInput* input = &input_template[i]; |
| 70 inputs->push_back(*input); | 71 inputs->push_back(*input); |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 // Constructs |inputs| from template data for a given |dialog_section|. | |
| 75 void BuildInputsForSection(DialogSection dialog_section, | 75 void BuildInputsForSection(DialogSection dialog_section, |
| 76 DetailInputs* inputs) { | 76 DetailInputs* inputs, |
| 77 const std::string& country_region) { |
| 77 const DetailInput kCCInputs[] = { | 78 const DetailInput kCCInputs[] = { |
| 78 { 1, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, | 79 { 1, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, |
| 79 { 2, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, | 80 { 2, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, |
| 80 { 2, CREDIT_CARD_EXP_4_DIGIT_YEAR, | 81 { 2, CREDIT_CARD_EXP_4_DIGIT_YEAR, |
| 81 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, | 82 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, |
| 82 { 2, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, | 83 { 2, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, |
| 83 1.5 }, | 84 1.5 }, |
| 84 }; | 85 }; |
| 85 | 86 |
| 87 const int kBillingInputsStartRow = 3; |
| 86 const DetailInput kBillingInputs[] = { | 88 const DetailInput kBillingInputs[] = { |
| 87 { 3, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, | 89 { 3, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, |
| 88 { 4, ADDRESS_BILLING_LINE1, | 90 { 4, ADDRESS_BILLING_LINE1, |
| 89 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | 91 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
| 90 { 5, ADDRESS_BILLING_LINE2, | 92 { 5, ADDRESS_BILLING_LINE2, |
| 91 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | 93 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
| 92 { 6, ADDRESS_BILLING_CITY, | 94 { 6, ADDRESS_BILLING_CITY, |
| 93 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | 95 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
| 94 // TODO(estade): state placeholder should depend on locale. | |
| 95 { 7, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | 96 { 7, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, |
| 96 { 7, ADDRESS_BILLING_ZIP, | 97 { 7, ADDRESS_BILLING_ZIP, |
| 97 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | 98 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
| 98 // We don't allow the user to change the country: http://crbug.com/247518 | 99 }; |
| 99 { -1, ADDRESS_BILLING_COUNTRY, 0 }, | 100 |
| 100 { 9, PHONE_BILLING_WHOLE_NUMBER, | 101 const DetailInput kBillingPhoneInputs[] = { |
| 102 { 19, PHONE_BILLING_WHOLE_NUMBER, |
| 101 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | 103 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
| 102 }; | 104 }; |
| 103 | 105 |
| 104 const DetailInput kEmailInputs[] = { | 106 const DetailInput kEmailInputs[] = { |
| 105 { 10, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 107 { 20, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
| 106 }; | 108 }; |
| 107 | 109 |
| 110 const int kShippingInputsStartRow = 21; |
| 108 const DetailInput kShippingInputs[] = { | 111 const DetailInput kShippingInputs[] = { |
| 109 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, | 112 { 21, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, |
| 110 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | 113 { 22, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
| 111 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | 114 { 23, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
| 112 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | 115 { 24, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
| 113 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | 116 { 25, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, |
| 114 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | 117 { 25, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
| 115 { -1, ADDRESS_HOME_COUNTRY, 0 }, | 118 }; |
| 116 { 17, PHONE_HOME_WHOLE_NUMBER, | 119 |
| 120 const DetailInput kShippingPhoneInputs[] = { |
| 121 { 37, PHONE_HOME_WHOLE_NUMBER, |
| 117 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | 122 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
| 118 }; | 123 }; |
| 119 | 124 |
| 120 switch (dialog_section) { | 125 switch (dialog_section) { |
| 121 case SECTION_CC: | 126 case SECTION_CC: |
| 122 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 127 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
| 123 break; | 128 break; |
| 124 | 129 |
| 125 case SECTION_BILLING: | 130 case SECTION_BILLING: |
| 126 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 131 if (i18ninput::IsI18nAddressInputEnabled()) { |
| 132 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING, |
| 133 country_region, |
| 134 kBillingInputsStartRow, |
| 135 inputs); |
| 136 } else { |
| 137 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
| 138 } |
| 139 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
| 127 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); | 140 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); |
| 128 break; | 141 break; |
| 129 | 142 |
| 130 case SECTION_CC_BILLING: | 143 case SECTION_CC_BILLING: |
| 131 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 144 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
| 132 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 145 if (i18ninput::IsI18nAddressInputEnabled()) { |
| 146 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING, |
| 147 country_region, |
| 148 kBillingInputsStartRow, |
| 149 inputs); |
| 150 } else { |
| 151 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); |
| 152 } |
| 153 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); |
| 133 break; | 154 break; |
| 134 | 155 |
| 135 case SECTION_SHIPPING: | 156 case SECTION_SHIPPING: |
| 136 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); | 157 if (i18ninput::IsI18nAddressInputEnabled()) { |
| 158 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_SHIPPING, |
| 159 country_region, |
| 160 kShippingInputsStartRow, |
| 161 inputs); |
| 162 } else { |
| 163 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); |
| 164 } |
| 165 BuildInputs( |
| 166 kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs); |
| 137 break; | 167 break; |
| 138 } | 168 } |
| 139 } | 169 } |
| 140 | 170 |
| 141 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( | 171 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( |
| 142 DialogSection section) { | 172 DialogSection section) { |
| 143 switch (section) { | 173 switch (section) { |
| 144 case SECTION_BILLING: | 174 case SECTION_BILLING: |
| 145 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; | 175 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; |
| 146 | 176 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { | 212 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { |
| 183 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); | 213 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); |
| 184 return country.name(); | 214 return country.name(); |
| 185 } | 215 } |
| 186 | 216 |
| 187 return string16(); | 217 return string16(); |
| 188 } | 218 } |
| 189 | 219 |
| 190 } // namespace common | 220 } // namespace common |
| 191 } // namespace autofill | 221 } // namespace autofill |
| OLD | NEW |