| 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/webrtc/libjingle/xmllite/xmlparser.h" | 17 #include "third_party/webrtc/libjingle/xmllite/xmlparser.h" |
| 18 | 18 |
| 19 namespace autofill { | 19 namespace autofill { |
| 20 | 20 |
| 21 // The base class that contains common functionality between | 21 // The base class that contains common functionality between |
| 22 // AutofillQueryXmlParser and AutofillUploadXmlParser. | 22 // AutofillQueryXmlParser and AutofillUploadXmlParser. |
| 23 class AutofillXmlParser : public buzz::XmlParseHandler { | 23 class AutofillXmlParser : public buzz::XmlParseHandler { |
| 24 public: | 24 public: |
| 25 AutofillXmlParser(); | 25 AutofillXmlParser(); |
| 26 virtual ~AutofillXmlParser(); | 26 ~AutofillXmlParser() override; |
| 27 | 27 |
| 28 // Returns true if no parsing errors were encountered. | 28 // Returns true if no parsing errors were encountered. |
| 29 bool succeeded() const { return succeeded_; } | 29 bool succeeded() const { return succeeded_; } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 // A callback for the end of an </element>, called by Expat. | 32 // A callback for the end of an </element>, called by Expat. |
| 33 // |context| is a parsing context used to resolve element/attribute names. | 33 // |context| is a parsing context used to resolve element/attribute names. |
| 34 // |name| is the name of the element. | 34 // |name| is the name of the element. |
| 35 virtual void EndElement(buzz::XmlParseContext* context, | 35 void EndElement(buzz::XmlParseContext* context, const char* name) override; |
| 36 const char* name) override; | |
| 37 | 36 |
| 38 // The callback for character data between tags (<element>text...</element>). | 37 // The callback for character data between tags (<element>text...</element>). |
| 39 // |context| is a parsing context used to resolve element/attribute names. | 38 // |context| is a parsing context used to resolve element/attribute names. |
| 40 // |text| is a pointer to the beginning of character data (not null | 39 // |text| is a pointer to the beginning of character data (not null |
| 41 // terminated). | 40 // terminated). |
| 42 // |len| is the length of the string pointed to by text. | 41 // |len| is the length of the string pointed to by text. |
| 43 virtual void CharacterData(buzz::XmlParseContext* context, | 42 void CharacterData(buzz::XmlParseContext* context, |
| 44 const char* text, | 43 const char* text, |
| 45 int len) override; | 44 int len) override; |
| 46 | 45 |
| 47 // The callback for parsing errors. | 46 // The callback for parsing errors. |
| 48 // |context| is a parsing context used to resolve names. | 47 // |context| is a parsing context used to resolve names. |
| 49 // |error_code| is a code representing the parsing error. | 48 // |error_code| is a code representing the parsing error. |
| 50 virtual void Error(buzz::XmlParseContext* context, | 49 void Error(buzz::XmlParseContext* context, XML_Error error_code) override; |
| 51 XML_Error error_code) override; | |
| 52 | 50 |
| 53 // True if parsing succeeded. | 51 // True if parsing succeeded. |
| 54 bool succeeded_; | 52 bool succeeded_; |
| 55 | 53 |
| 56 DISALLOW_COPY_AND_ASSIGN(AutofillXmlParser); | 54 DISALLOW_COPY_AND_ASSIGN(AutofillXmlParser); |
| 57 }; | 55 }; |
| 58 | 56 |
| 59 // The XML parse handler for parsing Autofill query responses. A typical | 57 // The XML parse handler for parsing Autofill query responses. A typical |
| 60 // response looks like: | 58 // response looks like: |
| 61 // | 59 // |
| 62 // <autofillqueryresponse experimentid="1"> | 60 // <autofillqueryresponse experimentid="1"> |
| 63 // <field autofilltype="0" /> | 61 // <field autofilltype="0" /> |
| 64 // <field autofilltype="1" /> | 62 // <field autofilltype="1" /> |
| 65 // <field autofilltype="3" /> | 63 // <field autofilltype="3" /> |
| 66 // <field autofilltype="2" /> | 64 // <field autofilltype="2" /> |
| 67 // </autofillqueryresponse> | 65 // </autofillqueryresponse> |
| 68 // | 66 // |
| 69 // Fields are returned in the same order they were sent to the server. | 67 // Fields are returned in the same order they were sent to the server. |
| 70 // autofilltype: The server's guess at what type of field this is. 0 | 68 // autofilltype: The server's guess at what type of field this is. 0 |
| 71 // is unknown, other types are documented in | 69 // is unknown, other types are documented in |
| 72 // components/autofill/core/browser/field_types.h. | 70 // components/autofill/core/browser/field_types.h. |
| 73 // Experiment ids are currently ignored. | 71 // Experiment ids are currently ignored. |
| 74 class AutofillQueryXmlParser : public AutofillXmlParser { | 72 class AutofillQueryXmlParser : public AutofillXmlParser { |
| 75 public: | 73 public: |
| 76 AutofillQueryXmlParser(std::vector<AutofillServerFieldInfo>* field_infos, | 74 AutofillQueryXmlParser(std::vector<AutofillServerFieldInfo>* field_infos, |
| 77 UploadRequired* upload_required); | 75 UploadRequired* upload_required); |
| 78 virtual ~AutofillQueryXmlParser(); | 76 ~AutofillQueryXmlParser() override; |
| 79 | 77 |
| 80 private: | 78 private: |
| 81 // A callback for the beginning of a new <element>, called by Expat. | 79 // A callback for the beginning of a new <element>, called by Expat. |
| 82 // |context| is a parsing context used to resolve element/attribute names. | 80 // |context| is a parsing context used to resolve element/attribute names. |
| 83 // |name| is the name of the element. | 81 // |name| is the name of the element. |
| 84 // |attrs| is the list of attributes (names and values) for the element. | 82 // |attrs| is the list of attributes (names and values) for the element. |
| 85 virtual void StartElement(buzz::XmlParseContext* context, | 83 void StartElement(buzz::XmlParseContext* context, |
| 86 const char* name, | 84 const char* name, |
| 87 const char** attrs) override; | 85 const char** attrs) override; |
| 88 | 86 |
| 89 // A helper function to parse a |WebElementDescriptor|. | 87 // A helper function to parse a |WebElementDescriptor|. |
| 90 // |context| is the current parsing context. | 88 // |context| is the current parsing context. |
| 91 // |attrs| is the list of attributes (names and values) for the element. | 89 // |attrs| is the list of attributes (names and values) for the element. |
| 92 // |element_descriptor| will be populated by this function. | 90 // |element_descriptor| will be populated by this function. |
| 93 void ParseElementDescriptor(buzz::XmlParseContext* context, | 91 void ParseElementDescriptor(buzz::XmlParseContext* context, |
| 94 const char* const* attrs, | 92 const char* const* attrs, |
| 95 WebElementDescriptor* element_descriptor); | 93 WebElementDescriptor* element_descriptor); |
| 96 | 94 |
| 97 // A helper function to retrieve integer values from strings. Raises an | 95 // A helper function to retrieve integer values from strings. Raises an |
| (...skipping 26 matching lines...) Expand all Loading... |
| 124 class AutofillUploadXmlParser : public AutofillXmlParser { | 122 class AutofillUploadXmlParser : public AutofillXmlParser { |
| 125 public: | 123 public: |
| 126 AutofillUploadXmlParser(double* positive_upload_rate, | 124 AutofillUploadXmlParser(double* positive_upload_rate, |
| 127 double* negative_upload_rate); | 125 double* negative_upload_rate); |
| 128 | 126 |
| 129 private: | 127 private: |
| 130 // A callback for the beginning of a new <element>, called by Expat. | 128 // A callback for the beginning of a new <element>, called by Expat. |
| 131 // |context| is a parsing context used to resolve element/attribute names. | 129 // |context| is a parsing context used to resolve element/attribute names. |
| 132 // |name| is the name of the element. | 130 // |name| is the name of the element. |
| 133 // |attrs| is the list of attributes (names and values) for the element. | 131 // |attrs| is the list of attributes (names and values) for the element. |
| 134 virtual void StartElement(buzz::XmlParseContext* context, | 132 void StartElement(buzz::XmlParseContext* context, |
| 135 const char* name, | 133 const char* name, |
| 136 const char** attrs) override; | 134 const char** attrs) override; |
| 137 | 135 |
| 138 // A helper function to retrieve double values from strings. Raises an XML | 136 // A helper function to retrieve double values from strings. Raises an XML |
| 139 // parse error if it fails. | 137 // parse error if it fails. |
| 140 // |context| is the current parsing context. | 138 // |context| is the current parsing context. |
| 141 // |value| is the string to convert. | 139 // |value| is the string to convert. |
| 142 double GetDoubleValue(buzz::XmlParseContext* context, const char* attribute); | 140 double GetDoubleValue(buzz::XmlParseContext* context, const char* attribute); |
| 143 | 141 |
| 144 // True if parsing succeeded. | 142 // True if parsing succeeded. |
| 145 bool succeeded_; | 143 bool succeeded_; |
| 146 | 144 |
| 147 double* positive_upload_rate_; | 145 double* positive_upload_rate_; |
| 148 double* negative_upload_rate_; | 146 double* negative_upload_rate_; |
| 149 | 147 |
| 150 DISALLOW_COPY_AND_ASSIGN(AutofillUploadXmlParser); | 148 DISALLOW_COPY_AND_ASSIGN(AutofillUploadXmlParser); |
| 151 }; | 149 }; |
| 152 | 150 |
| 153 } // namespace autofill | 151 } // namespace autofill |
| 154 | 152 |
| 155 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_XML_PARSER_H_ | 153 #endif // COMPONENTS_AUTOFILL_CORE_BROWSER_AUTOFILL_XML_PARSER_H_ |
| OLD | NEW |