OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/autofill/form_field.h" | 5 #include "chrome/browser/autofill/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 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 bool IsTelephoneField(const std::string& type) { | 40 bool IsTelephoneField(const std::string& type) { |
41 return type == "tel"; | 41 return type == "tel"; |
42 } | 42 } |
43 | 43 |
44 bool IsSelectField(const std::string& type) { | 44 bool IsSelectField(const std::string& type) { |
45 return type == "select-one"; | 45 return type == "select-one"; |
46 } | 46 } |
47 | 47 |
| 48 bool IsCheckable(const AutofillField* field) { |
| 49 return field->is_checkable; |
| 50 } |
| 51 |
48 } // namespace | 52 } // namespace |
49 | 53 |
50 // static | 54 // static |
51 void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, | 55 void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, |
52 FieldTypeMap* map) { | 56 FieldTypeMap* map) { |
53 // Set up a working copy of the fields to be processed. | 57 // Set up a working copy of the fields to be processed. |
54 std::vector<const AutofillField*> remaining_fields(fields.size()); | 58 std::vector<const AutofillField*> remaining_fields(fields.size()); |
55 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); | 59 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); |
56 | 60 |
| 61 // Ignore checkable fields as they interfere with parsers assuming context. |
| 62 // Eg., while parsing address, "Is PO box" checkbox after ADDRESS_LINE1 |
| 63 // interferes with correctly understanding ADDRESS_LINE2. |
| 64 remaining_fields.erase( |
| 65 std::remove_if(remaining_fields.begin(), remaining_fields.end(), |
| 66 IsCheckable), |
| 67 remaining_fields.end()); |
| 68 |
57 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 69 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
58 bool parse_new_field_types = | 70 bool parse_new_field_types = |
59 command_line.HasSwitch(switches::kEnableNewAutofillHeuristics); | 71 command_line.HasSwitch(switches::kEnableNewAutofillHeuristics); |
60 | 72 |
61 // Email pass. | 73 // Email pass. |
62 ParseFormFieldsPass(EmailField::Parse, parse_new_field_types, | 74 ParseFormFieldsPass(EmailField::Parse, parse_new_field_types, |
63 &remaining_fields, map); | 75 &remaining_fields, map); |
64 | 76 |
65 // Phone pass. | 77 // Phone pass. |
66 ParseFormFieldsPass(PhoneField::Parse, parse_new_field_types, | 78 ParseFormFieldsPass(PhoneField::Parse, parse_new_field_types, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 continue; | 200 continue; |
189 } | 201 } |
190 | 202 |
191 // Add entries into the map for each field type found in |form_field|. | 203 // Add entries into the map for each field type found in |form_field|. |
192 bool ok = form_field->ClassifyField(map); | 204 bool ok = form_field->ClassifyField(map); |
193 DCHECK(ok); | 205 DCHECK(ok); |
194 } | 206 } |
195 | 207 |
196 std::swap(*fields, remaining_fields); | 208 std::swap(*fields, remaining_fields); |
197 } | 209 } |
OLD | NEW |