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_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 method_ = GET; | 100 method_ = GET; |
101 } | 101 } |
102 } | 102 } |
103 | 103 |
104 FormStructure::~FormStructure() {} | 104 FormStructure::~FormStructure() {} |
105 | 105 |
106 bool FormStructure::EncodeUploadRequest(bool auto_fill_used, | 106 bool FormStructure::EncodeUploadRequest(bool auto_fill_used, |
107 std::string* encoded_xml) const { | 107 std::string* encoded_xml) const { |
108 DCHECK(encoded_xml); | 108 DCHECK(encoded_xml); |
109 encoded_xml->clear(); | 109 encoded_xml->clear(); |
110 bool auto_fillable = IsAutoFillable(); | 110 bool auto_fillable = IsAutoFillable(false); |
dhollowa
2010/11/15 18:47:57
These changes should not alter the types of form d
| |
111 DCHECK(auto_fillable); // Caller should've checked for search pages. | 111 DCHECK(auto_fillable); // Caller should've checked for search pages. |
112 if (!auto_fillable) | 112 if (!auto_fillable) |
113 return false; | 113 return false; |
114 | 114 |
115 buzz::XmlElement autofil_request_xml(buzz::QName("autofillupload")); | 115 buzz::XmlElement autofil_request_xml(buzz::QName("autofillupload")); |
116 | 116 |
117 // Attributes for the <autofillupload> element. | 117 // Attributes for the <autofillupload> element. |
118 // | 118 // |
119 // TODO(jhawkins): Work with toolbar devs to make a spec for autofill clients. | 119 // TODO(jhawkins): Work with toolbar devs to make a spec for autofill clients. |
120 // For now these values are hacked from the toolbar code. | 120 // For now these values are hacked from the toolbar code. |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 AutoFillType autofill_type((*field)->type()); | 225 AutoFillType autofill_type((*field)->type()); |
226 if (autofill_type.group() == AutoFillType::CREDIT_CARD) | 226 if (autofill_type.group() == AutoFillType::CREDIT_CARD) |
227 form->has_credit_card_field_ = true; | 227 form->has_credit_card_field_ = true; |
228 if (autofill_type.field_type() != UNKNOWN_TYPE) | 228 if (autofill_type.field_type() != UNKNOWN_TYPE) |
229 form->has_autofillable_field_ = true; | 229 form->has_autofillable_field_ = true; |
230 ++current_type; | 230 ++current_type; |
231 } | 231 } |
232 | 232 |
233 form->UpdateAutoFillCount(); | 233 form->UpdateAutoFillCount(); |
234 } | 234 } |
235 | |
236 return; | |
237 } | 235 } |
238 | 236 |
239 std::string FormStructure::FormSignature() const { | 237 std::string FormStructure::FormSignature() const { |
240 std::string form_string = target_url_.scheme() + | 238 std::string form_string = target_url_.scheme() + |
241 "://" + | 239 "://" + |
242 target_url_.host() + | 240 target_url_.host() + |
243 "&" + | 241 "&" + |
244 UTF16ToUTF8(form_name_) + | 242 UTF16ToUTF8(form_name_) + |
245 form_signature_field_names_; | 243 form_signature_field_names_; |
246 | 244 |
247 return Hash64Bit(form_string); | 245 return Hash64Bit(form_string); |
248 } | 246 } |
249 | 247 |
250 bool FormStructure::IsAutoFillable() const { | 248 bool FormStructure::IsAutoFillable(bool require_method_post) const { |
251 if (autofill_count() < kRequiredFillableFields) | 249 if (autofill_count() < kRequiredFillableFields) |
252 return false; | 250 return false; |
253 | 251 |
254 return ShouldBeParsed(); | 252 return ShouldBeParsed(require_method_post); |
255 } | 253 } |
256 | 254 |
257 bool FormStructure::HasAutoFillableValues() const { | 255 bool FormStructure::HasAutoFillableValues() const { |
258 if (autofill_count_ == 0) | 256 if (autofill_count_ == 0) |
259 return false; | 257 return false; |
260 | 258 |
261 for (std::vector<AutoFillField*>::const_iterator iter = begin(); | 259 for (std::vector<AutoFillField*>::const_iterator iter = begin(); |
262 iter != end(); ++iter) { | 260 iter != end(); ++iter) { |
263 AutoFillField* field = *iter; | 261 AutoFillField* field = *iter; |
264 if (field && !field->IsEmpty() && field->IsFieldFillable()) | 262 if (field && !field->IsEmpty() && field->IsFieldFillable()) |
265 return true; | 263 return true; |
266 } | 264 } |
267 | 265 |
268 return false; | 266 return false; |
269 } | 267 } |
270 | 268 |
271 // TODO(jhawkins): Cache this result. | |
272 bool FormStructure::HasBillingFields() const { | |
273 for (std::vector<AutoFillField*>::const_iterator iter = begin(); | |
274 iter != end(); ++iter) { | |
275 if (!*iter) | |
276 return false; | |
277 | |
278 AutoFillField* field = *iter; | |
279 if (!field) | |
280 continue; | |
281 | |
282 AutoFillType type(field->type()); | |
283 if (type.group() == AutoFillType::ADDRESS_BILLING || | |
284 type.group() == AutoFillType::CREDIT_CARD) | |
285 return true; | |
286 } | |
287 | |
288 return false; | |
289 } | |
290 | |
291 // TODO(jhawkins): Cache this result. | |
292 bool FormStructure::HasNonBillingFields() const { | |
293 for (std::vector<AutoFillField*>::const_iterator iter = begin(); | |
294 iter != end(); ++iter) { | |
295 if (!*iter) | |
296 return false; | |
297 | |
298 AutoFillField* field = *iter; | |
299 if (!field) | |
300 continue; | |
301 | |
302 AutoFillType type(field->type()); | |
303 if (type.group() != AutoFillType::ADDRESS_BILLING && | |
304 type.group() != AutoFillType::CREDIT_CARD) | |
305 return true; | |
306 } | |
307 | |
308 return false; | |
309 } | |
310 | |
311 void FormStructure::UpdateAutoFillCount() { | 269 void FormStructure::UpdateAutoFillCount() { |
312 autofill_count_ = 0; | 270 autofill_count_ = 0; |
313 for (std::vector<AutoFillField*>::const_iterator iter = begin(); | 271 for (std::vector<AutoFillField*>::const_iterator iter = begin(); |
314 iter != end(); ++iter) { | 272 iter != end(); ++iter) { |
315 AutoFillField* field = *iter; | 273 AutoFillField* field = *iter; |
316 if (field && field->IsFieldFillable()) | 274 if (field && field->IsFieldFillable()) |
317 ++autofill_count_; | 275 ++autofill_count_; |
318 } | 276 } |
319 } | 277 } |
320 | 278 |
321 bool FormStructure::ShouldBeParsed() const { | 279 bool FormStructure::ShouldBeParsed(bool require_method_post) const { |
322 if (field_count() < kRequiredFillableFields) | 280 if (field_count() < kRequiredFillableFields) |
323 return false; | 281 return false; |
324 | 282 |
325 // Rule out http(s)://*/search?... | 283 // Rule out http(s)://*/search?... |
326 // e.g. http://www.google.com/search?q=... | 284 // e.g. http://www.google.com/search?q=... |
327 // http://search.yahoo.com/search?p=... | 285 // http://search.yahoo.com/search?p=... |
328 if (target_url_.path() == "/search") | 286 if (target_url_.path() == "/search") |
329 return false; | 287 return false; |
330 | 288 |
331 if (method_ == GET) | 289 return !require_method_post || (method_ == POST); |
332 return false; | |
333 | |
334 return true; | |
335 } | 290 } |
336 | 291 |
337 void FormStructure::set_possible_types(int index, const FieldTypeSet& types) { | 292 void FormStructure::set_possible_types(int index, const FieldTypeSet& types) { |
338 int num_fields = static_cast<int>(field_count()); | 293 int num_fields = static_cast<int>(field_count()); |
339 DCHECK(index >= 0 && index < num_fields); | 294 DCHECK(index >= 0 && index < num_fields); |
340 if (index >= 0 && index < num_fields) | 295 if (index >= 0 && index < num_fields) |
341 fields_[index]->set_possible_types(types); | 296 fields_[index]->set_possible_types(types); |
342 } | 297 } |
343 | 298 |
344 const AutoFillField* FormStructure::field(int index) const { | 299 const AutoFillField* FormStructure::field(int index) const { |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 } else { | 396 } else { |
442 buzz::XmlElement *field_element = new buzz::XmlElement( | 397 buzz::XmlElement *field_element = new buzz::XmlElement( |
443 buzz::QName(kXMLElementField)); | 398 buzz::QName(kXMLElementField)); |
444 field_element->SetAttr(buzz::QName(kAttributeSignature), | 399 field_element->SetAttr(buzz::QName(kAttributeSignature), |
445 field->FieldSignature()); | 400 field->FieldSignature()); |
446 encompassing_xml_element->AddElement(field_element); | 401 encompassing_xml_element->AddElement(field_element); |
447 } | 402 } |
448 } | 403 } |
449 return true; | 404 return true; |
450 } | 405 } |
OLD | NEW |