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

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: remove return value from ParseElementDescriptor() Created 7 years, 6 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"
(...skipping 23 matching lines...) Expand all
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) {
Ilya Sherman 2013/05/31 23:14:49 Make sure to initialize |current_click_element_| h
benquan 2013/06/01 01:08:39 Done.
45 DCHECK(upload_required_); 45 DCHECK(upload_required_);
46 DCHECK(experiment_id_); 46 DCHECK(experiment_id_);
47 DCHECK(page_meta_data_); 47 DCHECK(page_meta_data_);
48 } 48 }
49 49
50 AutofillQueryXmlParser::~AutofillQueryXmlParser() {} 50 AutofillQueryXmlParser::~AutofillQueryXmlParser() {}
51 51
52 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, 52 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context,
53 const char* name, 53 const char* name,
54 const char** attrs) { 54 const char** attrs) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 buzz::QName attribute_qname = context->ResolveQName(*attrs, true); 114 buzz::QName attribute_qname = context->ResolveQName(*attrs, true);
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.
Ilya Sherman 2013/05/31 23:14:49 nit: This comment should be moved into ParseElemen
benquan 2013/06/01 01:08:39 Done.
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 = 135 }
136 autofill::WebElementDescriptor::ID; 136 }
137 page_meta_data_->proceed_element_descriptor.descriptor = 137
138 attribute_value; 138 void AutofillQueryXmlParser::HandleClickElement(
139 break; 139 std::vector<WebElementDescriptor>* click_elements) {
140 } else if (attribute_name.compare("css_selector") == 0 && 140 click_elements->push_back(WebElementDescriptor());
141 !attribute_value.empty()) { 141 current_click_element_ = &click_elements->back();
Ilya Sherman 2013/05/31 23:14:49 IMO it would be clearer to just inline this code i
benquan 2013/06/01 01:08:39 Done.
142 page_meta_data_->proceed_element_descriptor.retrieval_method = 142 }
143 autofill::WebElementDescriptor::CSS_SELECTOR; 143
144 page_meta_data_->proceed_element_descriptor.descriptor = 144 void AutofillQueryXmlParser::ParseElementDescriptor(
145 attribute_value; 145 buzz::XmlParseContext* context,
146 break; 146 const char* const* attrs,
147 } 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;
148 } 167 }
149 } 168 }
150 } 169 }
151 170
152 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, 171 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context,
153 const char* attribute) { 172 const char* attribute) {
154 char* attr_end = NULL; 173 char* attr_end = NULL;
155 int value = strtol(attribute, &attr_end, 10); 174 int value = strtol(attribute, &attr_end, 10);
156 if (attr_end != NULL && attr_end == attribute) { 175 if (attr_end != NULL && attr_end == attribute) {
157 context->RaiseError(XML_ERROR_SYNTAX); 176 context->RaiseError(XML_ERROR_SYNTAX);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 char* attr_end = NULL; 213 char* attr_end = NULL;
195 double value = strtod(attribute, &attr_end); 214 double value = strtod(attribute, &attr_end);
196 if (attr_end != NULL && attr_end == attribute) { 215 if (attr_end != NULL && attr_end == attribute) {
197 context->RaiseError(XML_ERROR_SYNTAX); 216 context->RaiseError(XML_ERROR_SYNTAX);
198 return 0.0; 217 return 0.0;
199 } 218 }
200 return value; 219 return value;
201 } 220 }
202 221
203 } // namespace autofill 222 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/autofill_xml_parser.h ('k') | components/autofill/browser/autofill_xml_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698