Chromium Code Reviews| OLD | NEW |
|---|---|
| 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" | |
|
Ilya Sherman
2011/02/03 04:24:20
nit: 80-col? I'm not exactly sure what our style
dhollowa
2011/02/03 16:23:02
Nothing to be done. Can't be split.
| |
| 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 Loading... | |
| 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. | |
|
Ilya Sherman
2011/02/03 04:24:20
nit: I find raw regexes hard to read; it would be
dhollowa
2011/02/03 16:23:02
I can't think of a comment that does any better th
| |
| 77 const string16 kEmailPattern = | |
| 78 ASCIIToUTF16("^[^@]+@.+\\.[a-z]{2,4}$"); | |
|
Ilya Sherman
2011/02/03 04:24:20
nit: Looks like ".museum" and ".travel" are valid
dhollowa
2011/02/03 16:23:02
Done.
| |
| 79 WebKit::WebRegularExpression re(WebKit::WebString(kEmailPattern), | |
| 80 WebKit::WebTextCaseInsensitive); | |
| 81 bool match = re.match( | |
| 82 WebKit::WebString(StringToLowerASCII(value))) != -1; | |
|
Ilya Sherman
2011/02/03 04:24:20
nit: I would skip the local variable and just "ret
dhollowa
2011/02/03 16:23:02
Done.
| |
| 83 return match; | |
| 84 } | |
| 85 | |
| 72 } // namespace | 86 } // namespace |
| 73 | 87 |
| 74 PersonalDataManager::~PersonalDataManager() { | 88 PersonalDataManager::~PersonalDataManager() { |
| 75 CancelPendingQuery(&pending_profiles_query_); | 89 CancelPendingQuery(&pending_profiles_query_); |
| 76 CancelPendingQuery(&pending_creditcards_query_); | 90 CancelPendingQuery(&pending_creditcards_query_); |
| 77 } | 91 } |
| 78 | 92 |
| 79 void PersonalDataManager::OnWebDataServiceRequestDone( | 93 void PersonalDataManager::OnWebDataServiceRequestDone( |
| 80 WebDataService::Handle h, | 94 WebDataService::Handle h, |
| 81 const WDTypedResult* result) { | 95 const WDTypedResult* result) { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 213 number_type = AutoFillType(PHONE_FAX_NUMBER); | 227 number_type = AutoFillType(PHONE_FAX_NUMBER); |
| 214 | 228 |
| 215 string16 stored_number = imported_profile_->GetFieldText(number_type); | 229 string16 stored_number = imported_profile_->GetFieldText(number_type); |
| 216 if (stored_number.size() == | 230 if (stored_number.size() == |
| 217 static_cast<size_t>(PhoneNumber::kPrefixLength) && | 231 static_cast<size_t>(PhoneNumber::kPrefixLength) && |
| 218 value.size() == static_cast<size_t>(PhoneNumber::kSuffixLength)) { | 232 value.size() == static_cast<size_t>(PhoneNumber::kSuffixLength)) { |
| 219 value = stored_number + value; | 233 value = stored_number + value; |
| 220 } | 234 } |
| 221 } | 235 } |
| 222 | 236 |
| 237 if (field_type.field_type() == EMAIL_ADDRESS && !IsValidEmail(value)) | |
| 238 continue; | |
| 239 | |
| 223 imported_profile_->SetInfo(AutoFillType(field_type.field_type()), | 240 imported_profile_->SetInfo(AutoFillType(field_type.field_type()), |
| 224 value); | 241 value); |
| 225 ++importable_fields; | 242 ++importable_fields; |
| 226 } | 243 } |
| 227 } | 244 } |
| 228 } | 245 } |
| 229 | 246 |
| 230 // If the user did not enter enough information on the page then don't bother | 247 // If the user did not enter enough information on the page then don't bother |
| 231 // importing the data. | 248 // importing the data. |
| 232 if (importable_fields < kMinProfileImportSize) | 249 if (importable_fields < kMinProfileImportSize) |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 792 } | 809 } |
| 793 | 810 |
| 794 creditcards.push_back(**iter); | 811 creditcards.push_back(**iter); |
| 795 } | 812 } |
| 796 | 813 |
| 797 if (!merged) | 814 if (!merged) |
| 798 creditcards.push_back(*imported_credit_card_); | 815 creditcards.push_back(*imported_credit_card_); |
| 799 | 816 |
| 800 SetCreditCards(&creditcards); | 817 SetCreditCards(&creditcards); |
| 801 } | 818 } |
| OLD | NEW |