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..ab53e3b3b70aa87443fa2116948d7b720a7e32ab 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/16 23:55:10
Please remove this function. This work should be
Pritam Nikam
2014/10/28 10:11:07
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,40 @@ 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>::iterator it = values->begin(); |
+ while (it != values->end()) { |
+ base::string16 card_number = |
+ AutofillField::GetCreditCardNumberValue(autofill_field, *it); |
+ if (StartsWith(card_number, field.value, false)) { |
+ ++it; |
+ continue; |
+ } |
+ |
+ // Prune the not-matching suggestions. |
+ size_t offset = it - values->begin(); |
+ it = values->erase(it); |
+ labels->erase(offset + labels->begin()); |
+ icons->erase(offset + icons->begin()); |
+ guid_pairs.erase(offset + guid_pairs.begin()); |
+ } |
+ |
+ // Obfuscate the credit card numbers in suggetions. |
+ for (size_t i = 0; i < values->size(); ++i) { |
+ (*values)[i] = ObfuscatedCreditCardNumber((*values)[i]); |
+ } |
+ } |
for (size_t i = 0; i < guid_pairs.size(); ++i) { |
unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |