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

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

Issue 1477733003: Replace xmllite with libxml in autofill (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@556433_remove_dead_code
Patch Set: Just rebased Created 5 years 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_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"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "components/autofill/core/browser/autofill_server_field_info.h"
15 #include "components/autofill/core/browser/field_types.h"
16 #include "components/autofill/core/browser/form_structure.h" 11 #include "components/autofill/core/browser/form_structure.h"
17 #include "third_party/webrtc/libjingle/xmllite/xmlparser.h"
18 12
19 namespace autofill { 13 namespace autofill {
20 14
21 // The base class that contains common functionality between 15 struct AutofillServerFieldInfo;
22 // AutofillQueryXmlParser and AutofillUploadXmlParser.
23 class AutofillXmlParser : public buzz::XmlParseHandler {
24 public:
25 AutofillXmlParser();
26 ~AutofillXmlParser() override;
27 16
28 // Returns true if no parsing errors were encountered. 17 // The XML parser for parsing Autofill query responses. A typical response
29 bool succeeded() const { return succeeded_; } 18 // looks like:
30
31 private:
32 // A callback for the end of an </element>, called by Expat.
33 // |context| is a parsing context used to resolve element/attribute names.
34 // |name| is the name of the element.
35 void EndElement(buzz::XmlParseContext* context, const char* name) override;
36
37 // The callback for character data between tags (<element>text...</element>).
38 // |context| is a parsing context used to resolve element/attribute names.
39 // |text| is a pointer to the beginning of character data (not null
40 // terminated).
41 // |len| is the length of the string pointed to by text.
42 void CharacterData(buzz::XmlParseContext* context,
43 const char* text,
44 int len) override;
45
46 // The callback for parsing errors.
47 // |context| is a parsing context used to resolve names.
48 // |error_code| is a code representing the parsing error.
49 void Error(buzz::XmlParseContext* context, XML_Error error_code) override;
50
51 // True if parsing succeeded.
52 bool succeeded_;
53
54 DISALLOW_COPY_AND_ASSIGN(AutofillXmlParser);
55 };
56
57 // The XML parse handler for parsing Autofill query responses. A typical
58 // response looks like:
59 // 19 //
60 // <autofillqueryresponse> 20 // <autofillqueryresponse uploadrequired="true">
61 // <field autofilltype="0" /> 21 // <field autofilltype="0" />
62 // <field autofilltype="1" /> 22 // <field autofilltype="1" />
63 // <field autofilltype="3" /> 23 // <field autofilltype="3" />
64 // <field autofilltype="2" /> 24 // <field autofilltype="2" />
25 // <field autofilltype="61" defaultvalue="default" />
65 // </autofillqueryresponse> 26 // </autofillqueryresponse>
66 // 27 //
67 // Fields are returned in the same order they were sent to the server. 28 // Fields are returned in the same order they were sent to the server.
68 // autofilltype: The server's guess at what type of field this is. 0 29 // autofilltype: The server's guess at what type of field this is. 0
69 // is unknown, other types are documented in 30 // is unknown, other types are documented in
70 // components/autofill/core/browser/field_types.h. 31 // components/autofill/core/browser/field_types.h.
71 class AutofillQueryXmlParser : public AutofillXmlParser { 32 //
72 public: 33 // Parses |xml| and on success returns true and fills |field_infos| based on the
73 AutofillQueryXmlParser(std::vector<AutofillServerFieldInfo>* field_infos, 34 // <field> tags and |upload_required| based on the uploadrequired attribute of
74 UploadRequired* upload_required); 35 // the autofillqueryresponse tag. On failure returns false.
75 ~AutofillQueryXmlParser() override; 36 bool ParseAutofillQueryXml(std::string xml,
37 std::vector<AutofillServerFieldInfo>* field_infos,
38 UploadRequired* upload_required);
76 39
77 private: 40 // The XML parser for Autofill upload responses. Typical upload responses look
78 // A callback for the beginning of a new <element>, called by Expat. 41 // like:
79 // |context| is a parsing context used to resolve element/attribute names.
80 // |name| is the name of the element.
81 // |attrs| is the list of attributes (names and values) for the element.
82 void StartElement(buzz::XmlParseContext* context,
83 const char* name,
84 const char** attrs) override;
85
86 // A helper function to retrieve integer values from strings. Raises an
87 // XML parse error if it fails.
88 // |context| is the current parsing context.
89 // |value| is the string to convert.
90 int GetIntValue(buzz::XmlParseContext* context, const char* attribute);
91
92 // The parsed <field type, default value> pairs.
93 std::vector<AutofillServerFieldInfo>* field_infos_;
94
95 // A flag indicating whether the client should upload Autofill data when this
96 // form is submitted.
97 UploadRequired* upload_required_;
98
99 DISALLOW_COPY_AND_ASSIGN(AutofillQueryXmlParser);
100 };
101
102 // The XML parser for handling Autofill upload responses. Typical upload
103 // responses look like:
104 // 42 //
105 // <autofilluploadresponse negativeuploadrate="0.00125" positiveuploadrate="1"/> 43 // <autofilluploadresponse negativeuploadrate="0.00125" positiveuploadrate="1"/>
106 // 44 //
107 // The positive upload rate is the percentage of uploads to send to the server 45 // The positive upload rate is the percentage of uploads to send to the server
108 // when something in the users profile matches what they have entered in a form. 46 // when something in the users profile matches what they have entered in a form.
109 // The negative upload rate is the percentage of uploads to send when nothing in 47 // The negative upload rate is the percentage of uploads to send when nothing in
110 // the form matches what's in the users profile. 48 // the form matches what's in the users profile.
111 // The negative upload rate is typically much lower than the positive upload 49 // The negative upload rate is typically much lower than the positive upload
112 // rate. 50 // rate.
113 class AutofillUploadXmlParser : public AutofillXmlParser { 51 //
114 public: 52 // Parses |xml| and on success returns true and fills the upload rates based on
115 AutofillUploadXmlParser(double* positive_upload_rate, 53 // the attributes of the autofilluploadresponse tag. On failure returns false.
116 double* negative_upload_rate); 54 bool ParseAutofillUploadXml(std::string xml,
117 55 double* positive_upload_rate,
118 private: 56 double* negative_upload_rate);
119 // A callback for the beginning of a new <element>, called by Expat.
120 // |context| is a parsing context used to resolve element/attribute names.
121 // |name| is the name of the element.
122 // |attrs| is the list of attributes (names and values) for the element.
123 void StartElement(buzz::XmlParseContext* context,
124 const char* name,
125 const char** attrs) override;
126
127 // A helper function to retrieve double values from strings. Raises an XML
128 // parse error if it fails.
129 // |context| is the current parsing context.
130 // |value| is the string to convert.
131 double GetDoubleValue(buzz::XmlParseContext* context, const char* attribute);
132
133 // True if parsing succeeded.
134 bool succeeded_;
135
136 double* positive_upload_rate_;
137 double* negative_upload_rate_;
138
139 DISALLOW_COPY_AND_ASSIGN(AutofillUploadXmlParser);
140 };
141 57
142 } // namespace autofill 58 } // namespace autofill
143 59
144 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_XML_PARSER_H_ 60 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_XML_PARSER_H_
OLDNEW
« no previous file with comments | « components/autofill/core/browser/autofill_manager.cc ('k') | components/autofill/core/browser/autofill_xml_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698