Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/core/browser/form_structure.h" | 5 #include "components/autofill/core/browser/form_structure.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 617 | 617 |
| 618 return has_text_field; | 618 return has_text_field; |
| 619 } | 619 } |
| 620 | 620 |
| 621 bool FormStructure::ShouldBeCrowdsourced() const { | 621 bool FormStructure::ShouldBeCrowdsourced() const { |
| 622 return (has_password_field_ || | 622 return (has_password_field_ || |
| 623 active_field_count() >= kRequiredFieldsForPredictionRoutines) && | 623 active_field_count() >= kRequiredFieldsForPredictionRoutines) && |
| 624 ShouldBeParsed(); | 624 ShouldBeParsed(); |
| 625 } | 625 } |
| 626 | 626 |
| 627 void FormStructure::UpdateFromCache(const FormStructure& cached_form) { | 627 void FormStructure::UpdateFromCache(const FormStructure& cached_form, |
| 628 const bool apply_is_autofilled) { | |
| 628 // Map from field signatures to cached fields. | 629 // Map from field signatures to cached fields. |
| 629 std::map<std::string, const AutofillField*> cached_fields; | 630 std::map<base::string16, const AutofillField*> cached_fields; |
| 630 for (size_t i = 0; i < cached_form.field_count(); ++i) { | 631 for (size_t i = 0; i < cached_form.field_count(); ++i) { |
| 631 auto* const field = cached_form.field(i); | 632 auto* const field = cached_form.field(i); |
| 632 cached_fields[field->FieldSignatureAsStr()] = field; | 633 cached_fields[field->unique_name()] = field; |
|
sense (YandexTeam)
2017/03/07 07:10:28
unique_name() is logically the same as FormSignatu
| |
| 633 } | 634 } |
| 634 | |
| 635 for (auto& field : *this) { | 635 for (auto& field : *this) { |
| 636 std::map<std::string, const AutofillField*>::const_iterator cached_field = | 636 const auto& cached_field = cached_fields.find(field->unique_name()); |
| 637 cached_fields.find(field->FieldSignatureAsStr()); | |
| 638 if (cached_field != cached_fields.end()) { | 637 if (cached_field != cached_fields.end()) { |
| 639 if (field->form_control_type != "select-one" && | 638 if (field->form_control_type != "select-one" && |
| 640 field->value == cached_field->second->value) { | 639 field->value == cached_field->second->value) { |
| 641 // From the perspective of learning user data, text fields containing | 640 // From the perspective of learning user data, text fields containing |
| 642 // default values are equivalent to empty fields. | 641 // default values are equivalent to empty fields. |
| 643 field->value = base::string16(); | 642 field->value = base::string16(); |
| 644 } | 643 } |
| 645 | 644 |
| 646 // Transfer attributes of the cached AutofillField to the newly created | 645 // Transfer attributes of the cached AutofillField to the newly created |
| 647 // AutofillField. | 646 // AutofillField. |
| 648 field->set_heuristic_type(cached_field->second->heuristic_type()); | 647 field->set_heuristic_type(cached_field->second->heuristic_type()); |
| 649 field->set_server_type(cached_field->second->server_type()); | 648 field->set_server_type(cached_field->second->server_type()); |
| 650 field->SetHtmlType(cached_field->second->html_type(), | 649 field->SetHtmlType(cached_field->second->html_type(), |
| 651 cached_field->second->html_mode()); | 650 cached_field->second->html_mode()); |
| 651 if (apply_is_autofilled) { | |
| 652 field->is_autofilled = cached_field->second->is_autofilled; | |
| 653 } | |
| 652 field->set_previously_autofilled( | 654 field->set_previously_autofilled( |
| 653 cached_field->second->previously_autofilled()); | 655 cached_field->second->previously_autofilled()); |
| 654 field->set_section(cached_field->second->section()); | 656 field->set_section(cached_field->second->section()); |
| 655 } | 657 } |
| 656 } | 658 } |
| 657 | 659 |
| 658 UpdateAutofillCount(); | 660 UpdateAutofillCount(); |
| 659 | 661 |
| 660 // The form signature should match between query and upload requests to the | 662 // The form signature should match between query and upload requests to the |
| 661 // server. On many websites, form elements are dynamically added, removed, or | 663 // server. On many websites, form elements are dynamically added, removed, or |
| 662 // rearranged via JavaScript between page load and form submission, so we | 664 // rearranged via JavaScript between page load and form submission, so we |
| 663 // copy over the |form_signature_field_names_| corresponding to the query | 665 // copy over the |form_signature_field_names_| corresponding to the query |
| 664 // request. | 666 // request. |
| 665 DCHECK_EQ(cached_form.form_name_, form_name_); | |
|
sense (YandexTeam)
2017/03/07 07:10:28
These DCHECKs were removed because the form now ca
| |
| 666 DCHECK_EQ(cached_form.source_url_, source_url_); | |
| 667 DCHECK_EQ(cached_form.target_url_, target_url_); | |
| 668 form_signature_ = cached_form.form_signature_; | 667 form_signature_ = cached_form.form_signature_; |
| 669 } | 668 } |
| 670 | 669 |
| 671 void FormStructure::LogQualityMetrics(const base::TimeTicks& load_time, | 670 void FormStructure::LogQualityMetrics(const base::TimeTicks& load_time, |
| 672 const base::TimeTicks& interaction_time, | 671 const base::TimeTicks& interaction_time, |
| 673 const base::TimeTicks& submission_time, | 672 const base::TimeTicks& submission_time, |
| 674 rappor::RapporServiceImpl* rappor_service, | 673 rappor::RapporServiceImpl* rappor_service, |
| 675 bool did_show_suggestions, | 674 bool did_show_suggestions, |
| 676 bool observed_submission) const { | 675 bool observed_submission) const { |
| 677 size_t num_detected_field_types = 0; | 676 size_t num_detected_field_types = 0; |
| (...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1320 filtered_strings[0].at(prefix_len)) { | 1319 filtered_strings[0].at(prefix_len)) { |
| 1321 // Mismatch found. | 1320 // Mismatch found. |
| 1322 return filtered_strings[i].substr(0, prefix_len); | 1321 return filtered_strings[i].substr(0, prefix_len); |
| 1323 } | 1322 } |
| 1324 } | 1323 } |
| 1325 } | 1324 } |
| 1326 return filtered_strings[0]; | 1325 return filtered_strings[0]; |
| 1327 } | 1326 } |
| 1328 | 1327 |
| 1329 } // namespace autofill | 1328 } // namespace autofill |
| OLD | NEW |