Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(320)

Side by Side Diff: components/autofill/core/browser/form_field.cc

Issue 1453193002: autofill: switch autofill_regexes to RE2 library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address reviews Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
16 #include "components/autofill/core/browser/address_field.h" 15 #include "components/autofill/core/browser/address_field.h"
17 #include "components/autofill/core/browser/autofill_field.h" 16 #include "components/autofill/core/browser/autofill_field.h"
18 #include "components/autofill/core/browser/autofill_scanner.h" 17 #include "components/autofill/core/browser/autofill_scanner.h"
19 #include "components/autofill/core/browser/credit_card_field.h" 18 #include "components/autofill/core/browser/credit_card_field.h"
20 #include "components/autofill/core/browser/email_field.h" 19 #include "components/autofill/core/browser/email_field.h"
21 #include "components/autofill/core/browser/form_structure.h" 20 #include "components/autofill/core/browser/form_structure.h"
22 #include "components/autofill/core/browser/name_field.h" 21 #include "components/autofill/core/browser/name_field.h"
23 #include "components/autofill/core/browser/phone_field.h" 22 #include "components/autofill/core/browser/phone_field.h"
24 #include "components/autofill/core/common/autofill_regexes.h" 23 #include "components/autofill/core/common/autofill_regexes.h"
25 24
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // only recognized field on account registration sites. 76 // only recognized field on account registration sites.
78 size_t kThreshold = 3; 77 size_t kThreshold = 3;
79 bool accept_parsing = (map->size() >= kThreshold || 78 bool accept_parsing = (map->size() >= kThreshold ||
80 (is_form_tag && email_count > 0)); 79 (is_form_tag && email_count > 0));
81 if (!accept_parsing) 80 if (!accept_parsing)
82 *map = saved_map; 81 *map = saved_map;
83 } 82 }
84 83
85 // static 84 // static
86 bool FormField::ParseField(AutofillScanner* scanner, 85 bool FormField::ParseField(AutofillScanner* scanner,
87 const base::string16& pattern, 86 const std::string& pattern,
88 AutofillField** match) { 87 AutofillField** match) {
89 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match); 88 return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match);
90 } 89 }
91 90
92 // static 91 // static
93 bool FormField::ParseFieldSpecifics(AutofillScanner* scanner, 92 bool FormField::ParseFieldSpecifics(AutofillScanner* scanner,
94 const base::string16& pattern, 93 const std::string& pattern,
95 int match_type, 94 int match_type,
96 AutofillField** match) { 95 AutofillField** match) {
97 if (scanner->IsEnd()) 96 if (scanner->IsEnd())
98 return false; 97 return false;
99 98
100 const AutofillField* field = scanner->Cursor(); 99 const AutofillField* field = scanner->Cursor();
101 100
102 if (!MatchesFormControlType(field->form_control_type, match_type)) 101 if (!MatchesFormControlType(field->form_control_type, match_type))
103 return false; 102 return false;
104 103
105 return MatchAndAdvance(scanner, pattern, match_type, match); 104 return MatchAndAdvance(scanner, pattern, match_type, match);
106 } 105 }
107 106
108 // static 107 // static
109 FormField::ParseNameLabelResult FormField::ParseNameAndLabelSeparately( 108 FormField::ParseNameLabelResult FormField::ParseNameAndLabelSeparately(
110 AutofillScanner* scanner, 109 AutofillScanner* scanner,
111 const base::string16& pattern, 110 const std::string& pattern,
112 int match_type, 111 int match_type,
113 AutofillField** match) { 112 AutofillField** match) {
114 if (scanner->IsEnd()) 113 if (scanner->IsEnd())
115 return RESULT_MATCH_NONE; 114 return RESULT_MATCH_NONE;
116 115
117 AutofillField* cur_match = nullptr; 116 AutofillField* cur_match = nullptr;
118 size_t saved_cursor = scanner->SaveCursor(); 117 size_t saved_cursor = scanner->SaveCursor();
119 bool parsed_name = ParseFieldSpecifics(scanner, 118 bool parsed_name = ParseFieldSpecifics(scanner,
120 pattern, 119 pattern,
121 match_type & ~MATCH_LABEL, 120 match_type & ~MATCH_LABEL,
(...skipping 14 matching lines...) Expand all
136 return RESULT_MATCH_NAME; 135 return RESULT_MATCH_NAME;
137 if (parsed_label) 136 if (parsed_label)
138 return RESULT_MATCH_LABEL; 137 return RESULT_MATCH_LABEL;
139 return RESULT_MATCH_NONE; 138 return RESULT_MATCH_NONE;
140 } 139 }
141 140
142 // static 141 // static
143 bool FormField::ParseEmptyLabel(AutofillScanner* scanner, 142 bool FormField::ParseEmptyLabel(AutofillScanner* scanner,
144 AutofillField** match) { 143 AutofillField** match) {
145 return ParseFieldSpecifics(scanner, 144 return ParseFieldSpecifics(scanner,
146 base::ASCIIToUTF16("^$"), 145 "^$",
147 MATCH_LABEL | MATCH_ALL_INPUTS, 146 MATCH_LABEL | MATCH_ALL_INPUTS,
148 match); 147 match);
149 } 148 }
150 149
151 // static 150 // static
152 bool FormField::AddClassification(const AutofillField* field, 151 bool FormField::AddClassification(const AutofillField* field,
153 ServerFieldType type, 152 ServerFieldType type,
154 ServerFieldTypeMap* map) { 153 ServerFieldTypeMap* map) {
155 // Several fields are optional. 154 // Several fields are optional.
156 if (!field) 155 if (!field)
157 return true; 156 return true;
158 157
159 return map->insert(make_pair(field->unique_name(), type)).second; 158 return map->insert(make_pair(field->unique_name(), type)).second;
160 } 159 }
161 160
162 // static. 161 // static.
163 bool FormField::MatchAndAdvance(AutofillScanner* scanner, 162 bool FormField::MatchAndAdvance(AutofillScanner* scanner,
164 const base::string16& pattern, 163 const std::string& pattern,
165 int match_type, 164 int match_type,
166 AutofillField** match) { 165 AutofillField** match) {
167 AutofillField* field = scanner->Cursor(); 166 AutofillField* field = scanner->Cursor();
168 if (FormField::Match(field, pattern, match_type)) { 167 if (FormField::Match(field, pattern, match_type)) {
169 if (match) 168 if (match)
170 *match = field; 169 *match = field;
171 scanner->Advance(); 170 scanner->Advance();
172 return true; 171 return true;
173 } 172 }
174 173
175 return false; 174 return false;
176 } 175 }
177 176
178 // static 177 // static
179 bool FormField::Match(const AutofillField* field, 178 bool FormField::Match(const AutofillField* field,
180 const base::string16& pattern, 179 const std::string& pattern,
181 int match_type) { 180 int match_type) {
182 if ((match_type & FormField::MATCH_LABEL) && 181 if ((match_type & FormField::MATCH_LABEL) &&
183 MatchesPattern(field->label, pattern)) { 182 MatchesPattern(field->label, pattern)) {
184 return true; 183 return true;
185 } 184 }
186 185
187 if ((match_type & FormField::MATCH_NAME) && 186 if ((match_type & FormField::MATCH_NAME) &&
188 MatchesPattern(field->name, pattern)) { 187 MatchesPattern(field->name, pattern)) {
189 return true; 188 return true;
190 } 189 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if ((match_type & MATCH_PASSWORD) && type == "password") 235 if ((match_type & MATCH_PASSWORD) && type == "password")
237 return true; 236 return true;
238 237
239 if ((match_type & MATCH_NUMBER) && type == "number") 238 if ((match_type & MATCH_NUMBER) && type == "number")
240 return true; 239 return true;
241 240
242 return false; 241 return false;
243 } 242 }
244 243
245 } // namespace autofill 244 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698