Chromium Code Reviews| Index: components/autofill/core/browser/autofill_manager.cc |
| diff --git a/components/autofill/core/browser/autofill_manager.cc b/components/autofill/core/browser/autofill_manager.cc |
| index 48cd5974c206b50c064630dace3cb85731b24497..d18e9f526178270c6e0ff6148935eed76afb7bce 100644 |
| --- a/components/autofill/core/browser/autofill_manager.cc |
| +++ b/components/autofill/core/browser/autofill_manager.cc |
| @@ -156,6 +156,22 @@ void DeterminePossibleFieldTypesForUpload( |
| } |
| } |
| +// Helper function to obfuscate the credit card digits with '*'. |
| +base::string16 ObfuscatedCreditCardNumber(const base::string16& card_number) { |
| + // If the number is shorter than four digits, there's no need to obfuscate it. |
| + if (card_number.size() < 4) |
| + return card_number; |
| + |
| + const size_t max_obfuscation_size = 20; |
| + const base::char16 obfuscation_symbol = '*'; |
| + |
| + // Avoid making very long obfuscated numbers. |
| + size_t obfuscated_digits = |
| + std::min(max_obfuscation_size, card_number.size() - 4); |
| + base::string16 result(obfuscated_digits, obfuscation_symbol); |
| + return result.append(card_number.substr(card_number.size() - 4)); |
| +} |
|
Ilya Sherman
2014/10/13 23:33:37
Hmm, I think we should continue to show the full,
Pritam Nikam
2014/10/15 09:12:11
Done.
|
| + |
| } // namespace |
| AutofillManager::AutofillManager( |
| @@ -473,7 +489,7 @@ void AutofillManager::OnQueryFormFieldAutofill(int query_id, |
| bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
| if (is_filling_credit_card) { |
| GetCreditCardSuggestions( |
| - field, type, &values, &labels, &icons, &unique_ids); |
| + field, *autofill_field, &values, &labels, &icons, &unique_ids); |
| } else { |
| GetProfileSuggestions(*form_structure, |
| field, |
| @@ -1104,8 +1120,8 @@ void AutofillManager::GetProfileSuggestions( |
| // Adjust phone number to display in prefix/suffix case. |
| if (autofill_field.Type().GetStorableType() == PHONE_HOME_NUMBER) { |
| for (size_t i = 0; i < values->size(); ++i) { |
| - (*values)[i] = AutofillField::GetPhoneNumberValue( |
| - autofill_field, (*values)[i], field); |
| + (*values)[i] = |
| + AutofillField::GetPhoneNumberValue(autofill_field, (*values)[i]); |
| } |
| } |
| @@ -1117,14 +1133,43 @@ void AutofillManager::GetProfileSuggestions( |
| void AutofillManager::GetCreditCardSuggestions( |
| const FormFieldData& field, |
| - const AutofillType& type, |
| + const AutofillField& autofill_field, |
| std::vector<base::string16>* values, |
| std::vector<base::string16>* labels, |
| std::vector<base::string16>* icons, |
| std::vector<int>* unique_ids) const { |
| std::vector<GUIDPair> guid_pairs; |
| + AutofillType type = autofill_field.Type(); |
| personal_data_->GetCreditCardSuggestions( |
| - type, field.value, values, labels, icons, &guid_pairs); |
| + type, field.value, values, labels, icons, &guid_pairs, false); |
| + |
| + // Remove the non-matching credit card suggestions. |
| + if (type.GetStorableType() == CREDIT_CARD_NUMBER) { |
| + std::vector<base::string16> suggetion_values; |
| + std::vector<base::string16> suggetion_labels; |
| + std::vector<base::string16> suggetion_icons; |
| + std::vector<GUIDPair> suggetion_guid_pairs; |
| + for (size_t i = 0; i < values->size(); ++i) { |
| + base::string16 card_number = |
| + AutofillField::GetCreditCardNumberValue(autofill_field, (*values)[i]); |
| + if (StartsWith(card_number, field.value, false)) { |
| + suggetion_values.push_back((*values)[i]); |
| + suggetion_labels.push_back((*labels)[i]); |
| + suggetion_icons.push_back((*icons)[i]); |
| + suggetion_guid_pairs.push_back(guid_pairs[i]); |
| + } |
| + } |
| + |
| + // Prune the not-matching suggestions. |
| + values->swap(suggetion_values); |
| + labels->swap(suggetion_labels); |
| + icons->swap(suggetion_icons); |
| + guid_pairs.swap(suggetion_guid_pairs); |
|
Ilya Sherman
2014/10/13 23:33:37
Please use .erase() from the original vectors, rat
Pritam Nikam
2014/10/15 09:12:11
Done.
|
| + |
| + // Obfuscate the credit card number in suggetions. |
|
Ilya Sherman
2014/10/13 23:33:37
nit: "number" -> "numbers".
Pritam Nikam
2014/10/15 09:12:11
Done.
|
| + for (size_t i = 0; i < values->size(); ++i) |
| + (*values)[i] = ObfuscatedCreditCardNumber((*values)[i]); |
|
Ilya Sherman
2014/10/13 23:33:37
nit: Please always use curly braces to contain loo
Pritam Nikam
2014/10/15 09:12:11
Done.
|
| + } |
| for (size_t i = 0; i < guid_pairs.size(); ++i) { |
| unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |