Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: components/autofill/core/browser/form_field.h

Issue 853523004: Autofill: Set requirements for number of recognized fields in an autofillable form (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More relaxed check for form tag Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
(...skipping 11 matching lines...) Expand all
22 // interface can identify themselves as a particular type of form field, e.g. 22 // interface can identify themselves as a particular type of form field, e.g.
23 // name, phone number, or address field. 23 // name, phone number, or address field.
24 class FormField { 24 class FormField {
25 public: 25 public:
26 virtual ~FormField() {} 26 virtual ~FormField() {}
27 27
28 // Classifies each field in |fields| with its heuristically detected type. 28 // Classifies each field in |fields| with its heuristically detected type.
29 // The association is stored into |map|. Each field has a derived unique name 29 // The association is stored into |map|. Each field has a derived unique name
30 // that is used as the key into the |map|. 30 // that is used as the key into the |map|.
31 static void ParseFormFields(const std::vector<AutofillField*>& fields, 31 static void ParseFormFields(const std::vector<AutofillField*>& fields,
32 bool is_unowned_form,
Evan Stade 2015/01/21 22:52:50 nit: |unowned_form| is a slight misnomer. How abou
Lei Zhang 2015/01/22 08:07:37 is_in_form_tag
32 ServerFieldTypeMap* map); 33 ServerFieldTypeMap* map);
33 34
34 protected: 35 protected:
35 // A bit-field used for matching specific parts of a field in question. 36 // A bit-field used for matching specific parts of a field in question.
36 enum MatchType { 37 enum MatchType {
37 // Attributes. 38 // Attributes.
38 MATCH_LABEL = 1 << 0, 39 MATCH_LABEL = 1 << 0,
39 MATCH_NAME = 1 << 1, 40 MATCH_NAME = 1 << 1,
40 MATCH_VALUE = 1 << 2, 41 MATCH_VALUE = 1 << 2,
41 42
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 static bool AddClassification(const AutofillField* field, 82 static bool AddClassification(const AutofillField* field,
82 ServerFieldType type, 83 ServerFieldType type,
83 ServerFieldTypeMap* map); 84 ServerFieldTypeMap* map);
84 85
85 // Derived classes must implement this interface to supply field type 86 // Derived classes must implement this interface to supply field type
86 // information. |ParseFormFields| coordinates the parsing and extraction 87 // information. |ParseFormFields| coordinates the parsing and extraction
87 // of types from an input vector of |AutofillField| objects and delegates 88 // of types from an input vector of |AutofillField| objects and delegates
88 // the type extraction via this method. 89 // the type extraction via this method.
89 virtual bool ClassifyField(ServerFieldTypeMap* map) const = 0; 90 virtual bool ClassifyField(ServerFieldTypeMap* map) const = 0;
90 91
92 // Returns the number of recognized fields.
93 virtual size_t FieldCount() const = 0;
94
91 private: 95 private:
92 FRIEND_TEST_ALL_PREFIXES(FormFieldTest, Match); 96 FRIEND_TEST_ALL_PREFIXES(FormFieldTest, Match);
93 97
94 // Function pointer type for the parsing function that should be passed to the 98 // Function pointer type for the parsing function that should be passed to the
95 // ParseFormFieldsPass() helper function. 99 // ParseFormFieldsPass() helper function.
96 typedef scoped_ptr<FormField> ParseFunction(AutofillScanner* scanner); 100 typedef scoped_ptr<FormField> ParseFunction(AutofillScanner* scanner);
97 101
98 // Matches |pattern| to the contents of the field at the head of the 102 // Matches |pattern| to the contents of the field at the head of the
99 // |scanner|. 103 // |scanner|.
100 // Returns |true| if a match is found according to |match_type|, and |false| 104 // Returns |true| if a match is found according to |match_type|, and |false|
101 // otherwise. 105 // otherwise.
102 static bool MatchAndAdvance(AutofillScanner* scanner, 106 static bool MatchAndAdvance(AutofillScanner* scanner,
103 const base::string16& pattern, 107 const base::string16& pattern,
104 int match_type, 108 int match_type,
105 AutofillField** match); 109 AutofillField** match);
106 110
107 // Matches the regular expression |pattern| against the components of |field| 111 // Matches the regular expression |pattern| against the components of |field|
108 // as specified in the |match_type| bit field (see |MatchType|). 112 // as specified in the |match_type| bit field (see |MatchType|).
109 static bool Match(const AutofillField* field, 113 static bool Match(const AutofillField* field,
110 const base::string16& pattern, 114 const base::string16& pattern,
111 int match_type); 115 int match_type);
112 116
113 // Perform a "pass" over the |fields| where each pass uses the supplied 117 // Perform a "pass" over the |fields| where each pass uses the supplied
114 // |parse| method to match content to a given field type. 118 // |parse| method to match content to a given field type.
115 // |fields| is both an input and an output parameter. Upon exit |fields| 119 // |fields| is both an input and an output parameter. Upon exit |fields|
116 // holds any remaining unclassified fields for further processing. 120 // holds any remaining unclassified fields for further processing.
117 // Classification results of the processed fields are stored in |map|. 121 // Classification results of the processed fields are stored in |map|.
118 static void ParseFormFieldsPass(ParseFunction parse, 122 // Returns the number of recognized fields.
119 std::vector<AutofillField*>* fields, 123 static size_t ParseFormFieldsPass(ParseFunction parse,
120 ServerFieldTypeMap* map); 124 std::vector<AutofillField*>* fields,
125 ServerFieldTypeMap* map);
121 126
122 // Returns true iff |type| matches |match_type|. 127 // Returns true iff |type| matches |match_type|.
123 static bool MatchesFormControlType(const std::string& type, int match_type); 128 static bool MatchesFormControlType(const std::string& type, int match_type);
124 129
125 DISALLOW_COPY_AND_ASSIGN(FormField); 130 DISALLOW_COPY_AND_ASSIGN(FormField);
126 }; 131 };
127 132
128 } // namespace autofill 133 } // namespace autofill
129 134
130 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_ 135 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_FORM_FIELD_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698