Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: components/autofill/browser/form_structure.cc

Issue 16164003: Field's server type mapping (using Autofill server response) for forms with checkable elements/pass… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 // Skip checkable and password elements when Autocheckout is not enabled,
309 // else these fields will interfere with existing field signatures with 309 // else these fields will interfere with existing field signatures with
310 // Autofill servers. 310 // Autofill servers.
Evan Stade 2013/05/28 19:24:07 I don't think the comment above each call to Shoul
Raman Kakilate 2013/05/28 20:38:44 Done.
311 if ((!field->is_checkable && field->form_control_type != "password") || 311 if (!ShouldSkipField(*field)) {
312 IsAutocheckoutEnabled()) {
313 // Add all supported form fields (including with empty names) to the 312 // Add all supported form fields (including with empty names) to the
314 // signature. This is a requirement for Autofill servers. 313 // signature. This is a requirement for Autofill servers.
315 form_signature_field_names_.append("&"); 314 form_signature_field_names_.append("&");
316 form_signature_field_names_.append(UTF16ToUTF8(field->name)); 315 form_signature_field_names_.append(UTF16ToUTF8(field->name));
317 316
318 ++active_field_count_; 317 ++active_field_count_;
319 } 318 }
320 319
321 // Generate a unique name for this field by appending a counter to the name. 320 // 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 321 // 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
552 // Copy the field types into the actual form. 551 // Copy the field types into the actual form.
553 std::vector<AutofillServerFieldInfo>::iterator current_info = 552 std::vector<AutofillServerFieldInfo>::iterator current_info =
554 field_infos.begin(); 553 field_infos.begin();
555 for (std::vector<FormStructure*>::const_iterator iter = forms.begin(); 554 for (std::vector<FormStructure*>::const_iterator iter = forms.begin();
556 iter != forms.end(); ++iter) { 555 iter != forms.end(); ++iter) {
557 FormStructure* form = *iter; 556 FormStructure* form = *iter;
558 form->upload_required_ = upload_required; 557 form->upload_required_ = upload_required;
559 form->server_experiment_id_ = experiment_id; 558 form->server_experiment_id_ = experiment_id;
560 559
561 for (std::vector<AutofillField*>::iterator field = form->fields_.begin(); 560 for (std::vector<AutofillField*>::iterator field = form->fields_.begin();
562 field != form->fields_.end(); ++field, ++current_info) { 561 field != form->fields_.end(); ++field) {
562 // Skip putting checkable and password fields in the request if
563 // Autocheckout is not enabled.
564 if (form->ShouldSkipField(**field))
565 continue;
566
563 // In some cases *successful* response does not return all the fields. 567 // In some cases *successful* response does not return all the fields.
564 // Quit the update of the types then. 568 // Quit the update of the types then.
565 if (current_info == field_infos.end()) 569 if (current_info == field_infos.end())
566 break; 570 break;
567 571
568 // UNKNOWN_TYPE is reserved for use by the client. 572 // UNKNOWN_TYPE is reserved for use by the client.
569 DCHECK_NE(current_info->field_type, UNKNOWN_TYPE); 573 DCHECK_NE(current_info->field_type, UNKNOWN_TYPE);
570 574
571 AutofillFieldType heuristic_type = (*field)->type(); 575 AutofillFieldType heuristic_type = (*field)->type();
572 if (heuristic_type != UNKNOWN_TYPE) 576 if (heuristic_type != UNKNOWN_TYPE)
573 heuristics_detected_fillable_field = true; 577 heuristics_detected_fillable_field = true;
574 578
575 (*field)->set_server_type(current_info->field_type); 579 (*field)->set_server_type(current_info->field_type);
576 if (heuristic_type != (*field)->type()) 580 if (heuristic_type != (*field)->type())
577 query_response_overrode_heuristics = true; 581 query_response_overrode_heuristics = true;
578 582
579 // Copy default value into the field if available. 583 // Copy default value into the field if available.
580 if (!current_info->default_value.empty()) 584 if (!current_info->default_value.empty())
581 (*field)->set_default_value(current_info->default_value); 585 (*field)->set_default_value(current_info->default_value);
586
587 ++current_info;
582 } 588 }
583 589
584 form->UpdateAutofillCount(); 590 form->UpdateAutofillCount();
585 form->IdentifySections(false); 591 form->IdentifySections(false);
586 } 592 }
587 593
588 AutofillMetrics::ServerQueryMetric metric; 594 AutofillMetrics::ServerQueryMetric metric;
589 if (query_response_overrode_heuristics) { 595 if (query_response_overrode_heuristics) {
590 if (heuristics_detected_fillable_field) { 596 if (heuristics_detected_fillable_field) {
591 metric = AutofillMetrics::QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS; 597 metric = AutofillMetrics::QUERY_RESPONSE_OVERRODE_LOCAL_HEURISTICS;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 UTF16ToUTF8(form_name_) + 656 UTF16ToUTF8(form_name_) +
651 form_signature_field_names_; 657 form_signature_field_names_;
652 658
653 return Hash64Bit(form_string); 659 return Hash64Bit(form_string);
654 } 660 }
655 661
656 bool FormStructure::IsAutocheckoutEnabled() const { 662 bool FormStructure::IsAutocheckoutEnabled() const {
657 return !autocheckout_url_prefix_.empty(); 663 return !autocheckout_url_prefix_.empty();
658 } 664 }
659 665
666 bool FormStructure::ShouldSkipField(const FormFieldData field) const {
667 return ((field.is_checkable || field.form_control_type == "password") &&
Evan Stade 2013/05/28 19:24:07 nit: no need for outer parens
Raman Kakilate 2013/05/28 20:38:44 Done.
668 !IsAutocheckoutEnabled());
669 }
670
660 size_t FormStructure::RequiredFillableFields() const { 671 size_t FormStructure::RequiredFillableFields() const {
661 return IsAutocheckoutEnabled() ? 0 : kRequiredAutofillFields; 672 return IsAutocheckoutEnabled() ? 0 : kRequiredAutofillFields;
662 } 673 }
663 674
664 bool FormStructure::IsAutofillable(bool require_method_post) const { 675 bool FormStructure::IsAutofillable(bool require_method_post) const {
665 if (autofill_count() < RequiredFillableFields()) 676 if (autofill_count() < RequiredFillableFields())
666 return false; 677 return false;
667 678
668 return ShouldBeParsed(require_method_post); 679 return ShouldBeParsed(require_method_post);
669 } 680 }
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after
1021 // Add the child nodes for the form fields. 1032 // Add the child nodes for the form fields.
1022 for (size_t index = 0; index < field_count(); ++index) { 1033 for (size_t index = 0; index < field_count(); ++index) {
1023 const AutofillField* field = fields_[index]; 1034 const AutofillField* field = fields_[index];
1024 switch (request_type) { 1035 switch (request_type) {
1025 case FormStructure::UPLOAD: 1036 case FormStructure::UPLOAD:
1026 EncodeFieldForUpload(*field, encompassing_xml_element); 1037 EncodeFieldForUpload(*field, encompassing_xml_element);
1027 break; 1038 break;
1028 case FormStructure::QUERY: 1039 case FormStructure::QUERY:
1029 // Skip putting checkable and password fields in the request if 1040 // Skip putting checkable and password fields in the request if
1030 // Autocheckout is not enabled. 1041 // Autocheckout is not enabled.
1031 if ((field->is_checkable || field->form_control_type == "password") && 1042 if (ShouldSkipField(*field))
1032 !IsAutocheckoutEnabled())
1033 continue; 1043 continue;
1034 EncodeFieldForQuery(*field, encompassing_xml_element); 1044 EncodeFieldForQuery(*field, encompassing_xml_element);
1035 break; 1045 break;
1036 case FormStructure::FIELD_ASSIGNMENTS: 1046 case FormStructure::FIELD_ASSIGNMENTS:
1037 EncodeFieldForFieldAssignments(*field, encompassing_xml_element); 1047 EncodeFieldForFieldAssignments(*field, encompassing_xml_element);
1038 break; 1048 break;
1039 } 1049 }
1040 } 1050 }
1041 return true; 1051 return true;
1042 } 1052 }
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 AutofillType::FieldTypeGroup field_type_group = 1220 AutofillType::FieldTypeGroup field_type_group =
1211 AutofillType((*field)->type()).group(); 1221 AutofillType((*field)->type()).group();
1212 if (field_type_group == AutofillType::CREDIT_CARD) 1222 if (field_type_group == AutofillType::CREDIT_CARD)
1213 (*field)->set_section((*field)->section() + "-cc"); 1223 (*field)->set_section((*field)->section() + "-cc");
1214 else 1224 else
1215 (*field)->set_section((*field)->section() + "-default"); 1225 (*field)->set_section((*field)->section() + "-default");
1216 } 1226 }
1217 } 1227 }
1218 1228
1219 } // namespace autofill 1229 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/browser/form_structure.h ('k') | components/autofill/browser/form_structure_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698