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 "chrome/browser/autofill/autofill_manager.h" | 5 #include "chrome/browser/autofill/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> |
11 #include <set> | 11 #include <set> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/command_line.h" | 15 #include "base/command_line.h" |
16 #include "base/guid.h" | 16 #include "base/guid.h" |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "base/prefs/public/pref_service_base.h" | 18 #include "base/prefs/public/pref_service_base.h" |
19 #include "base/string16.h" | 19 #include "base/string16.h" |
20 #include "base/string_util.h" | 20 #include "base/string_util.h" |
21 #include "base/supports_user_data.h" | 21 #include "base/supports_user_data.h" |
22 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
23 #include "base/utf_string_conversions.h" | 23 #include "base/utf_string_conversions.h" |
24 #include "chrome/browser/api/infobars/infobar_service.h" | 24 #include "chrome/browser/api/infobars/infobar_service.h" |
25 #include "chrome/browser/api/sync/profile_sync_service_base.h" | 25 #include "chrome/browser/api/sync/profile_sync_service_base.h" |
26 #include "chrome/browser/autofill/autocheckout/whitelist_manager.h" | |
26 #include "chrome/browser/autofill/autocheckout_manager.h" | 27 #include "chrome/browser/autofill/autocheckout_manager.h" |
27 #include "chrome/browser/autofill/autocheckout_infobar_delegate.h" | 28 #include "chrome/browser/autofill/autocheckout_infobar_delegate.h" |
28 #include "chrome/browser/autofill/autocomplete_history_manager.h" | 29 #include "chrome/browser/autofill/autocomplete_history_manager.h" |
29 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" | 30 #include "chrome/browser/autofill/autofill_cc_infobar_delegate.h" |
30 #include "chrome/browser/autofill/autofill_country.h" | 31 #include "chrome/browser/autofill/autofill_country.h" |
31 #include "chrome/browser/autofill/autofill_external_delegate.h" | 32 #include "chrome/browser/autofill/autofill_external_delegate.h" |
32 #include "chrome/browser/autofill/autofill_field.h" | 33 #include "chrome/browser/autofill/autofill_field.h" |
33 #include "chrome/browser/autofill/autofill_manager_delegate.h" | 34 #include "chrome/browser/autofill/autofill_manager_delegate.h" |
34 #include "chrome/browser/autofill/autofill_metrics.h" | 35 #include "chrome/browser/autofill/autofill_metrics.h" |
35 #include "chrome/browser/autofill/autofill_profile.h" | 36 #include "chrome/browser/autofill/autofill_profile.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 | 74 |
74 namespace { | 75 namespace { |
75 | 76 |
76 const char* kAutofillManagerWebContentsUserDataKey = "web_contents_autofill"; | 77 const char* kAutofillManagerWebContentsUserDataKey = "web_contents_autofill"; |
77 | 78 |
78 // We only send a fraction of the forms to upload server. | 79 // We only send a fraction of the forms to upload server. |
79 // The rate for positive/negative matches potentially could be different. | 80 // The rate for positive/negative matches potentially could be different. |
80 const double kAutofillPositiveUploadRateDefaultValue = 0.20; | 81 const double kAutofillPositiveUploadRateDefaultValue = 0.20; |
81 const double kAutofillNegativeUploadRateDefaultValue = 0.20; | 82 const double kAutofillNegativeUploadRateDefaultValue = 0.20; |
82 | 83 |
83 const size_t kMaxRecentFormSignaturesToRemember = 3; | 84 const size_t kMaxRecentFormSignaturesToRemember = 0; |
Ilya Sherman
2013/01/24 06:36:48
Why did you change this variable?
benquan
2013/01/24 18:30:42
ah, this change was for testing, reverted.
| |
84 | 85 |
85 // Set a conservative upper bound on the number of forms we are willing to | 86 // Set a conservative upper bound on the number of forms we are willing to |
86 // cache, simply to prevent unbounded memory consumption. | 87 // cache, simply to prevent unbounded memory consumption. |
87 const size_t kMaxFormCacheSize = 100; | 88 const size_t kMaxFormCacheSize = 100; |
88 | 89 |
89 // Removes duplicate suggestions whilst preserving their original order. | 90 // Removes duplicate suggestions whilst preserving their original order. |
90 void RemoveDuplicateSuggestions(std::vector<string16>* values, | 91 void RemoveDuplicateSuggestions(std::vector<string16>* values, |
91 std::vector<string16>* labels, | 92 std::vector<string16>* labels, |
92 std::vector<string16>* icons, | 93 std::vector<string16>* icons, |
93 std::vector<int>* unique_ids) { | 94 std::vector<int>* unique_ids) { |
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
387 return false; | 388 return false; |
388 | 389 |
389 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) | 390 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) |
390 return false; | 391 return false; |
391 | 392 |
392 // Don't save data that was submitted through JavaScript. | 393 // Don't save data that was submitted through JavaScript. |
393 if (!form.user_submitted) | 394 if (!form.user_submitted) |
394 return false; | 395 return false; |
395 | 396 |
396 // Grab a copy of the form data. | 397 // Grab a copy of the form data. |
397 scoped_ptr<FormStructure> submitted_form(new FormStructure(form)); | 398 scoped_ptr<FormStructure> submitted_form( |
399 new FormStructure(form, IsAutocheckoutEnabled())); | |
398 | 400 |
399 // Disregard forms that we wouldn't ever autofill in the first place. | 401 // Disregard forms that we wouldn't ever autofill in the first place. |
400 if (!submitted_form->ShouldBeParsed(true)) | 402 if (!submitted_form->ShouldBeParsed(true)) |
401 return false; | 403 return false; |
402 | 404 |
403 // Ignore forms not present in our cache. These are typically forms with | 405 // Ignore forms not present in our cache. These are typically forms with |
404 // wonky JavaScript that also makes them not auto-fillable. | 406 // wonky JavaScript that also makes them not auto-fillable. |
405 FormStructure* cached_submitted_form; | 407 FormStructure* cached_submitted_form; |
406 if (!FindCachedForm(form, &cached_submitted_form)) | 408 if (!FindCachedForm(form, &cached_submitted_form)) |
407 return false; | 409 return false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 forms_loaded_timestamp_, | 449 forms_loaded_timestamp_, |
448 initial_interaction_timestamp_, | 450 initial_interaction_timestamp_, |
449 timestamp)); | 451 timestamp)); |
450 } | 452 } |
451 | 453 |
452 return true; | 454 return true; |
453 } | 455 } |
454 | 456 |
455 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, | 457 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, |
456 const TimeTicks& timestamp) { | 458 const TimeTicks& timestamp) { |
459 DVLOG(1) << "Autocheckout is " | |
460 << (IsAutocheckoutEnabled() ? "enabled" : "disabled") | |
461 << " for " << web_contents()->GetURL(); | |
457 bool enabled = IsAutofillEnabled(); | 462 bool enabled = IsAutofillEnabled(); |
458 if (!has_logged_autofill_enabled_) { | 463 if (!has_logged_autofill_enabled_) { |
459 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); | 464 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); |
460 has_logged_autofill_enabled_ = true; | 465 has_logged_autofill_enabled_ = true; |
461 } | 466 } |
462 | 467 |
463 if (!enabled) | 468 if (!enabled) |
464 return; | 469 return; |
465 | 470 |
466 forms_loaded_timestamp_ = timestamp; | 471 forms_loaded_timestamp_ = timestamp; |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
880 | 885 |
881 void AutofillManager::OnDidEndTextFieldEditing() { | 886 void AutofillManager::OnDidEndTextFieldEditing() { |
882 if (external_delegate_) | 887 if (external_delegate_) |
883 external_delegate_->DidEndTextFieldEditing(); | 888 external_delegate_->DidEndTextFieldEditing(); |
884 } | 889 } |
885 | 890 |
886 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { | 891 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { |
887 // TODO(ahutter): Plug into WalletClient. | 892 // TODO(ahutter): Plug into WalletClient. |
888 } | 893 } |
889 | 894 |
895 bool AutofillManager::IsAutocheckoutEnabled() const { | |
896 if (!web_contents()) | |
897 return false; | |
898 | |
899 autocheckout::WhitelistManager* wm = | |
900 autocheckout::WhitelistManager::GetForBrowserContext( | |
901 web_contents()->GetBrowserContext()); | |
902 return wm->IsAutocheckoutEnabled(web_contents()->GetURL()); | |
903 } | |
904 | |
890 bool AutofillManager::IsAutofillEnabled() const { | 905 bool AutofillManager::IsAutofillEnabled() const { |
891 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 906 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled) || |
907 IsAutocheckoutEnabled(); | |
892 } | 908 } |
893 | 909 |
894 void AutofillManager::SendAutofillTypePredictions( | 910 void AutofillManager::SendAutofillTypePredictions( |
895 const std::vector<FormStructure*>& forms) const { | 911 const std::vector<FormStructure*>& forms) const { |
896 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 912 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
897 switches::kShowAutofillTypePredictions)) | 913 switches::kShowAutofillTypePredictions)) |
898 return; | 914 return; |
899 | 915 |
900 RenderViewHost* host = web_contents()->GetRenderViewHost(); | 916 RenderViewHost* host = web_contents()->GetRenderViewHost(); |
901 if (!host) | 917 if (!host) |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1080 } | 1096 } |
1081 | 1097 |
1082 bool AutofillManager::GetCachedFormAndField(const FormData& form, | 1098 bool AutofillManager::GetCachedFormAndField(const FormData& form, |
1083 const FormFieldData& field, | 1099 const FormFieldData& field, |
1084 FormStructure** form_structure, | 1100 FormStructure** form_structure, |
1085 AutofillField** autofill_field) { | 1101 AutofillField** autofill_field) { |
1086 // Find the FormStructure that corresponds to |form|. | 1102 // Find the FormStructure that corresponds to |form|. |
1087 // If we do not have this form in our cache but it is parseable, we'll add it | 1103 // If we do not have this form in our cache but it is parseable, we'll add it |
1088 // in the call to |UpdateCachedForm()|. | 1104 // in the call to |UpdateCachedForm()|. |
1089 if (!FindCachedForm(form, form_structure) && | 1105 if (!FindCachedForm(form, form_structure) && |
1090 !FormStructure(form).ShouldBeParsed(false)) { | 1106 !FormStructure(form, IsAutocheckoutEnabled()).ShouldBeParsed(false)) { |
1091 return false; | 1107 return false; |
1092 } | 1108 } |
1093 | 1109 |
1094 // Update the cached form to reflect any dynamic changes to the form data, if | 1110 // Update the cached form to reflect any dynamic changes to the form data, if |
1095 // necessary. | 1111 // necessary. |
1096 if (!UpdateCachedForm(form, *form_structure, form_structure)) | 1112 if (!UpdateCachedForm(form, *form_structure, form_structure)) |
1097 return false; | 1113 return false; |
1098 | 1114 |
1099 // No data to return if there are no auto-fillable fields. | 1115 // No data to return if there are no auto-fillable fields. |
1100 if (!(*form_structure)->autofill_count()) | 1116 if (!(*form_structure)->autofill_count()) |
(...skipping 26 matching lines...) Expand all Loading... | |
1127 needs_update = *cached_form->field(i) != live_form.fields[i]; | 1143 needs_update = *cached_form->field(i) != live_form.fields[i]; |
1128 } | 1144 } |
1129 | 1145 |
1130 if (!needs_update) | 1146 if (!needs_update) |
1131 return true; | 1147 return true; |
1132 | 1148 |
1133 if (form_structures_.size() >= kMaxFormCacheSize) | 1149 if (form_structures_.size() >= kMaxFormCacheSize) |
1134 return false; | 1150 return false; |
1135 | 1151 |
1136 // Add the new or updated form to our cache. | 1152 // Add the new or updated form to our cache. |
1137 form_structures_.push_back(new FormStructure(live_form)); | 1153 form_structures_.push_back( |
1154 new FormStructure(live_form, IsAutocheckoutEnabled())); | |
1138 *updated_form = *form_structures_.rbegin(); | 1155 *updated_form = *form_structures_.rbegin(); |
1139 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); | 1156 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); |
1140 | 1157 |
1141 // If we have cached data, propagate it to the updated form. | 1158 // If we have cached data, propagate it to the updated form. |
1142 if (cached_form) { | 1159 if (cached_form) { |
1143 std::map<string16, const AutofillField*> cached_fields; | 1160 std::map<string16, const AutofillField*> cached_fields; |
1144 for (size_t i = 0; i < cached_form->field_count(); ++i) { | 1161 for (size_t i = 0; i < cached_form->field_count(); ++i) { |
1145 const AutofillField* field = cached_form->field(i); | 1162 const AutofillField* field = cached_form->field(i); |
1146 cached_fields[field->unique_name()] = field; | 1163 cached_fields[field->unique_name()] = field; |
1147 } | 1164 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1203 personal_data_->GetCreditCardSuggestions( | 1220 personal_data_->GetCreditCardSuggestions( |
1204 type, field.value, values, labels, icons, &guid_pairs); | 1221 type, field.value, values, labels, icons, &guid_pairs); |
1205 | 1222 |
1206 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1223 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
1207 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); | 1224 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |
1208 } | 1225 } |
1209 } | 1226 } |
1210 | 1227 |
1211 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1228 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
1212 std::vector<FormStructure*> non_queryable_forms; | 1229 std::vector<FormStructure*> non_queryable_forms; |
1230 bool autocheckout_enabled = IsAutocheckoutEnabled(); | |
1213 for (std::vector<FormData>::const_iterator iter = forms.begin(); | 1231 for (std::vector<FormData>::const_iterator iter = forms.begin(); |
1214 iter != forms.end(); ++iter) { | 1232 iter != forms.end(); ++iter) { |
1215 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); | 1233 scoped_ptr<FormStructure> form_structure( |
1234 new FormStructure(*iter, autocheckout_enabled)); | |
1216 if (!form_structure->ShouldBeParsed(false)) | 1235 if (!form_structure->ShouldBeParsed(false)) |
1217 continue; | 1236 continue; |
1218 | 1237 |
1219 form_structure->DetermineHeuristicTypes(*metric_logger_); | 1238 form_structure->DetermineHeuristicTypes(*metric_logger_); |
1220 | 1239 |
1221 // Set aside forms with method GET or author-specified types, so that they | 1240 // Set aside forms with method GET or author-specified types, so that they |
1222 // are not included in the query to the server. | 1241 // are not included in the query to the server. |
1223 if (form_structure->ShouldBeCrowdsourced()) | 1242 if (form_structure->ShouldBeCrowdsourced()) |
1224 form_structures_.push_back(form_structure.release()); | 1243 form_structures_.push_back(form_structure.release()); |
1225 else | 1244 else |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1303 *profile_guid = IDToGUID(profile_id); | 1322 *profile_guid = IDToGUID(profile_id); |
1304 } | 1323 } |
1305 | 1324 |
1306 void AutofillManager::UpdateInitialInteractionTimestamp( | 1325 void AutofillManager::UpdateInitialInteractionTimestamp( |
1307 const TimeTicks& interaction_timestamp) { | 1326 const TimeTicks& interaction_timestamp) { |
1308 if (initial_interaction_timestamp_.is_null() || | 1327 if (initial_interaction_timestamp_.is_null() || |
1309 interaction_timestamp < initial_interaction_timestamp_) { | 1328 interaction_timestamp < initial_interaction_timestamp_) { |
1310 initial_interaction_timestamp_ = interaction_timestamp; | 1329 initial_interaction_timestamp_ = interaction_timestamp; |
1311 } | 1330 } |
1312 } | 1331 } |
OLD | NEW |