| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/browser/autofill_manager.h" | 5 #include "components/autofill/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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 const double kAutofillPositiveUploadRateDefaultValue = 0.20; | 73 const double kAutofillPositiveUploadRateDefaultValue = 0.20; |
| 74 const double kAutofillNegativeUploadRateDefaultValue = 0.20; | 74 const double kAutofillNegativeUploadRateDefaultValue = 0.20; |
| 75 | 75 |
| 76 const size_t kMaxRecentFormSignaturesToRemember = 3; | 76 const size_t kMaxRecentFormSignaturesToRemember = 3; |
| 77 | 77 |
| 78 // Set a conservative upper bound on the number of forms we are willing to | 78 // Set a conservative upper bound on the number of forms we are willing to |
| 79 // cache, simply to prevent unbounded memory consumption. | 79 // cache, simply to prevent unbounded memory consumption. |
| 80 const size_t kMaxFormCacheSize = 100; | 80 const size_t kMaxFormCacheSize = 100; |
| 81 | 81 |
| 82 // Removes duplicate suggestions whilst preserving their original order. | 82 // Removes duplicate suggestions whilst preserving their original order. |
| 83 void RemoveDuplicateSuggestions(std::vector<string16>* values, | 83 void RemoveDuplicateSuggestions(std::vector<base::string16>* values, |
| 84 std::vector<string16>* labels, | 84 std::vector<base::string16>* labels, |
| 85 std::vector<string16>* icons, | 85 std::vector<base::string16>* icons, |
| 86 std::vector<int>* unique_ids) { | 86 std::vector<int>* unique_ids) { |
| 87 DCHECK_EQ(values->size(), labels->size()); | 87 DCHECK_EQ(values->size(), labels->size()); |
| 88 DCHECK_EQ(values->size(), icons->size()); | 88 DCHECK_EQ(values->size(), icons->size()); |
| 89 DCHECK_EQ(values->size(), unique_ids->size()); | 89 DCHECK_EQ(values->size(), unique_ids->size()); |
| 90 | 90 |
| 91 std::set<std::pair<string16, string16> > seen_suggestions; | 91 std::set<std::pair<base::string16, base::string16> > seen_suggestions; |
| 92 std::vector<string16> values_copy; | 92 std::vector<base::string16> values_copy; |
| 93 std::vector<string16> labels_copy; | 93 std::vector<base::string16> labels_copy; |
| 94 std::vector<string16> icons_copy; | 94 std::vector<base::string16> icons_copy; |
| 95 std::vector<int> unique_ids_copy; | 95 std::vector<int> unique_ids_copy; |
| 96 | 96 |
| 97 for (size_t i = 0; i < values->size(); ++i) { | 97 for (size_t i = 0; i < values->size(); ++i) { |
| 98 const std::pair<string16, string16> suggestion((*values)[i], (*labels)[i]); | 98 const std::pair<base::string16, base::string16> suggestion( |
| 99 (*values)[i], (*labels)[i]); |
| 99 if (seen_suggestions.insert(suggestion).second) { | 100 if (seen_suggestions.insert(suggestion).second) { |
| 100 values_copy.push_back((*values)[i]); | 101 values_copy.push_back((*values)[i]); |
| 101 labels_copy.push_back((*labels)[i]); | 102 labels_copy.push_back((*labels)[i]); |
| 102 icons_copy.push_back((*icons)[i]); | 103 icons_copy.push_back((*icons)[i]); |
| 103 unique_ids_copy.push_back((*unique_ids)[i]); | 104 unique_ids_copy.push_back((*unique_ids)[i]); |
| 104 } | 105 } |
| 105 } | 106 } |
| 106 | 107 |
| 107 values->swap(values_copy); | 108 values->swap(values_copy); |
| 108 labels->swap(labels_copy); | 109 labels->swap(labels_copy); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 const std::vector<AutofillProfile>& profiles, | 141 const std::vector<AutofillProfile>& profiles, |
| 141 const std::vector<CreditCard>& credit_cards, | 142 const std::vector<CreditCard>& credit_cards, |
| 142 const std::string& app_locale, | 143 const std::string& app_locale, |
| 143 FormStructure* submitted_form) { | 144 FormStructure* submitted_form) { |
| 144 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); | 145 DCHECK(BrowserThread::GetBlockingPool()->RunsTasksOnCurrentThread()); |
| 145 | 146 |
| 146 // 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 |
| 147 // 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. |
| 148 for (size_t i = 0; i < submitted_form->field_count(); ++i) { | 149 for (size_t i = 0; i < submitted_form->field_count(); ++i) { |
| 149 AutofillField* field = submitted_form->field(i); | 150 AutofillField* field = submitted_form->field(i); |
| 150 string16 value = CollapseWhitespace(field->value, false); | 151 base::string16 value = CollapseWhitespace(field->value, false); |
| 151 | 152 |
| 152 FieldTypeSet matching_types; | 153 FieldTypeSet matching_types; |
| 153 for (std::vector<AutofillProfile>::const_iterator it = profiles.begin(); | 154 for (std::vector<AutofillProfile>::const_iterator it = profiles.begin(); |
| 154 it != profiles.end(); ++it) { | 155 it != profiles.end(); ++it) { |
| 155 it->GetMatchingTypes(value, app_locale, &matching_types); | 156 it->GetMatchingTypes(value, app_locale, &matching_types); |
| 156 } | 157 } |
| 157 for (std::vector<CreditCard>::const_iterator it = credit_cards.begin(); | 158 for (std::vector<CreditCard>::const_iterator it = credit_cards.begin(); |
| 158 it != credit_cards.end(); ++it) { | 159 it != credit_cards.end(); ++it) { |
| 159 it->GetMatchingTypes(value, app_locale, &matching_types); | 160 it->GetMatchingTypes(value, app_locale, &matching_types); |
| 160 } | 161 } |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 } | 511 } |
| 511 | 512 |
| 512 void AutofillManager::OnQueryFormFieldAutofill(int query_id, | 513 void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
| 513 const FormData& form, | 514 const FormData& form, |
| 514 const FormFieldData& field, | 515 const FormFieldData& field, |
| 515 const gfx::RectF& bounding_box, | 516 const gfx::RectF& bounding_box, |
| 516 bool display_warning) { | 517 bool display_warning) { |
| 517 if (autocheckout_manager_.is_autocheckout_bubble_showing()) | 518 if (autocheckout_manager_.is_autocheckout_bubble_showing()) |
| 518 return; | 519 return; |
| 519 | 520 |
| 520 std::vector<string16> values; | 521 std::vector<base::string16> values; |
| 521 std::vector<string16> labels; | 522 std::vector<base::string16> labels; |
| 522 std::vector<string16> icons; | 523 std::vector<base::string16> icons; |
| 523 std::vector<int> unique_ids; | 524 std::vector<int> unique_ids; |
| 524 | 525 |
| 525 if (external_delegate_) { | 526 if (external_delegate_) { |
| 526 external_delegate_->OnQuery(query_id, | 527 external_delegate_->OnQuery(query_id, |
| 527 form, | 528 form, |
| 528 field, | 529 field, |
| 529 bounding_box, | 530 bounding_box, |
| 530 display_warning); | 531 display_warning); |
| 531 } | 532 } |
| 532 | 533 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 556 // Don't provide Autofill suggestions when Autofill is disabled, and don't | 557 // Don't provide Autofill suggestions when Autofill is disabled, and don't |
| 557 // provide credit card suggestions for non-HTTPS pages. However, provide a | 558 // provide credit card suggestions for non-HTTPS pages. However, provide a |
| 558 // warning to the user in these cases. | 559 // warning to the user in these cases. |
| 559 int warning = 0; | 560 int warning = 0; |
| 560 if (!form_structure->IsAutofillable(true)) | 561 if (!form_structure->IsAutofillable(true)) |
| 561 warning = IDS_AUTOFILL_WARNING_FORM_DISABLED; | 562 warning = IDS_AUTOFILL_WARNING_FORM_DISABLED; |
| 562 else if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) | 563 else if (is_filling_credit_card && !FormIsHTTPS(*form_structure)) |
| 563 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; | 564 warning = IDS_AUTOFILL_WARNING_INSECURE_CONNECTION; |
| 564 if (warning) { | 565 if (warning) { |
| 565 values.assign(1, l10n_util::GetStringUTF16(warning)); | 566 values.assign(1, l10n_util::GetStringUTF16(warning)); |
| 566 labels.assign(1, string16()); | 567 labels.assign(1, base::string16()); |
| 567 icons.assign(1, string16()); | 568 icons.assign(1, base::string16()); |
| 568 unique_ids.assign(1, | 569 unique_ids.assign(1, |
| 569 WebKit::WebAutofillClient::MenuItemIDWarningMessage); | 570 WebKit::WebAutofillClient::MenuItemIDWarningMessage); |
| 570 } else { | 571 } else { |
| 571 bool section_is_autofilled = | 572 bool section_is_autofilled = |
| 572 SectionIsAutofilled(*form_structure, form, | 573 SectionIsAutofilled(*form_structure, form, |
| 573 autofill_field->section()); | 574 autofill_field->section()); |
| 574 if (section_is_autofilled) { | 575 if (section_is_autofilled) { |
| 575 // If the relevant section is auto-filled and the renderer is querying | 576 // If the relevant section is auto-filled and the renderer is querying |
| 576 // for suggestions, then the user is editing the value of a field. | 577 // for suggestions, then the user is editing the value of a field. |
| 577 // In this case, mimic autocomplete: don't display labels or icons, | 578 // In this case, mimic autocomplete: don't display labels or icons, |
| 578 // as that information is redundant. | 579 // as that information is redundant. |
| 579 labels.assign(labels.size(), string16()); | 580 labels.assign(labels.size(), base::string16()); |
| 580 icons.assign(icons.size(), string16()); | 581 icons.assign(icons.size(), base::string16()); |
| 581 } | 582 } |
| 582 | 583 |
| 583 // When filling credit card suggestions, the values and labels are | 584 // When filling credit card suggestions, the values and labels are |
| 584 // typically obfuscated, which makes detecting duplicates hard. Since | 585 // typically obfuscated, which makes detecting duplicates hard. Since |
| 585 // duplicates only tend to be a problem when filling address forms | 586 // duplicates only tend to be a problem when filling address forms |
| 586 // anyway, only don't de-dup credit card suggestions. | 587 // anyway, only don't de-dup credit card suggestions. |
| 587 if (!is_filling_credit_card) | 588 if (!is_filling_credit_card) |
| 588 RemoveDuplicateSuggestions(&values, &labels, &icons, &unique_ids); | 589 RemoveDuplicateSuggestions(&values, &labels, &icons, &unique_ids); |
| 589 | 590 |
| 590 // The first time we show suggestions on this page, log the number of | 591 // The first time we show suggestions on this page, log the number of |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 754 | 755 |
| 755 // TODO(csharp): If we are dealing with a variant only the variant should | 756 // TODO(csharp): If we are dealing with a variant only the variant should |
| 756 // be deleted, instead of doing nothing. | 757 // be deleted, instead of doing nothing. |
| 757 // http://crbug.com/124211 | 758 // http://crbug.com/124211 |
| 758 if (variant != 0) | 759 if (variant != 0) |
| 759 return; | 760 return; |
| 760 | 761 |
| 761 personal_data_->RemoveByGUID(form_group->GetGUID()); | 762 personal_data_->RemoveByGUID(form_group->GetGUID()); |
| 762 } | 763 } |
| 763 | 764 |
| 764 void AutofillManager::RemoveAutocompleteEntry(const string16& name, | 765 void AutofillManager::RemoveAutocompleteEntry(const base::string16& name, |
| 765 const string16& value) { | 766 const base::string16& value) { |
| 766 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value); | 767 autocomplete_history_manager_.OnRemoveAutocompleteEntry(name, value); |
| 767 } | 768 } |
| 768 | 769 |
| 769 content::WebContents* AutofillManager::GetWebContents() const { | 770 content::WebContents* AutofillManager::GetWebContents() const { |
| 770 return web_contents(); | 771 return web_contents(); |
| 771 } | 772 } |
| 772 | 773 |
| 773 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { | 774 const std::vector<FormStructure*>& AutofillManager::GetFormStructures() { |
| 774 return form_structures_.get(); | 775 return form_structures_.get(); |
| 775 } | 776 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 792 void AutofillManager::OnAddPasswordFormMapping( | 793 void AutofillManager::OnAddPasswordFormMapping( |
| 793 const FormFieldData& form, | 794 const FormFieldData& form, |
| 794 const PasswordFormFillData& fill_data) { | 795 const PasswordFormFillData& fill_data) { |
| 795 if (external_delegate_) | 796 if (external_delegate_) |
| 796 external_delegate_->AddPasswordFormMapping(form, fill_data); | 797 external_delegate_->AddPasswordFormMapping(form, fill_data); |
| 797 } | 798 } |
| 798 | 799 |
| 799 void AutofillManager::OnShowPasswordSuggestions( | 800 void AutofillManager::OnShowPasswordSuggestions( |
| 800 const FormFieldData& field, | 801 const FormFieldData& field, |
| 801 const gfx::RectF& bounds, | 802 const gfx::RectF& bounds, |
| 802 const std::vector<string16>& suggestions) { | 803 const std::vector<base::string16>& suggestions) { |
| 803 if (external_delegate_) | 804 if (external_delegate_) |
| 804 external_delegate_->OnShowPasswordSuggestions(suggestions, field, bounds); | 805 external_delegate_->OnShowPasswordSuggestions(suggestions, field, bounds); |
| 805 } | 806 } |
| 806 | 807 |
| 807 void AutofillManager::OnSetDataList(const std::vector<string16>& values, | 808 void AutofillManager::OnSetDataList(const std::vector<base::string16>& values, |
| 808 const std::vector<string16>& labels, | 809 const std::vector<base::string16>& labels, |
| 809 const std::vector<string16>& icons, | 810 const std::vector<base::string16>& icons, |
| 810 const std::vector<int>& unique_ids) { | 811 const std::vector<int>& unique_ids) { |
| 811 if (labels.size() != values.size() || | 812 if (labels.size() != values.size() || |
| 812 icons.size() != values.size() || | 813 icons.size() != values.size() || |
| 813 unique_ids.size() != values.size()) { | 814 unique_ids.size() != values.size()) { |
| 814 return; | 815 return; |
| 815 } | 816 } |
| 816 if (external_delegate_) { | 817 if (external_delegate_) { |
| 817 external_delegate_->SetCurrentDataListValues(values, | 818 external_delegate_->SetCurrentDataListValues(values, |
| 818 labels, | 819 labels, |
| 819 icons, | 820 icons, |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 return false; | 1167 return false; |
| 1167 | 1168 |
| 1168 // Add the new or updated form to our cache. | 1169 // Add the new or updated form to our cache. |
| 1169 form_structures_.push_back( | 1170 form_structures_.push_back( |
| 1170 new FormStructure(live_form, GetAutocheckoutURLPrefix())); | 1171 new FormStructure(live_form, GetAutocheckoutURLPrefix())); |
| 1171 *updated_form = *form_structures_.rbegin(); | 1172 *updated_form = *form_structures_.rbegin(); |
| 1172 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); | 1173 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); |
| 1173 | 1174 |
| 1174 // If we have cached data, propagate it to the updated form. | 1175 // If we have cached data, propagate it to the updated form. |
| 1175 if (cached_form) { | 1176 if (cached_form) { |
| 1176 std::map<string16, const AutofillField*> cached_fields; | 1177 std::map<base::string16, const AutofillField*> cached_fields; |
| 1177 for (size_t i = 0; i < cached_form->field_count(); ++i) { | 1178 for (size_t i = 0; i < cached_form->field_count(); ++i) { |
| 1178 const AutofillField* field = cached_form->field(i); | 1179 const AutofillField* field = cached_form->field(i); |
| 1179 cached_fields[field->unique_name()] = field; | 1180 cached_fields[field->unique_name()] = field; |
| 1180 } | 1181 } |
| 1181 | 1182 |
| 1182 for (size_t i = 0; i < (*updated_form)->field_count(); ++i) { | 1183 for (size_t i = 0; i < (*updated_form)->field_count(); ++i) { |
| 1183 AutofillField* field = (*updated_form)->field(i); | 1184 AutofillField* field = (*updated_form)->field(i); |
| 1184 std::map<string16, const AutofillField*>::iterator cached_field = | 1185 std::map<base::string16, const AutofillField*>::iterator cached_field = |
| 1185 cached_fields.find(field->unique_name()); | 1186 cached_fields.find(field->unique_name()); |
| 1186 if (cached_field != cached_fields.end()) { | 1187 if (cached_field != cached_fields.end()) { |
| 1187 field->set_server_type(cached_field->second->server_type()); | 1188 field->set_server_type(cached_field->second->server_type()); |
| 1188 field->is_autofilled = cached_field->second->is_autofilled; | 1189 field->is_autofilled = cached_field->second->is_autofilled; |
| 1189 } | 1190 } |
| 1190 } | 1191 } |
| 1191 | 1192 |
| 1192 // Note: We _must not_ remove the original version of the cached form from | 1193 // Note: We _must not_ remove the original version of the cached form from |
| 1193 // the list of |form_structures_|. Otherwise, we break parsing of the | 1194 // the list of |form_structures_|. Otherwise, we break parsing of the |
| 1194 // crowdsourcing server's response to our query. | 1195 // crowdsourcing server's response to our query. |
| 1195 } | 1196 } |
| 1196 | 1197 |
| 1197 // Annotate the updated form with its predicted types. | 1198 // Annotate the updated form with its predicted types. |
| 1198 std::vector<FormStructure*> forms(1, *updated_form); | 1199 std::vector<FormStructure*> forms(1, *updated_form); |
| 1199 SendAutofillTypePredictions(forms); | 1200 SendAutofillTypePredictions(forms); |
| 1200 | 1201 |
| 1201 return true; | 1202 return true; |
| 1202 } | 1203 } |
| 1203 | 1204 |
| 1204 void AutofillManager::GetProfileSuggestions( | 1205 void AutofillManager::GetProfileSuggestions( |
| 1205 FormStructure* form, | 1206 FormStructure* form, |
| 1206 const FormFieldData& field, | 1207 const FormFieldData& field, |
| 1207 AutofillFieldType type, | 1208 AutofillFieldType type, |
| 1208 std::vector<string16>* values, | 1209 std::vector<base::string16>* values, |
| 1209 std::vector<string16>* labels, | 1210 std::vector<base::string16>* labels, |
| 1210 std::vector<string16>* icons, | 1211 std::vector<base::string16>* icons, |
| 1211 std::vector<int>* unique_ids) const { | 1212 std::vector<int>* unique_ids) const { |
| 1212 std::vector<AutofillFieldType> field_types(form->field_count()); | 1213 std::vector<AutofillFieldType> field_types(form->field_count()); |
| 1213 for (size_t i = 0; i < form->field_count(); ++i) { | 1214 for (size_t i = 0; i < form->field_count(); ++i) { |
| 1214 field_types[i] = form->field(i)->type(); | 1215 field_types[i] = form->field(i)->type(); |
| 1215 } | 1216 } |
| 1216 std::vector<GUIDPair> guid_pairs; | 1217 std::vector<GUIDPair> guid_pairs; |
| 1217 | 1218 |
| 1218 personal_data_->GetProfileSuggestions( | 1219 personal_data_->GetProfileSuggestions( |
| 1219 type, field.value, field.is_autofilled, field_types, | 1220 type, field.value, field.is_autofilled, field_types, |
| 1220 values, labels, icons, &guid_pairs); | 1221 values, labels, icons, &guid_pairs); |
| 1221 | 1222 |
| 1222 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1223 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
| 1223 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), | 1224 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), |
| 1224 guid_pairs[i])); | 1225 guid_pairs[i])); |
| 1225 } | 1226 } |
| 1226 } | 1227 } |
| 1227 | 1228 |
| 1228 void AutofillManager::GetCreditCardSuggestions( | 1229 void AutofillManager::GetCreditCardSuggestions( |
| 1229 const FormFieldData& field, | 1230 const FormFieldData& field, |
| 1230 AutofillFieldType type, | 1231 AutofillFieldType type, |
| 1231 std::vector<string16>* values, | 1232 std::vector<base::string16>* values, |
| 1232 std::vector<string16>* labels, | 1233 std::vector<base::string16>* labels, |
| 1233 std::vector<string16>* icons, | 1234 std::vector<base::string16>* icons, |
| 1234 std::vector<int>* unique_ids) const { | 1235 std::vector<int>* unique_ids) const { |
| 1235 std::vector<GUIDPair> guid_pairs; | 1236 std::vector<GUIDPair> guid_pairs; |
| 1236 personal_data_->GetCreditCardSuggestions( | 1237 personal_data_->GetCreditCardSuggestions( |
| 1237 type, field.value, values, labels, icons, &guid_pairs); | 1238 type, field.value, values, labels, icons, &guid_pairs); |
| 1238 | 1239 |
| 1239 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1240 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
| 1240 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); | 1241 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |
| 1241 } | 1242 } |
| 1242 } | 1243 } |
| 1243 | 1244 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 *profile_guid = IDToGUID(profile_id); | 1339 *profile_guid = IDToGUID(profile_id); |
| 1339 } | 1340 } |
| 1340 | 1341 |
| 1341 void AutofillManager::UpdateInitialInteractionTimestamp( | 1342 void AutofillManager::UpdateInitialInteractionTimestamp( |
| 1342 const TimeTicks& interaction_timestamp) { | 1343 const TimeTicks& interaction_timestamp) { |
| 1343 if (initial_interaction_timestamp_.is_null() || | 1344 if (initial_interaction_timestamp_.is_null() || |
| 1344 interaction_timestamp < initial_interaction_timestamp_) { | 1345 interaction_timestamp < initial_interaction_timestamp_) { |
| 1345 initial_interaction_timestamp_ = interaction_timestamp; | 1346 initial_interaction_timestamp_ = interaction_timestamp; |
| 1346 } | 1347 } |
| 1347 } | 1348 } |
| OLD | NEW |