| Index: chrome/browser/autofill/form_field.cc
|
| diff --git a/chrome/browser/autofill/form_field.cc b/chrome/browser/autofill/form_field.cc
|
| index 926d3409a746e8d02d2f319a3f2cb99da3cefb38..58c33f29ec48de8d3756191938295d1de7fcb509 100644
|
| --- a/chrome/browser/autofill/form_field.cc
|
| +++ b/chrome/browser/autofill/form_field.cc
|
| @@ -145,6 +145,16 @@ bool HasECMLField(const std::vector<AutofillField*>& fields) {
|
| return false;
|
| }
|
|
|
| +bool isTextInput(const string16& form_control_type) {
|
| + const char* text_types[] = {"text", "email", "search", "tel", "url",
|
| + "number", "date", "datetime", "datetime-local", "month", "week",
|
| + "time", "range"};
|
| + bool is_text_input = false;
|
| + for (size_t i = 0; i < sizeof(text_types)/sizeof(const char*); ++i)
|
| + is_text_input |= form_control_type == ASCIIToUTF16(text_types[i]);
|
| + return is_text_input;
|
| +}
|
| +
|
| } // namespace
|
|
|
| // static
|
| @@ -170,22 +180,30 @@ void FormField::ParseFormFields(const std::vector<AutofillField*>& fields,
|
| }
|
|
|
| // static
|
| -bool FormField::Match(const AutofillField* field,
|
| - const string16& pattern,
|
| - bool match_label_only) {
|
| - if (MatchLabel(field, pattern))
|
| +bool FormField::MatchWithType(const AutofillField* field,
|
| + const string16& pattern,
|
| + int match_type) {
|
| + if ((match_type & MATCH_LABEL) && MatchLabel(field, pattern))
|
| return true;
|
|
|
| // For now, we apply the same pattern to the field's label and the field's
|
| // name. Matching the name is a bit of a long shot for many patterns, but
|
| // it generally doesn't hurt to try.
|
| - if (!match_label_only && MatchName(field, pattern))
|
| + if ((match_type & MATCH_NAME) && MatchName(field, pattern))
|
| return true;
|
|
|
| return false;
|
| }
|
|
|
| // static
|
| +bool FormField::Match(const AutofillField* field,
|
| + const string16& pattern,
|
| + bool match_label_only) {
|
| + return MatchWithType(field, pattern,
|
| + MATCH_NAME | (match_label_only ? 0 : MATCH_LABEL));
|
| +}
|
| +
|
| +// static
|
| bool FormField::MatchName(const AutofillField* field, const string16& pattern) {
|
| // TODO(jhawkins): Remove StringToLowerASCII. WebRegularExpression needs to
|
| // be fixed to take WebTextCaseInsensitive into account.
|
| @@ -235,41 +253,47 @@ FormField* FormField::ParseFormField(AutofillScanner* scanner, bool is_ecml) {
|
| }
|
|
|
| // static
|
| -bool FormField::ParseText(AutofillScanner* scanner, const string16& pattern) {
|
| +bool FormField::ParseText(AutofillScanner* scanner,
|
| + const string16& pattern,
|
| + int match_type) {
|
| const AutofillField* field;
|
| - return ParseText(scanner, pattern, &field);
|
| + return ParseText(scanner, pattern, match_type, &field);
|
| }
|
|
|
| // static
|
| bool FormField::ParseText(AutofillScanner* scanner,
|
| const string16& pattern,
|
| + int match_type,
|
| const AutofillField** dest) {
|
| - return ParseText(scanner, pattern, dest, false);
|
| + return ParseText(scanner, pattern, dest, match_type);
|
| }
|
|
|
| // static
|
| bool FormField::ParseEmptyText(AutofillScanner* scanner,
|
| const AutofillField** dest) {
|
| - return ParseLabelText(scanner, ASCIIToUTF16("^$"), dest);
|
| -}
|
| -
|
| -// static
|
| -bool FormField::ParseLabelText(AutofillScanner* scanner,
|
| - const string16& pattern,
|
| - const AutofillField** dest) {
|
| - return ParseText(scanner, pattern, dest, true);
|
| + return ParseText(scanner, ASCIIToUTF16("^$"),
|
| + MATCH_LABEL | MATCH_TEXT | MATCH_SELECT, dest);
|
| }
|
|
|
| // static
|
| bool FormField::ParseText(AutofillScanner* scanner,
|
| const string16& pattern,
|
| const AutofillField** dest,
|
| - bool match_label_only) {
|
| + int match_type) {
|
| if (scanner->IsEnd())
|
| return false;
|
|
|
| const AutofillField* field = scanner->Cursor();
|
| - if (Match(field, pattern, match_label_only)) {
|
| +
|
| +// if (!(match_type & MATCH_SELECT) &&
|
| +// field->form_control_type == ASCIIToUTF16("select-one"))
|
| +// return false;
|
| +//
|
| +// if (!(match_type & MATCH_TEXT) &&
|
| +// isTextInput(field->form_control_type))
|
| +// return false;
|
| +
|
| + if (MatchWithType(field, pattern, match_type)) {
|
| if (dest)
|
| *dest = field;
|
| scanner->Advance();
|
| @@ -280,13 +304,11 @@ bool FormField::ParseText(AutofillScanner* scanner,
|
| }
|
|
|
| // static
|
| -bool FormField::ParseLabelAndName(AutofillScanner* scanner,
|
| - const string16& pattern,
|
| - const AutofillField** dest) {
|
| +bool FormField::ParseEmpty(AutofillScanner* scanner) {
|
| + // TODO(jhawkins): Handle select fields.
|
| + const string16 pattern(ASCIIToUTF16("^$"));
|
| const AutofillField* field = scanner->Cursor();
|
| if (MatchLabel(field, pattern) && MatchName(field, pattern)) {
|
| - if (dest)
|
| - *dest = field;
|
| scanner->Advance();
|
| return true;
|
| }
|
| @@ -295,12 +317,6 @@ bool FormField::ParseLabelAndName(AutofillScanner* scanner,
|
| }
|
|
|
| // static
|
| -bool FormField::ParseEmpty(AutofillScanner* scanner) {
|
| - // TODO(jhawkins): Handle select fields.
|
| - return ParseLabelAndName(scanner, ASCIIToUTF16("^$"), NULL);
|
| -}
|
| -
|
| -// static
|
| bool FormField::Add(FieldTypeMap* field_type_map,
|
| const AutofillField* field,
|
| AutofillFieldType type) {
|
|
|