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

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

Issue 7013016: Autofill should reject aggregated profiles where email address is found in non-email fields (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adds test files. Created 9 years, 7 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/personal_data_manager.h" 5 #include "chrome/browser/autofill/personal_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <iterator> 8 #include <iterator>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 // been met. An address submitted via a form must have at least these fields 95 // been met. An address submitted via a form must have at least these fields
96 // filled. No verification of validity of the contents is preformed. This is 96 // filled. No verification of validity of the contents is preformed. This is
97 // and existence check only. 97 // and existence check only.
98 bool IsMinimumAddress(const AutofillProfile& profile) { 98 bool IsMinimumAddress(const AutofillProfile& profile) {
99 return !profile.GetInfo(ADDRESS_HOME_LINE1).empty() && 99 return !profile.GetInfo(ADDRESS_HOME_LINE1).empty() &&
100 !profile.GetInfo(ADDRESS_HOME_CITY).empty() && 100 !profile.GetInfo(ADDRESS_HOME_CITY).empty() &&
101 !profile.GetInfo(ADDRESS_HOME_STATE).empty() && 101 !profile.GetInfo(ADDRESS_HOME_STATE).empty() &&
102 !profile.GetInfo(ADDRESS_HOME_ZIP).empty(); 102 !profile.GetInfo(ADDRESS_HOME_ZIP).empty();
103 } 103 }
104 104
105 // Return true if the |field_type| and |value| are valid within the context
106 // of importing a form.
107 bool IsValidFieldTypeAndValue(const std::set<AutofillFieldType>& types_seen,
108 AutofillFieldType field_type,
109 const string16& value) {
110 // Abandon the import if two fields of the same type are encountered.
111 // This indicates ambiguous data or miscategorization of types.
112 // Make an exception for PHONE_HOME_NUMBER however as both prefix and
113 // suffix are stored against this type.
114 if (types_seen.count(field_type) &&
115 field_type != PHONE_HOME_NUMBER &&
116 field_type != PHONE_FAX_NUMBER) {
117 return false;
118 }
119
120 // Abandon the import if an email address value shows up in a field that is
121 // not an email address.
122 if (field_type != EMAIL_ADDRESS && IsValidEmail(value))
123 return false;
Ilya Sherman 2011/05/12 21:40:03 It's a little confusing to me that this check is h
dhollowa 2011/05/12 23:24:12 Done.
124
125 return true;
126 }
127
105 } // namespace 128 } // namespace
106 129
107 PersonalDataManager::~PersonalDataManager() { 130 PersonalDataManager::~PersonalDataManager() {
108 CancelPendingQuery(&pending_profiles_query_); 131 CancelPendingQuery(&pending_profiles_query_);
109 CancelPendingQuery(&pending_creditcards_query_); 132 CancelPendingQuery(&pending_creditcards_query_);
110 } 133 }
111 134
112 void PersonalDataManager::OnWebDataServiceRequestDone( 135 void PersonalDataManager::OnWebDataServiceRequestDone(
113 WebDataService::Handle h, 136 WebDataService::Handle h,
114 const WDTypedResult* result) { 137 const WDTypedResult* result) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 string16 value = CollapseWhitespace(field->value, false); 230 string16 value = CollapseWhitespace(field->value, false);
208 231
209 // If we don't know the type of the field, or the user hasn't entered any 232 // If we don't know the type of the field, or the user hasn't entered any
210 // information into the field, then skip it. 233 // information into the field, then skip it.
211 if (!field->IsFieldFillable() || value.empty()) 234 if (!field->IsFieldFillable() || value.empty())
212 continue; 235 continue;
213 236
214 AutofillFieldType field_type = field->type(); 237 AutofillFieldType field_type = field->type();
215 FieldTypeGroup group(AutofillType(field_type).group()); 238 FieldTypeGroup group(AutofillType(field_type).group());
216 239
217 // Abandon the import if two fields of the same type are encountered. 240 // If the |field_type| and |value| don't pass basic validity checks then
218 // This indicates ambiguous data or miscategorization of types. 241 // abandon the import.
219 // Make an exception for PHONE_HOME_NUMBER however as both prefix and 242 if (!IsValidFieldTypeAndValue(types_seen, field_type, value)) {
220 // suffix are stored against this type.
221 if (types_seen.count(field_type) &&
222 field_type != PHONE_HOME_NUMBER &&
223 field_type != PHONE_FAX_NUMBER) {
224 imported_profile.reset(); 243 imported_profile.reset();
225 local_imported_credit_card.reset(); 244 local_imported_credit_card.reset();
226 break; 245 break;
227 } else {
228 types_seen.insert(field_type);
229 } 246 }
230 247
248 types_seen.insert(field_type);
249
231 if (group == AutofillType::CREDIT_CARD) { 250 if (group == AutofillType::CREDIT_CARD) {
232 // If the user has a password set, we have no way of setting credit 251 // If the user has a password set, we have no way of setting credit
233 // card numbers. 252 // card numbers.
234 if (!HasPassword()) { 253 if (LowerCaseEqualsASCII(field->form_control_type, "month")) {
235 if (LowerCaseEqualsASCII(field->form_control_type, "month")) { 254 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type);
236 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type); 255 local_imported_credit_card->SetInfoForMonthInputType(value);
237 local_imported_credit_card->SetInfoForMonthInputType(value); 256 } else {
238 } else { 257 if (field_type == CREDIT_CARD_NUMBER) {
239 if (field_type == CREDIT_CARD_NUMBER) { 258 // Clean up any imported credit card numbers.
240 // Clean up any imported credit card numbers. 259 value = CreditCard::StripSeparators(value);
241 value = CreditCard::StripSeparators(value);
242 }
243 local_imported_credit_card->SetInfo(field_type, value);
244 } 260 }
245 ++importable_credit_card_fields; 261 local_imported_credit_card->SetInfo(field_type, value);
246 } 262 }
263 ++importable_credit_card_fields;
247 } else { 264 } else {
248 // In the case of a phone number, if the whole phone number was entered 265 // In the case of a phone number, if the whole phone number was entered
249 // into a single field, then parse it and set the sub components. 266 // into a single field, then parse it and set the sub components.
250 if (AutofillType(field_type).subgroup() == 267 if (AutofillType(field_type).subgroup() ==
251 AutofillType::PHONE_WHOLE_NUMBER) { 268 AutofillType::PHONE_WHOLE_NUMBER) {
252 string16 number; 269 string16 number;
253 string16 city_code; 270 string16 city_code;
254 string16 country_code; 271 string16 country_code;
255 PhoneNumber::ParsePhoneNumber(value, 272 PhoneNumber::ParsePhoneNumber(value,
256 &number, 273 &number,
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 iter != profiles.end(); ++iter) { 546 iter != profiles.end(); ++iter) {
530 (*iter)->GetNonEmptyTypes(non_empty_types); 547 (*iter)->GetNonEmptyTypes(non_empty_types);
531 } 548 }
532 549
533 for (ScopedVector<CreditCard>::const_iterator iter = credit_cards_.begin(); 550 for (ScopedVector<CreditCard>::const_iterator iter = credit_cards_.begin();
534 iter != credit_cards_.end(); ++iter) { 551 iter != credit_cards_.end(); ++iter) {
535 (*iter)->GetNonEmptyTypes(non_empty_types); 552 (*iter)->GetNonEmptyTypes(non_empty_types);
536 } 553 }
537 } 554 }
538 555
539 bool PersonalDataManager::HasPassword() {
540 return !password_hash_.empty();
541 }
542
543 bool PersonalDataManager::IsDataLoaded() const { 556 bool PersonalDataManager::IsDataLoaded() const {
544 return is_data_loaded_; 557 return is_data_loaded_;
545 } 558 }
546 559
547 const std::vector<AutofillProfile*>& PersonalDataManager::profiles() const { 560 const std::vector<AutofillProfile*>& PersonalDataManager::profiles() const {
548 // |profile_| is NULL in AutofillManagerTest. 561 // |profile_| is NULL in AutofillManagerTest.
549 bool auxiliary_profiles_enabled = profile_ ? profile_->GetPrefs()->GetBoolean( 562 bool auxiliary_profiles_enabled = profile_ ? profile_->GetPrefs()->GetBoolean(
550 prefs::kAutofillAuxiliaryProfilesEnabled) : false; 563 prefs::kAutofillAuxiliaryProfilesEnabled) : false;
551 if (!auxiliary_profiles_enabled) 564 if (!auxiliary_profiles_enabled)
552 return web_profiles(); 565 return web_profiles();
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
967 } 980 }
968 981
969 const AutofillMetrics* PersonalDataManager::metric_logger() const { 982 const AutofillMetrics* PersonalDataManager::metric_logger() const {
970 return metric_logger_.get(); 983 return metric_logger_.get();
971 } 984 }
972 985
973 void PersonalDataManager::set_metric_logger( 986 void PersonalDataManager::set_metric_logger(
974 const AutofillMetrics* metric_logger) { 987 const AutofillMetrics* metric_logger) {
975 metric_logger_.reset(metric_logger); 988 metric_logger_.reset(metric_logger);
976 } 989 }
OLDNEW
« no previous file with comments | « chrome/browser/autofill/personal_data_manager.h ('k') | chrome/test/data/autofill/merge/input/email.in » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698