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 #include "chrome/browser/autofill/autofill_xml_parser.h" | 5 #include "chrome/browser/autofill/autofill_xml_parser.h" |
6 | 6 |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "chrome/browser/autofill/autofill_server_field_info.h" | |
11 #include "third_party/libjingle/source/talk/xmllite/qname.h" | 12 #include "third_party/libjingle/source/talk/xmllite/qname.h" |
12 | 13 |
13 AutofillXmlParser::AutofillXmlParser() | 14 AutofillXmlParser::AutofillXmlParser() |
14 : succeeded_(true) { | 15 : succeeded_(true) { |
15 } | 16 } |
16 | 17 |
17 void AutofillXmlParser::CharacterData( | 18 void AutofillXmlParser::CharacterData( |
18 buzz::XmlParseContext* context, const char* text, int len) { | 19 buzz::XmlParseContext* context, const char* text, int len) { |
19 } | 20 } |
20 | 21 |
21 void AutofillXmlParser::EndElement(buzz::XmlParseContext* context, | 22 void AutofillXmlParser::EndElement(buzz::XmlParseContext* context, |
22 const char* name) { | 23 const char* name) { |
23 } | 24 } |
24 | 25 |
25 void AutofillXmlParser::Error(buzz::XmlParseContext* context, | 26 void AutofillXmlParser::Error(buzz::XmlParseContext* context, |
26 XML_Error error_code) { | 27 XML_Error error_code) { |
27 succeeded_ = false; | 28 succeeded_ = false; |
28 } | 29 } |
29 | 30 |
30 AutofillQueryXmlParser::AutofillQueryXmlParser( | 31 AutofillQueryXmlParser::AutofillQueryXmlParser( |
31 std::vector<AutofillFieldType>* field_types, | 32 std::vector<AutofillServerFieldInfo>* field_infos, |
32 UploadRequired* upload_required, | 33 UploadRequired* upload_required, |
33 std::string* experiment_id) | 34 std::string* experiment_id) |
34 : field_types_(field_types), | 35 : field_infos_(field_infos), |
35 upload_required_(upload_required), | 36 upload_required_(upload_required), |
36 experiment_id_(experiment_id) { | 37 experiment_id_(experiment_id) { |
37 DCHECK(upload_required_); | 38 DCHECK(upload_required_); |
38 DCHECK(experiment_id_); | 39 DCHECK(experiment_id_); |
39 } | 40 } |
40 | 41 |
41 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, | 42 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, |
42 const char* name, | 43 const char* name, |
43 const char** attrs) { | 44 const char** attrs) { |
44 buzz::QName qname = context->ResolveQName(name, false); | 45 buzz::QName qname = context->ResolveQName(name, false); |
(...skipping 23 matching lines...) Expand all Loading... | |
68 } | 69 } |
69 } else if (element.compare("field") == 0) { | 70 } else if (element.compare("field") == 0) { |
70 if (!attrs[0]) { | 71 if (!attrs[0]) { |
71 // Missing the "autofilltype" attribute, abort. | 72 // Missing the "autofilltype" attribute, abort. |
72 context->RaiseError(XML_ERROR_ABORTED); | 73 context->RaiseError(XML_ERROR_ABORTED); |
73 return; | 74 return; |
74 } | 75 } |
75 | 76 |
76 // Determine the field type from the attribute value. There should be one | 77 // Determine the field type from the attribute value. There should be one |
77 // attribute (autofilltype) with an integer value. | 78 // attribute (autofilltype) with an integer value. |
78 AutofillFieldType field_type = UNKNOWN_TYPE; | 79 AutofillServerFieldInfo field_info; |
79 buzz::QName attribute_qname = context->ResolveQName(attrs[0], true); | 80 field_info.field_type = UNKNOWN_TYPE; |
80 const std::string& attribute_name = attribute_qname.LocalPart(); | |
81 | 81 |
82 if (attribute_name.compare("autofilltype") == 0) { | 82 while (*attrs) { |
83 int value = GetIntValue(context, attrs[1]); | 83 buzz::QName attribute_qname = context->ResolveQName(attrs[0], true); |
84 field_type = static_cast<AutofillFieldType>(value); | 84 const std::string& attribute_name = attribute_qname.LocalPart(); |
85 if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE) { | 85 if (attribute_name.compare("autofilltype") == 0) { |
86 field_type = NO_SERVER_DATA; | 86 int value = GetIntValue(context, attrs[1]); |
87 field_info.field_type = static_cast<AutofillFieldType>(value); | |
88 if (field_info.field_type < 0 || | |
89 field_info.field_type > MAX_VALID_FIELD_TYPE) | |
90 field_info.field_type = NO_SERVER_DATA; | |
91 } else if (field_info.field_type == FIELD_WITH_DEFAULT_VALUE && | |
92 attribute_name.compare("defaultvalue") == 0) { | |
93 field_info.default_value.assign(attrs[1]); | |
87 } | 94 } |
95 | |
96 attrs +=2; | |
Albert Bodenhamer
2012/12/06 17:39:05
This is awkward.
If you're going to do C-style po
Raman Kakilate
2012/12/06 18:06:35
I was trying to be consistent with lines 55-69. I
Albert Bodenhamer
2012/12/06 23:15:45
I was thinking more like:
while (*attrs) {
| |
88 } | 97 } |
89 | 98 |
90 // Record this field type. | 99 // Record this field type, default value pair. |
91 field_types_->push_back(field_type); | 100 field_infos_->push_back(field_info); |
92 } | 101 } |
93 } | 102 } |
94 | 103 |
95 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, | 104 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, |
96 const char* attribute) { | 105 const char* attribute) { |
97 char* attr_end = NULL; | 106 char* attr_end = NULL; |
98 int value = strtol(attribute, &attr_end, 10); | 107 int value = strtol(attribute, &attr_end, 10); |
99 if (attr_end != NULL && attr_end == attribute) { | 108 if (attr_end != NULL && attr_end == attribute) { |
100 context->RaiseError(XML_ERROR_SYNTAX); | 109 context->RaiseError(XML_ERROR_SYNTAX); |
101 return 0; | 110 return 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 double AutofillUploadXmlParser::GetDoubleValue(buzz::XmlParseContext* context, | 144 double AutofillUploadXmlParser::GetDoubleValue(buzz::XmlParseContext* context, |
136 const char* attribute) { | 145 const char* attribute) { |
137 char* attr_end = NULL; | 146 char* attr_end = NULL; |
138 double value = strtod(attribute, &attr_end); | 147 double value = strtod(attribute, &attr_end); |
139 if (attr_end != NULL && attr_end == attribute) { | 148 if (attr_end != NULL && attr_end == attribute) { |
140 context->RaiseError(XML_ERROR_SYNTAX); | 149 context->RaiseError(XML_ERROR_SYNTAX); |
141 return 0.0; | 150 return 0.0; |
142 } | 151 } |
143 return value; | 152 return value; |
144 } | 153 } |
OLD | NEW |