Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: components/autofill/browser/autofill_xml_parser.cc

Issue 15487004: Autocheckout: parse multiple clicks setting in autofill response. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "components/autofill/browser/autocheckout_page_meta_data.h"
12 #include "components/autofill/browser/autofill_server_field_info.h" 11 #include "components/autofill/browser/autofill_server_field_info.h"
13 #include "third_party/libjingle/source/talk/xmllite/qname.h" 12 #include "third_party/libjingle/source/talk/xmllite/qname.h"
14 13
15 namespace autofill { 14 namespace autofill {
16 15
17 AutofillXmlParser::AutofillXmlParser() 16 AutofillXmlParser::AutofillXmlParser()
18 : succeeded_(true) { 17 : succeeded_(true) {
19 } 18 }
20 19
21 AutofillXmlParser::~AutofillXmlParser() {} 20 AutofillXmlParser::~AutofillXmlParser() {}
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 ++attrs; 114 ++attrs;
116 const std::string& attribute_name = attribute_qname.LocalPart(); 115 const std::string& attribute_name = attribute_qname.LocalPart();
117 if (attribute_name.compare("page_no") == 0) 116 if (attribute_name.compare("page_no") == 0)
118 page_meta_data_->current_page_number = GetIntValue(context, *attrs); 117 page_meta_data_->current_page_number = GetIntValue(context, *attrs);
119 else if (attribute_name.compare("total_pages") == 0) 118 else if (attribute_name.compare("total_pages") == 0)
120 page_meta_data_->total_pages = GetIntValue(context, *attrs); 119 page_meta_data_->total_pages = GetIntValue(context, *attrs);
121 ++attrs; 120 ++attrs;
122 } 121 }
123 } else if (element.compare("page_advance_button") == 0) { 122 } else if (element.compare("page_advance_button") == 0) {
124 // |attrs| is a NULL-terminated list of (attribute, value) pairs. 123 // |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 124 page_meta_data_->proceed_element_descriptor = WebElementDescriptor();
126 // precedence. 125 ParseElementDescriptor(context,
127 while (*attrs) { 126 attrs,
128 buzz::QName attribute_qname = context->ResolveQName(*attrs, true); 127 &page_meta_data_->proceed_element_descriptor);
129 ++attrs; 128 } else if (element.compare("click_elements_before_formfill") == 0) {
130 const std::string& attribute_name = attribute_qname.LocalPart(); 129 ParseClickElement(context,
131 buzz::QName value_qname = context->ResolveQName(*attrs, true); 130 attrs,
132 ++attrs; 131 &page_meta_data_->click_elements_before_formfill);
133 const std::string& attribute_value = value_qname.LocalPart(); 132 } else if (element.compare("click_elements_after_formfill") == 0) {
134 if (attribute_name.compare("id") == 0 && !attribute_value.empty()) { 133 ParseClickElement(context,
135 page_meta_data_->proceed_element_descriptor.retrieval_method = 134 attrs,
136 autofill::WebElementDescriptor::ID; 135 &page_meta_data_->click_elements_after_formfill);
137 page_meta_data_->proceed_element_descriptor.descriptor = 136 } else if (element.compare("web_element") == 0) {
138 attribute_value; 137 ParseElementDescriptor(context,
139 break; 138 attrs,
140 } else if (attribute_name.compare("css_selector") == 0 && 139 &current_click_element_->web_element);
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 } 140 }
150 } 141 }
151 142
143 void AutofillQueryXmlParser::ParseClickElement(
144 buzz::XmlParseContext* context,
145 const char** attrs,
146 std::vector<AutocheckoutPageMetaData::ClickElement>* click_elements) {
147 click_elements->push_back(AutocheckoutPageMetaData::ClickElement());
148 current_click_element_ = &click_elements->back();
149
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 if (attribute_name.compare("wait_time_ms") == 0)
156 current_click_element_->wait_time_ms = GetIntValue(context, *attrs);
157 ++attrs;
158 }
159 }
160
161 WebElementDescriptor* AutofillQueryXmlParser::ParseElementDescriptor(
162 buzz::XmlParseContext* context,
163 const char** attrs,
164 WebElementDescriptor* element_descriptor) {
165 // If both id and css_selector are set, the first one to appear will take
166 // precedence.
167 while (*attrs) {
168 buzz::QName attribute_qname = context->ResolveQName(*attrs, true);
169 ++attrs;
170 const std::string& attribute_name = attribute_qname.LocalPart();
171 buzz::QName value_qname = context->ResolveQName(*attrs, true);
172 ++attrs;
173 const std::string& attribute_value = value_qname.LocalPart();
174 if (attribute_name.compare("id") == 0 && !attribute_value.empty()) {
175 element_descriptor->retrieval_method = autofill::WebElementDescriptor::ID;
176 element_descriptor->descriptor = attribute_value;
177 break;
178 } else if (attribute_name.compare("css_selector") == 0 &&
179 !attribute_value.empty()) {
180 element_descriptor->retrieval_method =
181 autofill::WebElementDescriptor::CSS_SELECTOR;
182 element_descriptor->descriptor = attribute_value;
183 break;
184 }
185 }
186 return element_descriptor;
187 }
188
152 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, 189 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context,
153 const char* attribute) { 190 const char* attribute) {
154 char* attr_end = NULL; 191 char* attr_end = NULL;
155 int value = strtol(attribute, &attr_end, 10); 192 int value = strtol(attribute, &attr_end, 10);
156 if (attr_end != NULL && attr_end == attribute) { 193 if (attr_end != NULL && attr_end == attribute) {
157 context->RaiseError(XML_ERROR_SYNTAX); 194 context->RaiseError(XML_ERROR_SYNTAX);
158 return 0; 195 return 0;
159 } 196 }
160 return value; 197 return value;
161 } 198 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 char* attr_end = NULL; 231 char* attr_end = NULL;
195 double value = strtod(attribute, &attr_end); 232 double value = strtod(attribute, &attr_end);
196 if (attr_end != NULL && attr_end == attribute) { 233 if (attr_end != NULL && attr_end == attribute) {
197 context->RaiseError(XML_ERROR_SYNTAX); 234 context->RaiseError(XML_ERROR_SYNTAX);
198 return 0.0; 235 return 0.0;
199 } 236 }
200 return value; 237 return value;
201 } 238 }
202 239
203 } // namespace autofill 240 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698