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" |
(...skipping 10 matching lines...) Expand all Loading... | |
21 void AutofillXmlParser::EndElement(buzz::XmlParseContext* context, | 21 void AutofillXmlParser::EndElement(buzz::XmlParseContext* context, |
22 const char* name) { | 22 const char* name) { |
23 } | 23 } |
24 | 24 |
25 void AutofillXmlParser::Error(buzz::XmlParseContext* context, | 25 void AutofillXmlParser::Error(buzz::XmlParseContext* context, |
26 XML_Error error_code) { | 26 XML_Error error_code) { |
27 succeeded_ = false; | 27 succeeded_ = false; |
28 } | 28 } |
29 | 29 |
30 AutofillQueryXmlParser::AutofillQueryXmlParser( | 30 AutofillQueryXmlParser::AutofillQueryXmlParser( |
31 std::vector<AutofillFieldType>* field_types, | 31 std::vector<AutofillFieldInfo>* field_infos, |
32 UploadRequired* upload_required, | 32 UploadRequired* upload_required, |
33 std::string* experiment_id) | 33 std::string* experiment_id) |
34 : field_types_(field_types), | 34 : field_infos_(field_infos), |
35 upload_required_(upload_required), | 35 upload_required_(upload_required), |
36 experiment_id_(experiment_id) { | 36 experiment_id_(experiment_id) { |
37 DCHECK(upload_required_); | 37 DCHECK(upload_required_); |
38 DCHECK(experiment_id_); | 38 DCHECK(experiment_id_); |
39 } | 39 } |
40 | 40 |
41 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, | 41 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, |
42 const char* name, | 42 const char* name, |
43 const char** attrs) { | 43 const char** attrs) { |
44 buzz::QName qname = context->ResolveQName(name, false); | 44 buzz::QName qname = context->ResolveQName(name, false); |
(...skipping 26 matching lines...) Expand all Loading... | |
71 // Missing the "autofilltype" attribute, abort. | 71 // Missing the "autofilltype" attribute, abort. |
72 context->RaiseError(XML_ERROR_ABORTED); | 72 context->RaiseError(XML_ERROR_ABORTED); |
73 return; | 73 return; |
74 } | 74 } |
75 | 75 |
76 // Determine the field type from the attribute value. There should be one | 76 // Determine the field type from the attribute value. There should be one |
77 // attribute (autofilltype) with an integer value. | 77 // attribute (autofilltype) with an integer value. |
78 AutofillFieldType field_type = UNKNOWN_TYPE; | 78 AutofillFieldType field_type = UNKNOWN_TYPE; |
79 buzz::QName attribute_qname = context->ResolveQName(attrs[0], true); | 79 buzz::QName attribute_qname = context->ResolveQName(attrs[0], true); |
80 const std::string& attribute_name = attribute_qname.LocalPart(); | 80 const std::string& attribute_name = attribute_qname.LocalPart(); |
81 std::string default_value; | |
81 | 82 |
82 if (attribute_name.compare("autofilltype") == 0) { | 83 if (attribute_name.compare("autofilltype") == 0) { |
83 int value = GetIntValue(context, attrs[1]); | 84 int value = GetIntValue(context, attrs[1]); |
84 field_type = static_cast<AutofillFieldType>(value); | 85 field_type = static_cast<AutofillFieldType>(value); |
85 if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE) { | 86 if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE) { |
86 field_type = NO_SERVER_DATA; | 87 field_type = NO_SERVER_DATA; |
87 } | 88 } |
88 } | 89 } |
89 | 90 |
90 // Record this field type. | 91 // If default value is specified in the response, extract it. |
91 field_types_->push_back(field_type); | 92 if (field_type == FIELD_WITH_DEFAULT_VALUE && attrs[2]) { |
Albert Bodenhamer
2012/11/30 19:01:08
As the list of attributes gets longer the magic nu
Raman Kakilate
2012/11/30 22:36:53
ATTRIBUTE_1_NAME, ATTRIBUTE_1_VALUE, ATTRIBUTE_2_N
Ilya Sherman
2012/12/01 00:54:12
How about names like ATTRIBUTE_NAME_DEFAULT_FIELD_
Raman Kakilate
2012/12/06 01:54:05
changed the implementation to loop over attribute
| |
93 buzz::QName attrib_qname = context->ResolveQName(attrs[2], true); | |
94 const std::string& attrib = attrib_qname.LocalPart(); | |
95 if (attrib.compare("defaultvalue") == 0) { | |
96 default_value.assign(attrs[3]); | |
97 } | |
98 } | |
99 | |
100 // Record this field type, default value pair. | |
101 field_infos_->push_back(AutofillFieldInfo(field_type, default_value)); | |
92 } | 102 } |
93 } | 103 } |
94 | 104 |
95 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, | 105 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, |
96 const char* attribute) { | 106 const char* attribute) { |
97 char* attr_end = NULL; | 107 char* attr_end = NULL; |
98 int value = strtol(attribute, &attr_end, 10); | 108 int value = strtol(attribute, &attr_end, 10); |
99 if (attr_end != NULL && attr_end == attribute) { | 109 if (attr_end != NULL && attr_end == attribute) { |
100 context->RaiseError(XML_ERROR_SYNTAX); | 110 context->RaiseError(XML_ERROR_SYNTAX); |
101 return 0; | 111 return 0; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 double AutofillUploadXmlParser::GetDoubleValue(buzz::XmlParseContext* context, | 145 double AutofillUploadXmlParser::GetDoubleValue(buzz::XmlParseContext* context, |
136 const char* attribute) { | 146 const char* attribute) { |
137 char* attr_end = NULL; | 147 char* attr_end = NULL; |
138 double value = strtod(attribute, &attr_end); | 148 double value = strtod(attribute, &attr_end); |
139 if (attr_end != NULL && attr_end == attribute) { | 149 if (attr_end != NULL && attr_end == attribute) { |
140 context->RaiseError(XML_ERROR_SYNTAX); | 150 context->RaiseError(XML_ERROR_SYNTAX); |
141 return 0.0; | 151 return 0.0; |
142 } | 152 } |
143 return value; | 153 return value; |
144 } | 154 } |
OLD | NEW |