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" |
Ilya Sherman
2015/11/26 02:25:09
nit: Is this include still needed? Please check t
tfarina
2015/11/26 14:22:27
Done.
| |
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_scanner.h" | 18 #include "components/autofill/core/browser/autofill_scanner.h" |
19 #include "components/autofill/core/browser/credit_card_field.h" | 19 #include "components/autofill/core/browser/credit_card_field.h" |
20 #include "components/autofill/core/browser/email_field.h" | 20 #include "components/autofill/core/browser/email_field.h" |
21 #include "components/autofill/core/browser/form_structure.h" | 21 #include "components/autofill/core/browser/form_structure.h" |
22 #include "components/autofill/core/browser/name_field.h" | 22 #include "components/autofill/core/browser/name_field.h" |
23 #include "components/autofill/core/browser/phone_field.h" | 23 #include "components/autofill/core/browser/phone_field.h" |
24 #include "components/autofill/core/common/autofill_regexes.h" | 24 #include "components/autofill/core/common/autofill_regexes.h" |
25 | 25 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 // only recognized field on account registration sites. | 77 // only recognized field on account registration sites. |
78 size_t kThreshold = 3; | 78 size_t kThreshold = 3; |
79 bool accept_parsing = (map->size() >= kThreshold || | 79 bool accept_parsing = (map->size() >= kThreshold || |
80 (is_form_tag && email_count > 0)); | 80 (is_form_tag && email_count > 0)); |
81 if (!accept_parsing) | 81 if (!accept_parsing) |
82 *map = saved_map; | 82 *map = saved_map; |
83 } | 83 } |
84 | 84 |
85 // static | 85 // static |
86 bool FormField::ParseField(AutofillScanner* scanner, | 86 bool FormField::ParseField(AutofillScanner* scanner, |
87 const base::string16& pattern, | 87 const std::string& pattern, |
88 AutofillField** match) { | 88 AutofillField** match) { |
89 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match); | 89 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match); |
90 } | 90 } |
91 | 91 |
92 // static | 92 // static |
93 bool FormField::ParseFieldSpecifics(AutofillScanner* scanner, | 93 bool FormField::ParseFieldSpecifics(AutofillScanner* scanner, |
94 const base::string16& pattern, | 94 const std::string& pattern, |
95 int match_type, | 95 int match_type, |
96 AutofillField** match) { | 96 AutofillField** match) { |
97 if (scanner->IsEnd()) | 97 if (scanner->IsEnd()) |
98 return false; | 98 return false; |
99 | 99 |
100 const AutofillField* field = scanner->Cursor(); | 100 const AutofillField* field = scanner->Cursor(); |
101 | 101 |
102 if (!MatchesFormControlType(field->form_control_type, match_type)) | 102 if (!MatchesFormControlType(field->form_control_type, match_type)) |
103 return false; | 103 return false; |
104 | 104 |
105 return MatchAndAdvance(scanner, pattern, match_type, match); | 105 return MatchAndAdvance(scanner, pattern, match_type, match); |
106 } | 106 } |
107 | 107 |
108 // static | 108 // static |
109 FormField::ParseNameLabelResult FormField::ParseNameAndLabelSeparately( | 109 FormField::ParseNameLabelResult FormField::ParseNameAndLabelSeparately( |
110 AutofillScanner* scanner, | 110 AutofillScanner* scanner, |
111 const base::string16& pattern, | 111 const std::string& pattern, |
112 int match_type, | 112 int match_type, |
113 AutofillField** match) { | 113 AutofillField** match) { |
114 if (scanner->IsEnd()) | 114 if (scanner->IsEnd()) |
115 return RESULT_MATCH_NONE; | 115 return RESULT_MATCH_NONE; |
116 | 116 |
117 AutofillField* cur_match = nullptr; | 117 AutofillField* cur_match = nullptr; |
118 size_t saved_cursor = scanner->SaveCursor(); | 118 size_t saved_cursor = scanner->SaveCursor(); |
119 bool parsed_name = ParseFieldSpecifics(scanner, | 119 bool parsed_name = ParseFieldSpecifics(scanner, |
120 pattern, | 120 pattern, |
121 match_type & ~MATCH_LABEL, | 121 match_type & ~MATCH_LABEL, |
(...skipping 14 matching lines...) Expand all Loading... | |
136 return RESULT_MATCH_NAME; | 136 return RESULT_MATCH_NAME; |
137 if (parsed_label) | 137 if (parsed_label) |
138 return RESULT_MATCH_LABEL; | 138 return RESULT_MATCH_LABEL; |
139 return RESULT_MATCH_NONE; | 139 return RESULT_MATCH_NONE; |
140 } | 140 } |
141 | 141 |
142 // static | 142 // static |
143 bool FormField::ParseEmptyLabel(AutofillScanner* scanner, | 143 bool FormField::ParseEmptyLabel(AutofillScanner* scanner, |
144 AutofillField** match) { | 144 AutofillField** match) { |
145 return ParseFieldSpecifics(scanner, | 145 return ParseFieldSpecifics(scanner, |
146 base::ASCIIToUTF16("^$"), | 146 "^$", |
147 MATCH_LABEL | MATCH_ALL_INPUTS, | 147 MATCH_LABEL | MATCH_ALL_INPUTS, |
148 match); | 148 match); |
149 } | 149 } |
150 | 150 |
151 // static | 151 // static |
152 bool FormField::AddClassification(const AutofillField* field, | 152 bool FormField::AddClassification(const AutofillField* field, |
153 ServerFieldType type, | 153 ServerFieldType type, |
154 ServerFieldTypeMap* map) { | 154 ServerFieldTypeMap* map) { |
155 // Several fields are optional. | 155 // Several fields are optional. |
156 if (!field) | 156 if (!field) |
157 return true; | 157 return true; |
158 | 158 |
159 return map->insert(make_pair(field->unique_name(), type)).second; | 159 return map->insert(make_pair(field->unique_name(), type)).second; |
160 } | 160 } |
161 | 161 |
162 // static. | 162 // static. |
163 bool FormField::MatchAndAdvance(AutofillScanner* scanner, | 163 bool FormField::MatchAndAdvance(AutofillScanner* scanner, |
164 const base::string16& pattern, | 164 const std::string& pattern, |
165 int match_type, | 165 int match_type, |
166 AutofillField** match) { | 166 AutofillField** match) { |
167 AutofillField* field = scanner->Cursor(); | 167 AutofillField* field = scanner->Cursor(); |
168 if (FormField::Match(field, pattern, match_type)) { | 168 if (FormField::Match(field, pattern, match_type)) { |
169 if (match) | 169 if (match) |
170 *match = field; | 170 *match = field; |
171 scanner->Advance(); | 171 scanner->Advance(); |
172 return true; | 172 return true; |
173 } | 173 } |
174 | 174 |
175 return false; | 175 return false; |
176 } | 176 } |
177 | 177 |
178 // static | 178 // static |
179 bool FormField::Match(const AutofillField* field, | 179 bool FormField::Match(const AutofillField* field, |
180 const base::string16& pattern, | 180 const std::string& pattern, |
181 int match_type) { | 181 int match_type) { |
182 if ((match_type & FormField::MATCH_LABEL) && | 182 if ((match_type & FormField::MATCH_LABEL) && |
183 MatchesPattern(field->label, pattern)) { | 183 MatchesPattern(field->label, pattern)) { |
184 return true; | 184 return true; |
185 } | 185 } |
186 | 186 |
187 if ((match_type & FormField::MATCH_NAME) && | 187 if ((match_type & FormField::MATCH_NAME) && |
188 MatchesPattern(field->name, pattern)) { | 188 MatchesPattern(field->name, pattern)) { |
189 return true; | 189 return true; |
190 } | 190 } |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 if ((match_type & MATCH_PASSWORD) && type == "password") | 236 if ((match_type & MATCH_PASSWORD) && type == "password") |
237 return true; | 237 return true; |
238 | 238 |
239 if ((match_type & MATCH_NUMBER) && type == "number") | 239 if ((match_type & MATCH_NUMBER) && type == "number") |
240 return true; | 240 return true; |
241 | 241 |
242 return false; | 242 return false; |
243 } | 243 } |
244 | 244 |
245 } // namespace autofill | 245 } // namespace autofill |
OLD | NEW |