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 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
16 #include "components/autofill/core/browser/address_field.h" | 16 #include "components/autofill/core/browser/address_field.h" |
17 #include "components/autofill/core/browser/autofill_field.h" | 17 #include "components/autofill/core/browser/autofill_field.h" |
18 #include "components/autofill/core/browser/autofill_regexes.h" | 18 #include "components/autofill/core/browser/autofill_regexes.h" |
19 #include "components/autofill/core/browser/autofill_scanner.h" | 19 #include "components/autofill/core/browser/autofill_scanner.h" |
20 #include "components/autofill/core/browser/credit_card_field.h" | 20 #include "components/autofill/core/browser/credit_card_field.h" |
21 #include "components/autofill/core/browser/email_field.h" | 21 #include "components/autofill/core/browser/email_field.h" |
22 #include "components/autofill/core/browser/form_structure.h" | 22 #include "components/autofill/core/browser/form_structure.h" |
23 #include "components/autofill/core/browser/name_field.h" | 23 #include "components/autofill/core/browser/name_field.h" |
24 #include "components/autofill/core/browser/phone_field.h" | 24 #include "components/autofill/core/browser/phone_field.h" |
25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
26 | 26 |
27 namespace autofill { | 27 namespace autofill { |
28 namespace { | 28 namespace { |
29 | 29 |
30 bool IsCheckable(const AutofillField* field) { | 30 bool ShouldBeIgnored(const AutofillField* field) { |
31 return field->is_checkable; | 31 // Ignore checkable fields as they interfere with parsers assuming context. |
| 32 // Eg., while parsing address, "Is PO box" checkbox after ADDRESS_LINE1 |
| 33 // interferes with correctly understanding ADDRESS_LINE2. |
| 34 // Ignore fields marked as presentational. See |
| 35 // http://www.w3.org/TR/wai-aria/roles#presentation |
| 36 return field->is_checkable || |
| 37 field->role == FormFieldData::ROLE_ATTRIBUTE_PRESENTATION; |
32 } | 38 } |
33 | 39 |
34 } // namespace | 40 } // namespace |
35 | 41 |
36 // static | 42 // static |
37 void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, | 43 void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, |
38 ServerFieldTypeMap* map) { | 44 ServerFieldTypeMap* map) { |
39 // Set up a working copy of the fields to be processed. | 45 // Set up a working copy of the fields to be processed. |
40 std::vector<AutofillField*> remaining_fields(fields.size()); | 46 std::vector<AutofillField*> remaining_fields(fields.size()); |
41 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); | 47 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); |
42 | 48 |
43 // Ignore checkable fields as they interfere with parsers assuming context. | |
44 // Eg., while parsing address, "Is PO box" checkbox after ADDRESS_LINE1 | |
45 // interferes with correctly understanding ADDRESS_LINE2. | |
46 remaining_fields.erase( | 49 remaining_fields.erase( |
47 std::remove_if(remaining_fields.begin(), remaining_fields.end(), | 50 std::remove_if(remaining_fields.begin(), remaining_fields.end(), |
48 IsCheckable), | 51 ShouldBeIgnored), |
49 remaining_fields.end()); | 52 remaining_fields.end()); |
50 | 53 |
51 // Email pass. | 54 // Email pass. |
52 ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map); | 55 ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map); |
53 | 56 |
54 // Phone pass. | 57 // Phone pass. |
55 ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map); | 58 ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map); |
56 | 59 |
57 // Address pass. | 60 // Address pass. |
58 ParseFormFieldsPass(AddressField::Parse, &remaining_fields, map); | 61 ParseFormFieldsPass(AddressField::Parse, &remaining_fields, map); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if ((match_type & MATCH_TEXT_AREA) && type == "textarea") | 189 if ((match_type & MATCH_TEXT_AREA) && type == "textarea") |
187 return true; | 190 return true; |
188 | 191 |
189 if ((match_type & MATCH_PASSWORD) && type == "password") | 192 if ((match_type & MATCH_PASSWORD) && type == "password") |
190 return true; | 193 return true; |
191 | 194 |
192 return false; | 195 return false; |
193 } | 196 } |
194 | 197 |
195 } // namespace autofill | 198 } // namespace autofill |
OLD | NEW |