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

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

Issue 7043027: Autofill refactor form_field.h/cc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: OVERRIDE glitch. 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/email_field.cc ('k') | chrome/browser/autofill/form_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.h
diff --git a/chrome/browser/autofill/form_field.h b/chrome/browser/autofill/form_field.h
index 3bb5c0eca47528862efea72e7ff0e44fb250544f..db00e9e7f9efa9951937324cd5c462551d5d7a99 100644
--- a/chrome/browser/autofill/form_field.h
+++ b/chrome/browser/autofill/form_field.h
@@ -9,54 +9,13 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
#include "base/string16.h"
#include "chrome/browser/autofill/autofill_type.h"
class AutofillField;
class AutofillScanner;
-extern const char kEcmlShipToTitle[];
-extern const char kEcmlShipToFirstName[];
-extern const char kEcmlShipToMiddleName[];
-extern const char kEcmlShipToLastName[];
-extern const char kEcmlShipToNameSuffix[];
-extern const char kEcmlShipToCompanyName[];
-extern const char kEcmlShipToAddress1[];
-extern const char kEcmlShipToAddress2[];
-extern const char kEcmlShipToAddress3[];
-extern const char kEcmlShipToCity[];
-extern const char kEcmlShipToStateProv[];
-extern const char kEcmlShipToPostalCode[];
-extern const char kEcmlShipToCountry[];
-extern const char kEcmlShipToPhone[];
-extern const char kEcmlShipToEmail[];
-
-// billing name/address fields
-extern const char kEcmlBillToTitle[];
-extern const char kEcmlBillToFirstName[];
-extern const char kEcmlBillToMiddleName[];
-extern const char kEcmlBillToLastName[];
-extern const char kEcmlBillToNameSuffix[];
-extern const char kEcmlBillToCompanyName[];
-extern const char kEcmlBillToAddress1[];
-extern const char kEcmlBillToAddress2[];
-extern const char kEcmlBillToAddress3[];
-extern const char kEcmlBillToCity[];
-extern const char kEcmlBillToStateProv[];
-extern const char kEcmlBillToPostalCode[];
-extern const char kEcmlBillToCountry[];
-extern const char kEcmlBillToPhone[];
-extern const char kEcmlBillToEmail[];
-
-// credit card fields
-extern const char kEcmlCardHolder[];
-extern const char kEcmlCardType[];
-extern const char kEcmlCardNumber[];
-extern const char kEcmlCardVerification[];
-extern const char kEcmlCardExpireDay[];
-extern const char kEcmlCardExpireMonth[];
-extern const char kEcmlCardExpireYear[];
-
// Represents a logical form field in a web form. Classes that implement this
// interface can identify themselves as a particular type of form field, e.g.
// name, phone number, or address field.
@@ -64,82 +23,63 @@ class FormField {
public:
virtual ~FormField() {}
- // Associates each field in |fields| with its heuristically detected type.
- // The association is stored into |field_type_map|.
+ // Classifies each field in |fields| with its heuristically detected type.
+ // The association is stored into |map|. Each field has a derived unique name
+ // that is used as the key into the |map|.
static void ParseFormFields(const std::vector<AutofillField*>& fields,
- FieldTypeMap* field_type_map);
-
- // Associates the available AutofillTypes of a FormField into
- // |field_type_map|.
- virtual bool GetFieldInfo(FieldTypeMap* field_type_map) const = 0;
-
- // Returns true if |field| contains the regexp |pattern| in the name or label.
- // If |match_label_only| is true, then only the field's label is considered.
- static bool Match(const AutofillField* field,
- const string16& pattern,
- bool match_label_only);
-
- // Parses a field using the different field views we know about. |is_ecml|
- // should be true when the field conforms to the ECML specification.
- static FormField* ParseFormField(AutofillScanner* scanner, bool is_ecml);
-
- // Attempts to parse a text field with the given pattern; returns true on
- // success, but doesn't return the actual text field itself.
- static bool ParseText(AutofillScanner* scanner, const string16& pattern);
-
- // Attempts to parse a text field with the given pattern. Returns true on
- // success and fills |dest| with a pointer to the field.
- static bool ParseText(AutofillScanner* scanner,
- const string16& pattern,
- const AutofillField** dest);
-
- // Attempts to parse a text field with an empty name or label. Returns true
- // on success and fills |dest| with a pointer to the field.
- static bool ParseEmptyText(AutofillScanner* scanner,
- const AutofillField** dest);
-
- // Attempts to parse a text field label with the given pattern. Returns true
- // on success and fills |dest| with a pointer to the field.
- static bool ParseLabelText(AutofillScanner* scanner,
- const string16& pattern,
- const AutofillField** dest);
-
- // Attempts to parse a control with an empty label.
- static bool ParseEmpty(AutofillScanner* scanner);
-
- // Adds an association between a field and a type to |field_type_map|.
- static bool Add(FieldTypeMap* field_type_map,
- const AutofillField* field,
- AutofillFieldType type);
+ FieldTypeMap* map);
protected:
+ // A bit-field used for matching specific parts of a field in question.
+ enum MatchType {
+ MATCH_LABEL = 1 << 0,
+ MATCH_NAME = 1 << 1,
+ MATCH_ALL = MATCH_LABEL | MATCH_NAME
+ };
+
// Only derived classes may instantiate.
FormField() {}
- // Note: ECML compliance checking has been modified to accommodate Google
- // Checkout field name limitation. All ECML compliant web forms will be
- // recognized correctly as such however the restrictions on having exactly
- // ECML compliant names have been loosened to only require that field names
- // be prefixed with an ECML compliant name in order to accommodate checkout.
- // Additionally we allow the use of '.' as a word delimiter in addition to the
- // ECML standard '_' (see FormField::FormField for details).
- static string16 GetEcmlPattern(const char* ecml_name);
- static string16 GetEcmlPattern(const char* ecml_name1,
- const char* ecml_name2,
- char pattern_operator);
+ // Attempts to parse a form field with the given pattern. Returns true on
+ // success and fills |match| with a pointer to the field.
+ static bool ParseField(AutofillScanner* scanner,
+ const string16& pattern,
+ const AutofillField** match);
+
+ // Parses the stream of fields in |scanner| with regular expression |pattern|
+ // as specified in the |match_type| bit field (see |MatchType|). If |match|
+ // is non-NULL and the pattern matches, the matched field is returned.
+ // A |true| result is returned in the case of a successful match, false
+ // otherwise.
+ static bool ParseFieldSpecifics(AutofillScanner* scanner,
+ const string16& pattern,
+ int match_type,
+ const AutofillField** match);
+
+ // Attempts to parse a field with an empty label. Returns true
+ // on success and fills |match| with a pointer to the field.
+ static bool ParseEmptyLabel(AutofillScanner* scanner,
+ const AutofillField** match);
+
+ // Adds an association between a field and a type to |map|.
+ static bool AddClassification(const AutofillField* field,
+ AutofillFieldType type,
+ FieldTypeMap* map);
+
+ // Derived classes must implement this interface to supply field type
+ // information. |ParseFormFields| coordinates the parsing and extraction
+ // of types from an input vector of |AutofillField| objects and delegates
+ // the type extraction via this method.
+ virtual bool ClassifyField(FieldTypeMap* map) const = 0;
private:
- static bool ParseText(AutofillScanner* scanner,
- const string16& pattern,
- const AutofillField** dest,
- bool match_label_only);
-
- // For empty strings we need to test that both label and name are empty.
- static bool ParseLabelAndName(AutofillScanner* scanner,
- const string16& pattern,
- const AutofillField** dest);
- static bool MatchName(const AutofillField* field, const string16& pattern);
- static bool MatchLabel(const AutofillField* field, const string16& pattern);
+ FRIEND_TEST_ALL_PREFIXES(FormFieldTest, Match);
+
+ // Matches the regular expression |pattern| against the components of |field|
+ // as specified in the |match_type| bit field (see |MatchType|).
+ static bool Match(const AutofillField* field,
+ const string16& pattern,
+ int match_type);
DISALLOW_COPY_AND_ASSIGN(FormField);
};
« no previous file with comments | « chrome/browser/autofill/email_field.cc ('k') | chrome/browser/autofill/form_field.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698