OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/core/browser/personal_data_manager.h" | 5 #include "components/autofill/core/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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 for (size_t i = 0; i < form.field_count(); ++i) { | 252 for (size_t i = 0; i < form.field_count(); ++i) { |
253 const AutofillField* field = form.field(i); | 253 const AutofillField* field = form.field(i); |
254 base::string16 value = CollapseWhitespace(field->value, false); | 254 base::string16 value = CollapseWhitespace(field->value, false); |
255 | 255 |
256 // If we don't know the type of the field, or the user hasn't entered any | 256 // If we don't know the type of the field, or the user hasn't entered any |
257 // information into the field, then skip it. | 257 // information into the field, then skip it. |
258 if (!field->IsFieldFillable() || value.empty()) | 258 if (!field->IsFieldFillable() || value.empty()) |
259 continue; | 259 continue; |
260 | 260 |
261 AutofillType field_type = field->Type(); | 261 AutofillType field_type = field->Type(); |
262 NativeFieldType native_field_type = field_type.native_type(); | 262 NativeFieldType native_field_type = |
| 263 field_type.GetApproximateNativeFieldType(); |
263 FieldTypeGroup group(field_type.group()); | 264 FieldTypeGroup group(field_type.group()); |
264 | 265 |
265 // There can be multiple email fields (e.g. in the case of 'confirm email' | 266 // There can be multiple email fields (e.g. in the case of 'confirm email' |
266 // fields) but they must all contain the same value, else the profile is | 267 // fields) but they must all contain the same value, else the profile is |
267 // invalid. | 268 // invalid. |
268 if (native_field_type == EMAIL_ADDRESS) { | 269 if (native_field_type == EMAIL_ADDRESS) { |
269 if (types_seen.count(native_field_type) && | 270 if (types_seen.count(native_field_type) && |
270 imported_profile->GetRawInfo(EMAIL_ADDRESS) != value) { | 271 imported_profile->GetRawInfo(EMAIL_ADDRESS) != value) { |
271 imported_profile.reset(); | 272 imported_profile.reset(); |
272 break; | 273 break; |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 if (multi_values[i].empty()) | 611 if (multi_values[i].empty()) |
611 continue; | 612 continue; |
612 | 613 |
613 base::string16 profile_value_lower_case( | 614 base::string16 profile_value_lower_case( |
614 StringToLowerASCII(multi_values[i])); | 615 StringToLowerASCII(multi_values[i])); |
615 base::string16 field_value_lower_case( | 616 base::string16 field_value_lower_case( |
616 StringToLowerASCII(field_contents)); | 617 StringToLowerASCII(field_contents)); |
617 // Phone numbers could be split in US forms, so field value could be | 618 // Phone numbers could be split in US forms, so field value could be |
618 // either prefix or suffix of the phone. | 619 // either prefix or suffix of the phone. |
619 bool matched_phones = false; | 620 bool matched_phones = false; |
620 if ((type.native_type() == PHONE_HOME_NUMBER || | 621 if (type.GetEquivalentNativeType() == PHONE_HOME_NUMBER && |
621 type.native_type() == PHONE_BILLING_NUMBER) && | |
622 !field_value_lower_case.empty() && | 622 !field_value_lower_case.empty() && |
623 profile_value_lower_case.find(field_value_lower_case) != | 623 profile_value_lower_case.find(field_value_lower_case) != |
624 base::string16::npos) { | 624 base::string16::npos) { |
625 matched_phones = true; | 625 matched_phones = true; |
626 } | 626 } |
627 | 627 |
628 // Suggest variants of the profile that's already been filled in. | 628 // Suggest variants of the profile that's already been filled in. |
629 if (matched_phones || | 629 if (matched_phones || |
630 profile_value_lower_case == field_value_lower_case) { | 630 profile_value_lower_case == field_value_lower_case) { |
631 for (size_t j = 0; j < multi_values.size(); ++j) { | 631 for (size_t j = 0; j < multi_values.size(); ++j) { |
632 if (!multi_values[j].empty()) { | 632 if (!multi_values[j].empty()) { |
633 values->push_back(multi_values[j]); | 633 values->push_back(multi_values[j]); |
634 guid_pairs->push_back(GUIDPair(profile->guid(), j)); | 634 guid_pairs->push_back(GUIDPair(profile->guid(), j)); |
635 } | 635 } |
636 } | 636 } |
637 | 637 |
638 // We've added all the values for this profile so move on to the | 638 // We've added all the values for this profile so move on to the |
639 // next. | 639 // next. |
640 break; | 640 break; |
641 } | 641 } |
642 } | 642 } |
643 } | 643 } |
644 } | 644 } |
645 | 645 |
646 if (!field_is_autofilled) { | 646 if (!field_is_autofilled) { |
647 AutofillProfile::CreateInferredLabels( | 647 AutofillProfile::CreateInferredLabels( |
648 &matched_profiles, &other_field_types, | 648 &matched_profiles, &other_field_types, |
649 type.native_type(), 1, labels); | 649 type.GetApproximateNativeFieldType(), 1, labels); |
650 } else { | 650 } else { |
651 // No sub-labels for previously filled fields. | 651 // No sub-labels for previously filled fields. |
652 labels->resize(values->size()); | 652 labels->resize(values->size()); |
653 } | 653 } |
654 | 654 |
655 // No icons for profile suggestions. | 655 // No icons for profile suggestions. |
656 icons->resize(values->size()); | 656 icons->resize(values->size()); |
657 } | 657 } |
658 | 658 |
659 void PersonalDataManager::GetCreditCardSuggestions( | 659 void PersonalDataManager::GetCreditCardSuggestions( |
(...skipping 11 matching lines...) Expand all Loading... |
671 const std::vector<CreditCard*>& credit_cards = GetCreditCards(); | 671 const std::vector<CreditCard*>& credit_cards = GetCreditCards(); |
672 for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin(); | 672 for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin(); |
673 iter != credit_cards.end(); ++iter) { | 673 iter != credit_cards.end(); ++iter) { |
674 CreditCard* credit_card = *iter; | 674 CreditCard* credit_card = *iter; |
675 | 675 |
676 // The value of the stored data for this field type in the |credit_card|. | 676 // The value of the stored data for this field type in the |credit_card|. |
677 base::string16 creditcard_field_value = | 677 base::string16 creditcard_field_value = |
678 credit_card->GetInfo(type, app_locale_); | 678 credit_card->GetInfo(type, app_locale_); |
679 if (!creditcard_field_value.empty() && | 679 if (!creditcard_field_value.empty() && |
680 StartsWith(creditcard_field_value, field_contents, false)) { | 680 StartsWith(creditcard_field_value, field_contents, false)) { |
681 if (type.native_type() == CREDIT_CARD_NUMBER) | 681 if (type.GetEquivalentNativeType() == CREDIT_CARD_NUMBER) |
682 creditcard_field_value = credit_card->ObfuscatedNumber(); | 682 creditcard_field_value = credit_card->ObfuscatedNumber(); |
683 | 683 |
684 base::string16 label; | 684 base::string16 label; |
685 if (credit_card->number().empty()) { | 685 if (credit_card->number().empty()) { |
686 // If there is no CC number, return name to show something. | 686 // If there is no CC number, return name to show something. |
687 label = | 687 label = |
688 credit_card->GetInfo(AutofillType(CREDIT_CARD_NAME), app_locale_); | 688 credit_card->GetInfo(AutofillType(CREDIT_CARD_NAME), app_locale_); |
689 } else { | 689 } else { |
690 label = kCreditCardPrefix; | 690 label = kCreditCardPrefix; |
691 label.append(credit_card->LastFourDigits()); | 691 label.append(credit_card->LastFourDigits()); |
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1025 const AutofillMetrics* metric_logger) { | 1025 const AutofillMetrics* metric_logger) { |
1026 metric_logger_.reset(metric_logger); | 1026 metric_logger_.reset(metric_logger); |
1027 } | 1027 } |
1028 | 1028 |
1029 void PersonalDataManager::set_browser_context( | 1029 void PersonalDataManager::set_browser_context( |
1030 content::BrowserContext* context) { | 1030 content::BrowserContext* context) { |
1031 browser_context_ = context; | 1031 browser_context_ = context; |
1032 } | 1032 } |
1033 | 1033 |
1034 } // namespace autofill | 1034 } // namespace autofill |
OLD | NEW |