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

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

Issue 6368067: Autofill should filter malformed emails addresses when form is submitted (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome
Patch Set: Merge two. Created 9 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
« no previous file with comments | « no previous file | chrome/browser/autofill/personal_data_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/autofill/autofill_field.h" 13 #include "chrome/browser/autofill/autofill_field.h"
14 #include "chrome/browser/autofill/autofill-inl.h" 14 #include "chrome/browser/autofill/autofill-inl.h"
15 #include "chrome/browser/autofill/form_structure.h" 15 #include "chrome/browser/autofill/form_structure.h"
16 #include "chrome/browser/autofill/phone_number.h" 16 #include "chrome/browser/autofill/phone_number.h"
17 #include "chrome/browser/browser_thread.h" 17 #include "chrome/browser/browser_thread.h"
18 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
19 #include "chrome/browser/webdata/web_data_service.h" 19 #include "chrome/browser/webdata/web_data_service.h"
20 #include "chrome/browser/prefs/pref_service.h" 20 #include "chrome/browser/prefs/pref_service.h"
21 #include "chrome/common/pref_names.h" 21 #include "chrome/common/pref_names.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebRegularExpression. h"
23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebString.h"
22 24
23 namespace { 25 namespace {
24 26
25 // The minimum number of fields that must contain user data and have known types 27 // The minimum number of fields that must contain user data and have known types
26 // before AutoFill will attempt to import the data into a profile or a credit 28 // before AutoFill will attempt to import the data into a profile or a credit
27 // card. 29 // card.
28 const int kMinProfileImportSize = 3; 30 const int kMinProfileImportSize = 3;
29 const int kMinCreditCardImportSize = 2; 31 const int kMinCreditCardImportSize = 2;
30 32
31 template<typename T> 33 template<typename T>
(...skipping 30 matching lines...) Expand all
62 const T& operator()(const T_Iterator& iterator) { 64 const T& operator()(const T_Iterator& iterator) {
63 return *iterator; 65 return *iterator;
64 } 66 }
65 }; 67 };
66 68
67 template<typename T> 69 template<typename T>
68 T* address_of(T& v) { 70 T* address_of(T& v) {
69 return &v; 71 return &v;
70 } 72 }
71 73
74 bool IsValidEmail(const string16& value) {
75 // This regex is more permissive than the official rfc2822 spec on the
76 // subject, but it does reject obvious non-email addresses.
77 const string16 kEmailPattern =
78 ASCIIToUTF16("^[^@]+@[^@]+\\.[a-z]{2,6}$");
79 WebKit::WebRegularExpression re(WebKit::WebString(kEmailPattern),
80 WebKit::WebTextCaseInsensitive);
81 return re.match(WebKit::WebString(StringToLowerASCII(value))) != -1;
82 }
83
72 // Returns true if minimum requirements for import of a given |profile| have 84 // Returns true if minimum requirements for import of a given |profile| have
73 // been met. An address submitted via a form must have at least these fields 85 // been met. An address submitted via a form must have at least these fields
74 // filled. No verification of validity of the contents is preformed. This is 86 // filled. No verification of validity of the contents is preformed. This is
75 // and existence check only. 87 // and existence check only.
76 bool IsMinimumAddress(const AutoFillProfile& profile) { 88 bool IsMinimumAddress(const AutoFillProfile& profile) {
77 return !profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)).empty() && 89 return !profile.GetFieldText(AutoFillType(ADDRESS_HOME_LINE1)).empty() &&
78 !profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY)).empty() && 90 !profile.GetFieldText(AutoFillType(ADDRESS_HOME_CITY)).empty() &&
79 !profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE)).empty() && 91 !profile.GetFieldText(AutoFillType(ADDRESS_HOME_STATE)).empty() &&
80 !profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)).empty(); 92 !profile.GetFieldText(AutoFillType(ADDRESS_HOME_ZIP)).empty();
81 } 93 }
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 number_type = AutoFillType(PHONE_FAX_NUMBER); 236 number_type = AutoFillType(PHONE_FAX_NUMBER);
225 237
226 string16 stored_number = imported_profile_->GetFieldText(number_type); 238 string16 stored_number = imported_profile_->GetFieldText(number_type);
227 if (stored_number.size() == 239 if (stored_number.size() ==
228 static_cast<size_t>(PhoneNumber::kPrefixLength) && 240 static_cast<size_t>(PhoneNumber::kPrefixLength) &&
229 value.size() == static_cast<size_t>(PhoneNumber::kSuffixLength)) { 241 value.size() == static_cast<size_t>(PhoneNumber::kSuffixLength)) {
230 value = stored_number + value; 242 value = stored_number + value;
231 } 243 }
232 } 244 }
233 245
246 if (field_type.field_type() == EMAIL_ADDRESS && !IsValidEmail(value))
247 continue;
248
234 imported_profile_->SetInfo(AutoFillType(field_type.field_type()), 249 imported_profile_->SetInfo(AutoFillType(field_type.field_type()),
235 value); 250 value);
236 ++importable_fields; 251 ++importable_fields;
237 } 252 }
238 } 253 }
239 } 254 }
240 255
241 // If the user did not enter enough information on the page then don't bother 256 // If the user did not enter enough information on the page then don't bother
242 // importing the data. 257 // importing the data.
243 if (importable_fields < kMinProfileImportSize) 258 if (importable_fields < kMinProfileImportSize)
(...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after
806 } 821 }
807 822
808 creditcards.push_back(**iter); 823 creditcards.push_back(**iter);
809 } 824 }
810 825
811 if (!merged) 826 if (!merged)
812 creditcards.push_back(*imported_credit_card_); 827 creditcards.push_back(*imported_credit_card_);
813 828
814 SetCreditCards(&creditcards); 829 SetCreditCards(&creditcards);
815 } 830 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autofill/personal_data_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698