| 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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 driver_->RendererIsAvailable() && | 452 driver_->RendererIsAvailable() && |
| 453 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 453 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && |
| 454 // Don't send suggestions for forms that aren't auto-fillable. | 454 // Don't send suggestions for forms that aren't auto-fillable. |
| 455 form_structure->IsAutofillable()) { | 455 form_structure->IsAutofillable()) { |
| 456 AutofillType type = autofill_field->Type(); | 456 AutofillType type = autofill_field->Type(); |
| 457 bool is_filling_credit_card = (type.group() == CREDIT_CARD); | 457 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
| 458 if (is_filling_credit_card) { | 458 if (is_filling_credit_card) { |
| 459 GetCreditCardSuggestions( | 459 GetCreditCardSuggestions( |
| 460 field, type, &values, &labels, &icons, &unique_ids); | 460 field, type, &values, &labels, &icons, &unique_ids); |
| 461 } else { | 461 } else { |
| 462 GetProfileSuggestions( | 462 GetProfileSuggestions(*form_structure, |
| 463 *form_structure, field, type, &values, &labels, &icons, &unique_ids); | 463 field, |
| 464 *autofill_field, |
| 465 &values, |
| 466 &labels, |
| 467 &icons, |
| 468 &unique_ids); |
| 464 } | 469 } |
| 465 | 470 |
| 466 DCHECK_EQ(values.size(), labels.size()); | 471 DCHECK_EQ(values.size(), labels.size()); |
| 467 DCHECK_EQ(values.size(), icons.size()); | 472 DCHECK_EQ(values.size(), icons.size()); |
| 468 DCHECK_EQ(values.size(), unique_ids.size()); | 473 DCHECK_EQ(values.size(), unique_ids.size()); |
| 469 | 474 |
| 470 if (!values.empty()) { | 475 if (!values.empty()) { |
| 471 // Don't provide Autofill suggestions when Autofill is disabled, and don't | 476 // Don't provide Autofill suggestions when Autofill is disabled, and don't |
| 472 // provide credit card suggestions for non-HTTPS pages. However, provide a | 477 // provide credit card suggestions for non-HTTPS pages. However, provide a |
| 473 // warning to the user in these cases. | 478 // warning to the user in these cases. |
| (...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1057 // Annotate the updated form with its predicted types. | 1062 // Annotate the updated form with its predicted types. |
| 1058 std::vector<FormStructure*> forms(1, *updated_form); | 1063 std::vector<FormStructure*> forms(1, *updated_form); |
| 1059 driver_->SendAutofillTypePredictionsToRenderer(forms); | 1064 driver_->SendAutofillTypePredictionsToRenderer(forms); |
| 1060 | 1065 |
| 1061 return true; | 1066 return true; |
| 1062 } | 1067 } |
| 1063 | 1068 |
| 1064 void AutofillManager::GetProfileSuggestions( | 1069 void AutofillManager::GetProfileSuggestions( |
| 1065 const FormStructure& form, | 1070 const FormStructure& form, |
| 1066 const FormFieldData& field, | 1071 const FormFieldData& field, |
| 1067 const AutofillType& type, | 1072 const AutofillField& autofill_field, |
| 1068 std::vector<base::string16>* values, | 1073 std::vector<base::string16>* values, |
| 1069 std::vector<base::string16>* labels, | 1074 std::vector<base::string16>* labels, |
| 1070 std::vector<base::string16>* icons, | 1075 std::vector<base::string16>* icons, |
| 1071 std::vector<int>* unique_ids) const { | 1076 std::vector<int>* unique_ids) const { |
| 1072 std::vector<ServerFieldType> field_types(form.field_count()); | 1077 std::vector<ServerFieldType> field_types(form.field_count()); |
| 1073 for (size_t i = 0; i < form.field_count(); ++i) { | 1078 for (size_t i = 0; i < form.field_count(); ++i) { |
| 1074 field_types.push_back(form.field(i)->Type().GetStorableType()); | 1079 field_types.push_back(form.field(i)->Type().GetStorableType()); |
| 1075 } | 1080 } |
| 1076 std::vector<GUIDPair> guid_pairs; | 1081 std::vector<GUIDPair> guid_pairs; |
| 1077 | 1082 |
| 1078 personal_data_->GetProfileSuggestions( | 1083 personal_data_->GetProfileSuggestions( |
| 1079 type, field.value, field.is_autofilled, field_types, | 1084 autofill_field.Type(), field.value, field.is_autofilled, field_types, |
| 1080 base::Callback<bool(const AutofillProfile&)>(), | 1085 base::Callback<bool(const AutofillProfile&)>(), |
| 1081 values, labels, icons, &guid_pairs); | 1086 values, labels, icons, &guid_pairs); |
| 1082 | 1087 |
| 1088 // Adjust phone number to display in prefix/suffix case. |
| 1089 if (autofill_field.Type().GetStorableType() == PHONE_HOME_NUMBER) { |
| 1090 for (size_t i = 0; i < values->size(); ++i) { |
| 1091 (*values)[i] = AutofillField::GetPhoneNumberValue( |
| 1092 autofill_field, (*values)[i], field); |
| 1093 } |
| 1094 } |
| 1095 |
| 1083 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1096 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
| 1084 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), | 1097 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), |
| 1085 guid_pairs[i])); | 1098 guid_pairs[i])); |
| 1086 } | 1099 } |
| 1087 } | 1100 } |
| 1088 | 1101 |
| 1089 void AutofillManager::GetCreditCardSuggestions( | 1102 void AutofillManager::GetCreditCardSuggestions( |
| 1090 const FormFieldData& field, | 1103 const FormFieldData& field, |
| 1091 const AutofillType& type, | 1104 const AutofillType& type, |
| 1092 std::vector<base::string16>* values, | 1105 std::vector<base::string16>* values, |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 return false; | 1226 return false; |
| 1214 | 1227 |
| 1215 // Disregard forms that we wouldn't ever autofill in the first place. | 1228 // Disregard forms that we wouldn't ever autofill in the first place. |
| 1216 if (!form.ShouldBeParsed()) | 1229 if (!form.ShouldBeParsed()) |
| 1217 return false; | 1230 return false; |
| 1218 | 1231 |
| 1219 return true; | 1232 return true; |
| 1220 } | 1233 } |
| 1221 | 1234 |
| 1222 } // namespace autofill | 1235 } // namespace autofill |
| OLD | NEW |