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