OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/autofill/form_structure.h" | 5 #include "chrome/browser/autofill/form_structure.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/sha1.h" | 9 #include "base/sha1.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 if (method == kFormMethodPost) { | 83 if (method == kFormMethodPost) { |
84 method_ = POST; | 84 method_ = POST; |
85 } else { | 85 } else { |
86 // Either the method is 'get', or we don't know. In this case we default | 86 // Either the method is 'get', or we don't know. In this case we default |
87 // to GET. | 87 // to GET. |
88 method_ = GET; | 88 method_ = GET; |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 bool FormStructure::EncodeUploadRequest(bool auto_fill_used, | 92 bool FormStructure::EncodeUploadRequest(bool auto_fill_used, |
| 93 bool query, |
93 std::string* encoded_xml) const { | 94 std::string* encoded_xml) const { |
94 bool auto_fillable = IsAutoFillable(); | 95 bool auto_fillable = IsAutoFillable(); |
95 DCHECK(auto_fillable); // Caller should've checked for search pages. | 96 DCHECK(auto_fillable); // Caller should've checked for search pages. |
96 if (!auto_fillable) | 97 if (!auto_fillable) |
97 return false; | 98 return false; |
98 | 99 |
99 buzz::XmlElement autofill_upload(buzz::QName("autofillupload")); | 100 buzz::XmlElement autofil_request_xml(query ? buzz::QName("autofillquery") : |
| 101 buzz::QName("autofillupload")); |
| 102 buzz::XmlElement *encompassing_xml_element = &autofil_request_xml; |
| 103 if (query) |
| 104 encompassing_xml_element = new buzz::XmlElement(buzz::QName("form")); |
100 | 105 |
101 // Attributes for the <autofillupload> element. | 106 // Attributes for the <autofillupload>/<autofillquery> element. |
102 // | 107 // |
103 // TODO(jhawkins): Work with toolbar devs to make a spec for autofill clients. | 108 // TODO(jhawkins): Work with toolbar devs to make a spec for autofill clients. |
104 // For now these values are hacked from the toolbar code. | 109 // For now these values are hacked from the toolbar code. |
105 autofill_upload.SetAttr(buzz::QName(kAttributeClientVersion), | 110 autofil_request_xml.SetAttr(buzz::QName(kAttributeClientVersion), |
106 "6.1.1715.1442/en (GGLL)"); | 111 "6.1.1715.1442/en (GGLL)"); |
107 | 112 |
108 autofill_upload.SetAttr(buzz::QName(kAttributeFormSignature), | 113 encompassing_xml_element->SetAttr(query ? buzz::QName(kAttributeSignature) : |
109 FormSignature()); | 114 buzz::QName(kAttributeFormSignature), |
| 115 FormSignature()); |
110 | 116 |
111 autofill_upload.SetAttr(buzz::QName(kAttributeAutoFillUsed), | 117 if (!query) { |
112 auto_fill_used ? "true" : "false"); | 118 autofil_request_xml.SetAttr(buzz::QName(kAttributeAutoFillUsed), |
| 119 auto_fill_used ? "true" : "false"); |
113 | 120 |
114 // TODO(jhawkins): Hook this up to the personal data manager. | 121 // TODO(jhawkins): Hook this up to the personal data manager. |
115 // personaldata_manager_->GetDataPresent(); | 122 // personaldata_manager_->GetDataPresent(); |
116 autofill_upload.SetAttr(buzz::QName(kAttributeDataPresent), ""); | 123 autofil_request_xml.SetAttr(buzz::QName(kAttributeDataPresent), ""); |
| 124 } |
117 | 125 |
118 // Add the child nodes for the form fields. | 126 // Add the child nodes for the form fields. |
119 for (size_t index = 0; index < field_count(); index++) { | 127 for (size_t index = 0; index < field_count(); index++) { |
120 const AutoFillField* field = fields_[index]; | 128 const AutoFillField* field = fields_[index]; |
| 129 if (!query) { |
121 FieldTypeSet types = field->possible_types(); | 130 FieldTypeSet types = field->possible_types(); |
122 for (FieldTypeSet::const_iterator type = types.begin(); | 131 for (FieldTypeSet::const_iterator type = types.begin(); |
123 type != types.end(); type++) { | 132 type != types.end(); type++) { |
| 133 buzz::XmlElement *field_element = new buzz::XmlElement( |
| 134 buzz::QName(kXMLElementField)); |
| 135 |
| 136 field_element->SetAttr(buzz::QName(kAttributeSignature), |
| 137 field->FieldSignature()); |
| 138 field_element->SetAttr(buzz::QName(kAttributeAutoFillType), |
| 139 IntToString(*type)); |
| 140 encompassing_xml_element->AddElement(field_element); |
| 141 } |
| 142 } else { |
124 buzz::XmlElement *field_element = new buzz::XmlElement( | 143 buzz::XmlElement *field_element = new buzz::XmlElement( |
125 buzz::QName(kXMLElementField)); | 144 buzz::QName(kXMLElementField)); |
126 | |
127 field_element->SetAttr(buzz::QName(kAttributeSignature), | 145 field_element->SetAttr(buzz::QName(kAttributeSignature), |
128 field->FieldSignature()); | 146 field->FieldSignature()); |
129 | 147 encompassing_xml_element->AddElement(field_element); |
130 field_element->SetAttr(buzz::QName(kAttributeAutoFillType), | |
131 IntToString(*type)); | |
132 | |
133 autofill_upload.AddElement(field_element); | |
134 } | 148 } |
135 } | 149 } |
| 150 if (query) |
| 151 autofil_request_xml.AddElement(encompassing_xml_element); |
136 | 152 |
137 // Obtain the XML structure as a string. | 153 // Obtain the XML structure as a string. |
138 *encoded_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; | 154 *encoded_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; |
139 *encoded_xml += autofill_upload.Str().c_str(); | 155 *encoded_xml += autofil_request_xml.Str().c_str(); |
140 | 156 |
141 return true; | 157 return true; |
142 } | 158 } |
143 | 159 |
144 void FormStructure::GetHeuristicAutoFillTypes() { | 160 void FormStructure::GetHeuristicAutoFillTypes() { |
145 has_credit_card_field_ = false; | 161 has_credit_card_field_ = false; |
146 has_autofillable_field_ = false; | 162 has_autofillable_field_ = false; |
147 | 163 |
148 FieldTypeMap field_type_map; | 164 FieldTypeMap field_type_map; |
149 GetHeuristicFieldInfo(&field_type_map); | 165 GetHeuristicFieldInfo(&field_type_map); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 | 246 |
231 void FormStructure::GetHeuristicFieldInfo(FieldTypeMap* field_type_map) { | 247 void FormStructure::GetHeuristicFieldInfo(FieldTypeMap* field_type_map) { |
232 FormFieldSet fields = FormFieldSet(this); | 248 FormFieldSet fields = FormFieldSet(this); |
233 | 249 |
234 FormFieldSet::const_iterator field; | 250 FormFieldSet::const_iterator field; |
235 for (field = fields.begin(); field != fields.end(); field++) { | 251 for (field = fields.begin(); field != fields.end(); field++) { |
236 bool ok = (*field)->GetFieldInfo(field_type_map); | 252 bool ok = (*field)->GetFieldInfo(field_type_map); |
237 DCHECK(ok); | 253 DCHECK(ok); |
238 } | 254 } |
239 } | 255 } |
OLD | NEW |