Chromium Code Reviews| 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/autofill_manager.h" | 5 #include "components/autofill/core/browser/autofill_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 it->GetMatchingTypes(value, app_locale, &matching_types); | 149 it->GetMatchingTypes(value, app_locale, &matching_types); |
| 150 } | 150 } |
| 151 | 151 |
| 152 if (matching_types.empty()) | 152 if (matching_types.empty()) |
| 153 matching_types.insert(UNKNOWN_TYPE); | 153 matching_types.insert(UNKNOWN_TYPE); |
| 154 | 154 |
| 155 field->set_possible_types(matching_types); | 155 field->set_possible_types(matching_types); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 | 158 |
| 159 // Helper function to obfuscate the credit card digits with '*'. | |
| 160 base::string16 ObfuscatedCreditCardNumber(const base::string16& card_number) { | |
| 161 // If the number is shorter than four digits, there's no need to obfuscate it. | |
| 162 if (card_number.size() < 4) | |
| 163 return card_number; | |
| 164 | |
| 165 const size_t max_obfuscation_size = 20; | |
| 166 const base::char16 obfuscation_symbol = '*'; | |
| 167 | |
| 168 // Avoid making very long obfuscated numbers. | |
| 169 size_t obfuscated_digits = | |
| 170 std::min(max_obfuscation_size, card_number.size() - 4); | |
| 171 base::string16 result(obfuscated_digits, obfuscation_symbol); | |
| 172 return result.append(card_number.substr(card_number.size() - 4)); | |
| 173 } | |
|
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.
| |
| 174 | |
| 159 } // namespace | 175 } // namespace |
| 160 | 176 |
| 161 AutofillManager::AutofillManager( | 177 AutofillManager::AutofillManager( |
| 162 AutofillDriver* driver, | 178 AutofillDriver* driver, |
| 163 AutofillClient* client, | 179 AutofillClient* client, |
| 164 const std::string& app_locale, | 180 const std::string& app_locale, |
| 165 AutofillDownloadManagerState enable_download_manager) | 181 AutofillDownloadManagerState enable_download_manager) |
| 166 : driver_(driver), | 182 : driver_(driver), |
| 167 client_(client), | 183 client_(client), |
| 168 app_locale_(app_locale), | 184 app_locale_(app_locale), |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 466 AutofillField* autofill_field = NULL; | 482 AutofillField* autofill_field = NULL; |
| 467 if (RefreshDataModels() && | 483 if (RefreshDataModels() && |
| 468 driver_->RendererIsAvailable() && | 484 driver_->RendererIsAvailable() && |
| 469 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 485 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && |
| 470 // Don't send suggestions for forms that aren't auto-fillable. | 486 // Don't send suggestions for forms that aren't auto-fillable. |
| 471 form_structure->IsAutofillable()) { | 487 form_structure->IsAutofillable()) { |
| 472 AutofillType type = autofill_field->Type(); | 488 AutofillType type = autofill_field->Type(); |
| 473 bool is_filling_credit_card = (type.group() == CREDIT_CARD); | 489 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
| 474 if (is_filling_credit_card) { | 490 if (is_filling_credit_card) { |
| 475 GetCreditCardSuggestions( | 491 GetCreditCardSuggestions( |
| 476 field, type, &values, &labels, &icons, &unique_ids); | 492 field, *autofill_field, &values, &labels, &icons, &unique_ids); |
| 477 } else { | 493 } else { |
| 478 GetProfileSuggestions(*form_structure, | 494 GetProfileSuggestions(*form_structure, |
| 479 field, | 495 field, |
| 480 *autofill_field, | 496 *autofill_field, |
| 481 &values, | 497 &values, |
| 482 &labels, | 498 &labels, |
| 483 &icons, | 499 &icons, |
| 484 &unique_ids); | 500 &unique_ids); |
| 485 } | 501 } |
| 486 | 502 |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1097 std::vector<GUIDPair> guid_pairs; | 1113 std::vector<GUIDPair> guid_pairs; |
| 1098 | 1114 |
| 1099 personal_data_->GetProfileSuggestions( | 1115 personal_data_->GetProfileSuggestions( |
| 1100 autofill_field.Type(), field.value, field.is_autofilled, field_types, | 1116 autofill_field.Type(), field.value, field.is_autofilled, field_types, |
| 1101 base::Callback<bool(const AutofillProfile&)>(), | 1117 base::Callback<bool(const AutofillProfile&)>(), |
| 1102 values, labels, icons, &guid_pairs); | 1118 values, labels, icons, &guid_pairs); |
| 1103 | 1119 |
| 1104 // Adjust phone number to display in prefix/suffix case. | 1120 // Adjust phone number to display in prefix/suffix case. |
| 1105 if (autofill_field.Type().GetStorableType() == PHONE_HOME_NUMBER) { | 1121 if (autofill_field.Type().GetStorableType() == PHONE_HOME_NUMBER) { |
| 1106 for (size_t i = 0; i < values->size(); ++i) { | 1122 for (size_t i = 0; i < values->size(); ++i) { |
| 1107 (*values)[i] = AutofillField::GetPhoneNumberValue( | 1123 (*values)[i] = |
| 1108 autofill_field, (*values)[i], field); | 1124 AutofillField::GetPhoneNumberValue(autofill_field, (*values)[i]); |
| 1109 } | 1125 } |
| 1110 } | 1126 } |
| 1111 | 1127 |
| 1112 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1128 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
| 1113 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), | 1129 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), |
| 1114 guid_pairs[i])); | 1130 guid_pairs[i])); |
| 1115 } | 1131 } |
| 1116 } | 1132 } |
| 1117 | 1133 |
| 1118 void AutofillManager::GetCreditCardSuggestions( | 1134 void AutofillManager::GetCreditCardSuggestions( |
| 1119 const FormFieldData& field, | 1135 const FormFieldData& field, |
| 1120 const AutofillType& type, | 1136 const AutofillField& autofill_field, |
| 1121 std::vector<base::string16>* values, | 1137 std::vector<base::string16>* values, |
| 1122 std::vector<base::string16>* labels, | 1138 std::vector<base::string16>* labels, |
| 1123 std::vector<base::string16>* icons, | 1139 std::vector<base::string16>* icons, |
| 1124 std::vector<int>* unique_ids) const { | 1140 std::vector<int>* unique_ids) const { |
| 1125 std::vector<GUIDPair> guid_pairs; | 1141 std::vector<GUIDPair> guid_pairs; |
| 1142 AutofillType type = autofill_field.Type(); | |
| 1126 personal_data_->GetCreditCardSuggestions( | 1143 personal_data_->GetCreditCardSuggestions( |
| 1127 type, field.value, values, labels, icons, &guid_pairs); | 1144 type, field.value, values, labels, icons, &guid_pairs, false); |
| 1145 | |
| 1146 // Remove the non-matching credit card suggestions. | |
| 1147 if (type.GetStorableType() == CREDIT_CARD_NUMBER) { | |
| 1148 std::vector<base::string16> suggetion_values; | |
| 1149 std::vector<base::string16> suggetion_labels; | |
| 1150 std::vector<base::string16> suggetion_icons; | |
| 1151 std::vector<GUIDPair> suggetion_guid_pairs; | |
| 1152 for (size_t i = 0; i < values->size(); ++i) { | |
| 1153 base::string16 card_number = | |
| 1154 AutofillField::GetCreditCardNumberValue(autofill_field, (*values)[i]); | |
| 1155 if (StartsWith(card_number, field.value, false)) { | |
| 1156 suggetion_values.push_back((*values)[i]); | |
| 1157 suggetion_labels.push_back((*labels)[i]); | |
| 1158 suggetion_icons.push_back((*icons)[i]); | |
| 1159 suggetion_guid_pairs.push_back(guid_pairs[i]); | |
| 1160 } | |
| 1161 } | |
| 1162 | |
| 1163 // Prune the not-matching suggestions. | |
| 1164 values->swap(suggetion_values); | |
| 1165 labels->swap(suggetion_labels); | |
| 1166 icons->swap(suggetion_icons); | |
| 1167 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.
| |
| 1168 | |
| 1169 // 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.
| |
| 1170 for (size_t i = 0; i < values->size(); ++i) | |
| 1171 (*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.
| |
| 1172 } | |
| 1128 | 1173 |
| 1129 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1174 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
| 1130 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); | 1175 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |
| 1131 } | 1176 } |
| 1132 } | 1177 } |
| 1133 | 1178 |
| 1134 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1179 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
| 1135 std::vector<FormStructure*> non_queryable_forms; | 1180 std::vector<FormStructure*> non_queryable_forms; |
| 1136 for (std::vector<FormData>::const_iterator iter = forms.begin(); | 1181 for (std::vector<FormData>::const_iterator iter = forms.begin(); |
| 1137 iter != forms.end(); ++iter) { | 1182 iter != forms.end(); ++iter) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1242 return false; | 1287 return false; |
| 1243 | 1288 |
| 1244 // Disregard forms that we wouldn't ever autofill in the first place. | 1289 // Disregard forms that we wouldn't ever autofill in the first place. |
| 1245 if (!form.ShouldBeParsed()) | 1290 if (!form.ShouldBeParsed()) |
| 1246 return false; | 1291 return false; |
| 1247 | 1292 |
| 1248 return true; | 1293 return true; |
| 1249 } | 1294 } |
| 1250 | 1295 |
| 1251 } // namespace autofill | 1296 } // namespace autofill |
| OLD | NEW |