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 { |
18 namespace common { | 19 namespace common { |
19 | 20 |
21 namespace { | |
22 | |
23 const std::string& GetLocale() { | |
24 return g_browser_process->GetApplicationLocale(); | |
25 } | |
26 | |
27 } // namespace | |
28 | |
20 // Returns true if |input| should be shown when |field_type| has been requested. | 29 // Returns true if |input| should be shown when |field_type| has been requested. |
21 bool InputTypeMatchesFieldType(const DetailInput& input, | 30 bool InputTypeMatchesFieldType(const DetailInput& input, |
22 const AutofillType& field_type) { | 31 const AutofillType& field_type) { |
23 // If any credit card expiration info is asked for, show both month and year | 32 // If any credit card expiration info is asked for, show both month and year |
24 // inputs. | 33 // inputs. |
25 ServerFieldType server_type = field_type.GetStorableType(); | 34 ServerFieldType server_type = field_type.GetStorableType(); |
26 if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | 35 if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
27 server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || | 36 server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || |
28 server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || | 37 server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || |
29 server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || | 38 server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
64 // Constructs |inputs| from template data. | 73 // Constructs |inputs| from template data. |
65 void BuildInputs(const DetailInput* input_template, | 74 void BuildInputs(const DetailInput* input_template, |
66 size_t template_size, | 75 size_t template_size, |
67 DetailInputs* inputs) { | 76 DetailInputs* inputs) { |
68 for (size_t i = 0; i < template_size; ++i) { | 77 for (size_t i = 0; i < template_size; ++i) { |
69 const DetailInput* input = &input_template[i]; | 78 const DetailInput* input = &input_template[i]; |
70 inputs->push_back(*input); | 79 inputs->push_back(*input); |
71 } | 80 } |
72 } | 81 } |
73 | 82 |
74 // Constructs |inputs| from template data for a given |dialog_section|. | |
75 void BuildInputsForSection(DialogSection dialog_section, | 83 void BuildInputsForSection(DialogSection dialog_section, |
76 DetailInputs* inputs) { | 84 DetailInputs* inputs, |
85 const std::string& country_region) { | |
77 const DetailInput kCCInputs[] = { | 86 const DetailInput kCCInputs[] = { |
78 { 1, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, | 87 { 1, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, |
79 { 2, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, | 88 { 2, CREDIT_CARD_EXP_MONTH, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_MONTH }, |
80 { 2, CREDIT_CARD_EXP_4_DIGIT_YEAR, | 89 { 2, CREDIT_CARD_EXP_4_DIGIT_YEAR, |
81 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, | 90 IDS_AUTOFILL_DIALOG_PLACEHOLDER_EXPIRY_YEAR }, |
82 { 2, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, | 91 { 2, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, |
83 1.5 }, | 92 1.5 }, |
84 }; | 93 }; |
85 | 94 |
95 const int kBillingInputsStartRow = 3; | |
86 const DetailInput kBillingInputs[] = { | 96 const DetailInput kBillingInputs[] = { |
87 { 3, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, | 97 { 3, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, |
88 { 4, ADDRESS_BILLING_LINE1, | 98 { 4, ADDRESS_BILLING_LINE1, |
89 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | 99 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
90 { 5, ADDRESS_BILLING_LINE2, | 100 { 5, ADDRESS_BILLING_LINE2, |
91 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | 101 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
92 { 6, ADDRESS_BILLING_CITY, | 102 { 6, ADDRESS_BILLING_CITY, |
93 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | 103 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
94 // TODO(estade): state placeholder should depend on locale. | |
95 { 7, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | 104 { 7, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, |
96 { 7, ADDRESS_BILLING_ZIP, | 105 { 7, ADDRESS_BILLING_ZIP, |
97 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | 106 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
98 // We don't allow the user to change the country: http://crbug.com/247518 | 107 }; |
99 { -1, ADDRESS_BILLING_COUNTRY, 0 }, | 108 |
100 { 9, PHONE_BILLING_WHOLE_NUMBER, | 109 const DetailInput kBillingPhoneInputs[] = { |
110 { 19, PHONE_BILLING_WHOLE_NUMBER, | |
101 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | 111 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
102 }; | 112 }; |
103 | 113 |
104 const DetailInput kEmailInputs[] = { | 114 const DetailInput kEmailInputs[] = { |
105 { 10, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 115 { 20, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
106 }; | 116 }; |
107 | 117 |
118 const int kShippingInputsStartRow = 21; | |
108 const DetailInput kShippingInputs[] = { | 119 const DetailInput kShippingInputs[] = { |
109 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, | 120 { 21, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, |
110 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | 121 { 22, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, |
111 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | 122 { 23, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, |
112 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | 123 { 24, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, |
113 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | 124 { 25, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, |
114 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | 125 { 25, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, |
115 { -1, ADDRESS_HOME_COUNTRY, 0 }, | 126 }; |
116 { 17, PHONE_HOME_WHOLE_NUMBER, | 127 |
128 const DetailInput kShippingPhoneInputs[] = { | |
129 { 37, PHONE_HOME_WHOLE_NUMBER, | |
117 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | 130 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, |
118 }; | 131 }; |
119 | 132 |
120 switch (dialog_section) { | 133 switch (dialog_section) { |
121 case SECTION_CC: | 134 case SECTION_CC: |
122 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 135 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
123 break; | 136 break; |
124 | 137 |
125 case SECTION_BILLING: | 138 case SECTION_BILLING: |
126 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 139 if (i18ninput::IsI18nAddressInputEnabled()) { |
140 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING, | |
141 country_region, | |
142 kBillingInputsStartRow, | |
143 inputs); | |
144 } else { | |
145 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | |
146 } | |
147 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); | |
127 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); | 148 BuildInputs(kEmailInputs, arraysize(kEmailInputs), inputs); |
128 break; | 149 break; |
129 | 150 |
130 case SECTION_CC_BILLING: | 151 case SECTION_CC_BILLING: |
131 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); | 152 BuildInputs(kCCInputs, arraysize(kCCInputs), inputs); |
132 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | 153 if (i18ninput::IsI18nAddressInputEnabled()) { |
154 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_BILLING, | |
155 country_region, | |
156 kBillingInputsStartRow, | |
157 inputs); | |
158 } else { | |
159 BuildInputs(kBillingInputs, arraysize(kBillingInputs), inputs); | |
160 } | |
161 BuildInputs(kBillingPhoneInputs, arraysize(kBillingPhoneInputs), inputs); | |
133 break; | 162 break; |
134 | 163 |
135 case SECTION_SHIPPING: | 164 case SECTION_SHIPPING: |
136 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); | 165 if (i18ninput::IsI18nAddressInputEnabled()) { |
166 i18ninput::BuildI18nInputs(i18ninput::ADDRESS_TYPE_SHIPPING, | |
167 country_region, | |
168 kShippingInputsStartRow, | |
169 inputs); | |
170 } else { | |
171 BuildInputs(kShippingInputs, arraysize(kShippingInputs), inputs); | |
172 } | |
173 BuildInputs( | |
174 kShippingPhoneInputs, arraysize(kShippingPhoneInputs), inputs); | |
137 break; | 175 break; |
138 } | 176 } |
139 } | 177 } |
140 | 178 |
141 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( | 179 AutofillMetrics::DialogUiEvent DialogSectionToUiItemAddedEvent( |
142 DialogSection section) { | 180 DialogSection section) { |
143 switch (section) { | 181 switch (section) { |
144 case SECTION_BILLING: | 182 case SECTION_BILLING: |
145 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; | 183 return AutofillMetrics::DIALOG_UI_BILLING_ITEM_ADDED; |
146 | 184 |
(...skipping 24 matching lines...) Expand all Loading... | |
171 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED; | 209 return AutofillMetrics::DIALOG_UI_SHIPPING_SELECTED_SUGGESTION_CHANGED; |
172 | 210 |
173 case SECTION_CC: | 211 case SECTION_CC: |
174 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; | 212 return AutofillMetrics::DIALOG_UI_CC_SELECTED_SUGGESTION_CHANGED; |
175 } | 213 } |
176 | 214 |
177 NOTREACHED(); | 215 NOTREACHED(); |
178 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; | 216 return AutofillMetrics::NUM_DIALOG_UI_EVENTS; |
179 } | 217 } |
180 | 218 |
181 string16 GetHardcodedValueForType(ServerFieldType type) { | 219 base::string16 GetInitialValueForType(ServerFieldType type, |
182 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) { | 220 const std::string& country_code) { |
183 AutofillCountry country("US", g_browser_process->GetApplicationLocale()); | 221 if (AutofillType(type).GetStorableType() == ADDRESS_HOME_COUNTRY) |
184 return country.name(); | 222 return GetCountryName(country_code); |
185 } | 223 return base::string16(); |
224 } | |
186 | 225 |
187 return string16(); | 226 base::string16 GetCountryName(const std::string& country_code) { |
227 return AutofillCountry(country_code, GetLocale()).name(); | |
228 } | |
229 | |
230 std::string GetCountryCode(const base::string16& country_name) { | |
Evan Stade
2013/11/25 19:52:06
I don't think these 2 functions are particularly n
Dan Beam
2013/11/28 02:52:45
Done.
| |
231 return AutofillCountry::GetCountryCode(country_name, GetLocale()); | |
188 } | 232 } |
189 | 233 |
190 } // namespace common | 234 } // namespace common |
191 } // namespace autofill | 235 } // namespace autofill |
OLD | NEW |