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 23 matching lines...) Expand all Loading... |
34 } | 34 } |
35 | 35 |
36 AutofillQueryXmlParser::AutofillQueryXmlParser( | 36 AutofillQueryXmlParser::AutofillQueryXmlParser( |
37 std::vector<AutofillServerFieldInfo>* field_infos, | 37 std::vector<AutofillServerFieldInfo>* field_infos, |
38 UploadRequired* upload_required, | 38 UploadRequired* upload_required, |
39 std::string* experiment_id, | 39 std::string* experiment_id, |
40 AutocheckoutPageMetaData* page_meta_data) | 40 AutocheckoutPageMetaData* page_meta_data) |
41 : field_infos_(field_infos), | 41 : field_infos_(field_infos), |
42 upload_required_(upload_required), | 42 upload_required_(upload_required), |
43 experiment_id_(experiment_id), | 43 experiment_id_(experiment_id), |
44 page_meta_data_(page_meta_data) { | 44 page_meta_data_(page_meta_data), |
| 45 current_click_element_(NULL) { |
45 DCHECK(upload_required_); | 46 DCHECK(upload_required_); |
46 DCHECK(experiment_id_); | 47 DCHECK(experiment_id_); |
47 DCHECK(page_meta_data_); | 48 DCHECK(page_meta_data_); |
48 } | 49 } |
49 | 50 |
50 AutofillQueryXmlParser::~AutofillQueryXmlParser() {} | 51 AutofillQueryXmlParser::~AutofillQueryXmlParser() {} |
51 | 52 |
52 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, | 53 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, |
53 const char* name, | 54 const char* name, |
54 const char** attrs) { | 55 const char** attrs) { |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 buzz::QName attribute_qname = context->ResolveQName(*attrs, true); | 115 buzz::QName attribute_qname = context->ResolveQName(*attrs, true); |
115 ++attrs; | 116 ++attrs; |
116 const std::string& attribute_name = attribute_qname.LocalPart(); | 117 const std::string& attribute_name = attribute_qname.LocalPart(); |
117 if (attribute_name.compare("page_no") == 0) | 118 if (attribute_name.compare("page_no") == 0) |
118 page_meta_data_->current_page_number = GetIntValue(context, *attrs); | 119 page_meta_data_->current_page_number = GetIntValue(context, *attrs); |
119 else if (attribute_name.compare("total_pages") == 0) | 120 else if (attribute_name.compare("total_pages") == 0) |
120 page_meta_data_->total_pages = GetIntValue(context, *attrs); | 121 page_meta_data_->total_pages = GetIntValue(context, *attrs); |
121 ++attrs; | 122 ++attrs; |
122 } | 123 } |
123 } else if (element.compare("page_advance_button") == 0) { | 124 } else if (element.compare("page_advance_button") == 0) { |
124 // |attrs| is a NULL-terminated list of (attribute, value) pairs. | 125 page_meta_data_->proceed_element_descriptor = WebElementDescriptor(); |
125 // If both id and css_selector are set, the first one to appear will take | 126 ParseElementDescriptor(context, |
126 // precedence. | 127 attrs, |
127 while (*attrs) { | 128 &page_meta_data_->proceed_element_descriptor); |
128 buzz::QName attribute_qname = context->ResolveQName(*attrs, true); | 129 } else if (element.compare("click_elements_before_formfill") == 0) { |
129 ++attrs; | 130 page_meta_data_->click_elements_before_form_fill.push_back( |
130 const std::string& attribute_name = attribute_qname.LocalPart(); | 131 WebElementDescriptor()); |
131 buzz::QName value_qname = context->ResolveQName(*attrs, true); | 132 current_click_element_ = &page_meta_data_->click_elements_before_form_fill. |
132 ++attrs; | 133 back(); |
133 const std::string& attribute_value = value_qname.LocalPart(); | 134 } else if (element.compare("click_elements_after_formfill") == 0) { |
134 if (attribute_name.compare("id") == 0 && !attribute_value.empty()) { | 135 page_meta_data_->click_elements_after_form_fill.push_back( |
135 page_meta_data_->proceed_element_descriptor.retrieval_method = | 136 WebElementDescriptor()); |
136 autofill::WebElementDescriptor::ID; | 137 current_click_element_ = &page_meta_data_->click_elements_after_form_fill. |
137 page_meta_data_->proceed_element_descriptor.descriptor = | 138 back(); |
138 attribute_value; | 139 } else if (element.compare("web_element") == 0) { |
139 break; | 140 ParseElementDescriptor(context, attrs, current_click_element_); |
140 } else if (attribute_name.compare("css_selector") == 0 && | 141 } |
141 !attribute_value.empty()) { | 142 } |
142 page_meta_data_->proceed_element_descriptor.retrieval_method = | 143 |
143 autofill::WebElementDescriptor::CSS_SELECTOR; | 144 void AutofillQueryXmlParser::ParseElementDescriptor( |
144 page_meta_data_->proceed_element_descriptor.descriptor = | 145 buzz::XmlParseContext* context, |
145 attribute_value; | 146 const char* const* attrs, |
146 break; | 147 WebElementDescriptor* element_descriptor) { |
147 } | 148 // If both id and css_selector are set, the first one to appear will take |
| 149 // precedence. |
| 150 // |attrs| is a NULL-terminated list of (attribute, value) pairs. |
| 151 while (*attrs) { |
| 152 buzz::QName attribute_qname = context->ResolveQName(*attrs, true); |
| 153 ++attrs; |
| 154 const std::string& attribute_name = attribute_qname.LocalPart(); |
| 155 buzz::QName value_qname = context->ResolveQName(*attrs, true); |
| 156 ++attrs; |
| 157 const std::string& attribute_value = value_qname.LocalPart(); |
| 158 if (attribute_name.compare("id") == 0 && !attribute_value.empty()) { |
| 159 element_descriptor->retrieval_method = autofill::WebElementDescriptor::ID; |
| 160 element_descriptor->descriptor = attribute_value; |
| 161 break; |
| 162 } else if (attribute_name.compare("css_selector") == 0 && |
| 163 !attribute_value.empty()) { |
| 164 element_descriptor->retrieval_method = |
| 165 autofill::WebElementDescriptor::CSS_SELECTOR; |
| 166 element_descriptor->descriptor = attribute_value; |
| 167 break; |
148 } | 168 } |
149 } | 169 } |
150 } | 170 } |
151 | 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); |
(...skipping 36 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 |