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

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

Issue 853523004: Autofill: Set requirements for number of recognized fields in an autofillable form (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 5 years, 11 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/form_field.h" 5 #include "components/autofill/core/browser/form_field.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 22 matching lines...) Expand all
33 // Ignore fields marked as presentational. See 33 // Ignore fields marked as presentational. See
34 // http://www.w3.org/TR/wai-aria/roles#presentation 34 // http://www.w3.org/TR/wai-aria/roles#presentation
35 return field->is_checkable || 35 return field->is_checkable ||
36 field->role == FormFieldData::ROLE_ATTRIBUTE_PRESENTATION; 36 field->role == FormFieldData::ROLE_ATTRIBUTE_PRESENTATION;
37 } 37 }
38 38
39 } // namespace 39 } // namespace
40 40
41 // static 41 // static
42 void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, 42 void FormField::ParseFormFields(const std::vector<AutofillField*>& fields,
43 bool is_in_form_tag,
43 ServerFieldTypeMap* map) { 44 ServerFieldTypeMap* map) {
Evan Stade 2015/01/22 23:43:44 DCHECK(map->empty())?
Lei Zhang 2015/01/22 23:58:12 Done.
44 // Set up a working copy of the fields to be processed. 45 // Set up a working copy of the fields to be processed.
45 std::vector<AutofillField*> remaining_fields(fields.size()); 46 std::vector<AutofillField*> remaining_fields(fields.size());
46 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); 47 std::copy(fields.begin(), fields.end(), remaining_fields.begin());
47 48
48 remaining_fields.erase( 49 remaining_fields.erase(
49 std::remove_if(remaining_fields.begin(), remaining_fields.end(), 50 std::remove_if(remaining_fields.begin(), remaining_fields.end(),
50 ShouldBeIgnored), 51 ShouldBeIgnored),
51 remaining_fields.end()); 52 remaining_fields.end());
52 53
54 ServerFieldTypeMap saved_map = *map;
55
53 // Email pass. 56 // Email pass.
54 ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map); 57 ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map);
58 size_t email_count = map->size();
55 59
56 // Phone pass. 60 // Phone pass.
57 ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map); 61 ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map);
58 62
59 // Address pass. 63 // Address pass.
60 ParseFormFieldsPass(AddressField::Parse, &remaining_fields, map); 64 ParseFormFieldsPass(AddressField::Parse, &remaining_fields, map);
61 65
62 // Credit card pass. 66 // Credit card pass.
63 ParseFormFieldsPass(CreditCardField::Parse, &remaining_fields, map); 67 ParseFormFieldsPass(CreditCardField::Parse, &remaining_fields, map);
64 68
65 // Name pass. 69 // Name pass.
66 ParseFormFieldsPass(NameField::Parse, &remaining_fields, map); 70 ParseFormFieldsPass(NameField::Parse, &remaining_fields, map);
71
72 // Do not autofill a form if there are less than 3 recognized fields.
73 // Otherwise it is very easy to have false positives. http://crbug.com/447332
74 // For <form> tags, make an exception for email fields, which are commonly the
75 // only recognized field on account registration sites.
76 size_t count = map->size();
Evan Stade 2015/01/22 23:43:44 nit: no need for this variable
Lei Zhang 2015/01/22 23:58:12 Done.
77 size_t kThreshold = 3;
78 bool accept_parsing = (count >= kThreshold ||
79 (is_in_form_tag && email_count > 0));
80 if (!accept_parsing)
81 *map = saved_map;
67 } 82 }
68 83
69 // static 84 // static
70 bool FormField::ParseField(AutofillScanner* scanner, 85 bool FormField::ParseField(AutofillScanner* scanner,
71 const base::string16& pattern, 86 const base::string16& pattern,
72 AutofillField** match) { 87 AutofillField** match) {
73 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match); 88 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match);
74 } 89 }
75 90
76 // static 91 // static
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 } 138 }
124 139
125 return false; 140 return false;
126 } 141 }
127 142
128 // static 143 // static
129 bool FormField::Match(const AutofillField* field, 144 bool FormField::Match(const AutofillField* field,
130 const base::string16& pattern, 145 const base::string16& pattern,
131 int match_type) { 146 int match_type) {
132 if ((match_type & FormField::MATCH_LABEL) && 147 if ((match_type & FormField::MATCH_LABEL) &&
133 autofill::MatchesPattern(field->label, pattern)) { 148 MatchesPattern(field->label, pattern)) {
134 return true; 149 return true;
135 } 150 }
136 151
137 if ((match_type & FormField::MATCH_NAME) && 152 if ((match_type & FormField::MATCH_NAME) &&
138 autofill::MatchesPattern(field->name, pattern)) { 153 MatchesPattern(field->name, pattern)) {
139 return true; 154 return true;
140 } 155 }
141 156
142 if ((match_type & FormField::MATCH_VALUE) && 157 if ((match_type & FormField::MATCH_VALUE) &&
143 autofill::MatchesPattern(field->value, pattern)) { 158 MatchesPattern(field->value, pattern)) {
144 return true; 159 return true;
145 } 160 }
146 161
147 return false; 162 return false;
148 } 163 }
149 164
150 // static 165 // static
151 void FormField::ParseFormFieldsPass(ParseFunction parse, 166 void FormField::ParseFormFieldsPass(ParseFunction parse,
152 std::vector<AutofillField*>* fields, 167 std::vector<AutofillField*>* fields,
153 ServerFieldTypeMap* map) { 168 ServerFieldTypeMap* map) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 if ((match_type & MATCH_TEXT_AREA) && type == "textarea") 203 if ((match_type & MATCH_TEXT_AREA) && type == "textarea")
189 return true; 204 return true;
190 205
191 if ((match_type & MATCH_PASSWORD) && type == "password") 206 if ((match_type & MATCH_PASSWORD) && type == "password")
192 return true; 207 return true;
193 208
194 return false; 209 return false;
195 } 210 }
196 211
197 } // namespace autofill 212 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698