| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/sha1.h" | 13 #include "base/sha1.h" |
| 13 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
| 15 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 16 #include "base/time.h" | 17 #include "base/time.h" |
| 17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/browser/autofill/autofill_metrics.h" | 20 #include "chrome/browser/autofill/autofill_metrics.h" |
| 19 #include "chrome/browser/autofill/autofill_type.h" | 21 #include "chrome/browser/autofill/autofill_type.h" |
| 20 #include "chrome/browser/autofill/autofill_xml_parser.h" | 22 #include "chrome/browser/autofill/autofill_xml_parser.h" |
| 21 #include "chrome/browser/autofill/field_types.h" | 23 #include "chrome/browser/autofill/field_types.h" |
| 22 #include "chrome/browser/autofill/form_field.h" | 24 #include "chrome/browser/autofill/form_field.h" |
| 23 #include "chrome/common/form_data.h" | 25 #include "chrome/common/form_data.h" |
| 24 #include "chrome/common/form_data_predictions.h" | 26 #include "chrome/common/form_data_predictions.h" |
| 25 #include "chrome/common/form_field_data.h" | 27 #include "chrome/common/form_field_data.h" |
| 26 #include "chrome/common/form_field_data_predictions.h" | 28 #include "chrome/common/form_field_data_predictions.h" |
| 27 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 29 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 } | 512 } |
| 511 | 513 |
| 512 std::string form_string = scheme + "://" + host + "&" + | 514 std::string form_string = scheme + "://" + host + "&" + |
| 513 UTF16ToUTF8(form_name_) + | 515 UTF16ToUTF8(form_name_) + |
| 514 form_signature_field_names_; | 516 form_signature_field_names_; |
| 515 | 517 |
| 516 return Hash64Bit(form_string); | 518 return Hash64Bit(form_string); |
| 517 } | 519 } |
| 518 | 520 |
| 519 bool FormStructure::IsAutofillable(bool require_method_post) const { | 521 bool FormStructure::IsAutofillable(bool require_method_post) const { |
| 522 // TODO(ramankk): Remove this check once we have better way of identifying the |
| 523 // cases to trigger experimental form filling. |
| 524 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 525 switches::kEnableExperimentalFormFilling)) |
| 526 return true; |
| 527 |
| 520 if (autofill_count() < kRequiredFillableFields) | 528 if (autofill_count() < kRequiredFillableFields) |
| 521 return false; | 529 return false; |
| 522 | 530 |
| 523 return ShouldBeParsed(require_method_post); | 531 return ShouldBeParsed(require_method_post); |
| 524 } | 532 } |
| 525 | 533 |
| 526 void FormStructure::UpdateAutofillCount() { | 534 void FormStructure::UpdateAutofillCount() { |
| 527 autofill_count_ = 0; | 535 autofill_count_ = 0; |
| 528 for (std::vector<AutofillField*>::const_iterator iter = begin(); | 536 for (std::vector<AutofillField*>::const_iterator iter = begin(); |
| 529 iter != end(); ++iter) { | 537 iter != end(); ++iter) { |
| 530 AutofillField* field = *iter; | 538 AutofillField* field = *iter; |
| 531 if (field && field->IsFieldFillable()) | 539 if (field && field->IsFieldFillable()) |
| 532 ++autofill_count_; | 540 ++autofill_count_; |
| 533 } | 541 } |
| 534 } | 542 } |
| 535 | 543 |
| 536 bool FormStructure::ShouldBeParsed(bool require_method_post) const { | 544 bool FormStructure::ShouldBeParsed(bool require_method_post) const { |
| 545 // TODO(ramankk): Remove this check once we have better way of identifying the |
| 546 // cases to trigger experimental form filling. |
| 547 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 548 switches::kEnableExperimentalFormFilling)) |
| 549 return true; |
| 550 |
| 537 if (field_count() < kRequiredFillableFields) | 551 if (field_count() < kRequiredFillableFields) |
| 538 return false; | 552 return false; |
| 539 | 553 |
| 540 // Rule out http(s)://*/search?... | 554 // Rule out http(s)://*/search?... |
| 541 // e.g. http://www.google.com/search?q=... | 555 // e.g. http://www.google.com/search?q=... |
| 542 // http://search.yahoo.com/search?p=... | 556 // http://search.yahoo.com/search?p=... |
| 543 if (target_url_.path() == "/search") | 557 if (target_url_.path() == "/search") |
| 544 return false; | 558 return false; |
| 545 | 559 |
| 546 // Make sure there as at least one text field. | 560 // Make sure there as at least one text field. |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1053 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
| 1040 field != fields_.end(); ++field) { | 1054 field != fields_.end(); ++field) { |
| 1041 AutofillType::FieldTypeGroup field_type_group = | 1055 AutofillType::FieldTypeGroup field_type_group = |
| 1042 AutofillType((*field)->type()).group(); | 1056 AutofillType((*field)->type()).group(); |
| 1043 if (field_type_group == AutofillType::CREDIT_CARD) | 1057 if (field_type_group == AutofillType::CREDIT_CARD) |
| 1044 (*field)->set_section((*field)->section() + "-cc"); | 1058 (*field)->set_section((*field)->section() + "-cc"); |
| 1045 else | 1059 else |
| 1046 (*field)->set_section((*field)->section() + "-default"); | 1060 (*field)->set_section((*field)->section() + "-default"); |
| 1047 } | 1061 } |
| 1048 } | 1062 } |
| OLD | NEW |