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" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "components/autofill/core/browser/autofill_type.h" | 13 #include "components/autofill/core/browser/field_types.h" |
14 | 14 |
15 namespace autofill { | 15 namespace autofill { |
16 | 16 |
17 class AutofillField; | 17 class AutofillField; |
18 class AutofillScanner; | 18 class AutofillScanner; |
19 | 19 |
20 // Represents a logical form field in a web form. Classes that implement this | 20 // Represents a logical form field in a web form. Classes that implement this |
21 // interface can identify themselves as a particular type of form field, e.g. | 21 // interface can identify themselves as a particular type of form field, e.g. |
22 // name, phone number, or address field. | 22 // name, phone number, or address field. |
23 class FormField { | 23 class FormField { |
24 public: | 24 public: |
25 virtual ~FormField() {} | 25 virtual ~FormField() {} |
26 | 26 |
27 // Classifies each field in |fields| with its heuristically detected type. | 27 // Classifies each field in |fields| with its heuristically detected type. |
28 // The association is stored into |map|. Each field has a derived unique name | 28 // The association is stored into |map|. Each field has a derived unique name |
29 // that is used as the key into the |map|. | 29 // that is used as the key into the |map|. |
30 static void ParseFormFields(const std::vector<AutofillField*>& fields, | 30 static void ParseFormFields(const std::vector<AutofillField*>& fields, |
31 FieldTypeMap* map); | 31 ServerFieldTypeMap* map); |
32 | 32 |
33 protected: | 33 protected: |
34 // A bit-field used for matching specific parts of a field in question. | 34 // A bit-field used for matching specific parts of a field in question. |
35 enum MatchType { | 35 enum MatchType { |
36 // Attributes. | 36 // Attributes. |
37 MATCH_LABEL = 1 << 0, | 37 MATCH_LABEL = 1 << 0, |
38 MATCH_NAME = 1 << 1, | 38 MATCH_NAME = 1 << 1, |
39 MATCH_VALUE = 1 << 2, | 39 MATCH_VALUE = 1 << 2, |
40 | 40 |
41 // Input types. | 41 // Input types. |
(...skipping 27 matching lines...) Expand all Loading... |
69 int match_type, | 69 int match_type, |
70 const AutofillField** match); | 70 const AutofillField** match); |
71 | 71 |
72 // Attempts to parse a field with an empty label. Returns true | 72 // Attempts to parse a field with an empty label. Returns true |
73 // on success and fills |match| with a pointer to the field. | 73 // on success and fills |match| with a pointer to the field. |
74 static bool ParseEmptyLabel(AutofillScanner* scanner, | 74 static bool ParseEmptyLabel(AutofillScanner* scanner, |
75 const AutofillField** match); | 75 const AutofillField** match); |
76 | 76 |
77 // Adds an association between a field and a type to |map|. | 77 // Adds an association between a field and a type to |map|. |
78 static bool AddClassification(const AutofillField* field, | 78 static bool AddClassification(const AutofillField* field, |
79 AutofillFieldType type, | 79 ServerFieldType type, |
80 FieldTypeMap* map); | 80 ServerFieldTypeMap* map); |
81 | 81 |
82 // Derived classes must implement this interface to supply field type | 82 // Derived classes must implement this interface to supply field type |
83 // information. |ParseFormFields| coordinates the parsing and extraction | 83 // information. |ParseFormFields| coordinates the parsing and extraction |
84 // of types from an input vector of |AutofillField| objects and delegates | 84 // of types from an input vector of |AutofillField| objects and delegates |
85 // the type extraction via this method. | 85 // the type extraction via this method. |
86 virtual bool ClassifyField(FieldTypeMap* map) const = 0; | 86 virtual bool ClassifyField(ServerFieldTypeMap* map) const = 0; |
87 | 87 |
88 private: | 88 private: |
89 FRIEND_TEST_ALL_PREFIXES(FormFieldTest, Match); | 89 FRIEND_TEST_ALL_PREFIXES(FormFieldTest, Match); |
90 | 90 |
91 // Function pointer type for the parsing function that should be passed to the | 91 // Function pointer type for the parsing function that should be passed to the |
92 // ParseFormFieldsPass() helper function. | 92 // ParseFormFieldsPass() helper function. |
93 typedef FormField* ParseFunction(AutofillScanner* scanner); | 93 typedef FormField* ParseFunction(AutofillScanner* scanner); |
94 | 94 |
95 // Matches |pattern| to the contents of the field at the head of the | 95 // Matches |pattern| to the contents of the field at the head of the |
96 // |scanner|. | 96 // |scanner|. |
(...skipping 10 matching lines...) Expand all Loading... |
107 const base::string16& pattern, | 107 const base::string16& pattern, |
108 int match_type); | 108 int match_type); |
109 | 109 |
110 // Perform a "pass" over the |fields| where each pass uses the supplied | 110 // Perform a "pass" over the |fields| where each pass uses the supplied |
111 // |parse| method to match content to a given field type. | 111 // |parse| method to match content to a given field type. |
112 // |fields| is both an input and an output parameter. Upon exit |fields| | 112 // |fields| is both an input and an output parameter. Upon exit |fields| |
113 // holds any remaining unclassified fields for further processing. | 113 // holds any remaining unclassified fields for further processing. |
114 // Classification results of the processed fields are stored in |map|. | 114 // Classification results of the processed fields are stored in |map|. |
115 static void ParseFormFieldsPass(ParseFunction parse, | 115 static void ParseFormFieldsPass(ParseFunction parse, |
116 std::vector<const AutofillField*>* fields, | 116 std::vector<const AutofillField*>* fields, |
117 FieldTypeMap* map); | 117 ServerFieldTypeMap* map); |
118 | 118 |
119 DISALLOW_COPY_AND_ASSIGN(FormField); | 119 DISALLOW_COPY_AND_ASSIGN(FormField); |
120 }; | 120 }; |
121 | 121 |
122 } // namespace autofill | 122 } // namespace autofill |
123 | 123 |
124 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ | 124 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ |
OLD | NEW |