| 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 "components/autofill/browser/form_structure.h" | 5 #include "components/autofill/browser/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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 server_experiment_id_("no server response"), | 298 server_experiment_id_("no server response"), |
| 299 has_author_specified_types_(false), | 299 has_author_specified_types_(false), |
| 300 autocheckout_url_prefix_(autocheckout_url_prefix), | 300 autocheckout_url_prefix_(autocheckout_url_prefix), |
| 301 filled_by_autocheckout_(false) { | 301 filled_by_autocheckout_(false) { |
| 302 // Copy the form fields. | 302 // Copy the form fields. |
| 303 std::map<base::string16, size_t> unique_names; | 303 std::map<base::string16, size_t> unique_names; |
| 304 for (std::vector<FormFieldData>::const_iterator field = | 304 for (std::vector<FormFieldData>::const_iterator field = |
| 305 form.fields.begin(); | 305 form.fields.begin(); |
| 306 field != form.fields.end(); field++) { | 306 field != form.fields.end(); field++) { |
| 307 | 307 |
| 308 // Skip checkable and password elements when Autocheckout is not enabled, | 308 if (!ShouldSkipField(*field)) { |
| 309 // else these fields will interfere with existing field signatures with | |
| 310 // Autofill servers. | |
| 311 if ((!field->is_checkable && field->form_control_type != "password") || | |
| 312 IsAutocheckoutEnabled()) { | |
| 313 // Add all supported form fields (including with empty names) to the | 309 // Add all supported form fields (including with empty names) to the |
| 314 // signature. This is a requirement for Autofill servers. | 310 // signature. This is a requirement for Autofill servers. |
| 315 form_signature_field_names_.append("&"); | 311 form_signature_field_names_.append("&"); |
| 316 form_signature_field_names_.append(UTF16ToUTF8(field->name)); | 312 form_signature_field_names_.append(UTF16ToUTF8(field->name)); |
| 317 | 313 |
| 318 ++active_field_count_; | 314 ++active_field_count_; |
| 319 } | 315 } |
| 320 | 316 |
| 321 // Generate a unique name for this field by appending a counter to the name. | 317 // Generate a unique name for this field by appending a counter to the name. |
| 322 // Make sure to prepend the counter with a non-numeric digit so that we are | 318 // Make sure to prepend the counter with a non-numeric digit so that we are |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 // Copy the field types into the actual form. | 548 // Copy the field types into the actual form. |
| 553 std::vector<AutofillServerFieldInfo>::iterator current_info = | 549 std::vector<AutofillServerFieldInfo>::iterator current_info = |
| 554 field_infos.begin(); | 550 field_infos.begin(); |
| 555 for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); | 551 for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); |
| 556 iter != forms.end(); ++iter) { | 552 iter != forms.end(); ++iter) { |
| 557 FormStructure* form = *iter; | 553 FormStructure* form = *iter; |
| 558 form->upload_required_ = upload_required; | 554 form->upload_required_ = upload_required; |
| 559 form->server_experiment_id_ = experiment_id; | 555 form->server_experiment_id_ = experiment_id; |
| 560 | 556 |
| 561 for (std::vector<AutofillField*>::iterator field = form->fields_.begin(); | 557 for (std::vector<AutofillField*>::iterator field = form->fields_.begin(); |
| 562 field != form->fields_.end(); ++field, ++current_info) { | 558 field != form->fields_.end(); ++field) { |
| 559 if (form->ShouldSkipField(**field)) |
| 560 continue; |
| 561 |
| 563 // In some cases *successful* response does not return all the fields. | 562 // In some cases *successful* response does not return all the fields. |
| 564 // Quit the update of the types then. | 563 // Quit the update of the types then. |
| 565 if (current_info == field_infos.end()) | 564 if (current_info == field_infos.end()) |
| 566 break; | 565 break; |
| 567 | 566 |
| 568 // UNKNOWN_TYPE is reserved for use by the client. | 567 // UNKNOWN_TYPE is reserved for use by the client. |
| 569 DCHECK_NE(current_info->field_type, UNKNOWN_TYPE); | 568 DCHECK_NE(current_info->field_type, UNKNOWN_TYPE); |
| 570 | 569 |
| 571 AutofillFieldType heuristic_type = (*field)->type(); | 570 AutofillFieldType heuristic_type = (*field)->type(); |
| 572 if (heuristic_type != UNKNOWN_TYPE) | 571 if (heuristic_type != UNKNOWN_TYPE) |
| 573 heuristics_detected_fillable_field = true; | 572 heuristics_detected_fillable_field = true; |
| 574 | 573 |
| 575 (*field)->set_server_type(current_info->field_type); | 574 (*field)->set_server_type(current_info->field_type); |
| 576 if (heuristic_type != (*field)->type()) | 575 if (heuristic_type != (*field)->type()) |
| 577 query_response_overrode_heuristics = true; | 576 query_response_overrode_heuristics = true; |
| 578 | 577 |
| 579 // Copy default value into the field if available. | 578 // Copy default value into the field if available. |
| 580 if (!current_info->default_value.empty()) | 579 if (!current_info->default_value.empty()) |
| 581 (*field)->set_default_value(current_info->default_value); | 580 (*field)->set_default_value(current_info->default_value); |
| 581 |
| 582 ++current_info; |
| 582 } | 583 } |
| 583 | 584 |
| 584 form->UpdateAutofillCount(); | 585 form->UpdateAutofillCount(); |
| 585 form->IdentifySections(false); | 586 form->IdentifySections(false); |
| 586 } | 587 } |
| 587 | 588 |
| 588 AutofillMetrics::ServerQueryMetric metric; | 589 AutofillMetrics::ServerQueryMetric metric; |
| 589 if (query_response_overrode_heuristics) { | 590 if (query_response_overrode_heuristics) { |
| 590 if (heuristics_detected_fillable_field) { | 591 if (heuristics_detected_fillable_field) { |
| 591 metric = AutofillMetrics::QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS; | 592 metric = AutofillMetrics::QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 UTF16ToUTF8(form_name_) + | 651 UTF16ToUTF8(form_name_) + |
| 651 form_signature_field_names_; | 652 form_signature_field_names_; |
| 652 | 653 |
| 653 return Hash64Bit(form_string); | 654 return Hash64Bit(form_string); |
| 654 } | 655 } |
| 655 | 656 |
| 656 bool FormStructure::IsAutocheckoutEnabled() const { | 657 bool FormStructure::IsAutocheckoutEnabled() const { |
| 657 return !autocheckout_url_prefix_.empty(); | 658 return !autocheckout_url_prefix_.empty(); |
| 658 } | 659 } |
| 659 | 660 |
| 661 bool FormStructure::ShouldSkipField(const FormFieldData field) const { |
| 662 return (field.is_checkable || field.form_control_type == "password") && |
| 663 !IsAutocheckoutEnabled(); |
| 664 } |
| 665 |
| 660 size_t FormStructure::RequiredFillableFields() const { | 666 size_t FormStructure::RequiredFillableFields() const { |
| 661 return IsAutocheckoutEnabled() ? 0 : kRequiredAutofillFields; | 667 return IsAutocheckoutEnabled() ? 0 : kRequiredAutofillFields; |
| 662 } | 668 } |
| 663 | 669 |
| 664 bool FormStructure::IsAutofillable(bool require_method_post) const { | 670 bool FormStructure::IsAutofillable(bool require_method_post) const { |
| 665 if (autofill_count() < RequiredFillableFields()) | 671 if (autofill_count() < RequiredFillableFields()) |
| 666 return false; | 672 return false; |
| 667 | 673 |
| 668 return ShouldBeParsed(require_method_post); | 674 return ShouldBeParsed(require_method_post); |
| 669 } | 675 } |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1019 return false; | 1025 return false; |
| 1020 | 1026 |
| 1021 // Add the child nodes for the form fields. | 1027 // Add the child nodes for the form fields. |
| 1022 for (size_t index = 0; index < field_count(); ++index) { | 1028 for (size_t index = 0; index < field_count(); ++index) { |
| 1023 const AutofillField* field = fields_[index]; | 1029 const AutofillField* field = fields_[index]; |
| 1024 switch (request_type) { | 1030 switch (request_type) { |
| 1025 case FormStructure::UPLOAD: | 1031 case FormStructure::UPLOAD: |
| 1026 EncodeFieldForUpload(*field, encompassing_xml_element); | 1032 EncodeFieldForUpload(*field, encompassing_xml_element); |
| 1027 break; | 1033 break; |
| 1028 case FormStructure::QUERY: | 1034 case FormStructure::QUERY: |
| 1029 // Skip putting checkable and password fields in the request if | 1035 if (ShouldSkipField(*field)) |
| 1030 // Autocheckout is not enabled. | |
| 1031 if ((field->is_checkable || field->form_control_type == "password") && | |
| 1032 !IsAutocheckoutEnabled()) | |
| 1033 continue; | 1036 continue; |
| 1034 EncodeFieldForQuery(*field, encompassing_xml_element); | 1037 EncodeFieldForQuery(*field, encompassing_xml_element); |
| 1035 break; | 1038 break; |
| 1036 case FormStructure::FIELD_ASSIGNMENTS: | 1039 case FormStructure::FIELD_ASSIGNMENTS: |
| 1037 EncodeFieldForFieldAssignments(*field, encompassing_xml_element); | 1040 EncodeFieldForFieldAssignments(*field, encompassing_xml_element); |
| 1038 break; | 1041 break; |
| 1039 } | 1042 } |
| 1040 } | 1043 } |
| 1041 return true; | 1044 return true; |
| 1042 } | 1045 } |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 AutofillType::FieldTypeGroup field_type_group = | 1213 AutofillType::FieldTypeGroup field_type_group = |
| 1211 AutofillType((*field)->type()).group(); | 1214 AutofillType((*field)->type()).group(); |
| 1212 if (field_type_group == AutofillType::CREDIT_CARD) | 1215 if (field_type_group == AutofillType::CREDIT_CARD) |
| 1213 (*field)->set_section((*field)->section() + "-cc"); | 1216 (*field)->set_section((*field)->section() + "-cc"); |
| 1214 else | 1217 else |
| 1215 (*field)->set_section((*field)->section() + "-default"); | 1218 (*field)->set_section((*field)->section() + "-default"); |
| 1216 } | 1219 } |
| 1217 } | 1220 } |
| 1218 | 1221 |
| 1219 } // namespace autofill | 1222 } // namespace autofill |
| OLD | NEW |