Chromium Code Reviews| 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 "components/autofill/browser/autofill_xml_parser.h" | 5 #include "components/autofill/browser/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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 ++attrs; | 115 ++attrs; |
| 116 const std::string& attribute_name = attribute_qname.LocalPart(); | 116 const std::string& attribute_name = attribute_qname.LocalPart(); |
| 117 if (attribute_name.compare("page_no") == 0) | 117 if (attribute_name.compare("page_no") == 0) |
| 118 page_meta_data_->current_page_number = GetIntValue(context, *attrs); | 118 page_meta_data_->current_page_number = GetIntValue(context, *attrs); |
| 119 else if (attribute_name.compare("total_pages") == 0) | 119 else if (attribute_name.compare("total_pages") == 0) |
| 120 page_meta_data_->total_pages = GetIntValue(context, *attrs); | 120 page_meta_data_->total_pages = GetIntValue(context, *attrs); |
| 121 ++attrs; | 121 ++attrs; |
| 122 } | 122 } |
| 123 } else if (element.compare("page_advance_button") == 0) { | 123 } else if (element.compare("page_advance_button") == 0) { |
| 124 // |attrs| is a NULL-terminated list of (attribute, value) pairs. | 124 // |attrs| is a NULL-terminated list of (attribute, value) pairs. |
| 125 // If both id and css_selector are set, the first one to appear will take | 125 page_meta_data_->proceed_element_descriptor = WebElementDescriptor(); |
| 126 // precedence. | 126 ParseElementDescriptor(context, |
| 127 while (*attrs) { | 127 attrs, |
| 128 buzz::QName attribute_qname = context->ResolveQName(*attrs, true); | 128 &page_meta_data_->proceed_element_descriptor); |
| 129 ++attrs; | 129 } else if (element.compare("click_elements_before_formfill") == 0) { |
| 130 const std::string& attribute_name = attribute_qname.LocalPart(); | 130 HandleClickElement(&page_meta_data_->click_elements_before_form_fill); |
| 131 buzz::QName value_qname = context->ResolveQName(*attrs, true); | 131 } else if (element.compare("click_elements_after_formfill") == 0) { |
| 132 ++attrs; | 132 HandleClickElement(&page_meta_data_->click_elements_after_form_fill); |
| 133 const std::string& attribute_value = value_qname.LocalPart(); | 133 } else if (element.compare("web_element") == 0) { |
| 134 if (attribute_name.compare("id") == 0 && !attribute_value.empty()) { | 134 ParseElementDescriptor(context, attrs, current_click_element_); |
| 135 page_meta_data_->proceed_element_descriptor.retrieval_method = | |
| 136 autofill::WebElementDescriptor::ID; | |
| 137 page_meta_data_->proceed_element_descriptor.descriptor = | |
| 138 attribute_value; | |
| 139 break; | |
| 140 } else if (attribute_name.compare("css_selector") == 0 && | |
| 141 !attribute_value.empty()) { | |
| 142 page_meta_data_->proceed_element_descriptor.retrieval_method = | |
| 143 autofill::WebElementDescriptor::CSS_SELECTOR; | |
| 144 page_meta_data_->proceed_element_descriptor.descriptor = | |
| 145 attribute_value; | |
| 146 break; | |
| 147 } | |
| 148 } | |
| 149 } | 135 } |
| 150 } | 136 } |
| 151 | 137 |
| 138 void AutofillQueryXmlParser::HandleClickElement( | |
| 139 std::vector<WebElementDescriptor>* click_elements) { | |
| 140 click_elements->push_back(WebElementDescriptor()); | |
| 141 current_click_element_ = &click_elements->back(); | |
| 142 } | |
| 143 | |
| 144 WebElementDescriptor* AutofillQueryXmlParser::ParseElementDescriptor( | |
| 145 buzz::XmlParseContext* context, | |
| 146 const char* const* attrs, | |
| 147 WebElementDescriptor* element_descriptor) { | |
| 148 // If both id and css_selector are set, the first one to appear will take | |
| 149 // precedence. | |
| 150 while (*attrs) { | |
| 151 buzz::QName attribute_qname = context->ResolveQName(*attrs, true); | |
| 152 ++attrs; | |
| 153 const std::string& attribute_name = attribute_qname.LocalPart(); | |
| 154 buzz::QName value_qname = context->ResolveQName(*attrs, true); | |
| 155 ++attrs; | |
| 156 const std::string& attribute_value = value_qname.LocalPart(); | |
| 157 if (attribute_name.compare("id") == 0 && !attribute_value.empty()) { | |
| 158 element_descriptor->retrieval_method = autofill::WebElementDescriptor::ID; | |
| 159 element_descriptor->descriptor = attribute_value; | |
| 160 break; | |
| 161 } else if (attribute_name.compare("css_selector") == 0 && | |
| 162 !attribute_value.empty()) { | |
| 163 element_descriptor->retrieval_method = | |
| 164 autofill::WebElementDescriptor::CSS_SELECTOR; | |
| 165 element_descriptor->descriptor = attribute_value; | |
| 166 break; | |
| 167 } | |
| 168 } | |
| 169 return element_descriptor; | |
|
Evan Stade
2013/05/24 23:03:32
doesn't look like this return value is ever used?
benquan
2013/05/30 22:26:53
Done.
| |
| 170 } | |
| 171 | |
| 152 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, | 172 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, |
| 153 const char* attribute) { | 173 const char* attribute) { |
| 154 char* attr_end = NULL; | 174 char* attr_end = NULL; |
| 155 int value = strtol(attribute, &attr_end, 10); | 175 int value = strtol(attribute, &attr_end, 10); |
| 156 if (attr_end != NULL && attr_end == attribute) { | 176 if (attr_end != NULL && attr_end == attribute) { |
| 157 context->RaiseError(XML_ERROR_SYNTAX); | 177 context->RaiseError(XML_ERROR_SYNTAX); |
| 158 return 0; | 178 return 0; |
| 159 } | 179 } |
| 160 return value; | 180 return value; |
| 161 } | 181 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 char* attr_end = NULL; | 214 char* attr_end = NULL; |
| 195 double value = strtod(attribute, &attr_end); | 215 double value = strtod(attribute, &attr_end); |
| 196 if (attr_end != NULL && attr_end == attribute) { | 216 if (attr_end != NULL && attr_end == attribute) { |
| 197 context->RaiseError(XML_ERROR_SYNTAX); | 217 context->RaiseError(XML_ERROR_SYNTAX); |
| 198 return 0.0; | 218 return 0.0; |
| 199 } | 219 } |
| 200 return value; | 220 return value; |
| 201 } | 221 } |
| 202 | 222 |
| 203 } // namespace autofill | 223 } // namespace autofill |
| OLD | NEW |