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

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

Issue 23033016: Remove autocheckout code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Even more deletes, and Ilya review. Created 7 years, 3 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/core/browser/autofill_xml_parser.h" 5 #include "components/autofill/core/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 "base/strings/string_number_conversions.h"
12 #include "components/autofill/content/browser/autocheckout_page_meta_data.h"
13 #include "components/autofill/core/browser/autofill_server_field_info.h" 11 #include "components/autofill/core/browser/autofill_server_field_info.h"
14 #include "third_party/libjingle/source/talk/xmllite/qname.h" 12 #include "third_party/libjingle/source/talk/xmllite/qname.h"
15 13
16 namespace autofill { 14 namespace autofill {
17 15
18 AutofillXmlParser::AutofillXmlParser() 16 AutofillXmlParser::AutofillXmlParser()
19 : succeeded_(true) { 17 : succeeded_(true) {
20 } 18 }
21 19
22 AutofillXmlParser::~AutofillXmlParser() {} 20 AutofillXmlParser::~AutofillXmlParser() {}
23 21
24 void AutofillXmlParser::CharacterData( 22 void AutofillXmlParser::CharacterData(
25 buzz::XmlParseContext* context, const char* text, int len) { 23 buzz::XmlParseContext* context, const char* text, int len) {
26 } 24 }
27 25
28 void AutofillXmlParser::EndElement(buzz::XmlParseContext* context, 26 void AutofillXmlParser::EndElement(buzz::XmlParseContext* context,
29 const char* name) { 27 const char* name) {
30 } 28 }
31 29
32 void AutofillXmlParser::Error(buzz::XmlParseContext* context, 30 void AutofillXmlParser::Error(buzz::XmlParseContext* context,
33 XML_Error error_code) { 31 XML_Error error_code) {
34 succeeded_ = false; 32 succeeded_ = false;
35 } 33 }
36 34
37 AutofillQueryXmlParser::AutofillQueryXmlParser( 35 AutofillQueryXmlParser::AutofillQueryXmlParser(
38 std::vector<AutofillServerFieldInfo>* field_infos, 36 std::vector<AutofillServerFieldInfo>* field_infos,
39 UploadRequired* upload_required, 37 UploadRequired* upload_required,
40 std::string* experiment_id, 38 std::string* experiment_id)
41 AutocheckoutPageMetaData* page_meta_data)
42 : field_infos_(field_infos), 39 : field_infos_(field_infos),
43 upload_required_(upload_required), 40 upload_required_(upload_required),
44 experiment_id_(experiment_id), 41 experiment_id_(experiment_id) {
45 page_meta_data_(page_meta_data),
46 current_click_element_(NULL),
47 current_page_number_for_page_types_(0),
48 is_in_type_section_(false) {
49 DCHECK(upload_required_); 42 DCHECK(upload_required_);
50 DCHECK(experiment_id_); 43 DCHECK(experiment_id_);
51 DCHECK(page_meta_data_);
52 } 44 }
53 45
54 AutofillQueryXmlParser::~AutofillQueryXmlParser() {} 46 AutofillQueryXmlParser::~AutofillQueryXmlParser() {}
55 47
56 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context, 48 void AutofillQueryXmlParser::StartElement(buzz::XmlParseContext* context,
57 const char* name, 49 const char* name,
58 const char** attrs) { 50 const char** attrs) {
59 buzz::QName qname = context->ResolveQName(name, false); 51 buzz::QName qname = context->ResolveQName(name, false);
60 const std::string& element = qname.LocalPart(); 52 const std::string& element = qname.LocalPart();
61 if (element.compare("autofillqueryresponse") == 0) { 53 if (element.compare("autofillqueryresponse") == 0) {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 field_info.field_type = NO_SERVER_DATA; 97 field_info.field_type = NO_SERVER_DATA;
106 } else if (field_info.field_type == FIELD_WITH_DEFAULT_VALUE && 98 } else if (field_info.field_type == FIELD_WITH_DEFAULT_VALUE &&
107 attribute_name.compare("defaultvalue") == 0) { 99 attribute_name.compare("defaultvalue") == 0) {
108 field_info.default_value = *attrs; 100 field_info.default_value = *attrs;
109 } 101 }
110 ++attrs; 102 ++attrs;
111 } 103 }
112 104
113 // Record this field type, default value pair. 105 // Record this field type, default value pair.
114 field_infos_->push_back(field_info); 106 field_infos_->push_back(field_info);
115 } else if (element.compare("autofill_flow") == 0) {
116 // |attrs| is a NULL-terminated list of (attribute, value) pairs.
117 while (*attrs) {
118 buzz::QName attribute_qname = context->ResolveQName(*attrs, true);
119 ++attrs;
120 const std::string& attribute_name = attribute_qname.LocalPart();
121 if (attribute_name.compare("page_no") == 0)
122 page_meta_data_->current_page_number = GetIntValue(context, *attrs);
123 else if (attribute_name.compare("total_pages") == 0)
124 page_meta_data_->total_pages = GetIntValue(context, *attrs);
125 else if (attribute_name.compare("ignore_ajax") == 0)
126 page_meta_data_->ignore_ajax = strcmp(*attrs, "false") != 0;
127 ++attrs;
128 }
129 } else if (element.compare("page_advance_button") == 0) {
130 page_meta_data_->proceed_element_descriptor = WebElementDescriptor();
131 ParseElementDescriptor(context,
132 attrs,
133 &page_meta_data_->proceed_element_descriptor);
134 } else if (element.compare("click_elements_before_formfill") == 0) {
135 page_meta_data_->click_elements_before_form_fill.push_back(
136 WebElementDescriptor());
137 current_click_element_ = &page_meta_data_->click_elements_before_form_fill.
138 back();
139 } else if (element.compare("click_elements_after_formfill") == 0) {
140 page_meta_data_->click_elements_after_form_fill.push_back(
141 WebElementDescriptor());
142 current_click_element_ = &page_meta_data_->click_elements_after_form_fill.
143 back();
144 } else if (element.compare("web_element") == 0) {
145 ParseElementDescriptor(context, attrs, current_click_element_);
146 } else if (element.compare("flow_page") == 0) {
147 while (*attrs) {
148 buzz::QName attribute_qname = context->ResolveQName(*attrs, true);
149 ++attrs;
150 const std::string& attribute_name = attribute_qname.LocalPart();
151 if (attribute_name.compare("page_no") == 0)
152 current_page_number_for_page_types_ = GetIntValue(context, *attrs);
153 ++attrs;
154 }
155 } else if (element.compare("type") == 0) {
156 is_in_type_section_ = true;
157 } 107 }
158 } 108 }
159 109
160 void AutofillQueryXmlParser::ParseElementDescriptor( 110 void AutofillQueryXmlParser::ParseElementDescriptor(
161 buzz::XmlParseContext* context, 111 buzz::XmlParseContext* context,
162 const char* const* attrs, 112 const char* const* attrs,
163 WebElementDescriptor* element_descriptor) { 113 WebElementDescriptor* element_descriptor) {
164 // If both id and css_selector are set, the first one to appear will take 114 // If both id and css_selector are set, the first one to appear will take
165 // precedence. 115 // precedence.
166 // |attrs| is a NULL-terminated list of (attribute, value) pairs. 116 // |attrs| is a NULL-terminated list of (attribute, value) pairs.
(...skipping 11 matching lines...) Expand all
178 } else if (attribute_name.compare("css_selector") == 0 && 128 } else if (attribute_name.compare("css_selector") == 0 &&
179 !attribute_value.empty()) { 129 !attribute_value.empty()) {
180 element_descriptor->retrieval_method = 130 element_descriptor->retrieval_method =
181 autofill::WebElementDescriptor::CSS_SELECTOR; 131 autofill::WebElementDescriptor::CSS_SELECTOR;
182 element_descriptor->descriptor = attribute_value; 132 element_descriptor->descriptor = attribute_value;
183 break; 133 break;
184 } 134 }
185 } 135 }
186 } 136 }
187 137
188 void AutofillQueryXmlParser::EndElement(buzz::XmlParseContext* context,
189 const char* name) {
190 is_in_type_section_ = false;
191 }
192
193 void AutofillQueryXmlParser::CharacterData(
194 buzz::XmlParseContext* context, const char* text, int len) {
195 if (!is_in_type_section_)
196 return;
197
198 int type = -1;
199 base::StringToInt(std::string(text, len), &type);
200 if (type >= AUTOCHECKOUT_STEP_MIN_VALUE &&
201 type <= AUTOCHECKOUT_STEP_MAX_VALUE) {
202 AutocheckoutStepType step_type =
203 static_cast<AutocheckoutStepType>(type);
204 page_meta_data_->page_types[current_page_number_for_page_types_]
205 .push_back(step_type);
206 }
207 }
208
209 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context, 138 int AutofillQueryXmlParser::GetIntValue(buzz::XmlParseContext* context,
210 const char* attribute) { 139 const char* attribute) {
211 char* attr_end = NULL; 140 char* attr_end = NULL;
212 int value = strtol(attribute, &attr_end, 10); 141 int value = strtol(attribute, &attr_end, 10);
213 if (attr_end != NULL && attr_end == attribute) { 142 if (attr_end != NULL && attr_end == attribute) {
214 context->RaiseError(XML_ERROR_SYNTAX); 143 context->RaiseError(XML_ERROR_SYNTAX);
215 return 0; 144 return 0;
216 } 145 }
217 return value; 146 return value;
218 } 147 }
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 char* attr_end = NULL; 180 char* attr_end = NULL;
252 double value = strtod(attribute, &attr_end); 181 double value = strtod(attribute, &attr_end);
253 if (attr_end != NULL && attr_end == attribute) { 182 if (attr_end != NULL && attr_end == attribute) {
254 context->RaiseError(XML_ERROR_SYNTAX); 183 context->RaiseError(XML_ERROR_SYNTAX);
255 return 0.0; 184 return 0.0;
256 } 185 }
257 return value; 186 return value;
258 } 187 }
259 188
260 } // namespace autofill 189 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698