| 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(false); | 110 bool auto_fillable = IsAutoFillable(); |
| 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; |
| 235 } | 237 } |
| 236 | 238 |
| 237 std::string FormStructure::FormSignature() const { | 239 std::string FormStructure::FormSignature() const { |
| 238 std::string form_string = target_url_.scheme() + | 240 std::string form_string = target_url_.scheme() + |
| 239 "://" + | 241 "://" + |
| 240 target_url_.host() + | 242 target_url_.host() + |
| 241 "&" + | 243 "&" + |
| 242 UTF16ToUTF8(form_name_) + | 244 UTF16ToUTF8(form_name_) + |
| 243 form_signature_field_names_; | 245 form_signature_field_names_; |
| 244 | 246 |
| 245 return Hash64Bit(form_string); | 247 return Hash64Bit(form_string); |
| 246 } | 248 } |
| 247 | 249 |
| 248 bool FormStructure::IsAutoFillable(bool require_method_post) const { | 250 bool FormStructure::IsAutoFillable() const { |
| 249 if (autofill_count() < kRequiredFillableFields) | 251 if (autofill_count() < kRequiredFillableFields) |
| 250 return false; | 252 return false; |
| 251 | 253 |
| 252 return ShouldBeParsed(require_method_post); | 254 return ShouldBeParsed(); |
| 253 } | 255 } |
| 254 | 256 |
| 255 bool FormStructure::HasAutoFillableValues() const { | 257 bool FormStructure::HasAutoFillableValues() const { |
| 256 if (autofill_count_ == 0) | 258 if (autofill_count_ == 0) |
| 257 return false; | 259 return false; |
| 258 | 260 |
| 259 for (std::vector<AutoFillField*>::const_iterator iter = begin(); | 261 for (std::vector<AutoFillField*>::const_iterator iter = begin(); |
| 260 iter != end(); ++iter) { | 262 iter != end(); ++iter) { |
| 261 AutoFillField* field = *iter; | 263 AutoFillField* field = *iter; |
| 262 if (field && !field->IsEmpty() && field->IsFieldFillable()) | 264 if (field && !field->IsEmpty() && field->IsFieldFillable()) |
| 263 return true; | 265 return true; |
| 264 } | 266 } |
| 265 | 267 |
| 266 return false; | 268 return false; |
| 267 } | 269 } |
| 268 | 270 |
| 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 |
| 269 void FormStructure::UpdateAutoFillCount() { | 311 void FormStructure::UpdateAutoFillCount() { |
| 270 autofill_count_ = 0; | 312 autofill_count_ = 0; |
| 271 for (std::vector<AutoFillField*>::const_iterator iter = begin(); | 313 for (std::vector<AutoFillField*>::const_iterator iter = begin(); |
| 272 iter != end(); ++iter) { | 314 iter != end(); ++iter) { |
| 273 AutoFillField* field = *iter; | 315 AutoFillField* field = *iter; |
| 274 if (field && field->IsFieldFillable()) | 316 if (field && field->IsFieldFillable()) |
| 275 ++autofill_count_; | 317 ++autofill_count_; |
| 276 } | 318 } |
| 277 } | 319 } |
| 278 | 320 |
| 279 bool FormStructure::ShouldBeParsed(bool require_method_post) const { | 321 bool FormStructure::ShouldBeParsed() const { |
| 280 if (field_count() < kRequiredFillableFields) | 322 if (field_count() < kRequiredFillableFields) |
| 281 return false; | 323 return false; |
| 282 | 324 |
| 283 // Rule out http(s)://*/search?... | 325 // Rule out http(s)://*/search?... |
| 284 // e.g. http://www.google.com/search?q=... | 326 // e.g. http://www.google.com/search?q=... |
| 285 // http://search.yahoo.com/search?p=... | 327 // http://search.yahoo.com/search?p=... |
| 286 if (target_url_.path() == "/search") | 328 if (target_url_.path() == "/search") |
| 287 return false; | 329 return false; |
| 288 | 330 |
| 289 return !require_method_post || (method_ == POST); | 331 if (method_ == GET) |
| 332 return false; |
| 333 |
| 334 return true; |
| 290 } | 335 } |
| 291 | 336 |
| 292 void FormStructure::set_possible_types(int index, const FieldTypeSet& types) { | 337 void FormStructure::set_possible_types(int index, const FieldTypeSet& types) { |
| 293 int num_fields = static_cast<int>(field_count()); | 338 int num_fields = static_cast<int>(field_count()); |
| 294 DCHECK(index >= 0 && index < num_fields); | 339 DCHECK(index >= 0 && index < num_fields); |
| 295 if (index >= 0 && index < num_fields) | 340 if (index >= 0 && index < num_fields) |
| 296 fields_[index]->set_possible_types(types); | 341 fields_[index]->set_possible_types(types); |
| 297 } | 342 } |
| 298 | 343 |
| 299 const AutoFillField* FormStructure::field(int index) const { | 344 const AutoFillField* FormStructure::field(int index) const { |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 } else { | 441 } else { |
| 397 buzz::XmlElement *field_element = new buzz::XmlElement( | 442 buzz::XmlElement *field_element = new buzz::XmlElement( |
| 398 buzz::QName(kXMLElementField)); | 443 buzz::QName(kXMLElementField)); |
| 399 field_element->SetAttr(buzz::QName(kAttributeSignature), | 444 field_element->SetAttr(buzz::QName(kAttributeSignature), |
| 400 field->FieldSignature()); | 445 field->FieldSignature()); |
| 401 encompassing_xml_element->AddElement(field_element); | 446 encompassing_xml_element->AddElement(field_element); |
| 402 } | 447 } |
| 403 } | 448 } |
| 404 return true; | 449 return true; |
| 405 } | 450 } |
| OLD | NEW |