| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 const std::string& app_locale, | 143 const std::string& app_locale, |
| 144 FormStructure* submitted_form) { | 144 FormStructure* submitted_form) { |
| 145 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 145 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 146 | 146 |
| 147 // For each field in the |submitted_form|, extract the value. Then for each | 147 // For each field in the |submitted_form|, extract the value. Then for each |
| 148 // profile or credit card, identify any stored types that match the value. | 148 // profile or credit card, identify any stored types that match the value. |
| 149 for (size_t i = 0; i < submitted_form->field_count(); ++i) { | 149 for (size_t i = 0; i < submitted_form->field_count(); ++i) { |
| 150 AutofillField* field = submitted_form->field(i); | 150 AutofillField* field = submitted_form->field(i); |
| 151 base::string16 value = CollapseWhitespace(field->value, false); | 151 base::string16 value = CollapseWhitespace(field->value, false); |
| 152 | 152 |
| 153 FieldTypeSet matching_types; | 153 ServerFieldTypeSet matching_types; |
| 154 for (std::vector<AutofillProfile>::const_iterator it = profiles.begin(); | 154 for (std::vector<AutofillProfile>::const_iterator it = profiles.begin(); |
| 155 it != profiles.end(); ++it) { | 155 it != profiles.end(); ++it) { |
| 156 it->GetMatchingTypes(value, app_locale, &matching_types); | 156 it->GetMatchingTypes(value, app_locale, &matching_types); |
| 157 } | 157 } |
| 158 for (std::vector<CreditCard>::const_iterator it = credit_cards.begin(); | 158 for (std::vector<CreditCard>::const_iterator it = credit_cards.begin(); |
| 159 it != credit_cards.end(); ++it) { | 159 it != credit_cards.end(); ++it) { |
| 160 it->GetMatchingTypes(value, app_locale, &matching_types); | 160 it->GetMatchingTypes(value, app_locale, &matching_types); |
| 161 } | 161 } |
| 162 | 162 |
| 163 if (matching_types.empty()) | 163 if (matching_types.empty()) |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 bounding_box, | 417 bounding_box, |
| 418 display_warning); | 418 display_warning); |
| 419 | 419 |
| 420 RenderViewHost* host = NULL; | 420 RenderViewHost* host = NULL; |
| 421 FormStructure* form_structure = NULL; | 421 FormStructure* form_structure = NULL; |
| 422 AutofillField* autofill_field = NULL; | 422 AutofillField* autofill_field = NULL; |
| 423 if (GetHost(&host) && | 423 if (GetHost(&host) && |
| 424 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 424 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && |
| 425 // Don't send suggestions for forms that aren't auto-fillable. | 425 // Don't send suggestions for forms that aren't auto-fillable. |
| 426 form_structure->IsAutofillable(false)) { | 426 form_structure->IsAutofillable(false)) { |
| 427 AutofillFieldType type = autofill_field->type(); | 427 AutofillType type = autofill_field->Type(); |
| 428 bool is_filling_credit_card = | 428 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
| 429 (AutofillType(type).group() == CREDIT_CARD); | |
| 430 if (is_filling_credit_card) { | 429 if (is_filling_credit_card) { |
| 431 GetCreditCardSuggestions( | 430 GetCreditCardSuggestions( |
| 432 field, type, &values, &labels, &icons, &unique_ids); | 431 field, type, &values, &labels, &icons, &unique_ids); |
| 433 } else { | 432 } else { |
| 434 GetProfileSuggestions( | 433 GetProfileSuggestions( |
| 435 form_structure, field, type, &values, &labels, &icons, &unique_ids); | 434 form_structure, field, type, &values, &labels, &icons, &unique_ids); |
| 436 } | 435 } |
| 437 | 436 |
| 438 DCHECK_EQ(values.size(), labels.size()); | 437 DCHECK_EQ(values.size(), labels.size()); |
| 439 DCHECK_EQ(values.size(), icons.size()); | 438 DCHECK_EQ(values.size(), icons.size()); |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 autofill_field->is_autofilled = true; | 526 autofill_field->is_autofilled = true; |
| 528 break; | 527 break; |
| 529 } | 528 } |
| 530 } | 529 } |
| 531 | 530 |
| 532 driver_->SendFormDataToRenderer(query_id, result); | 531 driver_->SendFormDataToRenderer(query_id, result); |
| 533 return; | 532 return; |
| 534 } | 533 } |
| 535 | 534 |
| 536 // Cache the field type for the field from which the user initiated autofill. | 535 // Cache the field type for the field from which the user initiated autofill. |
| 537 FieldTypeGroup initiating_group_type = | 536 FieldTypeGroup initiating_group_type = autofill_field->Type().group(); |
| 538 AutofillType(autofill_field->type()).group(); | |
| 539 DCHECK_EQ(form_structure->field_count(), form.fields.size()); | 537 DCHECK_EQ(form_structure->field_count(), form.fields.size()); |
| 540 for (size_t i = 0; i < form_structure->field_count(); ++i) { | 538 for (size_t i = 0; i < form_structure->field_count(); ++i) { |
| 541 if (form_structure->field(i)->section() != autofill_field->section()) | 539 if (form_structure->field(i)->section() != autofill_field->section()) |
| 542 continue; | 540 continue; |
| 543 | 541 |
| 544 DCHECK_EQ(*form_structure->field(i), result.fields[i]); | 542 DCHECK_EQ(*form_structure->field(i), result.fields[i]); |
| 545 | 543 |
| 546 const AutofillField* cached_field = form_structure->field(i); | 544 const AutofillField* cached_field = form_structure->field(i); |
| 547 FieldTypeGroup field_group_type = | 545 FieldTypeGroup field_group_type = cached_field->Type().group(); |
| 548 AutofillType(cached_field->type()).group(); | |
| 549 if (field_group_type != NO_GROUP) { | 546 if (field_group_type != NO_GROUP) { |
| 550 // If the field being filled is either | 547 // If the field being filled is either |
| 551 // (a) the field that the user initiated the fill from, or | 548 // (a) the field that the user initiated the fill from, or |
| 552 // (b) part of the same logical unit, e.g. name or phone number, | 549 // (b) part of the same logical unit, e.g. name or phone number, |
| 553 // then take the multi-profile "variant" into account. | 550 // then take the multi-profile "variant" into account. |
| 554 // Otherwise fill with the default (zeroth) variant. | 551 // Otherwise fill with the default (zeroth) variant. |
| 555 size_t use_variant = 0; | 552 size_t use_variant = 0; |
| 556 if (result.fields[i] == field || | 553 if (result.fields[i] == field || |
| 557 field_group_type == initiating_group_type) { | 554 field_group_type == initiating_group_type) { |
| 558 use_variant = variant; | 555 use_variant = variant; |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 bool was_autofilled = false; | 847 bool was_autofilled = false; |
| 851 std::string form_signature = submitted_form.FormSignature(); | 848 std::string form_signature = submitted_form.FormSignature(); |
| 852 for (std::list<std::string>::const_iterator it = | 849 for (std::list<std::string>::const_iterator it = |
| 853 autofilled_form_signatures_.begin(); | 850 autofilled_form_signatures_.begin(); |
| 854 it != autofilled_form_signatures_.end() && !was_autofilled; | 851 it != autofilled_form_signatures_.end() && !was_autofilled; |
| 855 ++it) { | 852 ++it) { |
| 856 if (*it == form_signature) | 853 if (*it == form_signature) |
| 857 was_autofilled = true; | 854 was_autofilled = true; |
| 858 } | 855 } |
| 859 | 856 |
| 860 FieldTypeSet non_empty_types; | 857 ServerFieldTypeSet non_empty_types; |
| 861 personal_data_->GetNonEmptyTypes(&non_empty_types); | 858 personal_data_->GetNonEmptyTypes(&non_empty_types); |
| 862 | 859 |
| 863 download_manager_->StartUploadRequest(submitted_form, was_autofilled, | 860 download_manager_->StartUploadRequest(submitted_form, was_autofilled, |
| 864 non_empty_types); | 861 non_empty_types); |
| 865 } | 862 } |
| 866 | 863 |
| 867 void AutofillManager::Reset() { | 864 void AutofillManager::Reset() { |
| 868 form_structures_.clear(); | 865 form_structures_.clear(); |
| 869 has_logged_autofill_enabled_ = false; | 866 has_logged_autofill_enabled_ = false; |
| 870 has_logged_address_suggestions_count_ = false; | 867 has_logged_address_suggestions_count_ = false; |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1064 // Annotate the updated form with its predicted types. | 1061 // Annotate the updated form with its predicted types. |
| 1065 std::vector<FormStructure*> forms(1, *updated_form); | 1062 std::vector<FormStructure*> forms(1, *updated_form); |
| 1066 driver_->SendAutofillTypePredictionsToRenderer(forms); | 1063 driver_->SendAutofillTypePredictionsToRenderer(forms); |
| 1067 | 1064 |
| 1068 return true; | 1065 return true; |
| 1069 } | 1066 } |
| 1070 | 1067 |
| 1071 void AutofillManager::GetProfileSuggestions( | 1068 void AutofillManager::GetProfileSuggestions( |
| 1072 FormStructure* form, | 1069 FormStructure* form, |
| 1073 const FormFieldData& field, | 1070 const FormFieldData& field, |
| 1074 AutofillFieldType type, | 1071 const AutofillType& type, |
| 1075 std::vector<base::string16>* values, | 1072 std::vector<base::string16>* values, |
| 1076 std::vector<base::string16>* labels, | 1073 std::vector<base::string16>* labels, |
| 1077 std::vector<base::string16>* icons, | 1074 std::vector<base::string16>* icons, |
| 1078 std::vector<int>* unique_ids) const { | 1075 std::vector<int>* unique_ids) const { |
| 1079 std::vector<AutofillFieldType> field_types(form->field_count()); | 1076 std::vector<ServerFieldType> field_types(form->field_count()); |
| 1080 for (size_t i = 0; i < form->field_count(); ++i) { | 1077 for (size_t i = 0; i < form->field_count(); ++i) { |
| 1081 field_types[i] = form->field(i)->type(); | 1078 field_types.push_back(form->field(i)->Type().server_type()); |
| 1082 } | 1079 } |
| 1083 std::vector<GUIDPair> guid_pairs; | 1080 std::vector<GUIDPair> guid_pairs; |
| 1084 | 1081 |
| 1085 personal_data_->GetProfileSuggestions( | 1082 personal_data_->GetProfileSuggestions( |
| 1086 type, field.value, field.is_autofilled, field_types, | 1083 type, field.value, field.is_autofilled, field_types, |
| 1087 values, labels, icons, &guid_pairs); | 1084 values, labels, icons, &guid_pairs); |
| 1088 | 1085 |
| 1089 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1086 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
| 1090 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), | 1087 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), |
| 1091 guid_pairs[i])); | 1088 guid_pairs[i])); |
| 1092 } | 1089 } |
| 1093 } | 1090 } |
| 1094 | 1091 |
| 1095 void AutofillManager::GetCreditCardSuggestions( | 1092 void AutofillManager::GetCreditCardSuggestions( |
| 1096 const FormFieldData& field, | 1093 const FormFieldData& field, |
| 1097 AutofillFieldType type, | 1094 const AutofillType& type, |
| 1098 std::vector<base::string16>* values, | 1095 std::vector<base::string16>* values, |
| 1099 std::vector<base::string16>* labels, | 1096 std::vector<base::string16>* labels, |
| 1100 std::vector<base::string16>* icons, | 1097 std::vector<base::string16>* icons, |
| 1101 std::vector<int>* unique_ids) const { | 1098 std::vector<int>* unique_ids) const { |
| 1102 std::vector<GUIDPair> guid_pairs; | 1099 std::vector<GUIDPair> guid_pairs; |
| 1103 personal_data_->GetCreditCardSuggestions( | 1100 personal_data_->GetCreditCardSuggestions( |
| 1104 type, field.value, values, labels, icons, &guid_pairs); | 1101 type, field.value, values, labels, icons, &guid_pairs); |
| 1105 | 1102 |
| 1106 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1103 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
| 1107 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); | 1104 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 | 1210 |
| 1214 void AutofillManager::UpdateInitialInteractionTimestamp( | 1211 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1215 const TimeTicks& interaction_timestamp) { | 1212 const TimeTicks& interaction_timestamp) { |
| 1216 if (initial_interaction_timestamp_.is_null() || | 1213 if (initial_interaction_timestamp_.is_null() || |
| 1217 interaction_timestamp < initial_interaction_timestamp_) { | 1214 interaction_timestamp < initial_interaction_timestamp_) { |
| 1218 initial_interaction_timestamp_ = interaction_timestamp; | 1215 initial_interaction_timestamp_ = interaction_timestamp; |
| 1219 } | 1216 } |
| 1220 } | 1217 } |
| 1221 | 1218 |
| 1222 } // namespace autofill | 1219 } // namespace autofill |
| OLD | NEW |