Chromium Code Reviews| Index: chrome/browser/autofill/form_field.cc |
| diff --git a/chrome/browser/autofill/form_field.cc b/chrome/browser/autofill/form_field.cc |
| index 4560b4063ac13cc1529a9dba951e52e6b9dca29b..e25da5a59dcb6f04df730e4234713a364cb5cfca 100644 |
| --- a/chrome/browser/autofill/form_field.cc |
| +++ b/chrome/browser/autofill/form_field.cc |
| @@ -81,6 +81,26 @@ FormField* ParseFormField(AutofillScanner* scanner, bool is_ecml) { |
| return NameField::Parse(scanner, is_ecml); |
| } |
| +bool IsTextField(const string16& type) { |
| + return type == ASCIIToUTF16("text"); |
| +} |
| + |
| +bool IsEmailField(const string16& type) { |
| + return type == ASCIIToUTF16("email"); |
| +} |
| + |
| +bool IsMonthField(const string16& type) { |
| + return type == ASCIIToUTF16("month"); |
| +} |
| + |
| +bool IsTelephoneField(const string16& type) { |
| + return type == ASCIIToUTF16("tel"); |
| +} |
| + |
| +bool IsSelectField(const string16& type) { |
| + return type == ASCIIToUTF16("select-one"); |
| +} |
| + |
| } // namespace |
| // static |
| @@ -109,7 +129,7 @@ void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, |
| bool FormField::ParseField(AutofillScanner* scanner, |
| const string16& pattern, |
| const AutofillField** match) { |
| - return ParseFieldSpecifics(scanner, pattern, MATCH_ALL, match); |
| + return ParseFieldSpecifics(scanner, pattern, MATCH_DEFAULT, match); |
| } |
| // static |
| @@ -121,20 +141,34 @@ bool FormField::ParseFieldSpecifics(AutofillScanner* scanner, |
| return false; |
| const AutofillField* field = scanner->Cursor(); |
| - if (Match(field, pattern, match_type)) { |
| - if (match) |
| - *match = field; |
| - scanner->Advance(); |
| - return true; |
| + |
| + if ((match_type & MATCH_TEXT) && IsTextField(field->form_control_type)) |
| + return MatchAndAdvance(scanner, pattern, match_type, match); |
| + |
| + if ((match_type & MATCH_EMAIL) && IsEmailField(field->form_control_type)) |
| + return MatchAndAdvance(scanner, pattern, match_type, match); |
| + |
| + if ((match_type & MATCH_MONTH) && IsMonthField(field->form_control_type)) |
| + return MatchAndAdvance(scanner, pattern, match_type, match); |
|
Ilya Sherman
2011/05/25 03:52:02
There don't seem to be any clients who ever call i
dhollowa
2011/05/25 15:29:47
The credit card code currently explicitly looks fo
|
| + |
| + if ((match_type & MATCH_TELEPHONE) |
| + && IsTelephoneField(field->form_control_type)) { |
| + return MatchAndAdvance(scanner, pattern, match_type, match); |
| } |
| + if ((match_type & MATCH_SELECT) && IsSelectField(field->form_control_type)) |
| + return MatchAndAdvance(scanner, pattern, match_type, match); |
| + |
| return false; |
| } |
| // static |
| bool FormField::ParseEmptyLabel(AutofillScanner* scanner, |
| const AutofillField** match) { |
| - return ParseFieldSpecifics(scanner, ASCIIToUTF16("^$"), MATCH_LABEL, match); |
| + return ParseFieldSpecifics(scanner, |
| + ASCIIToUTF16("^$"), |
| + MATCH_LABEL | MATCH_ALL_INPUTS, |
| + match); |
| } |
| // static |
| @@ -148,6 +182,22 @@ bool FormField::AddClassification(const AutofillField* field, |
| return map->insert(make_pair(field->unique_name(), type)).second; |
| } |
| +// static. |
| +bool FormField::MatchAndAdvance(AutofillScanner* scanner, |
| + const string16& pattern, |
| + int match_type, |
| + const AutofillField** match) { |
| + const AutofillField* field = scanner->Cursor(); |
| + if (FormField::Match(field, pattern, match_type)) { |
| + if (match) |
| + *match = field; |
| + scanner->Advance(); |
| + return true; |
| + } |
| + |
| + return false; |
| +} |
| + |
| // static |
| bool FormField::Match(const AutofillField* field, |
| const string16& pattern, |