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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 return false; | 387 return false; |
387 | 388 |
388 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) | 389 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) |
389 return false; | 390 return false; |
390 | 391 |
391 // Don't save data that was submitted through JavaScript. | 392 // Don't save data that was submitted through JavaScript. |
392 if (!form.user_submitted) | 393 if (!form.user_submitted) |
393 return false; | 394 return false; |
394 | 395 |
395 // Grab a copy of the form data. | 396 // Grab a copy of the form data. |
396 scoped_ptr<FormStructure> submitted_form(new FormStructure(form)); | 397 scoped_ptr<FormStructure> submitted_form( |
| 398 new FormStructure(form, IsAutocheckoutEnabled())); |
397 | 399 |
398 // Disregard forms that we wouldn't ever autofill in the first place. | 400 // Disregard forms that we wouldn't ever autofill in the first place. |
399 if (!submitted_form->ShouldBeParsed(true)) | 401 if (!submitted_form->ShouldBeParsed(true)) |
400 return false; | 402 return false; |
401 | 403 |
402 // Ignore forms not present in our cache. These are typically forms with | 404 // Ignore forms not present in our cache. These are typically forms with |
403 // wonky JavaScript that also makes them not auto-fillable. | 405 // wonky JavaScript that also makes them not auto-fillable. |
404 FormStructure* cached_submitted_form; | 406 FormStructure* cached_submitted_form; |
405 if (!FindCachedForm(form, &cached_submitted_form)) | 407 if (!FindCachedForm(form, &cached_submitted_form)) |
406 return false; | 408 return false; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 forms_loaded_timestamp_, | 448 forms_loaded_timestamp_, |
447 initial_interaction_timestamp_, | 449 initial_interaction_timestamp_, |
448 timestamp)); | 450 timestamp)); |
449 } | 451 } |
450 | 452 |
451 return true; | 453 return true; |
452 } | 454 } |
453 | 455 |
454 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, | 456 void AutofillManager::OnFormsSeen(const std::vector<FormData>& forms, |
455 const TimeTicks& timestamp) { | 457 const TimeTicks& timestamp) { |
| 458 DVLOG(1) << "Autocheckout is " |
| 459 << (IsAutocheckoutEnabled() ? "enabled" : "disabled") |
| 460 << " for " << web_contents()->GetURL(); |
456 bool enabled = IsAutofillEnabled(); | 461 bool enabled = IsAutofillEnabled(); |
457 if (!has_logged_autofill_enabled_) { | 462 if (!has_logged_autofill_enabled_) { |
458 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); | 463 metric_logger_->LogIsAutofillEnabledAtPageLoad(enabled); |
459 has_logged_autofill_enabled_ = true; | 464 has_logged_autofill_enabled_ = true; |
460 } | 465 } |
461 | 466 |
462 if (!enabled) | 467 if (!enabled) |
463 return; | 468 return; |
464 | 469 |
465 forms_loaded_timestamp_ = timestamp; | 470 forms_loaded_timestamp_ = timestamp; |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 | 883 |
879 void AutofillManager::OnDidEndTextFieldEditing() { | 884 void AutofillManager::OnDidEndTextFieldEditing() { |
880 if (external_delegate_) | 885 if (external_delegate_) |
881 external_delegate_->DidEndTextFieldEditing(); | 886 external_delegate_->DidEndTextFieldEditing(); |
882 } | 887 } |
883 | 888 |
884 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { | 889 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { |
885 // TODO(ahutter): Plug into WalletClient. | 890 // TODO(ahutter): Plug into WalletClient. |
886 } | 891 } |
887 | 892 |
| 893 bool AutofillManager::IsAutocheckoutEnabled() const { |
| 894 if (!web_contents()) |
| 895 return false; |
| 896 |
| 897 autofill::autocheckout::WhitelistManager* whitelist_manager = |
| 898 autofill::autocheckout::WhitelistManager::GetForBrowserContext( |
| 899 web_contents()->GetBrowserContext()); |
| 900 return whitelist_manager->IsAutocheckoutEnabled(web_contents()->GetURL()); |
| 901 } |
| 902 |
888 bool AutofillManager::IsAutofillEnabled() const { | 903 bool AutofillManager::IsAutofillEnabled() const { |
889 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 904 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
890 } | 905 } |
891 | 906 |
892 void AutofillManager::SendAutofillTypePredictions( | 907 void AutofillManager::SendAutofillTypePredictions( |
893 const std::vector<FormStructure*>& forms) const { | 908 const std::vector<FormStructure*>& forms) const { |
894 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 909 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
895 switches::kShowAutofillTypePredictions)) | 910 switches::kShowAutofillTypePredictions)) |
896 return; | 911 return; |
897 | 912 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 } | 1093 } |
1079 | 1094 |
1080 bool AutofillManager::GetCachedFormAndField(const FormData& form, | 1095 bool AutofillManager::GetCachedFormAndField(const FormData& form, |
1081 const FormFieldData& field, | 1096 const FormFieldData& field, |
1082 FormStructure** form_structure, | 1097 FormStructure** form_structure, |
1083 AutofillField** autofill_field) { | 1098 AutofillField** autofill_field) { |
1084 // Find the FormStructure that corresponds to |form|. | 1099 // Find the FormStructure that corresponds to |form|. |
1085 // If we do not have this form in our cache but it is parseable, we'll add it | 1100 // If we do not have this form in our cache but it is parseable, we'll add it |
1086 // in the call to |UpdateCachedForm()|. | 1101 // in the call to |UpdateCachedForm()|. |
1087 if (!FindCachedForm(form, form_structure) && | 1102 if (!FindCachedForm(form, form_structure) && |
1088 !FormStructure(form).ShouldBeParsed(false)) { | 1103 !FormStructure(form, IsAutocheckoutEnabled()).ShouldBeParsed(false)) { |
1089 return false; | 1104 return false; |
1090 } | 1105 } |
1091 | 1106 |
1092 // Update the cached form to reflect any dynamic changes to the form data, if | 1107 // Update the cached form to reflect any dynamic changes to the form data, if |
1093 // necessary. | 1108 // necessary. |
1094 if (!UpdateCachedForm(form, *form_structure, form_structure)) | 1109 if (!UpdateCachedForm(form, *form_structure, form_structure)) |
1095 return false; | 1110 return false; |
1096 | 1111 |
1097 // No data to return if there are no auto-fillable fields. | 1112 // No data to return if there are no auto-fillable fields. |
1098 if (!(*form_structure)->autofill_count()) | 1113 if (!(*form_structure)->autofill_count()) |
(...skipping 26 matching lines...) Expand all Loading... |
1125 needs_update = *cached_form->field(i) != live_form.fields[i]; | 1140 needs_update = *cached_form->field(i) != live_form.fields[i]; |
1126 } | 1141 } |
1127 | 1142 |
1128 if (!needs_update) | 1143 if (!needs_update) |
1129 return true; | 1144 return true; |
1130 | 1145 |
1131 if (form_structures_.size() >= kMaxFormCacheSize) | 1146 if (form_structures_.size() >= kMaxFormCacheSize) |
1132 return false; | 1147 return false; |
1133 | 1148 |
1134 // Add the new or updated form to our cache. | 1149 // Add the new or updated form to our cache. |
1135 form_structures_.push_back(new FormStructure(live_form)); | 1150 form_structures_.push_back( |
| 1151 new FormStructure(live_form, IsAutocheckoutEnabled())); |
1136 *updated_form = *form_structures_.rbegin(); | 1152 *updated_form = *form_structures_.rbegin(); |
1137 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); | 1153 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); |
1138 | 1154 |
1139 // If we have cached data, propagate it to the updated form. | 1155 // If we have cached data, propagate it to the updated form. |
1140 if (cached_form) { | 1156 if (cached_form) { |
1141 std::map<string16, const AutofillField*> cached_fields; | 1157 std::map<string16, const AutofillField*> cached_fields; |
1142 for (size_t i = 0; i < cached_form->field_count(); ++i) { | 1158 for (size_t i = 0; i < cached_form->field_count(); ++i) { |
1143 const AutofillField* field = cached_form->field(i); | 1159 const AutofillField* field = cached_form->field(i); |
1144 cached_fields[field->unique_name()] = field; | 1160 cached_fields[field->unique_name()] = field; |
1145 } | 1161 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 personal_data_->GetCreditCardSuggestions( | 1217 personal_data_->GetCreditCardSuggestions( |
1202 type, field.value, values, labels, icons, &guid_pairs); | 1218 type, field.value, values, labels, icons, &guid_pairs); |
1203 | 1219 |
1204 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1220 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
1205 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); | 1221 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |
1206 } | 1222 } |
1207 } | 1223 } |
1208 | 1224 |
1209 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1225 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
1210 std::vector<FormStructure*> non_queryable_forms; | 1226 std::vector<FormStructure*> non_queryable_forms; |
| 1227 bool autocheckout_enabled = IsAutocheckoutEnabled(); |
1211 for (std::vector<FormData>::const_iterator iter = forms.begin(); | 1228 for (std::vector<FormData>::const_iterator iter = forms.begin(); |
1212 iter != forms.end(); ++iter) { | 1229 iter != forms.end(); ++iter) { |
1213 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); | 1230 scoped_ptr<FormStructure> form_structure( |
| 1231 new FormStructure(*iter, autocheckout_enabled)); |
1214 if (!form_structure->ShouldBeParsed(false)) | 1232 if (!form_structure->ShouldBeParsed(false)) |
1215 continue; | 1233 continue; |
1216 | 1234 |
1217 form_structure->DetermineHeuristicTypes(*metric_logger_); | 1235 form_structure->DetermineHeuristicTypes(*metric_logger_); |
1218 | 1236 |
1219 // Set aside forms with method GET or author-specified types, so that they | 1237 // Set aside forms with method GET or author-specified types, so that they |
1220 // are not included in the query to the server. | 1238 // are not included in the query to the server. |
1221 if (form_structure->ShouldBeCrowdsourced()) | 1239 if (form_structure->ShouldBeCrowdsourced()) |
1222 form_structures_.push_back(form_structure.release()); | 1240 form_structures_.push_back(form_structure.release()); |
1223 else | 1241 else |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 *profile_guid = IDToGUID(profile_id); | 1319 *profile_guid = IDToGUID(profile_id); |
1302 } | 1320 } |
1303 | 1321 |
1304 void AutofillManager::UpdateInitialInteractionTimestamp( | 1322 void AutofillManager::UpdateInitialInteractionTimestamp( |
1305 const TimeTicks& interaction_timestamp) { | 1323 const TimeTicks& interaction_timestamp) { |
1306 if (initial_interaction_timestamp_.is_null() || | 1324 if (initial_interaction_timestamp_.is_null() || |
1307 interaction_timestamp < initial_interaction_timestamp_) { | 1325 interaction_timestamp < initial_interaction_timestamp_) { |
1308 initial_interaction_timestamp_ = interaction_timestamp; | 1326 initial_interaction_timestamp_ = interaction_timestamp; |
1309 } | 1327 } |
1310 } | 1328 } |
OLD | NEW |