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 "components/autofill/browser/personal_data_manager.h" | 5 #include "components/autofill/browser/personal_data_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <functional> | 8 #include <functional> |
9 #include <iterator> | 9 #include <iterator> |
10 | 10 |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 } | 107 } |
108 | 108 |
109 // Return true if the |field_type| and |value| are valid within the context | 109 // Return true if the |field_type| and |value| are valid within the context |
110 // of importing a form. | 110 // of importing a form. |
111 bool IsValidFieldTypeAndValue(const std::set<AutofillFieldType>& types_seen, | 111 bool IsValidFieldTypeAndValue(const std::set<AutofillFieldType>& types_seen, |
112 AutofillFieldType field_type, | 112 AutofillFieldType field_type, |
113 const string16& value) { | 113 const string16& value) { |
114 // Abandon the import if two fields of the same type are encountered. | 114 // Abandon the import if two fields of the same type are encountered. |
115 // This indicates ambiguous data or miscategorization of types. | 115 // This indicates ambiguous data or miscategorization of types. |
116 // Make an exception for PHONE_HOME_NUMBER however as both prefix and | 116 // Make an exception for PHONE_HOME_NUMBER however as both prefix and |
117 // suffix are stored against this type. | 117 // suffix are stored against this type, and for EMAIL_ADDRESS because it is |
118 if (types_seen.count(field_type) && field_type != PHONE_HOME_NUMBER) | 118 // common to see second 'confirm email address' fields on forms. |
| 119 if (types_seen.count(field_type) && field_type != PHONE_HOME_NUMBER && |
| 120 field_type != EMAIL_ADDRESS) |
119 return false; | 121 return false; |
120 | 122 |
121 // Abandon the import if an email address value shows up in a field that is | 123 // Abandon the import if an email address value shows up in a field that is |
122 // not an email address. | 124 // not an email address. |
123 if (field_type != EMAIL_ADDRESS && autofill::IsValidEmailAddress(value)) | 125 if (field_type != EMAIL_ADDRESS && autofill::IsValidEmailAddress(value)) |
124 return false; | 126 return false; |
125 | 127 |
126 return true; | 128 return true; |
127 } | 129 } |
128 | 130 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 string16 value = CollapseWhitespace(field->value, false); | 244 string16 value = CollapseWhitespace(field->value, false); |
243 | 245 |
244 // If we don't know the type of the field, or the user hasn't entered any | 246 // If we don't know the type of the field, or the user hasn't entered any |
245 // information into the field, then skip it. | 247 // information into the field, then skip it. |
246 if (!field->IsFieldFillable() || value.empty()) | 248 if (!field->IsFieldFillable() || value.empty()) |
247 continue; | 249 continue; |
248 | 250 |
249 AutofillFieldType field_type = field->type(); | 251 AutofillFieldType field_type = field->type(); |
250 FieldTypeGroup group(AutofillType(field_type).group()); | 252 FieldTypeGroup group(AutofillType(field_type).group()); |
251 | 253 |
| 254 // There can be multiple email fields (e.g. in the case of 'confirm email' |
| 255 // fields) but they must all contain the same value, else the profile is |
| 256 // invalid. |
| 257 if (field_type == EMAIL_ADDRESS) { |
| 258 if (types_seen.count(field_type) && |
| 259 imported_profile->GetRawInfo(field_type) != value) { |
| 260 imported_profile.reset(); |
| 261 break; |
| 262 } |
| 263 } |
| 264 |
252 // If the |field_type| and |value| don't pass basic validity checks then | 265 // If the |field_type| and |value| don't pass basic validity checks then |
253 // abandon the import. | 266 // abandon the import. |
254 if (!IsValidFieldTypeAndValue(types_seen, field_type, value)) { | 267 if (!IsValidFieldTypeAndValue(types_seen, field_type, value)) { |
255 imported_profile.reset(); | 268 imported_profile.reset(); |
256 local_imported_credit_card.reset(); | 269 local_imported_credit_card.reset(); |
257 break; | 270 break; |
258 } | 271 } |
259 | 272 |
260 types_seen.insert(field_type); | 273 types_seen.insert(field_type); |
261 | 274 |
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 | 999 |
987 void PersonalDataManager::set_metric_logger( | 1000 void PersonalDataManager::set_metric_logger( |
988 const AutofillMetrics* metric_logger) { | 1001 const AutofillMetrics* metric_logger) { |
989 metric_logger_.reset(metric_logger); | 1002 metric_logger_.reset(metric_logger); |
990 } | 1003 } |
991 | 1004 |
992 void PersonalDataManager::set_browser_context( | 1005 void PersonalDataManager::set_browser_context( |
993 content::BrowserContext* context) { | 1006 content::BrowserContext* context) { |
994 browser_context_ = context; | 1007 browser_context_ = context; |
995 } | 1008 } |
OLD | NEW |