Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/autofill/form_field.h" | 5 #include "chrome/browser/autofill/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 |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 228 field = CreditCardField::Parse(scanner, is_ecml); | 228 field = CreditCardField::Parse(scanner, is_ecml); |
| 229 if (field) | 229 if (field) |
| 230 return field; | 230 return field; |
| 231 | 231 |
| 232 // We search for a |NameField| last since it matches the word "name", which is | 232 // We search for a |NameField| last since it matches the word "name", which is |
| 233 // relatively general. | 233 // relatively general. |
| 234 return NameField::Parse(scanner, is_ecml); | 234 return NameField::Parse(scanner, is_ecml); |
| 235 } | 235 } |
| 236 | 236 |
| 237 // static | 237 // static |
| 238 bool FormField::ParseText(AutofillScanner* scanner, const string16& pattern) { | |
| 239 const AutofillField* field; | |
| 240 return ParseText(scanner, pattern, &field); | |
| 241 } | |
| 242 | |
| 243 // static | |
| 244 bool FormField::ParseText(AutofillScanner* scanner, | 238 bool FormField::ParseText(AutofillScanner* scanner, |
| 245 const string16& pattern, | 239 const string16& pattern, |
| 240 int match_type) { | |
| 241 const AutofillField* field; | |
| 242 return ParseText(scanner, pattern, match_type, &field); | |
| 243 } | |
| 244 | |
| 245 // static | |
| 246 bool FormField::ParseText(AutofillScanner* scanner, | |
| 247 const string16& pattern, | |
| 248 int match_type, | |
| 246 const AutofillField** dest) { | 249 const AutofillField** dest) { |
| 247 return ParseText(scanner, pattern, dest, false); | 250 return ParseText(scanner, pattern, dest, match_type); |
| 248 } | 251 } |
| 249 | 252 |
| 250 // static | 253 // static |
| 251 bool FormField::ParseEmptyText(AutofillScanner* scanner, | 254 bool FormField::ParseEmptyText(AutofillScanner* scanner, |
| 252 const AutofillField** dest) { | 255 const AutofillField** dest) { |
| 253 return ParseLabelText(scanner, ASCIIToUTF16("^$"), dest); | 256 return ParseText(scanner, ASCIIToUTF16("^$"), |
| 254 } | 257 MATCH_LABEL | MATCH_TEXT | MATCH_SELECT, dest); |
| 255 | |
| 256 // static | |
| 257 bool FormField::ParseLabelText(AutofillScanner* scanner, | |
| 258 const string16& pattern, | |
| 259 const AutofillField** dest) { | |
| 260 return ParseText(scanner, pattern, dest, true); | |
| 261 } | 258 } |
| 262 | 259 |
| 263 // static | 260 // static |
| 264 bool FormField::ParseText(AutofillScanner* scanner, | 261 bool FormField::ParseText(AutofillScanner* scanner, |
| 265 const string16& pattern, | 262 const string16& pattern, |
| 266 const AutofillField** dest, | 263 const AutofillField** dest, |
| 267 bool match_label_only) { | 264 int match_type) { |
| 268 if (scanner->IsEnd()) | 265 if (scanner->IsEnd()) |
| 269 return false; | 266 return false; |
| 270 | 267 |
| 271 const AutofillField* field = scanner->Cursor(); | 268 const AutofillField* field = scanner->Cursor(); |
| 269 | |
| 270 if (!(match_type & MATCH_SELECT) && | |
| 271 field->form_control_type == ASCIIToUTF16("select-one")) | |
| 272 return false; | |
| 273 | |
| 274 if (!(match_type & MATCH_TEXT) && | |
| 275 field->form_control_type == ASCIIToUTF16("text")) | |
|
Ilya Sherman
2011/05/14 06:59:12
What about 'email', 'tel', and so on? Are there a
honten.org
2011/05/14 07:30:05
Yeah, you are right.
I completely forgot HTML5 ta
honten.org
2011/05/14 07:41:20
As I used to did in form_manager, maybe we should
| |
| 276 return false; | |
| 277 | |
| 278 bool match_label_only = (match_type & MATCH_LABEL) && | |
| 279 !(match_type & MATCH_NAME); | |
|
Ilya Sherman
2011/05/14 06:59:12
This computation doesn't seem right to me -- if MA
honten.org
2011/05/14 07:30:05
Actually, I wanted to refactor Match(), but it is
| |
| 272 if (Match(field, pattern, match_label_only)) { | 280 if (Match(field, pattern, match_label_only)) { |
| 273 if (dest) | 281 if (dest) |
| 274 *dest = field; | 282 *dest = field; |
| 275 scanner->Advance(); | 283 scanner->Advance(); |
| 276 return true; | 284 return true; |
| 277 } | 285 } |
| 278 | 286 |
| 279 return false; | 287 return false; |
| 280 } | 288 } |
| 281 | 289 |
| 282 // static | 290 // static |
| 283 bool FormField::ParseLabelAndName(AutofillScanner* scanner, | 291 bool FormField::ParseEmpty(AutofillScanner* scanner) { |
| 284 const string16& pattern, | 292 // TODO(jhawkins): Handle select fields. |
| 285 const AutofillField** dest) { | 293 const string16 pattern(ASCIIToUTF16("^$")); |
| 286 const AutofillField* field = scanner->Cursor(); | 294 const AutofillField* field = scanner->Cursor(); |
| 287 if (MatchLabel(field, pattern) && MatchName(field, pattern)) { | 295 if (MatchLabel(field, pattern) && MatchName(field, pattern)) { |
| 288 if (dest) | |
| 289 *dest = field; | |
| 290 scanner->Advance(); | 296 scanner->Advance(); |
| 291 return true; | 297 return true; |
| 292 } | 298 } |
| 293 | 299 |
| 294 return false; | 300 return false; |
| 295 } | 301 } |
| 296 | 302 |
| 297 // static | 303 // static |
| 298 bool FormField::ParseEmpty(AutofillScanner* scanner) { | |
| 299 // TODO(jhawkins): Handle select fields. | |
| 300 return ParseLabelAndName(scanner, ASCIIToUTF16("^$"), NULL); | |
| 301 } | |
| 302 | |
| 303 // static | |
| 304 bool FormField::Add(FieldTypeMap* field_type_map, | 304 bool FormField::Add(FieldTypeMap* field_type_map, |
| 305 const AutofillField* field, | 305 const AutofillField* field, |
| 306 AutofillFieldType type) { | 306 AutofillFieldType type) { |
| 307 // Several fields are optional. | 307 // Several fields are optional. |
| 308 if (!field) | 308 if (!field) |
| 309 return true; | 309 return true; |
| 310 | 310 |
| 311 // TODO(isherman): Is this the intent? | 311 // TODO(isherman): Is this the intent? |
| 312 return field_type_map->insert(make_pair(field->unique_name(), type)).second; | 312 return field_type_map->insert(make_pair(field->unique_name(), type)).second; |
| 313 } | 313 } |
| 314 | 314 |
| 315 string16 FormField::GetEcmlPattern(const char* ecml_name) { | 315 string16 FormField::GetEcmlPattern(const char* ecml_name) { |
| 316 return ASCIIToUTF16(std::string("^") + ecml_name); | 316 return ASCIIToUTF16(std::string("^") + ecml_name); |
| 317 } | 317 } |
| 318 | 318 |
| 319 string16 FormField::GetEcmlPattern(const char* ecml_name1, | 319 string16 FormField::GetEcmlPattern(const char* ecml_name1, |
| 320 const char* ecml_name2, | 320 const char* ecml_name2, |
| 321 char pattern_operator) { | 321 char pattern_operator) { |
| 322 return ASCIIToUTF16(StringPrintf("^%s%c^%s", | 322 return ASCIIToUTF16(StringPrintf("^%s%c^%s", |
| 323 ecml_name1, pattern_operator, ecml_name2)); | 323 ecml_name1, pattern_operator, ecml_name2)); |
| 324 } | 324 } |
| OLD | NEW |