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 14 matching lines...) Expand all Loading... |
25 | 25 |
26 // Classifies each field in |fields| with its heuristically detected type. | 26 // Classifies each field in |fields| with its heuristically detected type. |
27 // The association is stored into |map|. Each field has a derived unique name | 27 // The association is stored into |map|. Each field has a derived unique name |
28 // that is used as the key into the |map|. | 28 // that is used as the key into the |map|. |
29 static void ParseFormFields(const std::vector<AutofillField*>& fields, | 29 static void ParseFormFields(const std::vector<AutofillField*>& fields, |
30 FieldTypeMap* map); | 30 FieldTypeMap* map); |
31 | 31 |
32 protected: | 32 protected: |
33 // A bit-field used for matching specific parts of a field in question. | 33 // A bit-field used for matching specific parts of a field in question. |
34 enum MatchType { | 34 enum MatchType { |
35 MATCH_LABEL = 1 << 0, | 35 // Attributes. |
36 MATCH_NAME = 1 << 1, | 36 MATCH_LABEL = 1 << 0, |
37 MATCH_ALL = MATCH_LABEL | MATCH_NAME | 37 MATCH_NAME = 1 << 1, |
| 38 |
| 39 // Input types. |
| 40 MATCH_TEXT = 1 << 2, |
| 41 MATCH_EMAIL = 1 << 3, |
| 42 MATCH_TELEPHONE = 1 << 4, |
| 43 MATCH_SELECT = 1 << 5, |
| 44 MATCH_ALL_INPUTS = |
| 45 MATCH_TEXT | MATCH_EMAIL | MATCH_TELEPHONE | MATCH_SELECT, |
| 46 |
| 47 // By default match label and name for input/text types. |
| 48 MATCH_DEFAULT = MATCH_LABEL | MATCH_NAME | MATCH_TEXT, |
38 }; | 49 }; |
39 | 50 |
40 // Only derived classes may instantiate. | 51 // Only derived classes may instantiate. |
41 FormField() {} | 52 FormField() {} |
42 | 53 |
43 // Attempts to parse a form field with the given pattern. Returns true on | 54 // Attempts to parse a form field with the given pattern. Returns true on |
44 // success and fills |match| with a pointer to the field. | 55 // success and fills |match| with a pointer to the field. |
45 static bool ParseField(AutofillScanner* scanner, | 56 static bool ParseField(AutofillScanner* scanner, |
46 const string16& pattern, | 57 const string16& pattern, |
47 const AutofillField** match); | 58 const AutofillField** match); |
(...skipping 20 matching lines...) Expand all Loading... |
68 | 79 |
69 // Derived classes must implement this interface to supply field type | 80 // Derived classes must implement this interface to supply field type |
70 // information. |ParseFormFields| coordinates the parsing and extraction | 81 // information. |ParseFormFields| coordinates the parsing and extraction |
71 // of types from an input vector of |AutofillField| objects and delegates | 82 // of types from an input vector of |AutofillField| objects and delegates |
72 // the type extraction via this method. | 83 // the type extraction via this method. |
73 virtual bool ClassifyField(FieldTypeMap* map) const = 0; | 84 virtual bool ClassifyField(FieldTypeMap* map) const = 0; |
74 | 85 |
75 private: | 86 private: |
76 FRIEND_TEST_ALL_PREFIXES(FormFieldTest, Match); | 87 FRIEND_TEST_ALL_PREFIXES(FormFieldTest, Match); |
77 | 88 |
| 89 // Matches |pattern| to the contents of the field at the head of the |
| 90 // |scanner|. |
| 91 // Returns |true| if a match is found according to |match_type|, and |false| |
| 92 // otherwise. |
| 93 static bool MatchAndAdvance(AutofillScanner* scanner, |
| 94 const string16& pattern, |
| 95 int match_type, |
| 96 const AutofillField** match); |
| 97 |
78 // Matches the regular expression |pattern| against the components of |field| | 98 // Matches the regular expression |pattern| against the components of |field| |
79 // as specified in the |match_type| bit field (see |MatchType|). | 99 // as specified in the |match_type| bit field (see |MatchType|). |
80 static bool Match(const AutofillField* field, | 100 static bool Match(const AutofillField* field, |
81 const string16& pattern, | 101 const string16& pattern, |
82 int match_type); | 102 int match_type); |
83 | 103 |
84 DISALLOW_COPY_AND_ASSIGN(FormField); | 104 DISALLOW_COPY_AND_ASSIGN(FormField); |
85 }; | 105 }; |
86 | 106 |
87 #endif // CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_ | 107 #endif // CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_ |
OLD | NEW |