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_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 Loading... |
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.native_type() == CREDIT_CARD_EXP_4_DIGIT_YEAR || | 118 NativeFieldType native_type = field_type.GetEquivalentNativeType(); |
119 field_type.native_type() == CREDIT_CARD_EXP_2_DIGIT_YEAR || | 119 if (native_type == CREDIT_CARD_EXP_4_DIGIT_YEAR || |
120 field_type.native_type() == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || | 120 native_type == CREDIT_CARD_EXP_2_DIGIT_YEAR || |
121 field_type.native_type() == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || | 121 native_type == CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR || |
122 field_type.native_type() == CREDIT_CARD_EXP_MONTH) { | 122 native_type == CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR || |
| 123 native_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.native_type() == CREDIT_CARD_TYPE) | 128 if (native_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.native_type(); | 131 // Check the groups to distinguish billing types from shipping ones. |
| 132 AutofillType input_type = AutofillType(input.type); |
| 133 return input_type.GetEquivalentNativeType() == native_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.native_type() == CREDIT_CARD_NAME && | 145 if (field_type.GetEquivalentNativeType() == 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(NativeFieldType type) { | 153 bool IsCreditCardType(NativeFieldType 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 NativeFieldType field_type = | 164 NativeFieldType field_type = |
161 AutofillType::GetEquivalentBillingFieldType(field.Type().native_type()); | 165 AutofillType::GetEquivalentBillingFieldType( |
| 166 field.Type().GetEquivalentNativeType()); |
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 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 if (!invoked_from_same_origin_) { | 532 if (!invoked_from_same_origin_) { |
528 GetMetricLogger().LogDialogSecurityMetric( | 533 GetMetricLogger().LogDialogSecurityMetric( |
529 GetDialogType(), | 534 GetDialogType(), |
530 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); | 535 AutofillMetrics::SECURITY_METRIC_CROSS_ORIGIN_FRAME); |
531 } | 536 } |
532 | 537 |
533 // Determine what field types should be included in the dialog. | 538 // Determine what field types should be included in the dialog. |
534 bool has_types = false; | 539 bool has_types = false; |
535 bool has_sections = false; | 540 bool has_sections = false; |
536 form_structure_.ParseFieldTypesFromAutocompleteAttributes( | 541 form_structure_.ParseFieldTypesFromAutocompleteAttributes( |
537 FormStructure::PARSE_FOR_AUTOFILL_DIALOG, &has_types, &has_sections); | 542 &has_types, &has_sections); |
538 | 543 |
539 // Fail if the author didn't specify autocomplete types. | 544 // Fail if the author didn't specify autocomplete types. |
540 if (!has_types) { | 545 if (!has_types) { |
541 callback_.Run(NULL, std::string()); | 546 callback_.Run(NULL, std::string()); |
542 delete this; | 547 delete this; |
543 return; | 548 return; |
544 } | 549 } |
545 | 550 |
546 const DetailInput kEmailInputs[] = { | 551 const DetailInput kEmailInputs[] = { |
547 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, | 552 { 1, EMAIL_ADDRESS, IDS_AUTOFILL_DIALOG_PLACEHOLDER_EMAIL }, |
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 case SECTION_SHIPPING: | 1196 case SECTION_SHIPPING: |
1192 return requested_shipping_fields_; | 1197 return requested_shipping_fields_; |
1193 } | 1198 } |
1194 | 1199 |
1195 NOTREACHED(); | 1200 NOTREACHED(); |
1196 return requested_billing_fields_; | 1201 return requested_billing_fields_; |
1197 } | 1202 } |
1198 | 1203 |
1199 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( | 1204 ui::ComboboxModel* AutofillDialogControllerImpl::ComboboxModelForAutofillType( |
1200 NativeFieldType type) { | 1205 NativeFieldType type) { |
1201 switch (AutofillType::GetEquivalentFieldType(type)) { | 1206 switch (type) { |
1202 case CREDIT_CARD_EXP_MONTH: | 1207 case CREDIT_CARD_EXP_MONTH: |
1203 return &cc_exp_month_combobox_model_; | 1208 return &cc_exp_month_combobox_model_; |
1204 | 1209 |
1205 case CREDIT_CARD_EXP_4_DIGIT_YEAR: | 1210 case CREDIT_CARD_EXP_4_DIGIT_YEAR: |
1206 return &cc_exp_year_combobox_model_; | 1211 return &cc_exp_year_combobox_model_; |
1207 | 1212 |
1208 case ADDRESS_HOME_COUNTRY: | 1213 case ADDRESS_HOME_COUNTRY: |
| 1214 case ADDRESS_BILLING_COUNTRY: |
1209 return &country_combobox_model_; | 1215 return &country_combobox_model_; |
1210 | 1216 |
1211 default: | 1217 default: |
1212 return NULL; | 1218 return NULL; |
1213 } | 1219 } |
1214 } | 1220 } |
1215 | 1221 |
1216 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( | 1222 ui::MenuModel* AutofillDialogControllerImpl::MenuModelForSection( |
1217 DialogSection section) { | 1223 DialogSection section) { |
1218 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); | 1224 SuggestionsMenuModel* model = SuggestionsMenuModelForSection(section); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 if (it != wallet_errors_.end()) { | 1568 if (it != wallet_errors_.end()) { |
1563 TypeErrorInputMap::const_iterator iter = it->second.find(type); | 1569 TypeErrorInputMap::const_iterator iter = it->second.find(type); |
1564 if (iter != it->second.end()) { | 1570 if (iter != it->second.end()) { |
1565 if (iter->second.second == value) | 1571 if (iter->second.second == value) |
1566 return iter->second.first; | 1572 return iter->second.first; |
1567 it->second.erase(type); | 1573 it->second.erase(type); |
1568 } | 1574 } |
1569 } | 1575 } |
1570 } | 1576 } |
1571 | 1577 |
1572 switch (AutofillType::GetEquivalentFieldType(type)) { | 1578 switch (AutofillType(type).GetEquivalentNativeType()) { |
1573 case EMAIL_ADDRESS: | 1579 case EMAIL_ADDRESS: |
1574 if (!value.empty() && !IsValidEmailAddress(value)) { | 1580 if (!value.empty() && !IsValidEmailAddress(value)) { |
1575 return l10n_util::GetStringUTF16( | 1581 return l10n_util::GetStringUTF16( |
1576 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_EMAIL_ADDRESS); | 1582 IDS_AUTOFILL_DIALOG_VALIDATION_INVALID_EMAIL_ADDRESS); |
1577 } | 1583 } |
1578 break; | 1584 break; |
1579 | 1585 |
1580 case CREDIT_CARD_NUMBER: { | 1586 case CREDIT_CARD_NUMBER: { |
1581 if (!value.empty()) { | 1587 if (!value.empty()) { |
1582 base::string16 message = CreditCardNumberValidityMessage(value); | 1588 base::string16 message = CreditCardNumberValidityMessage(value); |
(...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2315 if (popup_controller_.get()) | 2321 if (popup_controller_.get()) |
2316 return popup_controller_->HandleKeyPressEvent(event); | 2322 return popup_controller_->HandleKeyPressEvent(event); |
2317 | 2323 |
2318 return false; | 2324 return false; |
2319 } | 2325 } |
2320 | 2326 |
2321 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { | 2327 bool AutofillDialogControllerImpl::RequestingCreditCardInfo() const { |
2322 DCHECK_GT(form_structure_.field_count(), 0U); | 2328 DCHECK_GT(form_structure_.field_count(), 0U); |
2323 | 2329 |
2324 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 2330 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
2325 if (IsCreditCardType(form_structure_.field(i)->Type().native_type())) | 2331 AutofillType type = form_structure_.field(i)->Type(); |
| 2332 if (IsCreditCardType(type.GetEquivalentNativeType())) |
2326 return true; | 2333 return true; |
2327 } | 2334 } |
2328 | 2335 |
2329 return false; | 2336 return false; |
2330 } | 2337 } |
2331 | 2338 |
2332 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { | 2339 bool AutofillDialogControllerImpl::TransmissionWillBeSecure() const { |
2333 return source_url_.SchemeIs(chrome::kHttpsScheme); | 2340 return source_url_.SchemeIs(chrome::kHttpsScheme); |
2334 } | 2341 } |
2335 | 2342 |
(...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2780 // any of the fields. | 2787 // any of the fields. |
2781 if (section == SECTION_SHIPPING) | 2788 if (section == SECTION_SHIPPING) |
2782 return cares_about_shipping_; | 2789 return cares_about_shipping_; |
2783 | 2790 |
2784 return true; | 2791 return true; |
2785 } | 2792 } |
2786 | 2793 |
2787 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { | 2794 void AutofillDialogControllerImpl::SetCvcResult(const string16& cvc) { |
2788 for (size_t i = 0; i < form_structure_.field_count(); ++i) { | 2795 for (size_t i = 0; i < form_structure_.field_count(); ++i) { |
2789 AutofillField* field = form_structure_.field(i); | 2796 AutofillField* field = form_structure_.field(i); |
2790 if (field->Type().native_type() == CREDIT_CARD_VERIFICATION_CODE) { | 2797 if (field->Type().GetEquivalentNativeType() == |
| 2798 CREDIT_CARD_VERIFICATION_CODE) { |
2791 field->value = cvc; | 2799 field->value = cvc; |
2792 break; | 2800 break; |
2793 } | 2801 } |
2794 } | 2802 } |
2795 } | 2803 } |
2796 | 2804 |
2797 string16 AutofillDialogControllerImpl::GetValueFromSection( | 2805 string16 AutofillDialogControllerImpl::GetValueFromSection( |
2798 DialogSection section, | 2806 DialogSection section, |
2799 NativeFieldType type) { | 2807 NativeFieldType type) { |
2800 DCHECK(SectionIsActive(section)); | 2808 DCHECK(SectionIsActive(section)); |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3474 view_->GetUserInput(SECTION_CC_BILLING, &output); | 3482 view_->GetUserInput(SECTION_CC_BILLING, &output); |
3475 CreditCard card; | 3483 CreditCard card; |
3476 GetBillingInfoFromOutputs(output, &card, NULL, NULL); | 3484 GetBillingInfoFromOutputs(output, &card, NULL, NULL); |
3477 backing_last_four = card.TypeAndLastFourDigits(); | 3485 backing_last_four = card.TypeAndLastFourDigits(); |
3478 } | 3486 } |
3479 AutofillCreditCardBubbleController::ShowGeneratedCardUI( | 3487 AutofillCreditCardBubbleController::ShowGeneratedCardUI( |
3480 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); | 3488 web_contents(), backing_last_four, full_wallet_->TypeAndLastFourDigits()); |
3481 } | 3489 } |
3482 | 3490 |
3483 } // namespace autofill | 3491 } // namespace autofill |
OLD | NEW |