Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: chrome/browser/ui/autofill/autofill_dialog_common.cc

Issue 22623002: Extract AutofillDialogController interface and common utilities. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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_common.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 namespace common {
17
18 // Returns true if |input| should be shown when |field_type| has been requested.
19 bool InputTypeMatchesFieldType(const DetailInput& input,
20 const AutofillType& field_type) {
21 // If any credit card expiration info is asked for, show both month and year
22 // inputs.
23 ServerFieldType server_type = field_type.GetStorableType();
24 if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
25 server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
26 server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR ||
27 server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR ||
28 server_type == CREDIT_CARD_EXP_MONTH) {
29 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
30 input.type == CREDIT_CARD_EXP_MONTH;
31 }
32
33 if (server_type == CREDIT_CARD_TYPE)
34 return input.type == CREDIT_CARD_NUMBER;
35
36 // Check the groups to distinguish billing types from shipping ones.
37 AutofillType input_type = AutofillType(input.type);
38 return input_type.GetStorableType() == server_type &&
39 input_type.group() == field_type.group();
40 }
41
42 // Returns true if |input| in the given |section| should be used for a
43 // site-requested |field|.
44 bool DetailInputMatchesField(DialogSection section,
45 const DetailInput& input,
46 const AutofillField& field) {
47 AutofillType field_type = field.Type();
48
49 // The credit card name is filled from the billing section's data.
50 if (field_type.GetStorableType() == CREDIT_CARD_NAME &&
51 (section == SECTION_BILLING || section == SECTION_CC_BILLING)) {
52 return input.type == NAME_BILLING_FULL;
53 }
54
55 return InputTypeMatchesFieldType(input, field_type);
56 }
57
58 bool IsCreditCardType(ServerFieldType type) {
59 return AutofillType(type).group() == CREDIT_CARD;
60 }
61
62 // Constructs |inputs| from template data.
63 void BuildInputs(const DetailInput* input_template,
64 size_t template_size,
65 DetailInputs* inputs) {
66 for (size_t i = 0; i < template_size; ++i) {
67 const DetailInput* input = &input_template[i];
68 inputs->push_back(*input);
69 }
70 }
71
72 // Constructs |inputs| from template data for a given |dialog_section|.
73 void BuildInputsForSection(DialogSection dialog_section,
74 DetailInputs* inputs) {
75 const DetailInput kEmailInputs[] = {
76 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL },
77 };
78
79 const DetailInput kCCInputs[] = {
80 { 2, CREDIT_CARD_NUMBER, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARD_NUMBER },
81 { 3, CREDIT_CARD_EXP_MONTH },
82 { 3, CREDIT_CARD_EXP_4_DIGIT_YEAR },
83 { 3, CREDIT_CARD_VERIFICATION_CODE, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC,
84 1.5 },
85 };
86
87 const DetailInput kBillingInputs[] = {
88 { 4, NAME_BILLING_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_CARDHOLDER_NAME },
89 { 5, ADDRESS_BILLING_LINE1,
90 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
91 { 6, ADDRESS_BILLING_LINE2,
92 IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
93 { 7, ADDRESS_BILLING_CITY,
94 IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
95 // TODO(estade): state placeholder should depend on locale.
96 { 8, ADDRESS_BILLING_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
97 { 8, ADDRESS_BILLING_ZIP,
98 IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
99 // We don't allow the user to change the country: http://crbug.com/247518
100 { -1, ADDRESS_BILLING_COUNTRY, 0 },
101 { 10, PHONE_BILLING_WHOLE_NUMBER,
102 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
103 };
104
105 const DetailInput kShippingInputs[] = {
106 { 11, NAME_FULL, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESSEE_NAME },
107 { 12, ADDRESS_HOME_LINE1, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_1 },
108 { 13, ADDRESS_HOME_LINE2, IDS_AUTOFILL_DIALOG_PLACEHOLDER_ADDRESS_LINE_2 },
109 { 14, ADDRESS_HOME_CITY, IDS_AUTOFILL_DIALOG_PLACEHOLDER_LOCALITY },
110 { 15, ADDRESS_HOME_STATE, IDS_AUTOFILL_FIELD_LABEL_STATE },
111 { 15, ADDRESS_HOME_ZIP, IDS_AUTOFILL_DIALOG_PLACEHOLDER_POSTAL_CODE },
112 { -1, ADDRESS_HOME_COUNTRY, 0 },
113 { 17, PHONE_HOME_WHOLE_NUMBER,
114 IDS_AUTOFILL_DIALOG_PLACEHOLDER_PHONE_NUMBER },
115 };
116
117 switch (dialog_section) {
118 case SECTION_EMAIL:
119 BuildInputs(kEmailInputs,
120 arraysize(kEmailInputs),
121 inputs);
122 break;
123
124 case SECTION_CC:
125 BuildInputs(kCCInputs,
126 arraysize(kCCInputs),
127 inputs);
128 break;
129
130 case SECTION_BILLING:
131 BuildInputs(kBillingInputs,
132 arraysize(kBillingInputs),
133 inputs);
134 break;
135
136 case SECTION_CC_BILLING:
137 BuildInputs(kCCInputs,
138 arraysize(kCCInputs),
139 inputs);
140 BuildInputs(kBillingInputs,
141 arraysize(kBillingInputs),
142 inputs);
143 break;
144
145 case SECTION_SHIPPING:
146 BuildInputs(kShippingInputs,
147 arraysize(kShippingInputs),
148 inputs);
149 break;
150 }
151 }
152
153 } // namespace common
154 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698