Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1090)

Side by Side Diff: components/autofill/core/browser/autofill_manager.cc

Issue 622773002: [Autofill] Autofill fails to show suggestions for credit card split across fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review comments. Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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/16 23:55:10 Please remove this function. This work should be
Pritam Nikam 2014/10/28 10:11:07 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
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
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>::iterator it = values->begin();
1149 while (it != values->end()) {
1150 base::string16 card_number =
1151 AutofillField::GetCreditCardNumberValue(autofill_field, *it);
1152 if (StartsWith(card_number, field.value, false)) {
1153 ++it;
1154 continue;
1155 }
1156
1157 // Prune the not-matching suggestions.
1158 size_t offset = it - values->begin();
1159 it = values->erase(it);
1160 labels->erase(offset + labels->begin());
1161 icons->erase(offset + icons->begin());
1162 guid_pairs.erase(offset + guid_pairs.begin());
1163 }
1164
1165 // Obfuscate the credit card numbers in suggetions.
1166 for (size_t i = 0; i < values->size(); ++i) {
1167 (*values)[i] = ObfuscatedCreditCardNumber((*values)[i]);
1168 }
1169 }
1128 1170
1129 for (size_t i = 0; i < guid_pairs.size(); ++i) { 1171 for (size_t i = 0; i < guid_pairs.size(); ++i) {
1130 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); 1172 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0)));
1131 } 1173 }
1132 } 1174 }
1133 1175
1134 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { 1176 void AutofillManager::ParseForms(const std::vector<FormData>& forms) {
1135 std::vector<FormStructure*> non_queryable_forms; 1177 std::vector<FormStructure*> non_queryable_forms;
1136 for (std::vector<FormData>::const_iterator iter = forms.begin(); 1178 for (std::vector<FormData>::const_iterator iter = forms.begin();
1137 iter != forms.end(); ++iter) { 1179 iter != forms.end(); ++iter) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 return false; 1284 return false;
1243 1285
1244 // Disregard forms that we wouldn't ever autofill in the first place. 1286 // Disregard forms that we wouldn't ever autofill in the first place.
1245 if (!form.ShouldBeParsed()) 1287 if (!form.ShouldBeParsed())
1246 return false; 1288 return false;
1247 1289
1248 return true; 1290 return true;
1249 } 1291 }
1250 1292
1251 } // namespace autofill 1293 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.h ('k') | components/autofill/core/browser/autofill_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698