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

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

Issue 1453193002: autofill: switch autofill_regexes to RE2 library (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 14 tests failing 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/name_field.h" 5 #include "components/autofill/core/browser/name_field.h"
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "components/autofill/core/browser/autofill_regex_constants.h" 10 #include "components/autofill/core/browser/autofill_regex_constants.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 73
74 // This is overriden in concrete subclasses. 74 // This is overriden in concrete subclasses.
75 bool NameField::ClassifyField(ServerFieldTypeMap* map) const { 75 bool NameField::ClassifyField(ServerFieldTypeMap* map) const {
76 return false; 76 return false;
77 } 77 }
78 78
79 // static 79 // static
80 scoped_ptr<FullNameField> FullNameField::Parse(AutofillScanner* scanner) { 80 scoped_ptr<FullNameField> FullNameField::Parse(AutofillScanner* scanner) {
81 // Exclude e.g. "username" or "nickname" fields. 81 // Exclude e.g. "username" or "nickname" fields.
82 scanner->SaveCursor(); 82 scanner->SaveCursor();
83 bool should_ignore = ParseField(scanner, UTF8ToUTF16(kNameIgnoredRe), NULL); 83 bool should_ignore = ParseField(scanner, kNameIgnoredRe, NULL);
84 scanner->Rewind(); 84 scanner->Rewind();
85 if (should_ignore) 85 if (should_ignore)
86 return NULL; 86 return NULL;
87 87
88 // Searching for any label containing the word "name" is too general; 88 // Searching for any label containing the word "name" is too general;
89 // for example, Travelocity_Edit travel profile.html contains a field 89 // for example, Travelocity_Edit travel profile.html contains a field
90 // "Travel Profile Name". 90 // "Travel Profile Name".
91 AutofillField* field = NULL; 91 AutofillField* field = NULL;
92 if (ParseField(scanner, UTF8ToUTF16(kNameRe), &field)) 92 if (ParseField(scanner, kNameRe, &field))
93 return make_scoped_ptr(new FullNameField(field)); 93 return make_scoped_ptr(new FullNameField(field));
94 94
95 return NULL; 95 return NULL;
96 } 96 }
97 97
98 bool FullNameField::ClassifyField(ServerFieldTypeMap* map) const { 98 bool FullNameField::ClassifyField(ServerFieldTypeMap* map) const {
99 return AddClassification(field_, NAME_FULL, map); 99 return AddClassification(field_, NAME_FULL, map);
100 } 100 }
101 101
102 FullNameField::FullNameField(AutofillField* field) : field_(field) { 102 FullNameField::FullNameField(AutofillField* field) : field_(field) {
103 } 103 }
104 104
105 scoped_ptr<FirstLastNameField> FirstLastNameField::ParseSpecificName( 105 scoped_ptr<FirstLastNameField> FirstLastNameField::ParseSpecificName(
106 AutofillScanner* scanner) { 106 AutofillScanner* scanner) {
107 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html) 107 // Some pages (e.g. Overstock_comBilling.html, SmithsonianCheckout.html)
108 // have the label "Name" followed by two or three text fields. 108 // have the label "Name" followed by two or three text fields.
109 scoped_ptr<FirstLastNameField> v(new FirstLastNameField); 109 scoped_ptr<FirstLastNameField> v(new FirstLastNameField);
110 scanner->SaveCursor(); 110 scanner->SaveCursor();
111 111
112 AutofillField* next = NULL; 112 AutofillField* next = NULL;
113 if (ParseField(scanner, UTF8ToUTF16(kNameSpecificRe), &v->first_name_) && 113 if (ParseField(scanner, kNameSpecificRe, &v->first_name_) &&
114 ParseEmptyLabel(scanner, &next)) { 114 ParseEmptyLabel(scanner, &next)) {
115 if (ParseEmptyLabel(scanner, &v->last_name_)) { 115 if (ParseEmptyLabel(scanner, &v->last_name_)) {
116 // There are three name fields; assume that the middle one is a 116 // There are three name fields; assume that the middle one is a
117 // middle initial (it is, at least, on SmithsonianCheckout.html). 117 // middle initial (it is, at least, on SmithsonianCheckout.html).
118 v->middle_name_ = next; 118 v->middle_name_ = next;
119 v->middle_initial_ = true; 119 v->middle_initial_ = true;
120 } else { // only two name fields 120 } else { // only two name fields
121 v->last_name_ = next; 121 v->last_name_ = next;
122 } 122 }
123 123
(...skipping 16 matching lines...) Expand all
140 // dell_checkout1.html). At least one UK page (The China Shop2.html) 140 // dell_checkout1.html). At least one UK page (The China Shop2.html)
141 // asks, in stuffy English style, for just initials and a surname, 141 // asks, in stuffy English style, for just initials and a surname,
142 // so we match "initials" here (and just fill in a first name there, 142 // so we match "initials" here (and just fill in a first name there,
143 // American-style). 143 // American-style).
144 // The ".*first$" matches fields ending in "first" (example in sample8.html). 144 // The ".*first$" matches fields ending in "first" (example in sample8.html).
145 // The ".*last$" matches fields ending in "last" (example in sample8.html). 145 // The ".*last$" matches fields ending in "last" (example in sample8.html).
146 146
147 // Allow name fields to appear in any order. 147 // Allow name fields to appear in any order.
148 while (!scanner->IsEnd()) { 148 while (!scanner->IsEnd()) {
149 // Skip over any unrelated fields, e.g. "username" or "nickname". 149 // Skip over any unrelated fields, e.g. "username" or "nickname".
150 if (ParseFieldSpecifics(scanner, UTF8ToUTF16(kNameIgnoredRe), 150 if (ParseFieldSpecifics(scanner, kNameIgnoredRe,
151 MATCH_DEFAULT | MATCH_SELECT, NULL)) { 151 MATCH_DEFAULT | MATCH_SELECT, NULL)) {
152 continue; 152 continue;
153 } 153 }
154 154
155 if (!v->first_name_ && 155 if (!v->first_name_ && ParseField(scanner, kFirstNameRe, &v->first_name_)) {
156 ParseField(scanner, UTF8ToUTF16(kFirstNameRe), &v->first_name_)) {
157 continue; 156 continue;
158 } 157 }
159 158
160 // We check for a middle initial before checking for a middle name 159 // We check for a middle initial before checking for a middle name
161 // because at least one page (PC Connection.html) has a field marked 160 // because at least one page (PC Connection.html) has a field marked
162 // as both (the label text is "MI" and the element name is 161 // as both (the label text is "MI" and the element name is
163 // "txtmiddlename"); such a field probably actually represents a 162 // "txtmiddlename"); such a field probably actually represents a
164 // middle initial. 163 // middle initial.
165 if (!v->middle_name_ && 164 if (!v->middle_name_ &&
166 ParseField(scanner, UTF8ToUTF16(kMiddleInitialRe), &v->middle_name_)) { 165 ParseField(scanner, kMiddleInitialRe, &v->middle_name_)) {
167 v->middle_initial_ = true; 166 v->middle_initial_ = true;
168 continue; 167 continue;
169 } 168 }
170 169
171 if (!v->middle_name_ && 170 if (!v->middle_name_ &&
172 ParseField(scanner, UTF8ToUTF16(kMiddleNameRe), &v->middle_name_)) { 171 ParseField(scanner, kMiddleNameRe, &v->middle_name_)) {
173 continue; 172 continue;
174 } 173 }
175 174
176 if (!v->last_name_ && 175 if (!v->last_name_ && ParseField(scanner, kLastNameRe, &v->last_name_)) {
177 ParseField(scanner, UTF8ToUTF16(kLastNameRe), &v->last_name_)) {
178 continue; 176 continue;
179 } 177 }
180 178
181 break; 179 break;
182 } 180 }
183 181
184 // Consider the match to be successful if we detected both first and last name 182 // Consider the match to be successful if we detected both first and last name
185 // fields. 183 // fields.
186 if (v->first_name_ && v->last_name_) 184 if (v->first_name_ && v->last_name_)
187 return v.Pass(); 185 return v.Pass();
(...skipping 20 matching lines...) Expand all
208 206
209 bool FirstLastNameField::ClassifyField(ServerFieldTypeMap* map) const { 207 bool FirstLastNameField::ClassifyField(ServerFieldTypeMap* map) const {
210 bool ok = AddClassification(first_name_, NAME_FIRST, map); 208 bool ok = AddClassification(first_name_, NAME_FIRST, map);
211 ok = ok && AddClassification(last_name_, NAME_LAST, map); 209 ok = ok && AddClassification(last_name_, NAME_LAST, map);
212 ServerFieldType type = middle_initial_ ? NAME_MIDDLE_INITIAL : NAME_MIDDLE; 210 ServerFieldType type = middle_initial_ ? NAME_MIDDLE_INITIAL : NAME_MIDDLE;
213 ok = ok && AddClassification(middle_name_, type, map); 211 ok = ok && AddClassification(middle_name_, type, map);
214 return ok; 212 return ok;
215 } 213 }
216 214
217 } // namespace autofill 215 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698