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_utils.h" | |
6 | |
7 #include "components/autofill/core/browser/autofill_field.h" | |
8 #include "components/autofill/core/browser/autofill_type.h" | |
9 #include "grit/chromium_strings.h" | |
10 #include "grit/component_strings.h" | |
11 #include "grit/generated_resources.h" | |
12 #include "grit/theme_resources.h" | |
13 #include "grit/webkit_resources.h" | |
14 | |
15 namespace autofill { | |
16 | |
17 namespace utils { | |
18 | |
19 const DetailInput kEmailInputs[] = { | |
Evan Stade
2013/08/01 19:44:52
I think it's better not to statically initialize a
aruslan
2013/08/07 23:17:03
Done.
| |
20 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | |
21 }; | |
22 | |
23 const DetailInput kCCInputs[] = { | |
24 { 2, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER }, | |
25 { 3, CREDIT_CARD_EXP_MONTH }, | |
26 { 3, CREDIT_CARD_EXP_4_DIGIT_YEAR }, | |
27 { 3, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC, | |
28 1.5 }, | |
29 }; | |
30 | |
31 const DetailInput kBillingInputs[] = { | |
32 { 4, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME }, | |
33 { 5, ADDRESS_BILLING_LINE1, | |
34 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | |
35 { 6, ADDRESS_BILLING_LINE2, | |
36 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | |
37 { 7, ADDRESS_BILLING_CITY, | |
38 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | |
39 // TODO(estade): state placeholder should depend on locale. | |
40 { 8, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | |
41 { 8, ADDRESS_BILLING_ZIP, | |
42 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | |
43 // We don't allow the user to change the country: http://crbug.com/247518 | |
44 { -1, ADDRESS_BILLING_COUNTRY, 0 }, | |
45 { 10, PHONE_BILLING_WHOLE_NUMBER, | |
46 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | |
47 }; | |
48 | |
49 const DetailInput kShippingInputs[] = { | |
50 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME }, | |
51 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 }, | |
52 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 }, | |
53 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY }, | |
54 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE }, | |
55 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE }, | |
56 { -1, ADDRESS_HOME_COUNTRY, 0 }, | |
57 { 17, PHONE_HOME_WHOLE_NUMBER, | |
58 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER }, | |
59 }; | |
60 | |
61 // Returns true if |input| should be shown when |field_type| has been requested. | |
62 bool InputTypeMatchesFieldType(const DetailInput& input, | |
63 AutofillFieldType field_type) { | |
64 // If any credit card expiration info is asked for, show both month and year | |
65 // inputs. | |
66 if (field_type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | |
67 field_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || | |
68 field_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || | |
69 field_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || | |
70 field_type == CREDIT_CARD_EXP_MONTH) { | |
71 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR || | |
72 input.type == CREDIT_CARD_EXP_MONTH; | |
73 } | |
74 | |
75 if (field_type == CREDIT_CARD_TYPE) | |
76 return input.type == CREDIT_CARD_NUMBER; | |
77 | |
78 return input.type == field_type; | |
79 } | |
80 | |
81 // Returns true if |input| in the given |section| should be used for a | |
82 // site-requested |field|. | |
83 bool DetailInputMatchesField(DialogSection section, | |
84 const DetailInput& input, | |
85 const AutofillField& field) { | |
86 // The credit card name is filled from the billing section's data. | |
87 if (field.type() == CREDIT_CARD_NAME && | |
88 (section == SECTION_BILLING || section == SECTION_CC_BILLING)) { | |
89 return input.type == NAME_FULL; | |
90 } | |
91 | |
92 return InputTypeMatchesFieldType(input, field.type()); | |
93 } | |
94 | |
95 bool IsCreditCardType(AutofillFieldType type) { | |
96 return AutofillType(type).group() == AutofillType::CREDIT_CARD; | |
97 } | |
98 | |
99 // Constructs |inputs| from template data. | |
100 void BuildInputs(const DetailInput* input_template, | |
101 size_t template_size, | |
102 DetailInputs* inputs) { | |
103 for (size_t i = 0; i < template_size; ++i) { | |
104 const DetailInput* input = &input_template[i]; | |
105 inputs->push_back(*input); | |
106 } | |
107 } | |
108 | |
109 // Constructs |inputs| from template data for a given |dialog_section|. | |
110 void BuildInputsForSection(DialogSection dialog_section, | |
111 DetailInputs* inputs) { | |
112 switch (dialog_section) { | |
113 case SECTION_EMAIL: | |
114 BuildInputs(kEmailInputs, | |
115 arraysize(kEmailInputs), | |
116 inputs); | |
117 break; | |
118 | |
119 case SECTION_CC: | |
120 BuildInputs(kCCInputs, | |
121 arraysize(kCCInputs), | |
122 inputs); | |
123 break; | |
124 | |
125 case SECTION_BILLING: | |
126 BuildInputs(kBillingInputs, | |
127 arraysize(kBillingInputs), | |
128 inputs); | |
129 break; | |
130 | |
131 case SECTION_CC_BILLING: | |
132 BuildInputs(kCCInputs, | |
133 arraysize(kCCInputs), | |
134 inputs); | |
135 BuildInputs(kBillingInputs, | |
136 arraysize(kBillingInputs), | |
137 inputs); | |
138 break; | |
139 | |
140 case SECTION_SHIPPING: | |
141 BuildInputs(kShippingInputs, | |
142 arraysize(kShippingInputs), | |
143 inputs); | |
144 break; | |
145 } | |
146 } | |
147 | |
148 } // namespace utils | |
149 } // namespace autofill | |
OLD | NEW |