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_AUTOFILL_XML_PARSER_H_ | 5 #ifndef COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_XML_PARSER_H_ |
6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_XML_PARSER_H_ | 6 #define COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_XML_PARSER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "components/autofill/core/browser/autofill_server_field_info.h" | 14 #include "components/autofill/core/browser/autofill_server_field_info.h" |
15 #include "components/autofill/core/browser/field_types.h" | 15 #include "components/autofill/core/browser/field_types.h" |
16 #include "components/autofill/core/browser/form_structure.h" | 16 #include "components/autofill/core/browser/form_structure.h" |
17 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" | 17 #include "third_party/libjingle/source/talk/xmllite/xmlparser.h" |
18 | 18 |
19 namespace autofill { | 19 namespace autofill { |
20 | 20 |
21 struct AutocheckoutPageMetaData; | |
22 | |
23 // The base class that contains common functionality between | 21 // The base class that contains common functionality between |
24 // AutofillQueryXmlParser and AutofillUploadXmlParser. | 22 // AutofillQueryXmlParser and AutofillUploadXmlParser. |
25 class AutofillXmlParser : public buzz::XmlParseHandler { | 23 class AutofillXmlParser : public buzz::XmlParseHandler { |
26 public: | 24 public: |
27 AutofillXmlParser(); | 25 AutofillXmlParser(); |
28 virtual ~AutofillXmlParser(); | 26 virtual ~AutofillXmlParser(); |
29 | 27 |
30 // Returns true if no parsing errors were encountered. | 28 // Returns true if no parsing errors were encountered. |
31 bool succeeded() const { return succeeded_; } | 29 bool succeeded() const { return succeeded_; } |
32 | 30 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // </autofillqueryresponse> | 67 // </autofillqueryresponse> |
70 // | 68 // |
71 // Fields are returned in the same order they were sent to the server. | 69 // Fields are returned in the same order they were sent to the server. |
72 // autofilltype: The server's guess at what type of field this is. 0 | 70 // autofilltype: The server's guess at what type of field this is. 0 |
73 // is unknown, other types are documented in | 71 // is unknown, other types are documented in |
74 // components/autofill/core/browser/field_types.h. | 72 // components/autofill/core/browser/field_types.h. |
75 class AutofillQueryXmlParser : public AutofillXmlParser { | 73 class AutofillQueryXmlParser : public AutofillXmlParser { |
76 public: | 74 public: |
77 AutofillQueryXmlParser(std::vector<AutofillServerFieldInfo>* field_infos, | 75 AutofillQueryXmlParser(std::vector<AutofillServerFieldInfo>* field_infos, |
78 UploadRequired* upload_required, | 76 UploadRequired* upload_required, |
79 std::string* experiment_id, | 77 std::string* experiment_id); |
80 AutocheckoutPageMetaData* page_meta_data); | |
81 virtual ~AutofillQueryXmlParser(); | 78 virtual ~AutofillQueryXmlParser(); |
82 | 79 |
83 private: | 80 private: |
84 // A callback for the beginning of a new <element>, called by Expat. | 81 // A callback for the beginning of a new <element>, called by Expat. |
85 // |context| is a parsing context used to resolve element/attribute names. | 82 // |context| is a parsing context used to resolve element/attribute names. |
86 // |name| is the name of the element. | 83 // |name| is the name of the element. |
87 // |attrs| is the list of attributes (names and values) for the element. | 84 // |attrs| is the list of attributes (names and values) for the element. |
88 virtual void StartElement(buzz::XmlParseContext* context, | 85 virtual void StartElement(buzz::XmlParseContext* context, |
89 const char* name, | 86 const char* name, |
90 const char** attrs) OVERRIDE; | 87 const char** attrs) OVERRIDE; |
91 | 88 |
92 // A helper function to parse a |WebElementDescriptor|. | 89 // A helper function to parse a |WebElementDescriptor|. |
93 // |context| is the current parsing context. | 90 // |context| is the current parsing context. |
94 // |attrs| is the list of attributes (names and values) for the element. | 91 // |attrs| is the list of attributes (names and values) for the element. |
95 // |element_descriptor| will be populated by this function. | 92 // |element_descriptor| will be populated by this function. |
96 void ParseElementDescriptor(buzz::XmlParseContext* context, | 93 void ParseElementDescriptor(buzz::XmlParseContext* context, |
97 const char* const* attrs, | 94 const char* const* attrs, |
98 WebElementDescriptor* element_descriptor); | 95 WebElementDescriptor* element_descriptor); |
99 | 96 |
100 // A callback for the end of an </element>, called by Expat. | |
101 // |context| is a parsing context used to resolve element/attribute names. | |
102 // |name| is the name of the element. | |
103 virtual void EndElement(buzz::XmlParseContext* context, | |
104 const char* name) OVERRIDE; | |
105 | |
106 // The callback for character data between tags (<element>text...</element>). | |
107 // |context| is a parsing context used to resolve element/attribute names. | |
108 // |text| is a pointer to the beginning of character data (not null | |
109 // terminated). | |
110 // |len| is the length of the string pointed to by text. | |
111 virtual void CharacterData(buzz::XmlParseContext* context, | |
112 const char* text, | |
113 int len) OVERRIDE; | |
114 | |
115 // A helper function to retrieve integer values from strings. Raises an | 97 // A helper function to retrieve integer values from strings. Raises an |
116 // XML parse error if it fails. | 98 // XML parse error if it fails. |
117 // |context| is the current parsing context. | 99 // |context| is the current parsing context. |
118 // |value| is the string to convert. | 100 // |value| is the string to convert. |
119 int GetIntValue(buzz::XmlParseContext* context, const char* attribute); | 101 int GetIntValue(buzz::XmlParseContext* context, const char* attribute); |
120 | 102 |
121 // The parsed <field type, default value> pairs. | 103 // The parsed <field type, default value> pairs. |
122 std::vector<AutofillServerFieldInfo>* field_infos_; | 104 std::vector<AutofillServerFieldInfo>* field_infos_; |
123 | 105 |
124 // A flag indicating whether the client should upload Autofill data when this | 106 // A flag indicating whether the client should upload Autofill data when this |
125 // form is submitted. | 107 // form is submitted. |
126 UploadRequired* upload_required_; | 108 UploadRequired* upload_required_; |
127 | 109 |
128 // The server experiment to which this query response belongs. | 110 // The server experiment to which this query response belongs. |
129 // For the default server implementation, this is empty. | 111 // For the default server implementation, this is empty. |
130 std::string* experiment_id_; | 112 std::string* experiment_id_; |
131 | 113 |
132 // Page metadata for multipage autofill flow. | |
133 AutocheckoutPageMetaData* page_meta_data_; | |
134 | |
135 // The click element the parser is currently processing. | |
136 WebElementDescriptor* current_click_element_; | |
137 | |
138 // Number of page whose type is currently being parsed. | |
139 int current_page_number_for_page_types_; | |
140 | |
141 // Whether the instance is currently parsing inside 'type' tags. | |
142 bool is_in_type_section_; | |
143 | |
144 DISALLOW_COPY_AND_ASSIGN(AutofillQueryXmlParser); | 114 DISALLOW_COPY_AND_ASSIGN(AutofillQueryXmlParser); |
145 }; | 115 }; |
146 | 116 |
147 // The XML parser for handling Autofill upload responses. Typical upload | 117 // The XML parser for handling Autofill upload responses. Typical upload |
148 // responses look like: | 118 // responses look like: |
149 // | 119 // |
150 // <autofilluploadresponse negativeuploadrate="0.00125" positiveuploadrate="1"/> | 120 // <autofilluploadresponse negativeuploadrate="0.00125" positiveuploadrate="1"/> |
151 // | 121 // |
152 // The positive upload rate is the percentage of uploads to send to the server | 122 // The positive upload rate is the percentage of uploads to send to the server |
153 // when something in the users profile matches what they have entered in a form. | 123 // when something in the users profile matches what they have entered in a form. |
(...skipping 26 matching lines...) Expand all Loading... |
180 | 150 |
181 double* positive_upload_rate_; | 151 double* positive_upload_rate_; |
182 double* negative_upload_rate_; | 152 double* negative_upload_rate_; |
183 | 153 |
184 DISALLOW_COPY_AND_ASSIGN(AutofillUploadXmlParser); | 154 DISALLOW_COPY_AND_ASSIGN(AutofillUploadXmlParser); |
185 }; | 155 }; |
186 | 156 |
187 } // namespace autofill | 157 } // namespace autofill |
188 | 158 |
189 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_XML_PARSER_H_ | 159 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_XML_PARSER_H_ |
OLD | NEW |