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

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

Issue 442403002: Adjust displayed phone number for prefix/suffix case. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update code as per 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 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 driver_->RendererIsAvailable() && 457 driver_->RendererIsAvailable() &&
458 GetCachedFormAndField(form, field, &form_structure, &autofill_field) && 458 GetCachedFormAndField(form, field, &form_structure, &autofill_field) &&
459 // Don't send suggestions for forms that aren't auto-fillable. 459 // Don't send suggestions for forms that aren't auto-fillable.
460 form_structure->IsAutofillable()) { 460 form_structure->IsAutofillable()) {
461 AutofillType type = autofill_field->Type(); 461 AutofillType type = autofill_field->Type();
462 bool is_filling_credit_card = (type.group() == CREDIT_CARD); 462 bool is_filling_credit_card = (type.group() == CREDIT_CARD);
463 if (is_filling_credit_card) { 463 if (is_filling_credit_card) {
464 GetCreditCardSuggestions( 464 GetCreditCardSuggestions(
465 field, type, &values, &labels, &icons, &unique_ids); 465 field, type, &values, &labels, &icons, &unique_ids);
466 } else { 466 } else {
467 GetProfileSuggestions( 467 GetProfileSuggestions(*form_structure,
468 *form_structure, field, type, &values, &labels, &icons, &unique_ids); 468 field,
469 *autofill_field,
470 &values,
471 &labels,
472 &icons,
473 &unique_ids);
469 } 474 }
470 475
471 DCHECK_EQ(values.size(), labels.size()); 476 DCHECK_EQ(values.size(), labels.size());
472 DCHECK_EQ(values.size(), icons.size()); 477 DCHECK_EQ(values.size(), icons.size());
473 DCHECK_EQ(values.size(), unique_ids.size()); 478 DCHECK_EQ(values.size(), unique_ids.size());
474 479
475 if (!values.empty()) { 480 if (!values.empty()) {
476 // Don't provide Autofill suggestions when Autofill is disabled, and don't 481 // Don't provide Autofill suggestions when Autofill is disabled, and don't
477 // provide credit card suggestions for non-HTTPS pages. However, provide a 482 // provide credit card suggestions for non-HTTPS pages. However, provide a
478 // warning to the user in these cases. 483 // warning to the user in these cases.
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
1067 // Annotate the updated form with its predicted types. 1072 // Annotate the updated form with its predicted types.
1068 std::vector<FormStructure*> forms(1, *updated_form); 1073 std::vector<FormStructure*> forms(1, *updated_form);
1069 driver_->SendAutofillTypePredictionsToRenderer(forms); 1074 driver_->SendAutofillTypePredictionsToRenderer(forms);
1070 1075
1071 return true; 1076 return true;
1072 } 1077 }
1073 1078
1074 void AutofillManager::GetProfileSuggestions( 1079 void AutofillManager::GetProfileSuggestions(
1075 const FormStructure& form, 1080 const FormStructure& form,
1076 const FormFieldData& field, 1081 const FormFieldData& field,
1077 const AutofillType& type, 1082 const AutofillField& autofill_field,
1078 std::vector<base::string16>* values, 1083 std::vector<base::string16>* values,
1079 std::vector<base::string16>* labels, 1084 std::vector<base::string16>* labels,
1080 std::vector<base::string16>* icons, 1085 std::vector<base::string16>* icons,
1081 std::vector<int>* unique_ids) const { 1086 std::vector<int>* unique_ids) const {
1082 std::vector<ServerFieldType> field_types(form.field_count()); 1087 std::vector<ServerFieldType> field_types(form.field_count());
1083 for (size_t i = 0; i < form.field_count(); ++i) { 1088 for (size_t i = 0; i < form.field_count(); ++i) {
1084 field_types.push_back(form.field(i)->Type().GetStorableType()); 1089 field_types.push_back(form.field(i)->Type().GetStorableType());
1085 } 1090 }
1086 std::vector<GUIDPair> guid_pairs; 1091 std::vector<GUIDPair> guid_pairs;
1087 1092
1088 personal_data_->GetProfileSuggestions( 1093 personal_data_->GetProfileSuggestions(
1089 type, field.value, field.is_autofilled, field_types, 1094 autofill_field.Type(), field.value, field.is_autofilled, field_types,
1090 base::Callback<bool(const AutofillProfile&)>(), 1095 base::Callback<bool(const AutofillProfile&)>(),
1091 values, labels, icons, &guid_pairs); 1096 values, labels, icons, &guid_pairs);
1092 1097
1098 // Adjust phone number to display in prefix/suffix case.
1099 if (autofill_field.Type().GetStorableType() == PHONE_HOME_NUMBER) {
1100 for (size_t i = 0; i < values->size(); ++i) {
1101 (*values)[i] = AutofillField::GetPhoneNumberValue(
1102 autofill_field, (*values)[i], field);
1103 }
1104 }
1105
1093 for (size_t i = 0; i < guid_pairs.size(); ++i) { 1106 for (size_t i = 0; i < guid_pairs.size(); ++i) {
1094 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0), 1107 unique_ids->push_back(PackGUIDs(GUIDPair(std::string(), 0),
1095 guid_pairs[i])); 1108 guid_pairs[i]));
1096 } 1109 }
1097 } 1110 }
1098 1111
1099 void AutofillManager::GetCreditCardSuggestions( 1112 void AutofillManager::GetCreditCardSuggestions(
1100 const FormFieldData& field, 1113 const FormFieldData& field,
1101 const AutofillType& type, 1114 const AutofillType& type,
1102 std::vector<base::string16>* values, 1115 std::vector<base::string16>* values,
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1223 return false; 1236 return false;
1224 1237
1225 // Disregard forms that we wouldn't ever autofill in the first place. 1238 // Disregard forms that we wouldn't ever autofill in the first place.
1226 if (!form.ShouldBeParsed()) 1239 if (!form.ShouldBeParsed())
1227 return false; 1240 return false;
1228 1241
1229 return true; 1242 return true;
1230 } 1243 }
1231 1244
1232 } // namespace autofill 1245 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698