Chromium Code Reviews| Index: chrome/browser/autofill/autofill_xml_parser.cc |
| diff --git a/chrome/browser/autofill/autofill_xml_parser.cc b/chrome/browser/autofill/autofill_xml_parser.cc |
| index 92a1ede91c0f94dbc96794d4060b2c51af488145..10fb4453dee12a36c6f7203ae9a08b4b3a56b275 100644 |
| --- a/chrome/browser/autofill/autofill_xml_parser.cc |
| +++ b/chrome/browser/autofill/autofill_xml_parser.cc |
| @@ -8,6 +8,7 @@ |
| #include <string.h> |
| #include "base/logging.h" |
| +#include "chrome/browser/autofill/autofill_server_field_info.h" |
| #include "third_party/libjingle/source/talk/xmllite/qname.h" |
| AutofillXmlParser::AutofillXmlParser() |
| @@ -28,10 +29,10 @@ void AutofillXmlParser::Error(buzz::XmlParseContext* context, |
| } |
| AutofillQueryXmlParser::AutofillQueryXmlParser( |
| - std::vector<AutofillFieldType>* field_types, |
| + std::vector<AutofillServerFieldInfo>* field_infos, |
| UploadRequired* upload_required, |
| std::string* experiment_id) |
| - : field_types_(field_types), |
| + : field_infos_(field_infos), |
| upload_required_(upload_required), |
| experiment_id_(experiment_id) { |
| DCHECK(upload_required_); |
| @@ -52,22 +53,21 @@ void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, |
| // |attrs| is a NULL-terminated list of (attribute, value) pairs. |
| while (*attrs) { |
| - buzz::QName attribute_qname = context->ResolveQName(attrs[0], true); |
| + buzz::QName attribute_qname = context->ResolveQName(*attrs, true); |
| + ++attrs; |
| const std::string& attribute_name = attribute_qname.LocalPart(); |
| if (attribute_name.compare("uploadrequired") == 0) { |
| - if (strcmp(attrs[1], "true") == 0) |
| + if (strcmp(*attrs, "true") == 0) |
| *upload_required_ = UPLOAD_REQUIRED; |
| - else if (strcmp(attrs[1], "false") == 0) |
| + else if (strcmp(*attrs, "false") == 0) |
| *upload_required_ = UPLOAD_NOT_REQUIRED; |
| } else if (attribute_name.compare("experimentid") == 0) { |
| - *experiment_id_ = attrs[1]; |
| + *experiment_id_ = *attrs; |
| } |
| - |
| - // Advance to the next (attribute, value) pair. |
| - attrs += 2; |
| + ++attrs; |
| } |
| } else if (element.compare("field") == 0) { |
| - if (!attrs[0]) { |
| + if (!*attrs) { |
| // Missing the "autofilltype" attribute, abort. |
| context->RaiseError(XML_ERROR_ABORTED); |
| return; |
| @@ -75,20 +75,28 @@ void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, |
| // Determine the field type from the attribute value. There should be one |
| // attribute (autofilltype) with an integer value. |
| - AutofillFieldType field_type = UNKNOWN_TYPE; |
| - buzz::QName attribute_qname = context->ResolveQName(attrs[0], true); |
| - const std::string& attribute_name = attribute_qname.LocalPart(); |
| - |
| - if (attribute_name.compare("autofilltype") == 0) { |
| - int value = GetIntValue(context, attrs[1]); |
| - field_type = static_cast<AutofillFieldType>(value); |
| - if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE) { |
| - field_type = NO_SERVER_DATA; |
| + AutofillServerFieldInfo field_info; |
| + field_info.field_type = UNKNOWN_TYPE; |
| + |
| + // |attrs| is a NULL-terminated list of (attribute, value) pairs. |
| + while (*attrs) { |
| + buzz::QName attribute_qname = context->ResolveQName(*attrs, true); |
| + ++attrs; |
| + const std::string& attribute_name = attribute_qname.LocalPart(); |
| + if (attribute_name.compare("autofilltype") == 0) { |
| + int value = GetIntValue(context, *attrs); |
| + field_info.field_type = static_cast<AutofillFieldType>(value); |
| + if (value < 0 || value > MAX_VALID_FIELD_TYPE) |
| + field_info.field_type = NO_SERVER_DATA; |
|
Ilya Sherman
2012/12/15 01:08:36
nit: To further reduce the chances of this getting
Raman Kakilate
2012/12/17 20:11:01
Done.
|
| + } else if (field_info.field_type == FIELD_WITH_DEFAULT_VALUE && |
| + attribute_name.compare("defaultvalue") == 0) { |
| + field_info.default_value = *attrs; |
| } |
| + ++attrs; |
| } |
| - // Record this field type. |
| - field_types_->push_back(field_type); |
| + // Record this field type, default value pair. |
| + field_infos_->push_back(field_info); |
| } |
| } |