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/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 Loading... | |
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_form_tag, | |
43 ServerFieldTypeMap* map) { | 44 ServerFieldTypeMap* map) { |
45 DCHECK(map->empty()); | |
46 | |
44 // Set up a working copy of the fields to be processed. | 47 // Set up a working copy of the fields to be processed. |
45 std::vector<AutofillField*> remaining_fields(fields.size()); | 48 std::vector<AutofillField*> remaining_fields(fields.size()); |
46 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); | 49 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); |
47 | 50 |
48 remaining_fields.erase( | 51 remaining_fields.erase( |
49 std::remove_if(remaining_fields.begin(), remaining_fields.end(), | 52 std::remove_if(remaining_fields.begin(), remaining_fields.end(), |
50 ShouldBeIgnored), | 53 ShouldBeIgnored), |
51 remaining_fields.end()); | 54 remaining_fields.end()); |
52 | 55 |
56 ServerFieldTypeMap saved_map = *map; | |
57 | |
53 // Email pass. | 58 // Email pass. |
54 ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map); | 59 ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map); |
60 size_t email_count = map->size(); | |
55 | 61 |
56 // Phone pass. | 62 // Phone pass. |
57 ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map); | 63 ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map); |
58 | 64 |
59 // Address pass. | 65 // Address pass. |
60 ParseFormFieldsPass(AddressField::Parse, &remaining_fields, map); | 66 ParseFormFieldsPass(AddressField::Parse, &remaining_fields, map); |
61 | 67 |
62 // Credit card pass. | 68 // Credit card pass. |
63 ParseFormFieldsPass(CreditCardField::Parse, &remaining_fields, map); | 69 ParseFormFieldsPass(CreditCardField::Parse, &remaining_fields, map); |
64 | 70 |
65 // Name pass. | 71 // Name pass. |
66 ParseFormFieldsPass(NameField::Parse, &remaining_fields, map); | 72 ParseFormFieldsPass(NameField::Parse, &remaining_fields, map); |
73 | |
74 // Do not autofill a form if there are less than 3 recognized fields. | |
75 // Otherwise it is very easy to have false positives. http://crbug.com/447332 | |
76 // For <form> tags, make an exception for email fields, which are commonly the | |
77 // only recognized field on account registration sites. | |
Ilya Sherman
2015/01/28 19:30:23
Why does this apply only for <form> tags? Are acc
Lei Zhang
2015/01/28 19:46:42
Treating email fields uniformly risks more bugs li
| |
78 size_t kThreshold = 3; | |
79 bool accept_parsing = (map->size() >= kThreshold || | |
80 (is_form_tag && email_count > 0)); | |
81 if (!accept_parsing) | |
82 *map = saved_map; | |
67 } | 83 } |
68 | 84 |
69 // static | 85 // static |
70 bool FormField::ParseField(AutofillScanner* scanner, | 86 bool FormField::ParseField(AutofillScanner* scanner, |
71 const base::string16& pattern, | 87 const base::string16& pattern, |
72 AutofillField** match) { | 88 AutofillField** match) { |
73 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match); | 89 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match); |
74 } | 90 } |
75 | 91 |
76 // static | 92 // static |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 } | 139 } |
124 | 140 |
125 return false; | 141 return false; |
126 } | 142 } |
127 | 143 |
128 // static | 144 // static |
129 bool FormField::Match(const AutofillField* field, | 145 bool FormField::Match(const AutofillField* field, |
130 const base::string16& pattern, | 146 const base::string16& pattern, |
131 int match_type) { | 147 int match_type) { |
132 if ((match_type & FormField::MATCH_LABEL) && | 148 if ((match_type & FormField::MATCH_LABEL) && |
133 autofill::MatchesPattern(field->label, pattern)) { | 149 MatchesPattern(field->label, pattern)) { |
134 return true; | 150 return true; |
135 } | 151 } |
136 | 152 |
137 if ((match_type & FormField::MATCH_NAME) && | 153 if ((match_type & FormField::MATCH_NAME) && |
138 autofill::MatchesPattern(field->name, pattern)) { | 154 MatchesPattern(field->name, pattern)) { |
139 return true; | 155 return true; |
140 } | 156 } |
141 | 157 |
142 if ((match_type & FormField::MATCH_VALUE) && | 158 if ((match_type & FormField::MATCH_VALUE) && |
143 autofill::MatchesPattern(field->value, pattern)) { | 159 MatchesPattern(field->value, pattern)) { |
144 return true; | 160 return true; |
145 } | 161 } |
146 | 162 |
147 return false; | 163 return false; |
148 } | 164 } |
149 | 165 |
150 // static | 166 // static |
151 void FormField::ParseFormFieldsPass(ParseFunction parse, | 167 void FormField::ParseFormFieldsPass(ParseFunction parse, |
152 std::vector<AutofillField*>* fields, | 168 std::vector<AutofillField*>* fields, |
153 ServerFieldTypeMap* map) { | 169 ServerFieldTypeMap* map) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 if ((match_type & MATCH_TEXT_AREA) && type == "textarea") | 204 if ((match_type & MATCH_TEXT_AREA) && type == "textarea") |
189 return true; | 205 return true; |
190 | 206 |
191 if ((match_type & MATCH_PASSWORD) && type == "password") | 207 if ((match_type & MATCH_PASSWORD) && type == "password") |
192 return true; | 208 return true; |
193 | 209 |
194 return false; | 210 return false; |
195 } | 211 } |
196 | 212 |
197 } // namespace autofill | 213 } // namespace autofill |
OLD | NEW |