| 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 static bool MatchWithType(const AutofillField* field, |
| 83 const string16& pattern, |
| 84 int match_type); |
| 85 |
| 86 enum MatchType { |
| 87 MATCH_LABEL = 1 << 0, |
| 88 MATCH_NAME = 1 << 1, |
| 89 MATCH_TEXT = 1 << 2, |
| 90 MATCH_SELECT = 1 << 3, |
| 91 }; |
| 92 |
| 82 // Parses a field using the different field views we know about. |is_ecml| | 93 // 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. | 94 // should be true when the field conforms to the ECML specification. |
| 84 static FormField* ParseFormField(AutofillScanner* scanner, bool is_ecml); | 95 static FormField* ParseFormField(AutofillScanner* scanner, bool is_ecml); |
| 85 | 96 |
| 86 // Attempts to parse a text field with the given pattern; returns true on | 97 // Attempts to parse a text field with the given pattern; returns true on |
| 87 // success, but doesn't return the actual text field itself. | 98 // success, but doesn't return the actual text field itself. |
| 88 static bool ParseText(AutofillScanner* scanner, const string16& pattern); | 99 static bool ParseText(AutofillScanner* scanner, |
| 100 const string16& pattern, |
| 101 int match_type); |
| 89 | 102 |
| 90 // Attempts to parse a text field with the given pattern. Returns true on | 103 // Attempts to parse a text field with the given pattern. Returns true on |
| 91 // success and fills |dest| with a pointer to the field. | 104 // success and fills |dest| with a pointer to the field. |
| 92 static bool ParseText(AutofillScanner* scanner, | 105 static bool ParseText(AutofillScanner* scanner, |
| 93 const string16& pattern, | 106 const string16& pattern, |
| 107 int match_type, |
| 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 | |
| 102 // on success and fills |dest| with a pointer to the field. | |
| 103 static bool ParseLabelText(AutofillScanner* scanner, | |
| 104 const string16& pattern, | |
| 105 const AutofillField** dest); | |
| 106 | |
| 107 // Attempts to parse a control with an empty label. | 115 // Attempts to parse a control with an empty label. |
| 108 static bool ParseEmpty(AutofillScanner* scanner); | 116 static bool ParseEmpty(AutofillScanner* scanner); |
| 109 | 117 |
| 110 // Adds an association between a field and a type to |field_type_map|. | 118 // Adds an association between a field and a type to |field_type_map|. |
| 111 static bool Add(FieldTypeMap* field_type_map, | 119 static bool Add(FieldTypeMap* field_type_map, |
| 112 const AutofillField* field, | 120 const AutofillField* field, |
| 113 AutofillFieldType type); | 121 AutofillFieldType type); |
| 114 | 122 |
| 115 protected: | 123 protected: |
| 116 // Only derived classes may instantiate. | 124 // Only derived classes may instantiate. |
| 117 FormField() {} | 125 FormField() {} |
| 118 | 126 |
| 119 // Note: ECML compliance checking has been modified to accommodate Google | 127 // Note: ECML compliance checking has been modified to accommodate Google |
| 120 // Checkout field name limitation. All ECML compliant web forms will be | 128 // Checkout field name limitation. All ECML compliant web forms will be |
| 121 // recognized correctly as such however the restrictions on having exactly | 129 // recognized correctly as such however the restrictions on having exactly |
| 122 // ECML compliant names have been loosened to only require that field names | 130 // 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. | 131 // 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 | 132 // Additionally we allow the use of '.' as a word delimiter in addition to the |
| 125 // ECML standard '_' (see FormField::FormField for details). | 133 // ECML standard '_' (see FormField::FormField for details). |
| 126 static string16 GetEcmlPattern(const char* ecml_name); | 134 static string16 GetEcmlPattern(const char* ecml_name); |
| 127 static string16 GetEcmlPattern(const char* ecml_name1, | 135 static string16 GetEcmlPattern(const char* ecml_name1, |
| 128 const char* ecml_name2, | 136 const char* ecml_name2, |
| 129 char pattern_operator); | 137 char pattern_operator); |
| 130 | 138 |
| 131 private: | 139 private: |
| 132 static bool ParseText(AutofillScanner* scanner, | 140 static bool ParseText(AutofillScanner* scanner, |
| 133 const string16& pattern, | 141 const string16& pattern, |
| 134 const AutofillField** dest, | 142 const AutofillField** dest, |
| 135 bool match_label_only); | 143 int match_type); |
| 136 | 144 |
| 137 // For empty strings we need to test that both label and name are empty. | |
| 138 static bool ParseLabelAndName(AutofillScanner* scanner, | |
| 139 const string16& pattern, | |
| 140 const AutofillField** dest); | |
| 141 static bool MatchName(const AutofillField* field, const string16& pattern); | 145 static bool MatchName(const AutofillField* field, const string16& pattern); |
| 142 static bool MatchLabel(const AutofillField* field, const string16& pattern); | 146 static bool MatchLabel(const AutofillField* field, const string16& pattern); |
| 143 | 147 |
| 144 DISALLOW_COPY_AND_ASSIGN(FormField); | 148 DISALLOW_COPY_AND_ASSIGN(FormField); |
| 145 }; | 149 }; |
| 146 | 150 |
| 147 #endif // CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_ | 151 #endif // CHROME_BROWSER_AUTOFILL_FORM_FIELD_H_ |
| OLD | NEW |