| 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 COMPONENTS_AUTOFILL_BROWSER_FORM_FIELD_H_ | 5 #ifndef COMPONENTS_AUTOFILL_BROWSER_FORM_FIELD_H_ |
| 6 #define COMPONENTS_AUTOFILL_BROWSER_FORM_FIELD_H_ | 6 #define COMPONENTS_AUTOFILL_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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 // By default match label and name for input/text types. | 47 // By default match label and name for input/text types. |
| 48 MATCH_DEFAULT = MATCH_LABEL | MATCH_NAME | MATCH_VALUE | MATCH_TEXT, | 48 MATCH_DEFAULT = MATCH_LABEL | MATCH_NAME | MATCH_VALUE | MATCH_TEXT, |
| 49 }; | 49 }; |
| 50 | 50 |
| 51 // Only derived classes may instantiate. | 51 // Only derived classes may instantiate. |
| 52 FormField() {} | 52 FormField() {} |
| 53 | 53 |
| 54 // 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 |
| 55 // success and fills |match| with a pointer to the field. | 55 // success and fills |match| with a pointer to the field. |
| 56 static bool ParseField(AutofillScanner* scanner, | 56 static bool ParseField(AutofillScanner* scanner, |
| 57 const string16& pattern, | 57 const base::string16& pattern, |
| 58 const AutofillField** match); | 58 const AutofillField** match); |
| 59 | 59 |
| 60 // Parses the stream of fields in |scanner| with regular expression |pattern| | 60 // Parses the stream of fields in |scanner| with regular expression |pattern| |
| 61 // as specified in the |match_type| bit field (see |MatchType|). If |match| | 61 // as specified in the |match_type| bit field (see |MatchType|). If |match| |
| 62 // is non-NULL and the pattern matches, the matched field is returned. | 62 // is non-NULL and the pattern matches, the matched field is returned. |
| 63 // A |true| result is returned in the case of a successful match, false | 63 // A |true| result is returned in the case of a successful match, false |
| 64 // otherwise. | 64 // otherwise. |
| 65 static bool ParseFieldSpecifics(AutofillScanner* scanner, | 65 static bool ParseFieldSpecifics(AutofillScanner* scanner, |
| 66 const string16& pattern, | 66 const base::string16& pattern, |
| 67 int match_type, | 67 int match_type, |
| 68 const AutofillField** match); | 68 const AutofillField** match); |
| 69 | 69 |
| 70 // Attempts to parse a field with an empty label. Returns true | 70 // Attempts to parse a field with an empty label. Returns true |
| 71 // on success and fills |match| with a pointer to the field. | 71 // on success and fills |match| with a pointer to the field. |
| 72 static bool ParseEmptyLabel(AutofillScanner* scanner, | 72 static bool ParseEmptyLabel(AutofillScanner* scanner, |
| 73 const AutofillField** match); | 73 const AutofillField** match); |
| 74 | 74 |
| 75 // Adds an association between a field and a type to |map|. | 75 // Adds an association between a field and a type to |map|. |
| 76 static bool AddClassification(const AutofillField* field, | 76 static bool AddClassification(const AutofillField* field, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 88 | 88 |
| 89 // Function pointer type for the parsing function that should be passed to the | 89 // Function pointer type for the parsing function that should be passed to the |
| 90 // ParseFormFieldsPass() helper function. | 90 // ParseFormFieldsPass() helper function. |
| 91 typedef FormField* ParseFunction(AutofillScanner* scanner); | 91 typedef FormField* ParseFunction(AutofillScanner* scanner); |
| 92 | 92 |
| 93 // Matches |pattern| to the contents of the field at the head of the | 93 // Matches |pattern| to the contents of the field at the head of the |
| 94 // |scanner|. | 94 // |scanner|. |
| 95 // Returns |true| if a match is found according to |match_type|, and |false| | 95 // Returns |true| if a match is found according to |match_type|, and |false| |
| 96 // otherwise. | 96 // otherwise. |
| 97 static bool MatchAndAdvance(AutofillScanner* scanner, | 97 static bool MatchAndAdvance(AutofillScanner* scanner, |
| 98 const string16& pattern, | 98 const base::string16& pattern, |
| 99 int match_type, | 99 int match_type, |
| 100 const AutofillField** match); | 100 const AutofillField** match); |
| 101 | 101 |
| 102 // Matches the regular expression |pattern| against the components of |field| | 102 // Matches the regular expression |pattern| against the components of |field| |
| 103 // as specified in the |match_type| bit field (see |MatchType|). | 103 // as specified in the |match_type| bit field (see |MatchType|). |
| 104 static bool Match(const AutofillField* field, | 104 static bool Match(const AutofillField* field, |
| 105 const string16& pattern, | 105 const base::string16& pattern, |
| 106 int match_type); | 106 int match_type); |
| 107 | 107 |
| 108 // Perform a "pass" over the |fields| where each pass uses the supplied | 108 // Perform a "pass" over the |fields| where each pass uses the supplied |
| 109 // |parse| method to match content to a given field type. | 109 // |parse| method to match content to a given field type. |
| 110 // |fields| is both an input and an output parameter. Upon exit |fields| | 110 // |fields| is both an input and an output parameter. Upon exit |fields| |
| 111 // holds any remaining unclassified fields for further processing. | 111 // holds any remaining unclassified fields for further processing. |
| 112 // Classification results of the processed fields are stored in |map|. | 112 // Classification results of the processed fields are stored in |map|. |
| 113 static void ParseFormFieldsPass(ParseFunction parse, | 113 static void ParseFormFieldsPass(ParseFunction parse, |
| 114 std::vector<const AutofillField*>* fields, | 114 std::vector<const AutofillField*>* fields, |
| 115 FieldTypeMap* map); | 115 FieldTypeMap* map); |
| 116 | 116 |
| 117 DISALLOW_COPY_AND_ASSIGN(FormField); | 117 DISALLOW_COPY_AND_ASSIGN(FormField); |
| 118 }; | 118 }; |
| 119 | 119 |
| 120 #endif // COMPONENTS_AUTOFILL_BROWSER_FORM_FIELD_H_ | 120 #endif // COMPONENTS_AUTOFILL_BROWSER_FORM_FIELD_H_ |
| OLD | NEW |