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 // When parsing a field's label and name separately with a given pattern: |
| 59 enum ParseNameLabelResult { |
| 60 RESULT_MATCH_NONE, // No match with the label or name. |
| 61 RESULT_MATCH_LABEL, // Only the label matches the pattern. |
| 62 RESULT_MATCH_NAME, // Only the name matches the pattern. |
| 63 RESULT_MATCH_NAME_LABEL // Name and label both match the pattern. |
| 64 }; |
| 65 |
58 // Only derived classes may instantiate. | 66 // Only derived classes may instantiate. |
59 FormField() {} | 67 FormField() {} |
60 | 68 |
61 // Attempts to parse a form field with the given pattern. Returns true on | 69 // Attempts to parse a form field with the given pattern. Returns true on |
62 // success and fills |match| with a pointer to the field. | 70 // success and fills |match| with a pointer to the field. |
63 static bool ParseField(AutofillScanner* scanner, | 71 static bool ParseField(AutofillScanner* scanner, |
64 const base::string16& pattern, | 72 const base::string16& pattern, |
65 AutofillField** match); | 73 AutofillField** match); |
66 | 74 |
67 // Parses the stream of fields in |scanner| with regular expression |pattern| | 75 // Parses the stream of fields in |scanner| with regular expression |pattern| |
68 // as specified in the |match_type| bit field (see |MatchType|). If |match| | 76 // 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. | 77 // 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 | 78 // A |true| result is returned in the case of a successful match, false |
71 // otherwise. | 79 // otherwise. |
72 static bool ParseFieldSpecifics(AutofillScanner* scanner, | 80 static bool ParseFieldSpecifics(AutofillScanner* scanner, |
73 const base::string16& pattern, | 81 const base::string16& pattern, |
74 int match_type, | 82 int match_type, |
75 AutofillField** match); | 83 AutofillField** match); |
76 | 84 |
| 85 // Like ParseFieldSpecifics(), but applies |pattern| against the name and |
| 86 // label of the current field separately. If the return value is |
| 87 // RESULT_MATCH_NAME_LABEL, then |scanner| advances and |match| is filled if |
| 88 // it is non-NULL. Otherwise |scanner| does not advance and |match| does not |
| 89 // change. |
| 90 static ParseNameLabelResult ParseNameAndLabelSeparately( |
| 91 AutofillScanner* scanner, |
| 92 const base::string16& pattern, |
| 93 int match_type, |
| 94 AutofillField** match); |
| 95 |
77 // Attempts to parse a field with an empty label. Returns true | 96 // Attempts to parse a field with an empty label. Returns true |
78 // on success and fills |match| with a pointer to the field. | 97 // on success and fills |match| with a pointer to the field. |
79 static bool ParseEmptyLabel(AutofillScanner* scanner, AutofillField** match); | 98 static bool ParseEmptyLabel(AutofillScanner* scanner, AutofillField** match); |
80 | 99 |
81 // Adds an association between a field and a type to |map|. | 100 // Adds an association between a field and a type to |map|. |
82 static bool AddClassification(const AutofillField* field, | 101 static bool AddClassification(const AutofillField* field, |
83 ServerFieldType type, | 102 ServerFieldType type, |
84 ServerFieldTypeMap* map); | 103 ServerFieldTypeMap* map); |
85 | 104 |
86 // Returns true iff |type| matches |match_type|. | 105 // Returns true iff |type| matches |match_type|. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 static void ParseFormFieldsPass(ParseFunction parse, | 141 static void ParseFormFieldsPass(ParseFunction parse, |
123 std::vector<AutofillField*>* fields, | 142 std::vector<AutofillField*>* fields, |
124 ServerFieldTypeMap* map); | 143 ServerFieldTypeMap* map); |
125 | 144 |
126 DISALLOW_COPY_AND_ASSIGN(FormField); | 145 DISALLOW_COPY_AND_ASSIGN(FormField); |
127 }; | 146 }; |
128 | 147 |
129 } // namespace autofill | 148 } // namespace autofill |
130 | 149 |
131 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ | 150 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ |
OLD | NEW |