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 get the suggetions for |user_input| matching to | |
160 // |card_number_filed| split. | |
161 void GetCredtCardSuggetionsForNumberSplit( | |
162 const base::string16& user_input, | |
163 const AutofillField& card_number_filed, | |
164 PersonalDataManager* personal_data, | |
165 std::vector<base::string16>* values, | |
166 std::vector<base::string16>* labels, | |
167 std::vector<base::string16>* icons, | |
168 std::vector<GUIDPair>* guid_pairs) { | |
169 const std::vector<CreditCard*>& credit_cards = | |
170 personal_data->GetCreditCards(); | |
171 for (std::vector<CreditCard*>::const_iterator iter = credit_cards.begin(); | |
172 iter != credit_cards.end(); | |
173 ++iter) { | |
174 CreditCard* credit_card = *iter; | |
175 base::string16 stored_card_number = | |
176 CreditCard::StripSeparators(credit_card->number()); | |
177 | |
178 // Exclude first split, as it would have already included in the | |
179 // suggestions. | |
180 if (!stored_card_number.empty() && | |
181 !StartsWith(stored_card_number, user_input, false)) { | |
182 | |
183 // Make sure the suggetions get include for rest of the | |
184 // |card_number_filed|s. | |
185 stored_card_number = AutofillField::GetCreditCardNumberValue( | |
186 card_number_filed, stored_card_number); | |
187 if (StartsWith(stored_card_number, user_input, false)) { | |
188 personal_data->AppendCreditCardSuggetions( | |
189 credit_card, | |
190 AutofillType(CREDIT_CARD_NUMBER), | |
191 user_input, | |
192 values, | |
193 labels, | |
194 icons, | |
195 guid_pairs); | |
196 } | |
197 } | |
198 } | |
199 } | |
Ilya Sherman
2014/10/07 21:49:10
Can all of this logic be moved into the PersonalDa
Pritam Nikam
2014/10/08 05:17:17
In my opinion, we *cannot* move this logic to Pers
Ilya Sherman
2014/10/08 21:04:38
Phone numbers are also handled within the Personal
Pritam Nikam
2014/10/09 06:11:11
Acknowledged.
I'll align my changes along these l
Ilya Sherman
2014/10/09 21:35:12
That's true. It's such an edge case that I'm hone
Pritam Nikam
2014/10/13 04:33:52
Currently, *current field value* (i.e. const base:
| |
200 | |
159 } // namespace | 201 } // namespace |
160 | 202 |
161 AutofillManager::AutofillManager( | 203 AutofillManager::AutofillManager( |
162 AutofillDriver* driver, | 204 AutofillDriver* driver, |
163 AutofillClient* client, | 205 AutofillClient* client, |
164 const std::string& app_locale, | 206 const std::string& app_locale, |
165 AutofillDownloadManagerState enable_download_manager) | 207 AutofillDownloadManagerState enable_download_manager) |
166 : driver_(driver), | 208 : driver_(driver), |
167 client_(client), | 209 client_(client), |
168 app_locale_(app_locale), | 210 app_locale_(app_locale), |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 AutofillField* autofill_field = NULL; | 508 AutofillField* autofill_field = NULL; |
467 if (RefreshDataModels() && | 509 if (RefreshDataModels() && |
468 driver_->RendererIsAvailable() && | 510 driver_->RendererIsAvailable() && |
469 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && | 511 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && |
470 // Don't send suggestions for forms that aren't auto-fillable. | 512 // Don't send suggestions for forms that aren't auto-fillable. |
471 form_structure->IsAutofillable()) { | 513 form_structure->IsAutofillable()) { |
472 AutofillType type = autofill_field->Type(); | 514 AutofillType type = autofill_field->Type(); |
473 bool is_filling_credit_card = (type.group() == CREDIT_CARD); | 515 bool is_filling_credit_card = (type.group() == CREDIT_CARD); |
474 if (is_filling_credit_card) { | 516 if (is_filling_credit_card) { |
475 GetCreditCardSuggestions( | 517 GetCreditCardSuggestions( |
476 field, type, &values, &labels, &icons, &unique_ids); | 518 field, *autofill_field, &values, &labels, &icons, &unique_ids); |
477 } else { | 519 } else { |
478 GetProfileSuggestions(*form_structure, | 520 GetProfileSuggestions(*form_structure, |
479 field, | 521 field, |
480 *autofill_field, | 522 *autofill_field, |
481 &values, | 523 &values, |
482 &labels, | 524 &labels, |
483 &icons, | 525 &icons, |
484 &unique_ids); | 526 &unique_ids); |
485 } | 527 } |
486 | 528 |
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1110 } | 1152 } |
1111 | 1153 |
1112 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1154 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
1113 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), | 1155 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), |
1114 guid_pairs[i])); | 1156 guid_pairs[i])); |
1115 } | 1157 } |
1116 } | 1158 } |
1117 | 1159 |
1118 void AutofillManager::GetCreditCardSuggestions( | 1160 void AutofillManager::GetCreditCardSuggestions( |
1119 const FormFieldData& field, | 1161 const FormFieldData& field, |
1120 const AutofillType& type, | 1162 const AutofillField& autofill_field, |
1121 std::vector<base::string16>* values, | 1163 std::vector<base::string16>* values, |
1122 std::vector<base::string16>* labels, | 1164 std::vector<base::string16>* labels, |
1123 std::vector<base::string16>* icons, | 1165 std::vector<base::string16>* icons, |
1124 std::vector<int>* unique_ids) const { | 1166 std::vector<int>* unique_ids) const { |
1125 std::vector<GUIDPair> guid_pairs; | 1167 std::vector<GUIDPair> guid_pairs; |
1168 AutofillType type = autofill_field.Type(); | |
1126 personal_data_->GetCreditCardSuggestions( | 1169 personal_data_->GetCreditCardSuggestions( |
1127 type, field.value, values, labels, icons, &guid_pairs); | 1170 type, field.value, values, labels, icons, &guid_pairs); |
1128 | 1171 |
1172 // Populate suggetions for number split case (http://crbug.com/420323). | |
1173 if (!field.value.empty() && | |
1174 autofill_field.Type().GetStorableType() == CREDIT_CARD_NUMBER) | |
1175 GetCredtCardSuggetionsForNumberSplit(field.value, | |
1176 autofill_field, | |
1177 personal_data_, | |
1178 values, | |
1179 labels, | |
1180 icons, | |
1181 &guid_pairs); | |
Ilya Sherman
2014/10/07 21:49:10
nit: Please add curly braces, since the body spans
Pritam Nikam
2014/10/08 05:17:17
Done.
| |
1182 | |
1129 for (size_t i = 0; i < guid_pairs.size(); ++i) { | 1183 for (size_t i = 0; i < guid_pairs.size(); ++i) { |
1130 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); | 1184 unique_ids->push_back(PackGUIDs(guid_pairs[i], GUIDPair(std::string(), 0))); |
1131 } | 1185 } |
1132 } | 1186 } |
1133 | 1187 |
1134 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { | 1188 void AutofillManager::ParseForms(const std::vector<FormData>& forms) { |
1135 std::vector<FormStructure*> non_queryable_forms; | 1189 std::vector<FormStructure*> non_queryable_forms; |
1136 for (std::vector<FormData>::const_iterator iter = forms.begin(); | 1190 for (std::vector<FormData>::const_iterator iter = forms.begin(); |
1137 iter != forms.end(); ++iter) { | 1191 iter != forms.end(); ++iter) { |
1138 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); | 1192 scoped_ptr<FormStructure> form_structure(new FormStructure(*iter)); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1242 return false; | 1296 return false; |
1243 | 1297 |
1244 // Disregard forms that we wouldn't ever autofill in the first place. | 1298 // Disregard forms that we wouldn't ever autofill in the first place. |
1245 if (!form.ShouldBeParsed()) | 1299 if (!form.ShouldBeParsed()) |
1246 return false; | 1300 return false; |
1247 | 1301 |
1248 return true; | 1302 return true; |
1249 } | 1303 } |
1250 | 1304 |
1251 } // namespace autofill | 1305 } // namespace autofill |
OLD | NEW |