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, GetAutocheckoutURLPrefix())); |
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 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
878 | 880 |
879 void AutofillManager::OnDidEndTextFieldEditing() { | 881 void AutofillManager::OnDidEndTextFieldEditing() { |
880 if (external_delegate_) | 882 if (external_delegate_) |
881 external_delegate_->DidEndTextFieldEditing(); | 883 external_delegate_->DidEndTextFieldEditing(); |
882 } | 884 } |
883 | 885 |
884 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { | 886 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { |
885 // TODO(ahutter): Plug into WalletClient. | 887 // TODO(ahutter): Plug into WalletClient. |
886 } | 888 } |
887 | 889 |
| 890 std::string AutofillManager::GetAutocheckoutURLPrefix() const { |
| 891 if (!web_contents()) |
| 892 return false; |
| 893 |
| 894 autofill::autocheckout::WhitelistManager* whitelist_manager = |
| 895 autofill::autocheckout::WhitelistManager::GetForBrowserContext( |
| 896 web_contents()->GetBrowserContext()); |
| 897 return whitelist_manager->GetMatchedURLPrefix(web_contents()->GetURL()); |
| 898 } |
| 899 |
888 bool AutofillManager::IsAutofillEnabled() const { | 900 bool AutofillManager::IsAutofillEnabled() const { |
889 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); | 901 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); |
890 } | 902 } |
891 | 903 |
892 void AutofillManager::SendAutofillTypePredictions( | 904 void AutofillManager::SendAutofillTypePredictions( |
893 const std::vector<FormStructure*>& forms) const { | 905 const std::vector<FormStructure*>& forms) const { |
894 if (!CommandLine::ForCurrentProcess()->HasSwitch( | 906 if (!CommandLine::ForCurrentProcess()->HasSwitch( |
895 switches::kShowAutofillTypePredictions)) | 907 switches::kShowAutofillTypePredictions)) |
896 return; | 908 return; |
897 | 909 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 } | 1090 } |
1079 | 1091 |
1080 bool AutofillManager::GetCachedFormAndField(const FormData& form, | 1092 bool AutofillManager::GetCachedFormAndField(const FormData& form, |
1081 const FormFieldData& field, | 1093 const FormFieldData& field, |
1082 FormStructure** form_structure, | 1094 FormStructure** form_structure, |
1083 AutofillField** autofill_field) { | 1095 AutofillField** autofill_field) { |
1084 // Find the FormStructure that corresponds to |form|. | 1096 // 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 | 1097 // If we do not have this form in our cache but it is parseable, we'll add it |
1086 // in the call to |UpdateCachedForm()|. | 1098 // in the call to |UpdateCachedForm()|. |
1087 if (!FindCachedForm(form, form_structure) && | 1099 if (!FindCachedForm(form, form_structure) && |
1088 !FormStructure(form).ShouldBeParsed(false)) { | 1100 !FormStructure(form, GetAutocheckoutURLPrefix()).ShouldBeParsed(false)) { |
1089 return false; | 1101 return false; |
1090 } | 1102 } |
1091 | 1103 |
1092 // Update the cached form to reflect any dynamic changes to the form data, if | 1104 // Update the cached form to reflect any dynamic changes to the form data, if |
1093 // necessary. | 1105 // necessary. |
1094 if (!UpdateCachedForm(form, *form_structure, form_structure)) | 1106 if (!UpdateCachedForm(form, *form_structure, form_structure)) |
1095 return false; | 1107 return false; |
1096 | 1108 |
1097 // No data to return if there are no auto-fillable fields. | 1109 // No data to return if there are no auto-fillable fields. |
1098 if (!(*form_structure)->autofill_count()) | 1110 if (!(*form_structure)->autofill_count()) |
(...skipping 26 matching lines...) Expand all Loading... |
1125 needs_update = *cached_form->field(i) != live_form.fields[i]; | 1137 needs_update = *cached_form->field(i) != live_form.fields[i]; |
1126 } | 1138 } |
1127 | 1139 |
1128 if (!needs_update) | 1140 if (!needs_update) |
1129 return true; | 1141 return true; |
1130 | 1142 |
1131 if (form_structures_.size() >= kMaxFormCacheSize) | 1143 if (form_structures_.size() >= kMaxFormCacheSize) |
1132 return false; | 1144 return false; |
1133 | 1145 |
1134 // Add the new or updated form to our cache. | 1146 // Add the new or updated form to our cache. |
1135 form_structures_.push_back(new FormStructure(live_form)); | 1147 form_structures_.push_back( |
| 1148 new FormStructure(live_form, GetAutocheckoutURLPrefix())); |
1136 *updated_form = *form_structures_.rbegin(); | 1149 *updated_form = *form_structures_.rbegin(); |
1137 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); | 1150 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); |
1138 | 1151 |
1139 // If we have cached data, propagate it to the updated form. | 1152 // If we have cached data, propagate it to the updated form. |
1140 if (cached_form) { | 1153 if (cached_form) { |
1141 std::map<string16, const AutofillField*> cached_fields; | 1154 std::map<string16, const AutofillField*> cached_fields; |
1142 for (size_t i = 0; i < cached_form->field_count(); ++i) { | 1155 for (size_t i = 0; i < cached_form->field_count(); ++i) { |
1143 const AutofillField* field = cached_form->field(i); | 1156 const AutofillField* field = cached_form->field(i); |
1144 cached_fields[field->unique_name()] = field; | 1157 cached_fields[field->unique_name()] = field; |
1145 } | 1158 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 personal_data_->GetCreditCardSuggestions( | 1214 personal_data_->GetCreditCardSuggestions( |
1202 type, field.value, values, labels, icons, &guid_pairs); | 1215 type, field.value, values, labels, icons, &guid_pairs); |
1203 | 1216 |
1204 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1217 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
1205 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); | 1218 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |
1206 } | 1219 } |
1207 } | 1220 } |
1208 | 1221 |
1209 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1222 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
1210 std::vector<FormStructure*> non_queryable_forms; | 1223 std::vector<FormStructure*> non_queryable_forms; |
| 1224 std::string autocheckout_url_prefix = GetAutocheckoutURLPrefix(); |
1211 for (std::vector<FormData>::const_iterator iter = forms.begin(); | 1225 for (std::vector<FormData>::const_iterator iter = forms.begin(); |
1212 iter != forms.end(); ++iter) { | 1226 iter != forms.end(); ++iter) { |
1213 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); | 1227 scoped_ptr<FormStructure> form_structure( |
| 1228 new FormStructure(*iter, autocheckout_url_prefix)); |
1214 if (!form_structure->ShouldBeParsed(false)) | 1229 if (!form_structure->ShouldBeParsed(false)) |
1215 continue; | 1230 continue; |
1216 | 1231 |
1217 form_structure->DetermineHeuristicTypes(*metric_logger_); | 1232 form_structure->DetermineHeuristicTypes(*metric_logger_); |
1218 | 1233 |
1219 // Set aside forms with method GET or author-specified types, so that they | 1234 // Set aside forms with method GET or author-specified types, so that they |
1220 // are not included in the query to the server. | 1235 // are not included in the query to the server. |
1221 if (form_structure->ShouldBeCrowdsourced()) | 1236 if (form_structure->ShouldBeCrowdsourced()) |
1222 form_structures_.push_back(form_structure.release()); | 1237 form_structures_.push_back(form_structure.release()); |
1223 else | 1238 else |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1301 *profile_guid = IDToGUID(profile_id); | 1316 *profile_guid = IDToGUID(profile_id); |
1302 } | 1317 } |
1303 | 1318 |
1304 void AutofillManager::UpdateInitialInteractionTimestamp( | 1319 void AutofillManager::UpdateInitialInteractionTimestamp( |
1305 const TimeTicks& interaction_timestamp) { | 1320 const TimeTicks& interaction_timestamp) { |
1306 if (initial_interaction_timestamp_.is_null() || | 1321 if (initial_interaction_timestamp_.is_null() || |
1307 interaction_timestamp < initial_interaction_timestamp_) { | 1322 interaction_timestamp < initial_interaction_timestamp_) { |
1308 initial_interaction_timestamp_ = interaction_timestamp; | 1323 initial_interaction_timestamp_ = interaction_timestamp; |
1309 } | 1324 } |
1310 } | 1325 } |
OLD | NEW |