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/command_line.h" |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 UTF16ToUTF8(form_name_) + | 515 UTF16ToUTF8(form_name_) + |
516 form_signature_field_names_; | 516 form_signature_field_names_; |
517 | 517 |
518 return Hash64Bit(form_string); | 518 return Hash64Bit(form_string); |
519 } | 519 } |
520 | 520 |
521 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 | 522 // TODO(ramankk): Remove this check once we have better way of identifying the |
523 // cases to trigger experimental form filling. | 523 // cases to trigger experimental form filling. |
524 if (CommandLine::ForCurrentProcess()->HasSwitch( | 524 if (CommandLine::ForCurrentProcess()->HasSwitch( |
525 switches::kEnableExperimentalFormFilling)) | 525 switches::kEnableExperimentalFormFilling)) |
526 return true; | 526 return true; |
527 | 527 |
528 if (autofill_count() < kRequiredFillableFields) | 528 if (autofill_count() < kRequiredFillableFields) |
529 return false; | 529 return false; |
530 | 530 |
531 return ShouldBeParsed(require_method_post); | 531 return ShouldBeParsed(require_method_post); |
532 } | 532 } |
533 | 533 |
534 void FormStructure::UpdateAutofillCount() { | 534 void FormStructure::UpdateAutofillCount() { |
535 autofill_count_ = 0; | 535 autofill_count_ = 0; |
536 for (std::vector<AutofillField*>::const_iterator iter = begin(); | 536 for (std::vector<AutofillField*>::const_iterator iter = begin(); |
537 iter != end(); ++iter) { | 537 iter != end(); ++iter) { |
538 AutofillField* field = *iter; | 538 AutofillField* field = *iter; |
539 if (field && field->IsFieldFillable()) | 539 if (field && field->IsFieldFillable()) |
540 ++autofill_count_; | 540 ++autofill_count_; |
541 } | 541 } |
542 } | 542 } |
543 | 543 |
544 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 | 545 // TODO(ramankk): Remove this check once we have better way of identifying the |
546 // cases to trigger experimental form filling. | 546 // cases to trigger experimental form filling. |
547 if (CommandLine::ForCurrentProcess()->HasSwitch( | 547 if (CommandLine::ForCurrentProcess()->HasSwitch( |
548 switches::kEnableExperimentalFormFilling)) | 548 switches::kEnableExperimentalFormFilling)) |
549 return true; | 549 return true; |
550 | 550 |
551 if (field_count() < kRequiredFillableFields) | 551 if (field_count() < kRequiredFillableFields) |
552 return false; | 552 return false; |
553 | 553 |
554 // Rule out http(s)://*/search?... | 554 // Rule out http(s)://*/search?... |
555 // e.g. http://www.google.com/search?q=... | 555 // e.g. http://www.google.com/search?q=... |
556 // http://search.yahoo.com/search?p=... | 556 // http://search.yahoo.com/search?p=... |
557 if (target_url_.path() == "/search") | 557 if (target_url_.path() == "/search") |
558 return false; | 558 return false; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 } | 807 } |
808 | 808 |
809 size_t FormStructure::field_count() const { | 809 size_t FormStructure::field_count() const { |
810 return fields_.size(); | 810 return fields_.size(); |
811 } | 811 } |
812 | 812 |
813 std::string FormStructure::server_experiment_id() const { | 813 std::string FormStructure::server_experiment_id() const { |
814 return server_experiment_id_; | 814 return server_experiment_id_; |
815 } | 815 } |
816 | 816 |
817 FormData* FormStructure::ToFormData() const { | |
818 // TODO(dbeam): Store user_submitted in ctor if it's important. | |
Ilya Sherman
2012/11/28 06:16:39
It's not important. Just include a comment that i
Dan Beam
2012/11/28 19:59:10
Done.
| |
819 FormData* data = new FormData(); | |
Ilya Sherman
2012/11/28 06:16:39
If you keep the heap allocation, please use a scop
Dan Beam
2012/11/28 19:59:10
Done. How would I do this alternatively? I'm a C
| |
820 data->name = form_name_; | |
821 data->origin = source_url_; | |
822 data->action = target_url_; | |
823 data->method = method_; | |
824 | |
825 for (size_t i = 0; i < fields_.size(); ++i) { | |
826 const FormFieldData* copy = | |
827 new AutofillField(*fields_[i], fields_[i]->unique_name()); | |
Ilya Sherman
2012/11/28 06:16:39
This sure looks like it will leak. Why isn't this
Dan Beam
2012/11/28 19:59:10
Done.
| |
828 data->fields.push_back(*copy); | |
Ilya Sherman
2012/11/28 06:16:39
Methinks the body of this for loop should be:
dat
Dan Beam
2012/11/28 19:59:10
Done.
| |
829 } | |
830 | |
831 return data; | |
832 } | |
833 | |
817 bool FormStructure::operator==(const FormData& form) const { | 834 bool FormStructure::operator==(const FormData& form) const { |
818 // TODO(jhawkins): Is this enough to differentiate a form? | 835 // TODO(jhawkins): Is this enough to differentiate a form? |
819 if (form_name_ == form.name && | 836 if (form_name_ == form.name && |
820 source_url_ == form.origin && | 837 source_url_ == form.origin && |
821 target_url_ == form.action) { | 838 target_url_ == form.action) { |
822 return true; | 839 return true; |
823 } | 840 } |
824 | 841 |
825 // TODO(jhawkins): Compare field names, IDs and labels once we have labels | 842 // TODO(jhawkins): Compare field names, IDs and labels once we have labels |
826 // set up. | 843 // set up. |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1053 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1070 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
1054 field != fields_.end(); ++field) { | 1071 field != fields_.end(); ++field) { |
1055 AutofillType::FieldTypeGroup field_type_group = | 1072 AutofillType::FieldTypeGroup field_type_group = |
1056 AutofillType((*field)->type()).group(); | 1073 AutofillType((*field)->type()).group(); |
1057 if (field_type_group == AutofillType::CREDIT_CARD) | 1074 if (field_type_group == AutofillType::CREDIT_CARD) |
1058 (*field)->set_section((*field)->section() + "-cc"); | 1075 (*field)->set_section((*field)->section() + "-cc"); |
1059 else | 1076 else |
1060 (*field)->set_section((*field)->section() + "-default"); | 1077 (*field)->set_section((*field)->section() + "-default"); |
1061 } | 1078 } |
1062 } | 1079 } |
OLD | NEW |