OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ |
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 MATCH_PASSWORD = 1 << 7, | 48 MATCH_PASSWORD = 1 << 7, |
49 MATCH_NUMBER = 1 << 8, | 49 MATCH_NUMBER = 1 << 8, |
50 MATCH_ALL_INPUTS = | 50 MATCH_ALL_INPUTS = |
51 MATCH_TEXT | MATCH_EMAIL | MATCH_TELEPHONE | MATCH_SELECT | | 51 MATCH_TEXT | MATCH_EMAIL | MATCH_TELEPHONE | MATCH_SELECT | |
52 MATCH_TEXT_AREA | MATCH_PASSWORD | MATCH_NUMBER, | 52 MATCH_TEXT_AREA | MATCH_PASSWORD | MATCH_NUMBER, |
53 | 53 |
54 // By default match label and name for input/text types. | 54 // By default match label and name for input/text types. |
55 MATCH_DEFAULT = MATCH_LABEL | MATCH_NAME | MATCH_TEXT, | 55 MATCH_DEFAULT = MATCH_LABEL | MATCH_NAME | MATCH_TEXT, |
56 }; | 56 }; |
57 | 57 |
58 enum ParseNameLabelResult { | |
Evan Stade
2015/03/24 00:04:32
docs
Lei Zhang
2015/03/25 00:42:28
Done.
| |
59 RESULT_MATCH_NONE, | |
60 RESULT_MATCH_LABEL, | |
61 RESULT_MATCH_NAME, | |
62 RESULT_MATCH_NAME_LABEL | |
63 }; | |
64 | |
58 // Only derived classes may instantiate. | 65 // Only derived classes may instantiate. |
59 FormField() {} | 66 FormField() {} |
60 | 67 |
61 // Attempts to parse a form field with the given pattern. Returns true on | 68 // Attempts to parse a form field with the given pattern. Returns true on |
62 // success and fills |match| with a pointer to the field. | 69 // success and fills |match| with a pointer to the field. |
63 static bool ParseField(AutofillScanner* scanner, | 70 static bool ParseField(AutofillScanner* scanner, |
64 const base::string16& pattern, | 71 const base::string16& pattern, |
65 AutofillField** match); | 72 AutofillField** match); |
66 | 73 |
67 // Parses the stream of fields in |scanner| with regular expression |pattern| | 74 // Parses the stream of fields in |scanner| with regular expression |pattern| |
68 // as specified in the |match_type| bit field (see |MatchType|). If |match| | 75 // as specified in the |match_type| bit field (see |MatchType|). If |match| |
69 // is non-NULL and the pattern matches, the matched field is returned. | 76 // is non-NULL and the pattern matches, the matched field is returned. |
70 // A |true| result is returned in the case of a successful match, false | 77 // A |true| result is returned in the case of a successful match, false |
71 // otherwise. | 78 // otherwise. |
72 static bool ParseFieldSpecifics(AutofillScanner* scanner, | 79 static bool ParseFieldSpecifics(AutofillScanner* scanner, |
73 const base::string16& pattern, | 80 const base::string16& pattern, |
74 int match_type, | 81 int match_type, |
75 AutofillField** match); | 82 AutofillField** match); |
76 | 83 |
84 // Like ParseFieldSpecifics(), but applies |pattern| against the name and | |
85 // label of the current field separately. If the return value is | |
86 // RESULT_MATCH_NAME_LABEL, then |scanner| advances and |match| is filled if | |
87 // it is non-NULL. Otherwise |scanner| does not advance and |match| does not | |
88 // change. | |
89 static ParseNameLabelResult ParseNameAndLabelSeparately( | |
90 AutofillScanner* scanner, | |
91 const base::string16& pattern, | |
92 int match_type, | |
93 AutofillField** match); | |
94 | |
77 // Attempts to parse a field with an empty label. Returns true | 95 // Attempts to parse a field with an empty label. Returns true |
78 // on success and fills |match| with a pointer to the field. | 96 // on success and fills |match| with a pointer to the field. |
79 static bool ParseEmptyLabel(AutofillScanner* scanner, AutofillField** match); | 97 static bool ParseEmptyLabel(AutofillScanner* scanner, AutofillField** match); |
80 | 98 |
81 // Adds an association between a field and a type to |map|. | 99 // Adds an association between a field and a type to |map|. |
82 static bool AddClassification(const AutofillField* field, | 100 static bool AddClassification(const AutofillField* field, |
83 ServerFieldType type, | 101 ServerFieldType type, |
84 ServerFieldTypeMap* map); | 102 ServerFieldTypeMap* map); |
85 | 103 |
86 // Returns true iff |type| matches |match_type|. | 104 // Returns true iff |type| matches |match_type|. |
(...skipping 20 matching lines...) Expand all Loading... | |
107 const base::string16& pattern, | 125 const base::string16& pattern, |
108 int match_type, | 126 int match_type, |
109 AutofillField** match); | 127 AutofillField** match); |
110 | 128 |
111 // Matches the regular expression |pattern| against the components of |field| | 129 // Matches the regular expression |pattern| against the components of |field| |
112 // as specified in the |match_type| bit field (see |MatchType|). | 130 // as specified in the |match_type| bit field (see |MatchType|). |
113 static bool Match(const AutofillField* field, | 131 static bool Match(const AutofillField* field, |
114 const base::string16& pattern, | 132 const base::string16& pattern, |
115 int match_type); | 133 int match_type); |
116 | 134 |
135 // Returns |match_type| sans MATCH_LABEL/MATCH_NAME. | |
136 static int MatchTypeWithoutLabel(int match_type); | |
137 static int MatchTypeWithoutName(int match_type); | |
138 | |
117 // Perform a "pass" over the |fields| where each pass uses the supplied | 139 // Perform a "pass" over the |fields| where each pass uses the supplied |
118 // |parse| method to match content to a given field type. | 140 // |parse| method to match content to a given field type. |
119 // |fields| is both an input and an output parameter. Upon exit |fields| | 141 // |fields| is both an input and an output parameter. Upon exit |fields| |
120 // holds any remaining unclassified fields for further processing. | 142 // holds any remaining unclassified fields for further processing. |
121 // Classification results of the processed fields are stored in |map|. | 143 // Classification results of the processed fields are stored in |map|. |
122 static void ParseFormFieldsPass(ParseFunction parse, | 144 static void ParseFormFieldsPass(ParseFunction parse, |
123 std::vector<AutofillField*>* fields, | 145 std::vector<AutofillField*>* fields, |
124 ServerFieldTypeMap* map); | 146 ServerFieldTypeMap* map); |
125 | 147 |
126 DISALLOW_COPY_AND_ASSIGN(FormField); | 148 DISALLOW_COPY_AND_ASSIGN(FormField); |
127 }; | 149 }; |
128 | 150 |
129 } // namespace autofill | 151 } // namespace autofill |
130 | 152 |
131 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ | 153 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ |
OLD | NEW |