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

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

Issue 659793005: [Password Generation] Always query password forms via Autofill (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Done Created 6 years, 1 month 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
OLDNEW
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 <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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 345
346 } // namespace 346 } // namespace
347 347
348 FormStructure::FormStructure(const FormData& form) 348 FormStructure::FormStructure(const FormData& form)
349 : form_name_(form.name), 349 : form_name_(form.name),
350 source_url_(form.origin), 350 source_url_(form.origin),
351 target_url_(form.action), 351 target_url_(form.action),
352 autofill_count_(0), 352 autofill_count_(0),
353 active_field_count_(0), 353 active_field_count_(0),
354 upload_required_(USE_UPLOAD_RATES), 354 upload_required_(USE_UPLOAD_RATES),
355 has_author_specified_types_(false) { 355 has_author_specified_types_(false),
356 has_password_field_(false) {
356 // Copy the form fields. 357 // Copy the form fields.
357 std::map<base::string16, size_t> unique_names; 358 std::map<base::string16, size_t> unique_names;
358 for (std::vector<FormFieldData>::const_iterator field = 359 for (std::vector<FormFieldData>::const_iterator field =
359 form.fields.begin(); 360 form.fields.begin();
360 field != form.fields.end(); ++field) { 361 field != form.fields.end(); ++field) {
361 if (!ShouldSkipField(*field)) { 362 if (!ShouldSkipField(*field)) {
362 // Add all supported form fields (including with empty names) to the 363 // Add all supported form fields (including with empty names) to the
363 // signature. This is a requirement for Autofill servers. 364 // signature. This is a requirement for Autofill servers.
364 form_signature_field_names_.append("&"); 365 form_signature_field_names_.append("&");
365 form_signature_field_names_.append(StripDigitsIfRequired(field->name)); 366 form_signature_field_names_.append(StripDigitsIfRequired(field->name));
366 367
367 ++active_field_count_; 368 ++active_field_count_;
368 } 369 }
369 370
371 if (field->form_control_type == "password")
372 has_password_field_ = true;
373
370 // Generate a unique name for this field by appending a counter to the name. 374 // Generate a unique name for this field by appending a counter to the name.
371 // Make sure to prepend the counter with a non-numeric digit so that we are 375 // Make sure to prepend the counter with a non-numeric digit so that we are
372 // guaranteed to avoid collisions. 376 // guaranteed to avoid collisions.
373 if (!unique_names.count(field->name)) 377 if (!unique_names.count(field->name))
374 unique_names[field->name] = 1; 378 unique_names[field->name] = 1;
375 else 379 else
376 ++unique_names[field->name]; 380 ++unique_names[field->name];
377 base::string16 unique_name = field->name + base::ASCIIToUTF16("_") + 381 base::string16 unique_name = field->name + base::ASCIIToUTF16("_") +
378 base::IntToString16(unique_names[field->name]); 382 base::IntToString16(unique_names[field->name]);
379 fields_.push_back(new AutofillField(*field, unique_name)); 383 fields_.push_back(new AutofillField(*field, unique_name));
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 for (std::vector<AutofillField*>::iterator field = form->fields_.begin(); 576 for (std::vector<AutofillField*>::iterator field = form->fields_.begin();
573 field != form->fields_.end(); ++field) { 577 field != form->fields_.end(); ++field) {
574 if (form->ShouldSkipField(**field)) 578 if (form->ShouldSkipField(**field))
575 continue; 579 continue;
576 580
577 // In some cases *successful* response does not return all the fields. 581 // In some cases *successful* response does not return all the fields.
578 // Quit the update of the types then. 582 // Quit the update of the types then.
579 if (current_info == field_infos.end()) 583 if (current_info == field_infos.end())
580 break; 584 break;
581 585
582 // UNKNOWN_TYPE is reserved for use by the client. 586 // If |form->has_author_specified_types| only password fields should be
583 DCHECK_NE(current_info->field_type, UNKNOWN_TYPE); 587 // updated.
588 if (!form->has_author_specified_types_ ||
589 (*field)->form_control_type == "password") {
590 // UNKNOWN_TYPE is reserved for use by the client.
591 DCHECK_NE(current_info->field_type, UNKNOWN_TYPE);
584 592
585 ServerFieldType heuristic_type = (*field)->heuristic_type(); 593 ServerFieldType heuristic_type = (*field)->heuristic_type();
586 if (heuristic_type != UNKNOWN_TYPE) 594 if (heuristic_type != UNKNOWN_TYPE)
587 heuristics_detected_fillable_field = true; 595 heuristics_detected_fillable_field = true;
588 596
589 (*field)->set_server_type(current_info->field_type); 597 (*field)->set_server_type(current_info->field_type);
590 if (heuristic_type != (*field)->Type().GetStorableType()) 598 if (heuristic_type != (*field)->Type().GetStorableType())
591 query_response_overrode_heuristics = true; 599 query_response_overrode_heuristics = true;
592 600
593 // Copy default value into the field if available. 601 // Copy default value into the field if available.
594 if (!current_info->default_value.empty()) 602 if (!current_info->default_value.empty())
595 (*field)->set_default_value(current_info->default_value); 603 (*field)->set_default_value(current_info->default_value);
604 }
596 605
597 ++current_info; 606 ++current_info;
598 } 607 }
599 608
600 form->UpdateAutofillCount(); 609 form->UpdateAutofillCount();
601 form->IdentifySections(false); 610 form->IdentifySections(false);
602 } 611 }
603 612
604 AutofillMetrics::ServerQueryMetric metric; 613 AutofillMetrics::ServerQueryMetric metric;
605 if (query_response_overrode_heuristics) { 614 if (query_response_overrode_heuristics) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 bool has_text_field = false; 708 bool has_text_field = false;
700 for (std::vector<AutofillField*>::const_iterator it = begin(); 709 for (std::vector<AutofillField*>::const_iterator it = begin();
701 it != end() && !has_text_field; ++it) { 710 it != end() && !has_text_field; ++it) {
702 has_text_field |= (*it)->form_control_type != "select-one"; 711 has_text_field |= (*it)->form_control_type != "select-one";
703 } 712 }
704 713
705 return has_text_field; 714 return has_text_field;
706 } 715 }
707 716
708 bool FormStructure::ShouldBeCrowdsourced() const { 717 bool FormStructure::ShouldBeCrowdsourced() const {
709 return !has_author_specified_types_ && ShouldBeParsed(); 718 return (has_password_field_ || !has_author_specified_types_) &&
719 ShouldBeParsed();
710 } 720 }
711 721
712 void FormStructure::UpdateFromCache(const FormStructure& cached_form) { 722 void FormStructure::UpdateFromCache(const FormStructure& cached_form) {
713 // Map from field signatures to cached fields. 723 // Map from field signatures to cached fields.
714 std::map<std::string, const AutofillField*> cached_fields; 724 std::map<std::string, const AutofillField*> cached_fields;
715 for (size_t i = 0; i < cached_form.field_count(); ++i) { 725 for (size_t i = 0; i < cached_form.field_count(); ++i) {
716 const AutofillField* field = cached_form.field(i); 726 const AutofillField* field = cached_form.field(i);
717 cached_fields[field->FieldSignature()] = field; 727 cached_fields[field->FieldSignature()] = field;
718 } 728 }
719 729
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 field != fields_.end(); ++field) { 1238 field != fields_.end(); ++field) {
1229 FieldTypeGroup field_type_group = (*field)->Type().group(); 1239 FieldTypeGroup field_type_group = (*field)->Type().group();
1230 if (field_type_group == CREDIT_CARD) 1240 if (field_type_group == CREDIT_CARD)
1231 (*field)->set_section((*field)->section() + "-cc"); 1241 (*field)->set_section((*field)->section() + "-cc");
1232 else 1242 else
1233 (*field)->set_section((*field)->section() + "-default"); 1243 (*field)->set_section((*field)->section() + "-default");
1234 } 1244 }
1235 } 1245 }
1236 1246
1237 } // namespace autofill 1247 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/core/browser/form_structure.h ('k') | components/autofill/core/browser/form_structure_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698