Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: chrome/browser/autofill/autofill_manager.cc

Issue 11867025: Download autocheckout whitelist and enable autocheckout for whitelisted sites only. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync to head Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_infobar_delegate.h" 27 #include "chrome/browser/autofill/autocheckout_infobar_delegate.h"
27 #include "chrome/browser/autofill/autocheckout_manager.h" 28 #include "chrome/browser/autofill/autocheckout_manager.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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 return false; 389 return false;
389 390
390 if (web_contents()->GetBrowserContext()->IsOffTheRecord()) 391 if (web_contents()->GetBrowserContext()->IsOffTheRecord())
391 return false; 392 return false;
392 393
393 // Don't save data that was submitted through JavaScript. 394 // Don't save data that was submitted through JavaScript.
394 if (!form.user_submitted) 395 if (!form.user_submitted)
395 return false; 396 return false;
396 397
397 // Grab a copy of the form data. 398 // Grab a copy of the form data.
398 scoped_ptr<FormStructure> submitted_form(new FormStructure(form)); 399 scoped_ptr<FormStructure> submitted_form(
400 new FormStructure(form, GetAutocheckoutURLPrefix()));
399 401
400 // Disregard forms that we wouldn't ever autofill in the first place. 402 // Disregard forms that we wouldn't ever autofill in the first place.
401 if (!submitted_form->ShouldBeParsed(true)) 403 if (!submitted_form->ShouldBeParsed(true))
402 return false; 404 return false;
403 405
404 // Ignore forms not present in our cache. These are typically forms with 406 // Ignore forms not present in our cache. These are typically forms with
405 // wonky JavaScript that also makes them not auto-fillable. 407 // wonky JavaScript that also makes them not auto-fillable.
406 FormStructure* cached_submitted_form; 408 FormStructure* cached_submitted_form;
407 if (!FindCachedForm(form, &cached_submitted_form)) 409 if (!FindCachedForm(form, &cached_submitted_form))
408 return false; 410 return false;
(...skipping 473 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 884
883 void AutofillManager::OnDidEndTextFieldEditing() { 885 void AutofillManager::OnDidEndTextFieldEditing() {
884 if (external_delegate_) 886 if (external_delegate_)
885 external_delegate_->DidEndTextFieldEditing(); 887 external_delegate_->DidEndTextFieldEditing();
886 } 888 }
887 889
888 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) { 890 void AutofillManager::OnClickFailed(autofill::AutocheckoutStatus status) {
889 // TODO(ahutter): Plug into WalletClient. 891 // TODO(ahutter): Plug into WalletClient.
890 } 892 }
891 893
894 std::string AutofillManager::GetAutocheckoutURLPrefix() const {
895 if (!web_contents())
896 return std::string();
897
898 autofill::autocheckout::WhitelistManager* whitelist_manager =
899 autofill::autocheckout::WhitelistManager::GetForBrowserContext(
900 web_contents()->GetBrowserContext());
901 return whitelist_manager->GetMatchedURLPrefix(web_contents()->GetURL());
902 }
903
892 bool AutofillManager::IsAutofillEnabled() const { 904 bool AutofillManager::IsAutofillEnabled() const {
893 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled); 905 return manager_delegate_->GetPrefs()->GetBoolean(prefs::kAutofillEnabled);
894 } 906 }
895 907
896 void AutofillManager::SendAutofillTypePredictions( 908 void AutofillManager::SendAutofillTypePredictions(
897 const std::vector<FormStructure*>& forms) const { 909 const std::vector<FormStructure*>& forms) const {
898 if (!CommandLine::ForCurrentProcess()->HasSwitch( 910 if (!CommandLine::ForCurrentProcess()->HasSwitch(
899 switches::kShowAutofillTypePredictions)) 911 switches::kShowAutofillTypePredictions))
900 return; 912 return;
901 913
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
1082 } 1094 }
1083 1095
1084 bool AutofillManager::GetCachedFormAndField(const FormData& form, 1096 bool AutofillManager::GetCachedFormAndField(const FormData& form,
1085 const FormFieldData& field, 1097 const FormFieldData& field,
1086 FormStructure** form_structure, 1098 FormStructure** form_structure,
1087 AutofillField** autofill_field) { 1099 AutofillField** autofill_field) {
1088 // Find the FormStructure that corresponds to |form|. 1100 // Find the FormStructure that corresponds to |form|.
1089 // If we do not have this form in our cache but it is parseable, we'll add it 1101 // If we do not have this form in our cache but it is parseable, we'll add it
1090 // in the call to |UpdateCachedForm()|. 1102 // in the call to |UpdateCachedForm()|.
1091 if (!FindCachedForm(form, form_structure) && 1103 if (!FindCachedForm(form, form_structure) &&
1092 !FormStructure(form).ShouldBeParsed(false)) { 1104 !FormStructure(form, GetAutocheckoutURLPrefix()).ShouldBeParsed(false)) {
1093 return false; 1105 return false;
1094 } 1106 }
1095 1107
1096 // Update the cached form to reflect any dynamic changes to the form data, if 1108 // Update the cached form to reflect any dynamic changes to the form data, if
1097 // necessary. 1109 // necessary.
1098 if (!UpdateCachedForm(form, *form_structure, form_structure)) 1110 if (!UpdateCachedForm(form, *form_structure, form_structure))
1099 return false; 1111 return false;
1100 1112
1101 // No data to return if there are no auto-fillable fields. 1113 // No data to return if there are no auto-fillable fields.
1102 if (!(*form_structure)->autofill_count()) 1114 if (!(*form_structure)->autofill_count())
(...skipping 26 matching lines...) Expand all
1129 needs_update = *cached_form->field(i) != live_form.fields[i]; 1141 needs_update = *cached_form->field(i) != live_form.fields[i];
1130 } 1142 }
1131 1143
1132 if (!needs_update) 1144 if (!needs_update)
1133 return true; 1145 return true;
1134 1146
1135 if (form_structures_.size() >= kMaxFormCacheSize) 1147 if (form_structures_.size() >= kMaxFormCacheSize)
1136 return false; 1148 return false;
1137 1149
1138 // Add the new or updated form to our cache. 1150 // Add the new or updated form to our cache.
1139 form_structures_.push_back(new FormStructure(live_form)); 1151 form_structures_.push_back(
1152 new FormStructure(live_form, GetAutocheckoutURLPrefix()));
1140 *updated_form = *form_structures_.rbegin(); 1153 *updated_form = *form_structures_.rbegin();
1141 (*updated_form)->DetermineHeuristicTypes(*metric_logger_); 1154 (*updated_form)->DetermineHeuristicTypes(*metric_logger_);
1142 1155
1143 // If we have cached data, propagate it to the updated form. 1156 // If we have cached data, propagate it to the updated form.
1144 if (cached_form) { 1157 if (cached_form) {
1145 std::map<string16, const AutofillField*> cached_fields; 1158 std::map<string16, const AutofillField*> cached_fields;
1146 for (size_t i = 0; i < cached_form->field_count(); ++i) { 1159 for (size_t i = 0; i < cached_form->field_count(); ++i) {
1147 const AutofillField* field = cached_form->field(i); 1160 const AutofillField* field = cached_form->field(i);
1148 cached_fields[field->unique_name()] = field; 1161 cached_fields[field->unique_name()] = field;
1149 } 1162 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1205 personal_data_->GetCreditCardSuggestions( 1218 personal_data_->GetCreditCardSuggestions(
1206 type, field.value, values, labels, icons, &guid_pairs); 1219 type, field.value, values, labels, icons, &guid_pairs);
1207 1220
1208 for (size_t i = 0; i < guid_pairs.size(); ++i) { 1221 for (size_t i = 0; i < guid_pairs.size(); ++i) {
1209 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); 1222 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0)));
1210 } 1223 }
1211 } 1224 }
1212 1225
1213 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { 1226 void AutofillManager::ParseForms(const std::vector<FormData>& forms) {
1214 std::vector<FormStructure*> non_queryable_forms; 1227 std::vector<FormStructure*> non_queryable_forms;
1228 std::string autocheckout_url_prefix = GetAutocheckoutURLPrefix();
1215 for (std::vector<FormData>::const_iterator iter = forms.begin(); 1229 for (std::vector<FormData>::const_iterator iter = forms.begin();
1216 iter != forms.end(); ++iter) { 1230 iter != forms.end(); ++iter) {
1217 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); 1231 scoped_ptr<FormStructure> form_structure(
1232 new FormStructure(*iter, autocheckout_url_prefix));
1218 if (!form_structure->ShouldBeParsed(false)) 1233 if (!form_structure->ShouldBeParsed(false))
1219 continue; 1234 continue;
1220 1235
1221 form_structure->DetermineHeuristicTypes(*metric_logger_); 1236 form_structure->DetermineHeuristicTypes(*metric_logger_);
1222 1237
1223 // Set aside forms with method GET or author-specified types, so that they 1238 // Set aside forms with method GET or author-specified types, so that they
1224 // are not included in the query to the server. 1239 // are not included in the query to the server.
1225 if (form_structure->ShouldBeCrowdsourced()) 1240 if (form_structure->ShouldBeCrowdsourced())
1226 form_structures_.push_back(form_structure.release()); 1241 form_structures_.push_back(form_structure.release());
1227 else 1242 else
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1305 *profile_guid = IDToGUID(profile_id); 1320 *profile_guid = IDToGUID(profile_id);
1306 } 1321 }
1307 1322
1308 void AutofillManager::UpdateInitialInteractionTimestamp( 1323 void AutofillManager::UpdateInitialInteractionTimestamp(
1309 const TimeTicks& interaction_timestamp) { 1324 const TimeTicks& interaction_timestamp) {
1310 if (initial_interaction_timestamp_.is_null() || 1325 if (initial_interaction_timestamp_.is_null() ||
1311 interaction_timestamp < initial_interaction_timestamp_) { 1326 interaction_timestamp < initial_interaction_timestamp_) {
1312 initial_interaction_timestamp_ = interaction_timestamp; 1327 initial_interaction_timestamp_ = interaction_timestamp;
1313 } 1328 }
1314 } 1329 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/autofill_manager.h ('k') | chrome/browser/autofill/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698