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 "components/autofill/core/browser/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <limits> | 9 #include <limits> |
10 #include <map> | 10 #include <map> |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 unmasking_field_ = field; | 584 unmasking_field_ = field; |
585 real_pan_client_.Prepare(); | 585 real_pan_client_.Prepare(); |
586 client()->ShowUnmaskPrompt(unmasking_card_, | 586 client()->ShowUnmaskPrompt(unmasking_card_, |
587 weak_ptr_factory_.GetWeakPtr()); | 587 weak_ptr_factory_.GetWeakPtr()); |
588 credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion(); | 588 credit_card_form_event_logger_->OnDidSelectMaskedServerCardSuggestion(); |
589 return; | 589 return; |
590 } | 590 } |
591 credit_card_form_event_logger_->OnDidFillSuggestion(credit_card); | 591 credit_card_form_event_logger_->OnDidFillSuggestion(credit_card); |
592 } | 592 } |
593 | 593 |
594 FillOrPreviewDataModelForm(action, query_id, form, field, &credit_card, | 594 FillOrPreviewDataModelForm(action, query_id, form, field, credit_card, |
595 variant, true /* is_credit_card */); | 595 variant, true /* is_credit_card */); |
596 } | 596 } |
597 | 597 |
598 void AutofillManager::FillOrPreviewProfileForm( | 598 void AutofillManager::FillOrPreviewProfileForm( |
599 AutofillDriver::RendererFormDataAction action, | 599 AutofillDriver::RendererFormDataAction action, |
600 int query_id, | 600 int query_id, |
601 const FormData& form, | 601 const FormData& form, |
602 const FormFieldData& field, | 602 const FormFieldData& field, |
603 const AutofillProfile& profile, | 603 const AutofillProfile& profile, |
604 size_t variant) { | 604 size_t variant) { |
605 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) | 605 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) |
606 address_form_event_logger_->OnDidFillSuggestion(profile); | 606 address_form_event_logger_->OnDidFillSuggestion(profile); |
607 | 607 |
608 FillOrPreviewDataModelForm(action, query_id, form, field, &profile, variant, | 608 FillOrPreviewDataModelForm(action, query_id, form, field, profile, variant, |
609 false /* is_credit_card */); | 609 false /* is_credit_card */); |
610 } | 610 } |
611 | 611 |
612 void AutofillManager::FillOrPreviewForm( | 612 void AutofillManager::FillOrPreviewForm( |
613 AutofillDriver::RendererFormDataAction action, | 613 AutofillDriver::RendererFormDataAction action, |
614 int query_id, | 614 int query_id, |
615 const FormData& form, | 615 const FormData& form, |
616 const FormFieldData& field, | 616 const FormFieldData& field, |
617 int unique_id) { | 617 int unique_id) { |
618 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) | 618 if (!IsValidFormData(form) || !IsValidFormFieldData(field)) |
(...skipping 17 matching lines...) Expand all Loading... | |
636 void AutofillManager::FillCreditCardForm(int query_id, | 636 void AutofillManager::FillCreditCardForm(int query_id, |
637 const FormData& form, | 637 const FormData& form, |
638 const FormFieldData& field, | 638 const FormFieldData& field, |
639 const CreditCard& credit_card) { | 639 const CreditCard& credit_card) { |
640 if (!IsValidFormData(form) || !IsValidFormFieldData(field) || | 640 if (!IsValidFormData(form) || !IsValidFormFieldData(field) || |
641 !driver_->RendererIsAvailable()) { | 641 !driver_->RendererIsAvailable()) { |
642 return; | 642 return; |
643 } | 643 } |
644 | 644 |
645 FillOrPreviewDataModelForm(AutofillDriver::FORM_DATA_ACTION_FILL, query_id, | 645 FillOrPreviewDataModelForm(AutofillDriver::FORM_DATA_ACTION_FILL, query_id, |
646 form, field, &credit_card, 0, true); | 646 form, field, credit_card, 0, true); |
647 } | 647 } |
648 | 648 |
649 void AutofillManager::OnDidPreviewAutofillFormData() { | 649 void AutofillManager::OnDidPreviewAutofillFormData() { |
650 if (test_delegate_) | 650 if (test_delegate_) |
651 test_delegate_->DidPreviewFormData(); | 651 test_delegate_->DidPreviewFormData(); |
652 } | 652 } |
653 | 653 |
654 void AutofillManager::OnDidFillAutofillFormData(const TimeTicks& timestamp) { | 654 void AutofillManager::OnDidFillAutofillFormData(const TimeTicks& timestamp) { |
655 if (test_delegate_) | 655 if (test_delegate_) |
656 test_delegate_->DidFillFormData(); | 656 test_delegate_->DidFillFormData(); |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1032 if (base::IsValidGUID(credit_card_id.guid)) | 1032 if (base::IsValidGUID(credit_card_id.guid)) |
1033 *credit_card = personal_data_->GetCreditCardByGUID(credit_card_id.guid); | 1033 *credit_card = personal_data_->GetCreditCardByGUID(credit_card_id.guid); |
1034 return !!*credit_card; | 1034 return !!*credit_card; |
1035 } | 1035 } |
1036 | 1036 |
1037 void AutofillManager::FillOrPreviewDataModelForm( | 1037 void AutofillManager::FillOrPreviewDataModelForm( |
1038 AutofillDriver::RendererFormDataAction action, | 1038 AutofillDriver::RendererFormDataAction action, |
1039 int query_id, | 1039 int query_id, |
1040 const FormData& form, | 1040 const FormData& form, |
1041 const FormFieldData& field, | 1041 const FormFieldData& field, |
1042 const AutofillDataModel* data_model, | 1042 const AutofillDataModel& data_model, |
1043 size_t variant, | 1043 size_t variant, |
1044 bool is_credit_card) { | 1044 bool is_credit_card) { |
1045 FormStructure* form_structure = NULL; | 1045 FormStructure* form_structure = NULL; |
1046 AutofillField* autofill_field = NULL; | 1046 AutofillField* autofill_field = NULL; |
1047 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) | 1047 if (!GetCachedFormAndField(form, field, &form_structure, &autofill_field)) |
1048 return; | 1048 return; |
1049 | 1049 |
1050 DCHECK(form_structure); | 1050 DCHECK(form_structure); |
1051 DCHECK(autofill_field); | 1051 DCHECK(autofill_field); |
1052 | 1052 |
1053 FormData result = form; | 1053 FormData result = form; |
1054 | 1054 |
1055 base::string16 profile_full_name; | 1055 base::string16 profile_full_name; |
1056 std::string profile_language_code; | 1056 std::string profile_language_code; |
1057 if (!is_credit_card) { | 1057 if (!is_credit_card) { |
1058 profile_full_name = data_model->GetInfo( | 1058 profile_full_name = data_model.GetInfo( |
1059 AutofillType(NAME_FULL), app_locale_); | 1059 AutofillType(NAME_FULL), app_locale_); |
1060 profile_language_code = | 1060 profile_language_code = |
1061 static_cast<const AutofillProfile*>(data_model)->language_code(); | 1061 static_cast<const AutofillProfile*>(&data_model)->language_code(); |
1062 } | 1062 } |
1063 | 1063 |
1064 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) | |
1065 personal_data_->RecordUseOf(*data_model); | |
1066 | |
1067 // If the relevant section is auto-filled, we should fill |field| but not the | 1064 // If the relevant section is auto-filled, we should fill |field| but not the |
1068 // rest of the form. | 1065 // rest of the form. |
1069 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) { | 1066 if (SectionIsAutofilled(*form_structure, form, autofill_field->section())) { |
1070 for (std::vector<FormFieldData>::iterator iter = result.fields.begin(); | 1067 for (std::vector<FormFieldData>::iterator iter = result.fields.begin(); |
1071 iter != result.fields.end(); ++iter) { | 1068 iter != result.fields.end(); ++iter) { |
1072 if (iter->SameFieldAs(field)) { | 1069 if (iter->SameFieldAs(field)) { |
1073 base::string16 value = data_model->GetInfoForVariant( | 1070 base::string16 value = data_model.GetInfoForVariant( |
1074 autofill_field->Type(), variant, app_locale_); | 1071 autofill_field->Type(), variant, app_locale_); |
1075 if (AutofillField::FillFormField(*autofill_field, | 1072 if (AutofillField::FillFormField(*autofill_field, |
1076 value, | 1073 value, |
1077 profile_language_code, | 1074 profile_language_code, |
1078 app_locale_, | 1075 app_locale_, |
1079 &(*iter))) { | 1076 &(*iter))) { |
1080 // Mark the cached field as autofilled, so that we can detect when a | 1077 // Mark the cached field as autofilled, so that we can detect when a |
1081 // user edits an autofilled field (for metrics). | 1078 // user edits an autofilled field (for metrics). |
1082 autofill_field->is_autofilled = true; | 1079 autofill_field->is_autofilled = true; |
1083 | 1080 |
1084 // Mark the field as autofilled when a non-empty value is assigned to | 1081 // Mark the field as autofilled when a non-empty value is assigned to |
1085 // it. This allows the renderer to distinguish autofilled fields from | 1082 // it. This allows the renderer to distinguish autofilled fields from |
1086 // fields with non-empty values, such as select-one fields. | 1083 // fields with non-empty values, such as select-one fields. |
1087 iter->is_autofilled = true; | 1084 iter->is_autofilled = true; |
1088 | 1085 |
1089 if (!is_credit_card && !value.empty()) | 1086 if (!is_credit_card && !value.empty()) |
1090 client_->DidFillOrPreviewField(value, profile_full_name); | 1087 client_->DidFillOrPreviewField(value, profile_full_name); |
1091 } | 1088 } |
1092 break; | 1089 break; |
1093 } | 1090 } |
1094 } | 1091 } |
1095 | 1092 |
1096 driver_->SendFormDataToRenderer(query_id, action, result); | 1093 driver_->SendFormDataToRenderer(query_id, action, result); |
1094 | |
1095 // Note that this may invalidate |data_model|, particularly if it is a Mac | |
1096 // address book entry. | |
1097 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) | |
1098 personal_data_->RecordUseOf(data_model); | |
Evan Stade
2015/02/18 21:05:35
as you can see, the meat of the change is moving t
| |
1099 | |
1097 return; | 1100 return; |
1098 } | 1101 } |
1099 | 1102 |
1100 // Cache the field type for the field from which the user initiated autofill. | 1103 // Cache the field type for the field from which the user initiated autofill. |
1101 FieldTypeGroup initiating_group_type = autofill_field->Type().group(); | 1104 FieldTypeGroup initiating_group_type = autofill_field->Type().group(); |
1102 DCHECK_EQ(form_structure->field_count(), form.fields.size()); | 1105 DCHECK_EQ(form_structure->field_count(), form.fields.size()); |
1103 for (size_t i = 0; i < form_structure->field_count(); ++i) { | 1106 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
1104 if (form_structure->field(i)->section() != autofill_field->section()) | 1107 if (form_structure->field(i)->section() != autofill_field->section()) |
1105 continue; | 1108 continue; |
1106 | 1109 |
1107 DCHECK(form_structure->field(i)->SameFieldAs(result.fields[i])); | 1110 DCHECK(form_structure->field(i)->SameFieldAs(result.fields[i])); |
1108 | 1111 |
1109 const AutofillField* cached_field = form_structure->field(i); | 1112 const AutofillField* cached_field = form_structure->field(i); |
1110 FieldTypeGroup field_group_type = cached_field->Type().group(); | 1113 FieldTypeGroup field_group_type = cached_field->Type().group(); |
1111 | 1114 |
1112 if (field_group_type == NO_GROUP) | 1115 if (field_group_type == NO_GROUP) |
1113 continue; | 1116 continue; |
1114 | 1117 |
1115 // If the field being filled is either | 1118 // If the field being filled is either |
1116 // (a) the field that the user initiated the fill from, or | 1119 // (a) the field that the user initiated the fill from, or |
1117 // (b) part of the same logical unit, e.g. name or phone number, | 1120 // (b) part of the same logical unit, e.g. name or phone number, |
1118 // then take the multi-profile "variant" into account. | 1121 // then take the multi-profile "variant" into account. |
1119 // Otherwise fill with the default (zeroth) variant. | 1122 // Otherwise fill with the default (zeroth) variant. |
1120 size_t use_variant = 0; | 1123 size_t use_variant = 0; |
1121 if (result.fields[i].SameFieldAs(field) || | 1124 if (result.fields[i].SameFieldAs(field) || |
1122 field_group_type == initiating_group_type) { | 1125 field_group_type == initiating_group_type) { |
1123 use_variant = variant; | 1126 use_variant = variant; |
1124 } | 1127 } |
1125 base::string16 value = data_model->GetInfoForVariant( | 1128 base::string16 value = data_model.GetInfoForVariant( |
1126 cached_field->Type(), use_variant, app_locale_); | 1129 cached_field->Type(), use_variant, app_locale_); |
1127 if (is_credit_card && | 1130 if (is_credit_card && |
1128 cached_field->Type().GetStorableType() == | 1131 cached_field->Type().GetStorableType() == |
1129 CREDIT_CARD_VERIFICATION_CODE) { | 1132 CREDIT_CARD_VERIFICATION_CODE) { |
1130 // If this is |unmasking_card_|, |unmask_response_,cvc| should be | 1133 // If this is |unmasking_card_|, |unmask_response_.cvc| should be |
1131 // non-empty and vice versa. | 1134 // non-empty and vice versa. |
1132 value = unmask_response_.cvc; | 1135 value = unmask_response_.cvc; |
1133 DCHECK_EQ(&unmasking_card_ == data_model, value.empty()); | 1136 DCHECK_EQ(unmasking_card_ == data_model, !value.empty()); |
1134 } | 1137 } |
1135 | 1138 |
1136 // Must match ForEachMatchingFormField() in form_autofill_util.cc. | 1139 // Must match ForEachMatchingFormField() in form_autofill_util.cc. |
1137 // Only notify autofilling of empty fields and the field that initiated | 1140 // Only notify autofilling of empty fields and the field that initiated |
1138 // the filling (note that "select-one" controls may not be empty but will | 1141 // the filling (note that "select-one" controls may not be empty but will |
1139 // still be autofilled). | 1142 // still be autofilled). |
1140 bool should_notify = | 1143 bool should_notify = |
1141 !is_credit_card && | 1144 !is_credit_card && |
1142 !value.empty() && | 1145 !value.empty() && |
1143 (result.fields[i].SameFieldAs(field) || | 1146 (result.fields[i].SameFieldAs(field) || |
(...skipping 17 matching lines...) Expand all Loading... | |
1161 client_->DidFillOrPreviewField(value, profile_full_name); | 1164 client_->DidFillOrPreviewField(value, profile_full_name); |
1162 } | 1165 } |
1163 } | 1166 } |
1164 | 1167 |
1165 autofilled_form_signatures_.push_front(form_structure->FormSignature()); | 1168 autofilled_form_signatures_.push_front(form_structure->FormSignature()); |
1166 // Only remember the last few forms that we've seen, both to avoid false | 1169 // Only remember the last few forms that we've seen, both to avoid false |
1167 // positives and to avoid wasting memory. | 1170 // positives and to avoid wasting memory. |
1168 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember) | 1171 if (autofilled_form_signatures_.size() > kMaxRecentFormSignaturesToRemember) |
1169 autofilled_form_signatures_.pop_back(); | 1172 autofilled_form_signatures_.pop_back(); |
1170 | 1173 |
1174 // Note that this may invalidate |data_model|, particularly if it is a Mac | |
1175 // address book entry. | |
1176 if (action == AutofillDriver::FORM_DATA_ACTION_FILL) | |
1177 personal_data_->RecordUseOf(data_model); | |
1178 | |
1171 driver_->SendFormDataToRenderer(query_id, action, result); | 1179 driver_->SendFormDataToRenderer(query_id, action, result); |
1172 } | 1180 } |
1173 | 1181 |
1174 bool AutofillManager::FindCachedForm(const FormData& form, | 1182 bool AutofillManager::FindCachedForm(const FormData& form, |
1175 FormStructure** form_structure) const { | 1183 FormStructure** form_structure) const { |
1176 // Find the FormStructure that corresponds to |form|. | 1184 // Find the FormStructure that corresponds to |form|. |
1177 // Scan backward through the cached |form_structures_|, as updated versions of | 1185 // Scan backward through the cached |form_structures_|, as updated versions of |
1178 // forms are added to the back of the list, whereas original versions of these | 1186 // forms are added to the back of the list, whereas original versions of these |
1179 // forms might appear toward the beginning of the list. The communication | 1187 // forms might appear toward the beginning of the list. The communication |
1180 // protocol with the crowdsourcing server does not permit us to discard the | 1188 // protocol with the crowdsourcing server does not permit us to discard the |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1456 return false; | 1464 return false; |
1457 | 1465 |
1458 // Disregard forms that we wouldn't ever autofill in the first place. | 1466 // Disregard forms that we wouldn't ever autofill in the first place. |
1459 if (!form.ShouldBeParsed()) | 1467 if (!form.ShouldBeParsed()) |
1460 return false; | 1468 return false; |
1461 | 1469 |
1462 return true; | 1470 return true; |
1463 } | 1471 } |
1464 | 1472 |
1465 } // namespace autofill | 1473 } // namespace autofill |
OLD | NEW |