| 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 15 matching lines...) Expand all Loading... |
| 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<AutofillFieldType>* field_types, |
| 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_types_(field_types), |
| 35 upload_required_(upload_required), | 35 upload_required_(upload_required), |
| 36 current_page_number_(-1), |
| 37 total_pages_(-1), |
| 36 experiment_id_(experiment_id) { | 38 experiment_id_(experiment_id) { |
| 37 DCHECK(upload_required_); | 39 DCHECK(upload_required_); |
| 38 DCHECK(experiment_id_); | 40 DCHECK(experiment_id_); |
| 39 } | 41 } |
| 40 | 42 |
| 41 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, | 43 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, |
| 42 const char* name, | 44 const char* name, |
| 43 const char** attrs) { | 45 const char** attrs) { |
| 44 buzz::QName qname = context->ResolveQName(name, false); | 46 buzz::QName qname = context->ResolveQName(name, false); |
| 45 const std::string& element = qname.LocalPart(); | 47 const std::string& element = qname.LocalPart(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 if (attribute_name.compare("autofilltype") == 0) { | 84 if (attribute_name.compare("autofilltype") == 0) { |
| 83 int value = GetIntValue(context, attrs[1]); | 85 int value = GetIntValue(context, attrs[1]); |
| 84 field_type = static_cast<AutofillFieldType>(value); | 86 field_type = static_cast<AutofillFieldType>(value); |
| 85 if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE) { | 87 if (field_type < 0 || field_type > MAX_VALID_FIELD_TYPE) { |
| 86 field_type = NO_SERVER_DATA; | 88 field_type = NO_SERVER_DATA; |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 | 91 |
| 90 // Record this field type. | 92 // Record this field type. |
| 91 field_types_->push_back(field_type); | 93 field_types_->push_back(field_type); |
| 94 } else if (element.compare("autofill_flow") == 0) { |
| 95 // |attrs| is a NULL-terminated list of (attribute, value) pairs. |
| 96 while (*attrs) { |
| 97 buzz::QName attribute_qname = context->ResolveQName(*attrs, true); |
| 98 ++attrs; |
| 99 const std::string& attribute_name = attribute_qname.LocalPart(); |
| 100 if (attribute_name.compare("page_no") == 0) |
| 101 current_page_number_ = GetIntValue(context, *attrs); |
| 102 else if (attribute_name.compare("total_pages") == 0) |
| 103 total_pages_ = GetIntValue(context, *attrs); |
| 104 ++attrs; |
| 105 } |
| 92 } | 106 } |
| 93 } | 107 } |
| 94 | 108 |
| 95 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, | 109 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, |
| 96 const char* attribute) { | 110 const char* attribute) { |
| 97 char* attr_end = NULL; | 111 char* attr_end = NULL; |
| 98 int value = strtol(attribute, &attr_end, 10); | 112 int value = strtol(attribute, &attr_end, 10); |
| 99 if (attr_end != NULL && attr_end == attribute) { | 113 if (attr_end != NULL && attr_end == attribute) { |
| 100 context->RaiseError(XML_ERROR_SYNTAX); | 114 context->RaiseError(XML_ERROR_SYNTAX); |
| 101 return 0; | 115 return 0; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 double AutofillUploadXmlParser::GetDoubleValue(buzz::XmlParseContext* context, | 149 double AutofillUploadXmlParser::GetDoubleValue(buzz::XmlParseContext* context, |
| 136 const char* attribute) { | 150 const char* attribute) { |
| 137 char* attr_end = NULL; | 151 char* attr_end = NULL; |
| 138 double value = strtod(attribute, &attr_end); | 152 double value = strtod(attribute, &attr_end); |
| 139 if (attr_end != NULL && attr_end == attribute) { | 153 if (attr_end != NULL && attr_end == attribute) { |
| 140 context->RaiseError(XML_ERROR_SYNTAX); | 154 context->RaiseError(XML_ERROR_SYNTAX); |
| 141 return 0.0; | 155 return 0.0; |
| 142 } | 156 } |
| 143 return value; | 157 return value; |
| 144 } | 158 } |
| OLD | NEW |