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

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

Issue 7038003: Refactor autofill form fields. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 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
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..db608e58e4bb1f0e0019982136b380f84f16f056 100644
--- a/chrome/browser/autofill/form_field.cc
+++ b/chrome/browser/autofill/form_field.cc
@@ -170,22 +170,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 Match(field, pattern,
+ MATCH_NAME | (match_label_only ? 0 : MATCH_NAME));
+}
+
+// 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 +243,46 @@ 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) && field->is_text_input)
+ return false;
+
+ if (MatchWithType(field, pattern, match_type)) {
if (dest)
*dest = field;
scanner->Advance();
@@ -280,13 +293,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 +306,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) {

Powered by Google App Engine
This is Rietveld 408576698