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 void FormStructure::ToFormData(FormData* out_data) const { | |
818 // |data->user_submitted| will always be false. | |
819 scoped_ptr<FormData> data(new FormData); | |
820 data->name = form_name_; | |
821 data->origin = source_url_; | |
822 data->action = target_url_; | |
823 data->method = method_; | |
Ilya Sherman
2012/11/29 00:08:59
Why not just directly set the members of |out_data
Dan Beam
2012/11/29 00:51:13
Changed to passing value rather than using out par
| |
824 | |
825 for (size_t i = 0; i < fields_.size(); ++i) { | |
826 data->fields.push_back(FormFieldData(*fields_[i])); | |
827 } | |
828 | |
829 out_data = data.release(); | |
Evan Stade
2012/11/28 22:45:51
this doesn't do anything
Dan Beam
2012/11/29 00:51:13
Thanks for the explanation.
| |
830 } | |
831 | |
817 bool FormStructure::operator==(const FormData& form) const { | 832 bool FormStructure::operator==(const FormData& form) const { |
818 // TODO(jhawkins): Is this enough to differentiate a form? | 833 // TODO(jhawkins): Is this enough to differentiate a form? |
819 if (form_name_ == form.name && | 834 if (form_name_ == form.name && |
820 source_url_ == form.origin && | 835 source_url_ == form.origin && |
821 target_url_ == form.action) { | 836 target_url_ == form.action) { |
822 return true; | 837 return true; |
823 } | 838 } |
824 | 839 |
825 // TODO(jhawkins): Compare field names, IDs and labels once we have labels | 840 // TODO(jhawkins): Compare field names, IDs and labels once we have labels |
826 // set up. | 841 // set up. |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1053 for (std::vector<AutofillField*>::iterator field = fields_.begin(); | 1068 for (std::vector<AutofillField*>::iterator field = fields_.begin(); |
1054 field != fields_.end(); ++field) { | 1069 field != fields_.end(); ++field) { |
1055 AutofillType::FieldTypeGroup field_type_group = | 1070 AutofillType::FieldTypeGroup field_type_group = |
1056 AutofillType((*field)->type()).group(); | 1071 AutofillType((*field)->type()).group(); |
1057 if (field_type_group == AutofillType::CREDIT_CARD) | 1072 if (field_type_group == AutofillType::CREDIT_CARD) |
1058 (*field)->set_section((*field)->section() + "-cc"); | 1073 (*field)->set_section((*field)->section() + "-cc"); |
1059 else | 1074 else |
1060 (*field)->set_section((*field)->section() + "-default"); | 1075 (*field)->set_section((*field)->section() + "-default"); |
1061 } | 1076 } |
1062 } | 1077 } |
OLD | NEW |