OLD | NEW |
---|---|
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 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
72 // Associates the available AutofillTypes of a FormField into | 72 // Associates the available AutofillTypes of a FormField into |
73 // |field_type_map|. | 73 // |field_type_map|. |
74 virtual bool GetFieldInfo(FieldTypeMap* field_type_map) const = 0; | 74 virtual bool GetFieldInfo(FieldTypeMap* field_type_map) const = 0; |
75 | 75 |
76 // Returns true if |field| contains the regexp |pattern| in the name or label. | 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. | 77 // If |match_label_only| is true, then only the field's label is considered. |
78 static bool Match(const AutofillField* field, | 78 static bool Match(const AutofillField* field, |
79 const string16& pattern, | 79 const string16& pattern, |
80 bool match_label_only); | 80 bool match_label_only); |
81 | 81 |
82 struct Pattern { | |
83 string16 pattern; | |
84 bool select_one_is_ok; | |
85 | |
86 Pattern(const string16& pattern) | |
honten.org
2011/05/12 05:36:33
I know we need to add explicit.
But before adding
Ilya Sherman
2011/05/13 00:54:53
Let's instead create an enum along the lines of
e
honten.org
2011/05/13 01:39:48
After this change, we might need to implement more
dhollowa
2011/05/14 02:15:50
I think this may be a good opportunity to use a bi
| |
87 : pattern(pattern), | |
88 select_one_is_ok(false) { | |
89 } | |
90 Pattern(const string16& pattern, bool select_one_is_ok) | |
91 : pattern(pattern), | |
92 select_one_is_ok(select_one_is_ok) { | |
93 } | |
94 }; | |
95 | |
82 // Parses a field using the different field views we know about. |is_ecml| | 96 // 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. | 97 // should be true when the field conforms to the ECML specification. |
84 static FormField* ParseFormField(AutofillScanner* scanner, bool is_ecml); | 98 static FormField* ParseFormField(AutofillScanner* scanner, bool is_ecml); |
85 | 99 |
86 // Attempts to parse a text field with the given pattern; returns true on | 100 // Attempts to parse a text field with the given pattern; returns true on |
87 // success, but doesn't return the actual text field itself. | 101 // success, but doesn't return the actual text field itself. |
88 static bool ParseText(AutofillScanner* scanner, const string16& pattern); | 102 static bool ParseText(AutofillScanner* scanner, const Pattern& pattern); |
89 | 103 |
90 // Attempts to parse a text field with the given pattern. Returns true on | 104 // Attempts to parse a text field with the given pattern. Returns true on |
91 // success and fills |dest| with a pointer to the field. | 105 // success and fills |dest| with a pointer to the field. |
92 static bool ParseText(AutofillScanner* scanner, | 106 static bool ParseText(AutofillScanner* scanner, |
93 const string16& pattern, | 107 const Pattern& pattern, |
94 const AutofillField** dest); | 108 const AutofillField** dest); |
95 | 109 |
96 // Attempts to parse a text field with an empty name or label. Returns true | 110 // 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. | 111 // on success and fills |dest| with a pointer to the field. |
98 static bool ParseEmptyText(AutofillScanner* scanner, | 112 static bool ParseEmptyText(AutofillScanner* scanner, |
99 const AutofillField** dest); | 113 const AutofillField** dest); |
100 | 114 |
101 // Attempts to parse a text field label with the given pattern. Returns true | 115 // 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. | 116 // on success and fills |dest| with a pointer to the field. |
103 static bool ParseLabelText(AutofillScanner* scanner, | 117 static bool ParseLabelText(AutofillScanner* scanner, |
104 const string16& pattern, | 118 const Pattern& pattern, |
105 const AutofillField** dest); | 119 const AutofillField** dest); |
106 | 120 |
107 // Attempts to parse a control with an empty label. | 121 // Attempts to parse a control with an empty label. |
108 static bool ParseEmpty(AutofillScanner* scanner); | 122 static bool ParseEmpty(AutofillScanner* scanner); |
109 | 123 |
110 // Adds an association between a field and a type to |field_type_map|. | 124 // Adds an association between a field and a type to |field_type_map|. |
111 static bool Add(FieldTypeMap* field_type_map, | 125 static bool Add(FieldTypeMap* field_type_map, |
112 const AutofillField* field, | 126 const AutofillField* field, |
113 AutofillFieldType type); | 127 AutofillFieldType type); |
114 | 128 |
115 protected: | 129 protected: |
116 // Only derived classes may instantiate. | 130 // Only derived classes may instantiate. |
117 FormField() {} | 131 FormField() {} |
118 | 132 |
119 // Note: ECML compliance checking has been modified to accommodate Google | 133 // Note: ECML compliance checking has been modified to accommodate Google |
120 // Checkout field name limitation. All ECML compliant web forms will be | 134 // Checkout field name limitation. All ECML compliant web forms will be |
121 // recognized correctly as such however the restrictions on having exactly | 135 // recognized correctly as such however the restrictions on having exactly |
122 // ECML compliant names have been loosened to only require that field names | 136 // ECML compliant names have been loosened to only require that field names |
123 // be prefixed with an ECML compliant name in order to accommodate checkout. | 137 // be prefixed with an ECML compliant name in order to accommodate checkout. |
124 // Additionally we allow the use of '.' as a word delimiter in addition to the | 138 // Additionally we allow the use of '.' as a word delimiter in addition to the |
125 // ECML standard '_' (see FormField::FormField for details). | 139 // ECML standard '_' (see FormField::FormField for details). |
126 static string16 GetEcmlPattern(const char* ecml_name); | 140 static string16 GetEcmlPattern(const char* ecml_name); |
127 static string16 GetEcmlPattern(const char* ecml_name1, | 141 static string16 GetEcmlPattern(const char* ecml_name1, |
128 const char* ecml_name2, | 142 const char* ecml_name2, |
129 char pattern_operator); | 143 char pattern_operator); |
130 | 144 |
131 private: | 145 private: |
132 static bool ParseText(AutofillScanner* scanner, | 146 static bool ParseText(AutofillScanner* scanner, |
133 const string16& pattern, | 147 const Pattern& pattern, |
134 const AutofillField** dest, | 148 const AutofillField** dest, |
135 bool match_label_only); | 149 bool match_label_only); |
136 | 150 |
137 // For empty strings we need to test that both label and name are empty. | 151 // For empty strings we need to test that both label and name are empty. |
138 static bool ParseLabelAndName(AutofillScanner* scanner, | 152 static bool ParseLabelAndName(AutofillScanner* scanner, |
139 const string16& pattern, | 153 const string16& pattern, |
140 const AutofillField** dest); | 154 const AutofillField** dest); |
141 static bool MatchName(const AutofillField* field, const string16& pattern); | 155 static bool MatchName(const AutofillField* field, const string16& pattern); |
142 static bool MatchLabel(const AutofillField* field, const string16& pattern); | 156 static bool MatchLabel(const AutofillField* field, const string16& pattern); |
143 | 157 |
144 DISALLOW_COPY_AND_ASSIGN(FormField); | 158 DISALLOW_COPY_AND_ASSIGN(FormField); |
145 }; | 159 }; |
146 | 160 |
147 #endif // CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_ | 161 #endif // CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_ |
OLD | NEW |