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

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

Issue 22040002: [Autofill] Add a separate enumeration for HTML field type hints. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix browser test 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
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_controller_impl.h" 5 #include "chrome/browser/ui/autofill/autofill_dialog_controller_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 10
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 return card_type == autofill::kVisaCard || 108 return card_type == autofill::kVisaCard ||
109 card_type == autofill::kMasterCard || 109 card_type == autofill::kMasterCard ||
110 card_type == autofill::kDiscoverCard; 110 card_type == autofill::kDiscoverCard;
111 } 111 }
112 112
113 // Returns true if |input| should be shown when |field_type| has been requested. 113 // Returns true if |input| should be shown when |field_type| has been requested.
114 bool InputTypeMatchesFieldType(const DetailInput& input, 114 bool InputTypeMatchesFieldType(const DetailInput& input,
115 const AutofillType& field_type) { 115 const AutofillType& field_type) {
116 // If any credit card expiration info is asked for, show both month and year 116 // If any credit card expiration info is asked for, show both month and year
117 // inputs. 117 // inputs.
118 if (field_type.server_type() == CREDIT_CARD_EXP_4_DIGIT_YEAR || 118 ServerFieldType server_type = field_type.GetStorableType();
119 field_type.server_type() == CREDIT_CARD_EXP_2_DIGIT_YEAR || 119 if (server_type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
120 field_type.server_type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || 120 server_type == CREDIT_CARD_EXP_2_DIGIT_YEAR ||
121 field_type.server_type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || 121 server_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR ||
122 field_type.server_type() == CREDIT_CARD_EXP_MONTH) { 122 server_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR ||
123 server_type == CREDIT_CARD_EXP_MONTH) {
123 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR || 124 return input.type == CREDIT_CARD_EXP_4_DIGIT_YEAR ||
124 input.type == CREDIT_CARD_EXP_MONTH; 125 input.type == CREDIT_CARD_EXP_MONTH;
125 } 126 }
126 127
127 if (field_type.server_type() == CREDIT_CARD_TYPE) 128 if (server_type == CREDIT_CARD_TYPE)
128 return input.type == CREDIT_CARD_NUMBER; 129 return input.type == CREDIT_CARD_NUMBER;
129 130
130 return input.type == field_type.server_type(); 131 // Check the groups to distinguish billing types from shipping ones.
132 AutofillType input_type = AutofillType(input.type);
133 return input_type.GetStorableType() == server_type &&
134 input_type.group() == field_type.group();
131 } 135 }
132 136
133 // Returns true if |input| in the given |section| should be used for a 137 // Returns true if |input| in the given |section| should be used for a
134 // site-requested |field|. 138 // site-requested |field|.
135 bool DetailInputMatchesField(DialogSection section, 139 bool DetailInputMatchesField(DialogSection section,
136 const DetailInput& input, 140 const DetailInput& input,
137 const AutofillField& field) { 141 const AutofillField& field) {
138 AutofillType field_type = field.Type(); 142 AutofillType field_type = field.Type();
139 143
140 // The credit card name is filled from the billing section's data. 144 // The credit card name is filled from the billing section's data.
141 if (field_type.server_type() == CREDIT_CARD_NAME && 145 if (field_type.GetStorableType() == CREDIT_CARD_NAME &&
142 (section == SECTION_BILLING || section == SECTION_CC_BILLING)) { 146 (section == SECTION_BILLING || section == SECTION_CC_BILLING)) {
143 return input.type == NAME_BILLING_FULL; 147 return input.type == NAME_BILLING_FULL;
144 } 148 }
145 149
146 return InputTypeMatchesFieldType(input, field_type); 150 return InputTypeMatchesFieldType(input, field_type);
147 } 151 }
148 152
149 bool IsCreditCardType(ServerFieldType type) { 153 bool IsCreditCardType(ServerFieldType type) {
150 return AutofillType(type).group() == CREDIT_CARD; 154 return AutofillType(type).group() == CREDIT_CARD;
151 } 155 }
152 156
153 // Returns true if |input| should be used to fill a site-requested |field| which 157 // Returns true if |input| should be used to fill a site-requested |field| which
154 // is notated with a "shipping" tag, for use when the user has decided to use 158 // is notated with a "shipping" tag, for use when the user has decided to use
155 // the billing address as the shipping address. 159 // the billing address as the shipping address.
156 bool DetailInputMatchesShippingField(const DetailInput& input, 160 bool DetailInputMatchesShippingField(const DetailInput& input,
157 const AutofillField& field) { 161 const AutofillField& field) {
158 // Equivalent billing field type is used to support UseBillingAsShipping 162 // Equivalent billing field type is used to support UseBillingAsShipping
159 // usecase. 163 // usecase.
160 ServerFieldType field_type = 164 ServerFieldType field_type =
161 AutofillType::GetEquivalentBillingFieldType(field.Type().server_type()); 165 AutofillType::GetEquivalentBillingFieldType(
166 field.Type().GetStorableType());
162 167
163 return InputTypeMatchesFieldType(input, AutofillType(field_type)); 168 return InputTypeMatchesFieldType(input, AutofillType(field_type));
164 } 169 }
165 170
166 // Constructs |inputs| from template data. 171 // Constructs |inputs| from template data.
167 void BuildInputs(const DetailInput* input_template, 172 void BuildInputs(const DetailInput* input_template,
168 size_t template_size, 173 size_t template_size,
169 DetailInputs* inputs) { 174 DetailInputs* inputs) {
170 for (size_t i = 0; i < template_size; ++i) { 175 for (size_t i = 0; i < template_size; ++i) {
171 const DetailInput* input = &input_template[i]; 176 const DetailInput* input = &input_template[i];
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 if (!invoked_from_same_origin_) { 534 if (!invoked_from_same_origin_) {
530 GetMetricLogger().LogDialogSecurityMetric( 535 GetMetricLogger().LogDialogSecurityMetric(
531 GetDialogType(), 536 GetDialogType(),
532 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); 537 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME);
533 } 538 }
534 539
535 // Determine what field types should be included in the dialog. 540 // Determine what field types should be included in the dialog.
536 bool has_types = false; 541 bool has_types = false;
537 bool has_sections = false; 542 bool has_sections = false;
538 form_structure_.ParseFieldTypesFromAutocompleteAttributes( 543 form_structure_.ParseFieldTypesFromAutocompleteAttributes(
539 FormStructure::PARSE_FOR_AUTOFILL_DIALOG, &has_types, &has_sections); 544 &has_types, &has_sections);
540 545
541 // Fail if the author didn't specify autocomplete types. 546 // Fail if the author didn't specify autocomplete types.
542 if (!has_types) { 547 if (!has_types) {
543 callback_.Run(NULL, std::string()); 548 callback_.Run(NULL, std::string());
544 delete this; 549 delete this;
545 return; 550 return;
546 } 551 }
547 552
548 const DetailInput kEmailInputs[] = { 553 const DetailInput kEmailInputs[] = {
549 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, 554 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL },
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1193 case SECTION_SHIPPING: 1198 case SECTION_SHIPPING:
1194 return requested_shipping_fields_; 1199 return requested_shipping_fields_;
1195 } 1200 }
1196 1201
1197 NOTREACHED(); 1202 NOTREACHED();
1198 return requested_billing_fields_; 1203 return requested_billing_fields_;
1199 } 1204 }
1200 1205
1201 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( 1206 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType(
1202 ServerFieldType type) { 1207 ServerFieldType type) {
1203 switch (AutofillType::GetEquivalentFieldType(type)) { 1208 switch (type) {
1204 case CREDIT_CARD_EXP_MONTH: 1209 case CREDIT_CARD_EXP_MONTH:
1205 return &cc_exp_month_combobox_model_; 1210 return &cc_exp_month_combobox_model_;
1206 1211
1207 case CREDIT_CARD_EXP_4_DIGIT_YEAR: 1212 case CREDIT_CARD_EXP_4_DIGIT_YEAR:
1208 return &cc_exp_year_combobox_model_; 1213 return &cc_exp_year_combobox_model_;
1209 1214
1210 case ADDRESS_HOME_COUNTRY: 1215 case ADDRESS_HOME_COUNTRY:
1216 case ADDRESS_BILLING_COUNTRY:
1211 return &country_combobox_model_; 1217 return &country_combobox_model_;
1212 1218
1213 default: 1219 default:
1214 return NULL; 1220 return NULL;
1215 } 1221 }
1216 } 1222 }
1217 1223
1218 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( 1224 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection(
1219 DialogSection section) { 1225 DialogSection section) {
1220 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); 1226 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section);
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
1566 if (it != wallet_errors_.end()) { 1572 if (it != wallet_errors_.end()) {
1567 TypeErrorInputMap::const_iterator iter = it->second.find(type); 1573 TypeErrorInputMap::const_iterator iter = it->second.find(type);
1568 if (iter != it->second.end()) { 1574 if (iter != it->second.end()) {
1569 if (iter->second.second == value) 1575 if (iter->second.second == value)
1570 return iter->second.first; 1576 return iter->second.first;
1571 it->second.erase(type); 1577 it->second.erase(type);
1572 } 1578 }
1573 } 1579 }
1574 } 1580 }
1575 1581
1576 switch (AutofillType::GetEquivalentFieldType(type)) { 1582 switch (AutofillType(type).GetStorableType()) {
1577 case EMAIL_ADDRESS: 1583 case EMAIL_ADDRESS:
1578 if (!value.empty() && !IsValidEmailAddress(value)) { 1584 if (!value.empty() && !IsValidEmailAddress(value)) {
1579 return l10n_util::GetStringUTF16( 1585 return l10n_util::GetStringUTF16(
1580 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_EMAIL_ADDRESS); 1586 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_EMAIL_ADDRESS);
1581 } 1587 }
1582 break; 1588 break;
1583 1589
1584 case CREDIT_CARD_NUMBER: { 1590 case CREDIT_CARD_NUMBER: {
1585 if (!value.empty()) { 1591 if (!value.empty()) {
1586 base::string16 message = CreditCardNumberValidityMessage(value); 1592 base::string16 message = CreditCardNumberValidityMessage(value);
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after
2319 if (popup_controller_.get()) 2325 if (popup_controller_.get())
2320 return popup_controller_->HandleKeyPressEvent(event); 2326 return popup_controller_->HandleKeyPressEvent(event);
2321 2327
2322 return false; 2328 return false;
2323 } 2329 }
2324 2330
2325 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { 2331 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const {
2326 DCHECK_GT(form_structure_.field_count(), 0U); 2332 DCHECK_GT(form_structure_.field_count(), 0U);
2327 2333
2328 for (size_t i = 0; i < form_structure_.field_count(); ++i) { 2334 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
2329 if (IsCreditCardType(form_structure_.field(i)->Type().server_type())) 2335 AutofillType type = form_structure_.field(i)->Type();
2336 if (IsCreditCardType(type.GetStorableType()))
2330 return true; 2337 return true;
2331 } 2338 }
2332 2339
2333 return false; 2340 return false;
2334 } 2341 }
2335 2342
2336 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { 2343 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const {
2337 return source_url_.SchemeIs(chrome::kHttpsScheme); 2344 return source_url_.SchemeIs(chrome::kHttpsScheme);
2338 } 2345 }
2339 2346
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
2779 // any of the fields. 2786 // any of the fields.
2780 if (section == SECTION_SHIPPING) 2787 if (section == SECTION_SHIPPING)
2781 return cares_about_shipping_; 2788 return cares_about_shipping_;
2782 2789
2783 return true; 2790 return true;
2784 } 2791 }
2785 2792
2786 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { 2793 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) {
2787 for (size_t i = 0; i < form_structure_.field_count(); ++i) { 2794 for (size_t i = 0; i < form_structure_.field_count(); ++i) {
2788 AutofillField* field = form_structure_.field(i); 2795 AutofillField* field = form_structure_.field(i);
2789 if (field->Type().server_type() == CREDIT_CARD_VERIFICATION_CODE) { 2796 if (field->Type().GetStorableType() == CREDIT_CARD_VERIFICATION_CODE) {
2790 field->value = cvc; 2797 field->value = cvc;
2791 break; 2798 break;
2792 } 2799 }
2793 } 2800 }
2794 } 2801 }
2795 2802
2796 string16 AutofillDialogControllerImpl::GetValueFromSection( 2803 string16 AutofillDialogControllerImpl::GetValueFromSection(
2797 DialogSection section, 2804 DialogSection section,
2798 ServerFieldType type) { 2805 ServerFieldType type) {
2799 DCHECK(SectionIsActive(section)); 2806 DCHECK(SectionIsActive(section));
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
3473 view_->GetUserInput(SECTION_CC_BILLING, &output); 3480 view_->GetUserInput(SECTION_CC_BILLING, &output);
3474 CreditCard card; 3481 CreditCard card;
3475 GetBillingInfoFromOutputs(output, &card, NULL, NULL); 3482 GetBillingInfoFromOutputs(output, &card, NULL, NULL);
3476 backing_last_four = card.TypeAndLastFourDigits(); 3483 backing_last_four = card.TypeAndLastFourDigits();
3477 } 3484 }
3478 AutofillCreditCardBubbleController::ShowGeneratedCardUI( 3485 AutofillCreditCardBubbleController::ShowGeneratedCardUI(
3479 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); 3486 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits());
3480 } 3487 }
3481 3488
3482 } // namespace autofill 3489 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698