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

Unified Diff: chrome/browser/autofill/form_field.cc

Issue 7063031: Heuristics for grabber-continental.com.out (select-one) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: nits Created 9 years, 7 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autofill/form_field.h ('k') | chrome/browser/autofill/phone_field.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8e628d3cffe2c3513c03aebea05319b474de69ab 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,31 @@ 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_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 +179,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,
« no previous file with comments | « chrome/browser/autofill/form_field.h ('k') | chrome/browser/autofill/phone_field.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698