| OLD | NEW |
| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 WebKit::WebRegularExpression re(WebKit::WebString(kEmailPattern), | 80 WebKit::WebRegularExpression re(WebKit::WebString(kEmailPattern), |
| 81 WebKit::WebTextCaseInsensitive); | 81 WebKit::WebTextCaseInsensitive); |
| 82 return re.match(WebKit::WebString(StringToLowerASCII(value))) != -1; | 82 return re.match(WebKit::WebString(StringToLowerASCII(value))) != -1; |
| 83 } | 83 } |
| 84 | 84 |
| 85 // Returns true if minimum requirements for import of a given |profile| have | 85 // Returns true if minimum requirements for import of a given |profile| have |
| 86 // been met. An address submitted via a form must have at least these fields | 86 // been met. An address submitted via a form must have at least these fields |
| 87 // filled. No verification of validity of the contents is preformed. This is | 87 // filled. No verification of validity of the contents is preformed. This is |
| 88 // and existence check only. | 88 // and existence check only. |
| 89 bool IsMinimumAddress(const AutofillProfile& profile) { | 89 bool IsMinimumAddress(const AutofillProfile& profile) { |
| 90 return !profile.GetFieldText(AutofillType(ADDRESS_HOME_LINE1)).empty() && | 90 return !profile.GetFieldText(ADDRESS_HOME_LINE1).empty() && |
| 91 !profile.GetFieldText(AutofillType(ADDRESS_HOME_CITY)).empty() && | 91 !profile.GetFieldText(ADDRESS_HOME_CITY).empty() && |
| 92 !profile.GetFieldText(AutofillType(ADDRESS_HOME_STATE)).empty() && | 92 !profile.GetFieldText(ADDRESS_HOME_STATE).empty() && |
| 93 !profile.GetFieldText(AutofillType(ADDRESS_HOME_ZIP)).empty(); | 93 !profile.GetFieldText(ADDRESS_HOME_ZIP).empty(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 // Whether we have already logged the number of profiles this session. | 96 // Whether we have already logged the number of profiles this session. |
| 97 bool g_has_logged_profile_count = false; | 97 bool g_has_logged_profile_count = false; |
| 98 | 98 |
| 99 } // namespace | 99 } // namespace |
| 100 | 100 |
| 101 PersonalDataManager::~PersonalDataManager() { | 101 PersonalDataManager::~PersonalDataManager() { |
| 102 CancelPendingQuery(&pending_profiles_query_); | 102 CancelPendingQuery(&pending_profiles_query_); |
| 103 CancelPendingQuery(&pending_creditcards_query_); | 103 CancelPendingQuery(&pending_creditcards_query_); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 const FormStructure* form = *iter; | 167 const FormStructure* form = *iter; |
| 168 for (size_t i = 0; i < form->field_count(); ++i) { | 168 for (size_t i = 0; i < form->field_count(); ++i) { |
| 169 const AutofillField* field = form->field(i); | 169 const AutofillField* field = form->field(i); |
| 170 string16 value = CollapseWhitespace(field->value, false); | 170 string16 value = CollapseWhitespace(field->value, false); |
| 171 | 171 |
| 172 // If we don't know the type of the field, or the user hasn't entered any | 172 // If we don't know the type of the field, or the user hasn't entered any |
| 173 // information into the field, then skip it. | 173 // information into the field, then skip it. |
| 174 if (!field->IsFieldFillable() || value.empty()) | 174 if (!field->IsFieldFillable() || value.empty()) |
| 175 continue; | 175 continue; |
| 176 | 176 |
| 177 AutofillType field_type(field->type()); | 177 AutofillFieldType field_type = field->type(); |
| 178 FieldTypeGroup group(field_type.group()); | 178 FieldTypeGroup group(AutofillType(field_type).group()); |
| 179 | 179 |
| 180 if (group == AutofillType::CREDIT_CARD) { | 180 if (group == AutofillType::CREDIT_CARD) { |
| 181 // If the user has a password set, we have no way of setting credit | 181 // If the user has a password set, we have no way of setting credit |
| 182 // card numbers. | 182 // card numbers. |
| 183 if (!HasPassword()) { | 183 if (!HasPassword()) { |
| 184 if (LowerCaseEqualsASCII(field->form_control_type, "month")) { | 184 if (LowerCaseEqualsASCII(field->form_control_type, "month")) { |
| 185 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type.field_type()); | 185 DCHECK_EQ(CREDIT_CARD_EXP_MONTH, field_type); |
| 186 local_imported_credit_card->SetInfoForMonthInputType(value); | 186 local_imported_credit_card->SetInfoForMonthInputType(value); |
| 187 } else { | 187 } else { |
| 188 local_imported_credit_card->SetInfo( | 188 local_imported_credit_card->SetInfo(field_type, value); |
| 189 AutofillType(field_type.field_type()), value); | |
| 190 } | 189 } |
| 191 ++importable_credit_card_fields; | 190 ++importable_credit_card_fields; |
| 192 } | 191 } |
| 193 } else { | 192 } else { |
| 194 // In the case of a phone number, if the whole phone number was entered | 193 // In the case of a phone number, if the whole phone number was entered |
| 195 // into a single field, then parse it and set the sub components. | 194 // into a single field, then parse it and set the sub components. |
| 196 if (field_type.subgroup() == AutofillType::PHONE_WHOLE_NUMBER) { | 195 if (AutofillType(field_type).subgroup() == |
| 196 AutofillType::PHONE_WHOLE_NUMBER) { |
| 197 string16 number; | 197 string16 number; |
| 198 string16 city_code; | 198 string16 city_code; |
| 199 string16 country_code; | 199 string16 country_code; |
| 200 PhoneNumber::ParsePhoneNumber(value, | 200 PhoneNumber::ParsePhoneNumber(value, |
| 201 &number, | 201 &number, |
| 202 &city_code, | 202 &city_code, |
| 203 &country_code); | 203 &country_code); |
| 204 if (number.empty()) | 204 if (number.empty()) |
| 205 continue; | 205 continue; |
| 206 | 206 |
| 207 if (group == AutofillType::PHONE_HOME) { | 207 if (group == AutofillType::PHONE_HOME) { |
| 208 imported_profile->SetInfo(AutofillType(PHONE_HOME_COUNTRY_CODE), | 208 imported_profile->SetInfo(PHONE_HOME_COUNTRY_CODE, country_code); |
| 209 country_code); | 209 imported_profile->SetInfo(PHONE_HOME_CITY_CODE, city_code); |
| 210 imported_profile->SetInfo(AutofillType(PHONE_HOME_CITY_CODE), | 210 imported_profile->SetInfo(PHONE_HOME_NUMBER, number); |
| 211 city_code); | |
| 212 imported_profile->SetInfo(AutofillType(PHONE_HOME_NUMBER), number); | |
| 213 } else if (group == AutofillType::PHONE_FAX) { | 211 } else if (group == AutofillType::PHONE_FAX) { |
| 214 imported_profile->SetInfo(AutofillType(PHONE_FAX_COUNTRY_CODE), | 212 imported_profile->SetInfo(PHONE_FAX_COUNTRY_CODE, country_code); |
| 215 country_code); | 213 imported_profile->SetInfo(PHONE_FAX_CITY_CODE, city_code); |
| 216 imported_profile->SetInfo(AutofillType(PHONE_FAX_CITY_CODE), | 214 imported_profile->SetInfo(PHONE_FAX_NUMBER, number); |
| 217 city_code); | |
| 218 imported_profile->SetInfo(AutofillType(PHONE_FAX_NUMBER), number); | |
| 219 } | 215 } |
| 220 | 216 |
| 221 continue; | 217 continue; |
| 222 } | 218 } |
| 223 | 219 |
| 224 // Phone and fax numbers can be split across multiple fields, so we | 220 // Phone and fax numbers can be split across multiple fields, so we |
| 225 // might have already stored the prefix, and now be at the suffix. | 221 // might have already stored the prefix, and now be at the suffix. |
| 226 // If so, combine them to form the full number. | 222 // If so, combine them to form the full number. |
| 227 if (group == AutofillType::PHONE_HOME || | 223 if (group == AutofillType::PHONE_HOME || |
| 228 group == AutofillType::PHONE_FAX) { | 224 group == AutofillType::PHONE_FAX) { |
| 229 AutofillType number_type(PHONE_HOME_NUMBER); | 225 AutofillFieldType number_type = PHONE_HOME_NUMBER; |
| 230 if (group == AutofillType::PHONE_FAX) | 226 if (group == AutofillType::PHONE_FAX) |
| 231 number_type = AutofillType(PHONE_FAX_NUMBER); | 227 number_type = PHONE_FAX_NUMBER; |
| 232 | 228 |
| 233 string16 stored_number = imported_profile->GetFieldText(number_type); | 229 string16 stored_number = imported_profile->GetFieldText(number_type); |
| 234 if (stored_number.size() == | 230 if (stored_number.size() == |
| 235 static_cast<size_t>(PhoneNumber::kPrefixLength) && | 231 static_cast<size_t>(PhoneNumber::kPrefixLength) && |
| 236 value.size() == static_cast<size_t>(PhoneNumber::kSuffixLength)) { | 232 value.size() == static_cast<size_t>(PhoneNumber::kSuffixLength)) { |
| 237 value = stored_number + value; | 233 value = stored_number + value; |
| 238 } | 234 } |
| 239 } | 235 } |
| 240 | 236 |
| 241 if (field_type.field_type() == EMAIL_ADDRESS && !IsValidEmail(value)) | 237 if (field_type == EMAIL_ADDRESS && !IsValidEmail(value)) |
| 242 continue; | 238 continue; |
| 243 | 239 |
| 244 imported_profile->SetInfo(AutofillType(field_type.field_type()), | 240 imported_profile->SetInfo(field_type, value); |
| 245 value); | |
| 246 ++importable_fields; | 241 ++importable_fields; |
| 247 } | 242 } |
| 248 } | 243 } |
| 249 } | 244 } |
| 250 | 245 |
| 251 // If the user did not enter enough information on the page then don't bother | 246 // If the user did not enter enough information on the page then don't bother |
| 252 // importing the data. | 247 // importing the data. |
| 253 if (importable_fields < kMinProfileImportSize) | 248 if (importable_fields < kMinProfileImportSize) |
| 254 imported_profile.reset(); | 249 imported_profile.reset(); |
| 255 if (importable_credit_card_fields < kMinCreditCardImportSize) | 250 if (importable_credit_card_fields < kMinCreditCardImportSize) |
| 256 local_imported_credit_card.reset(); | 251 local_imported_credit_card.reset(); |
| 257 | 252 |
| 258 if (imported_profile.get() && !IsMinimumAddress(*imported_profile.get())) | 253 if (imported_profile.get() && !IsMinimumAddress(*imported_profile.get())) |
| 259 imported_profile.reset(); | 254 imported_profile.reset(); |
| 260 | 255 |
| 261 if (local_imported_credit_card.get() && | 256 if (local_imported_credit_card.get() && |
| 262 !CreditCard::IsCreditCardNumber(local_imported_credit_card->GetFieldText( | 257 !CreditCard::IsCreditCardNumber(local_imported_credit_card->GetFieldText( |
| 263 AutofillType(CREDIT_CARD_NUMBER)))) { | 258 CREDIT_CARD_NUMBER))) { |
| 264 local_imported_credit_card.reset(); | 259 local_imported_credit_card.reset(); |
| 265 } | 260 } |
| 266 | 261 |
| 267 // Don't import if we already have this info. | 262 // Don't import if we already have this info. |
| 268 if (local_imported_credit_card.get()) { | 263 if (local_imported_credit_card.get()) { |
| 269 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); | 264 for (std::vector<CreditCard*>::const_iterator iter = credit_cards_.begin(); |
| 270 iter != credit_cards_.end(); | 265 iter != credit_cards_.end(); |
| 271 ++iter) { | 266 ++iter) { |
| 272 if (local_imported_credit_card->IsSubsetOf(**iter)) { | 267 if (local_imported_credit_card->IsSubsetOf(**iter)) { |
| 273 local_imported_credit_card.reset(); | 268 local_imported_credit_card.reset(); |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 } | 803 } |
| 809 | 804 |
| 810 const AutofillMetrics* PersonalDataManager::metric_logger() const { | 805 const AutofillMetrics* PersonalDataManager::metric_logger() const { |
| 811 return metric_logger_.get(); | 806 return metric_logger_.get(); |
| 812 } | 807 } |
| 813 | 808 |
| 814 void PersonalDataManager::set_metric_logger( | 809 void PersonalDataManager::set_metric_logger( |
| 815 const AutofillMetrics* metric_logger) { | 810 const AutofillMetrics* metric_logger) { |
| 816 metric_logger_.reset(metric_logger); | 811 metric_logger_.reset(metric_logger); |
| 817 } | 812 } |
| OLD | NEW |