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/field_types.h" | |
23 #include "components/autofill/core/browser/form_structure.h" | 22 #include "components/autofill/core/browser/form_structure.h" |
24 #include "components/autofill/core/browser/name_field.h" | 23 #include "components/autofill/core/browser/name_field.h" |
25 #include "components/autofill/core/browser/phone_field.h" | 24 #include "components/autofill/core/browser/phone_field.h" |
26 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
27 | 26 |
28 namespace autofill { | 27 namespace autofill { |
29 namespace { | 28 namespace { |
30 | 29 |
31 bool IsTextField(const std::string& type) { | 30 bool IsTextField(const std::string& type) { |
32 return type == "text"; | 31 return type == "text"; |
(...skipping 12 matching lines...) Expand all Loading... |
45 } | 44 } |
46 | 45 |
47 bool IsCheckable(const AutofillField* field) { | 46 bool IsCheckable(const AutofillField* field) { |
48 return field->is_checkable; | 47 return field->is_checkable; |
49 } | 48 } |
50 | 49 |
51 } // namespace | 50 } // namespace |
52 | 51 |
53 // static | 52 // static |
54 void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, | 53 void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, |
55 FieldTypeMap* map) { | 54 ServerFieldTypeMap* map) { |
56 // Set up a working copy of the fields to be processed. | 55 // Set up a working copy of the fields to be processed. |
57 std::vector<const AutofillField*> remaining_fields(fields.size()); | 56 std::vector<const AutofillField*> remaining_fields(fields.size()); |
58 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); | 57 std::copy(fields.begin(), fields.end(), remaining_fields.begin()); |
59 | 58 |
60 // Ignore checkable fields as they interfere with parsers assuming context. | 59 // Ignore checkable fields as they interfere with parsers assuming context. |
61 // Eg., while parsing address, "Is PO box" checkbox after ADDRESS_LINE1 | 60 // Eg., while parsing address, "Is PO box" checkbox after ADDRESS_LINE1 |
62 // interferes with correctly understanding ADDRESS_LINE2. | 61 // interferes with correctly understanding ADDRESS_LINE2. |
63 remaining_fields.erase( | 62 remaining_fields.erase( |
64 std::remove_if(remaining_fields.begin(), remaining_fields.end(), | 63 std::remove_if(remaining_fields.begin(), remaining_fields.end(), |
65 IsCheckable), | 64 IsCheckable), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 bool FormField::ParseEmptyLabel(AutofillScanner* scanner, | 118 bool FormField::ParseEmptyLabel(AutofillScanner* scanner, |
120 const AutofillField** match) { | 119 const AutofillField** match) { |
121 return ParseFieldSpecifics(scanner, | 120 return ParseFieldSpecifics(scanner, |
122 ASCIIToUTF16("^$"), | 121 ASCIIToUTF16("^$"), |
123 MATCH_LABEL | MATCH_ALL_INPUTS, | 122 MATCH_LABEL | MATCH_ALL_INPUTS, |
124 match); | 123 match); |
125 } | 124 } |
126 | 125 |
127 // static | 126 // static |
128 bool FormField::AddClassification(const AutofillField* field, | 127 bool FormField::AddClassification(const AutofillField* field, |
129 AutofillFieldType type, | 128 ServerFieldType type, |
130 FieldTypeMap* map) { | 129 ServerFieldTypeMap* map) { |
131 // Several fields are optional. | 130 // Several fields are optional. |
132 if (!field) | 131 if (!field) |
133 return true; | 132 return true; |
134 | 133 |
135 return map->insert(make_pair(field->unique_name(), type)).second; | 134 return map->insert(make_pair(field->unique_name(), type)).second; |
136 } | 135 } |
137 | 136 |
138 // static. | 137 // static. |
139 bool FormField::MatchAndAdvance(AutofillScanner* scanner, | 138 bool FormField::MatchAndAdvance(AutofillScanner* scanner, |
140 const base::string16& pattern, | 139 const base::string16& pattern, |
(...skipping 28 matching lines...) Expand all Loading... |
169 autofill::MatchesPattern(field->value, pattern)) { | 168 autofill::MatchesPattern(field->value, pattern)) { |
170 return true; | 169 return true; |
171 } | 170 } |
172 | 171 |
173 return false; | 172 return false; |
174 } | 173 } |
175 | 174 |
176 // static | 175 // static |
177 void FormField::ParseFormFieldsPass(ParseFunction parse, | 176 void FormField::ParseFormFieldsPass(ParseFunction parse, |
178 std::vector<const AutofillField*>* fields, | 177 std::vector<const AutofillField*>* fields, |
179 FieldTypeMap* map) { | 178 ServerFieldTypeMap* map) { |
180 // Store unmatched fields for further processing by the caller. | 179 // Store unmatched fields for further processing by the caller. |
181 std::vector<const AutofillField*> remaining_fields; | 180 std::vector<const AutofillField*> remaining_fields; |
182 | 181 |
183 AutofillScanner scanner(*fields); | 182 AutofillScanner scanner(*fields); |
184 while (!scanner.IsEnd()) { | 183 while (!scanner.IsEnd()) { |
185 scoped_ptr<FormField> form_field(parse(&scanner)); | 184 scoped_ptr<FormField> form_field(parse(&scanner)); |
186 if (!form_field.get()) { | 185 if (!form_field.get()) { |
187 remaining_fields.push_back(scanner.Cursor()); | 186 remaining_fields.push_back(scanner.Cursor()); |
188 scanner.Advance(); | 187 scanner.Advance(); |
189 continue; | 188 continue; |
190 } | 189 } |
191 | 190 |
192 // Add entries into the map for each field type found in |form_field|. | 191 // Add entries into the map for each field type found in |form_field|. |
193 bool ok = form_field->ClassifyField(map); | 192 bool ok = form_field->ClassifyField(map); |
194 DCHECK(ok); | 193 DCHECK(ok); |
195 } | 194 } |
196 | 195 |
197 std::swap(*fields, remaining_fields); | 196 std::swap(*fields, remaining_fields); |
198 } | 197 } |
199 | 198 |
200 } // namespace autofill | 199 } // namespace autofill |
OLD | NEW |