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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_ 5 #ifndef CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_
6 #define CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_ 6 #define CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_
7 #pragma once 7 #pragma once
8 8
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/gtest_prod_util.h"
12 #include "base/string16.h" 13 #include "base/string16.h"
13 #include "chrome/browser/autofill/autofill_type.h" 14 #include "chrome/browser/autofill/autofill_type.h"
14 15
15 class AutofillField; 16 class AutofillField;
16 class AutofillScanner; 17 class AutofillScanner;
17 18
18 extern const char kEcmlShipToTitle[];
19 extern const char kEcmlShipToFirstName[];
20 extern const char kEcmlShipToMiddleName[];
21 extern const char kEcmlShipToLastName[];
22 extern const char kEcmlShipToNameSuffix[];
23 extern const char kEcmlShipToCompanyName[];
24 extern const char kEcmlShipToAddress1[];
25 extern const char kEcmlShipToAddress2[];
26 extern const char kEcmlShipToAddress3[];
27 extern const char kEcmlShipToCity[];
28 extern const char kEcmlShipToStateProv[];
29 extern const char kEcmlShipToPostalCode[];
30 extern const char kEcmlShipToCountry[];
31 extern const char kEcmlShipToPhone[];
32 extern const char kEcmlShipToEmail[];
33
34 // billing name/address fields
35 extern const char kEcmlBillToTitle[];
36 extern const char kEcmlBillToFirstName[];
37 extern const char kEcmlBillToMiddleName[];
38 extern const char kEcmlBillToLastName[];
39 extern const char kEcmlBillToNameSuffix[];
40 extern const char kEcmlBillToCompanyName[];
41 extern const char kEcmlBillToAddress1[];
42 extern const char kEcmlBillToAddress2[];
43 extern const char kEcmlBillToAddress3[];
44 extern const char kEcmlBillToCity[];
45 extern const char kEcmlBillToStateProv[];
46 extern const char kEcmlBillToPostalCode[];
47 extern const char kEcmlBillToCountry[];
48 extern const char kEcmlBillToPhone[];
49 extern const char kEcmlBillToEmail[];
50
51 // credit card fields
52 extern const char kEcmlCardHolder[];
53 extern const char kEcmlCardType[];
54 extern const char kEcmlCardNumber[];
55 extern const char kEcmlCardVerification[];
56 extern const char kEcmlCardExpireDay[];
57 extern const char kEcmlCardExpireMonth[];
58 extern const char kEcmlCardExpireYear[];
59
60 // Represents a logical form field in a web form. Classes that implement this 19 // Represents a logical form field in a web form. Classes that implement this
61 // interface can identify themselves as a particular type of form field, e.g. 20 // interface can identify themselves as a particular type of form field, e.g.
62 // name, phone number, or address field. 21 // name, phone number, or address field.
63 class FormField { 22 class FormField {
64 public: 23 public:
65 virtual ~FormField() {} 24 virtual ~FormField() {}
66 25
67 // Associates each field in |fields| with its heuristically detected type. 26 // Classifies each field in |fields| with its heuristically detected type.
68 // The association is stored into |field_type_map|. 27 // The association is stored into |map|. Each field has a |unique_name| that
Ilya Sherman 2011/05/19 05:44:16 nit: I don't see "unique_name" used as a variable
dhollowa 2011/05/19 17:53:08 Done.
28 // is used as the key into the |map|.
69 static void ParseFormFields(const std::vector<AutofillField*>& fields, 29 static void ParseFormFields(const std::vector<AutofillField*>& fields,
70 FieldTypeMap* field_type_map); 30 FieldTypeMap* map);
71
72 // Associates the available AutofillTypes of a FormField into
73 // |field_type_map|.
74 virtual bool GetFieldInfo(FieldTypeMap* field_type_map) const = 0;
75
76 // Returns true if |field| contains the regexp |pattern| in the name or label.
77 // If |match_label_only| is true, then only the field's label is considered.
78 static bool Match(const AutofillField* field,
79 const string16& pattern,
80 bool match_label_only);
81
82 // Parses a field using the different field views we know about. |is_ecml|
83 // should be true when the field conforms to the ECML specification.
84 static FormField* ParseFormField(AutofillScanner* scanner, bool is_ecml);
85
86 // Attempts to parse a text field with the given pattern; returns true on
87 // success, but doesn't return the actual text field itself.
88 static bool ParseText(AutofillScanner* scanner, const string16& pattern);
89
90 // Attempts to parse a text field with the given pattern. Returns true on
91 // success and fills |dest| with a pointer to the field.
92 static bool ParseText(AutofillScanner* scanner,
93 const string16& pattern,
94 const AutofillField** dest);
95
96 // Attempts to parse a text field with an empty name or label. Returns true
97 // on success and fills |dest| with a pointer to the field.
98 static bool ParseEmptyText(AutofillScanner* scanner,
99 const AutofillField** dest);
100
101 // Attempts to parse a text field label with the given pattern. Returns true
102 // on success and fills |dest| with a pointer to the field.
103 static bool ParseLabelText(AutofillScanner* scanner,
104 const string16& pattern,
105 const AutofillField** dest);
106
107 // Attempts to parse a control with an empty label.
108 static bool ParseEmpty(AutofillScanner* scanner);
109
110 // Adds an association between a field and a type to |field_type_map|.
111 static bool Add(FieldTypeMap* field_type_map,
112 const AutofillField* field,
113 AutofillFieldType type);
114 31
115 protected: 32 protected:
33 // A bit-field used for matching specific parts of a field in question.
34 enum MatchType {
35 MATCH_LABEL = 1 << 0,
36 MATCH_NAME = 1 << 1,
37 MATCH_ALL = MATCH_LABEL | MATCH_NAME
38 };
39
116 // Only derived classes may instantiate. 40 // Only derived classes may instantiate.
117 FormField() {} 41 FormField() {}
118 42
119 // Note: ECML compliance checking has been modified to accommodate Google 43 // Attempts to parse a form field with the given pattern. Returns true on
120 // Checkout field name limitation. All ECML compliant web forms will be 44 // success and fills |match| with a pointer to the field.
121 // recognized correctly as such however the restrictions on having exactly 45 static bool ParseField(AutofillScanner* scanner,
122 // ECML compliant names have been loosened to only require that field names 46 const string16& pattern,
123 // be prefixed with an ECML compliant name in order to accommodate checkout. 47 const AutofillField** match);
124 // Additionally we allow the use of '.' as a word delimiter in addition to the
125 // ECML standard '_' (see FormField::FormField for details).
126 static string16 GetEcmlPattern(const char* ecml_name);
127 static string16 GetEcmlPattern(const char* ecml_name1,
128 const char* ecml_name2,
129 char pattern_operator);
130 48
49 // Parses the stream of fields in |scanner| with regular expression |pattern|
50 // as specified in the |match_type| bit field (see |MatchType|). If |match|
51 // is non-NULL and the pattern matches, the matched field is returned.
Ilya Sherman 2011/05/19 05:44:16 nit: When does this return true/false? We should
dhollowa 2011/05/19 17:53:08 Done.
52 static bool ParseFieldSpecifics(AutofillScanner* scanner,
Ilya Sherman 2011/05/19 05:44:16 I don't really get much out of the term "Specifics
dhollowa 2011/05/19 17:53:08 I had a few: ParseFieldVariant, ParseFieldWithMatc
Ilya Sherman 2011/05/19 20:24:09 Ok. "Specifics" still doesn't evoke "label and/or
53 const string16& pattern,
54 int match_type,
55 const AutofillField** match);
56
57 // Attempts to parse a field with an empty label. Returns true
58 // on success and fills |match| with a pointer to the field.
59 static bool ParseEmptyLabel(AutofillScanner* scanner,
60 const AutofillField** match);
61
62 // Adds an association between a field and a type to |map|.
63 static bool AddClassification(const AutofillField* field,
64 AutofillFieldType type,
65 FieldTypeMap* map);
131 private: 66 private:
132 static bool ParseText(AutofillScanner* scanner, 67 FRIEND_TEST_ALL_PREFIXES(FormFieldTest, Match);
133 const string16& pattern,
134 const AutofillField** dest,
135 bool match_label_only);
136 68
137 // For empty strings we need to test that both label and name are empty. 69 // Derived classes must implement this interface to supply field type
138 static bool ParseLabelAndName(AutofillScanner* scanner, 70 // information. |ParseFormFields| coordinates the parsing and extraction
139 const string16& pattern, 71 // of types from an input vector of |AutofillField| objects and delegates
140 const AutofillField** dest); 72 // the type extraction via this method.
141 static bool MatchName(const AutofillField* field, const string16& pattern); 73 virtual bool ClassifyField(FieldTypeMap* map) const = 0;
Ilya Sherman 2011/05/19 05:44:16 nit: It seems odd to me to give a virtual method |
dhollowa 2011/05/19 17:53:08 I was following a principle of least visibility, w
142 static bool MatchLabel(const AutofillField* field, const string16& pattern); 74
75 // Matches the regular expression |pattern| against the components of |field|
76 // as specified in the |match_type| bit field (see |MatchType|).
77 static bool Match(const AutofillField* field,
78 const string16& pattern,
79 int match_type);
143 80
144 DISALLOW_COPY_AND_ASSIGN(FormField); 81 DISALLOW_COPY_AND_ASSIGN(FormField);
145 }; 82 };
146 83
147 #endif // CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_ 84 #endif // CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698