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

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: Test 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;
Ilya Sherman 2014/10/24 22:42:30 Now that this is only used in one place, I wonder
Garrett Casto 2014/10/24 23:19:52 I think that I slightly prefer keeping it here jus
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 // Heuristic values can be ignored for password fields as Autofill
590 // doesn't handle them. UMA stats can also be skipped in that case.
Ilya Sherman 2014/10/24 22:42:30 nit: This comment talks about UMA stats, but I don
Garrett Casto 2014/10/24 23:19:52 Removed.
591 if ((*field)->form_control_type == "password")
592 (*field)->set_server_type(current_info->field_type);
Ilya Sherman 2014/10/24 22:42:30 I think it would be simpler to write this code as
Garrett Casto 2014/10/24 23:19:52 I had originally done it this way to avoid influen
Ilya Sherman 2014/10/24 23:40:14 I really prefer less indentation over avoiding con
Garrett Casto 2014/10/25 00:04:54 Done.
593 } else {
594 // UNKNOWN_TYPE is reserved for use by the client.
595 DCHECK_NE(current_info->field_type, UNKNOWN_TYPE);
584 596
585 ServerFieldType heuristic_type = (*field)->heuristic_type(); 597 ServerFieldType heuristic_type = (*field)->heuristic_type();
586 if (heuristic_type != UNKNOWN_TYPE) 598 if (heuristic_type != UNKNOWN_TYPE)
587 heuristics_detected_fillable_field = true; 599 heuristics_detected_fillable_field = true;
588 600
589 (*field)->set_server_type(current_info->field_type); 601 (*field)->set_server_type(current_info->field_type);
590 if (heuristic_type != (*field)->Type().GetStorableType()) 602 if (heuristic_type != (*field)->Type().GetStorableType())
591 query_response_overrode_heuristics = true; 603 query_response_overrode_heuristics = true;
592 604
593 // Copy default value into the field if available. 605 // Copy default value into the field if available.
594 if (!current_info->default_value.empty()) 606 if (!current_info->default_value.empty())
595 (*field)->set_default_value(current_info->default_value); 607 (*field)->set_default_value(current_info->default_value);
608 }
596 609
597 ++current_info; 610 ++current_info;
598 } 611 }
599 612
600 form->UpdateAutofillCount(); 613 form->UpdateAutofillCount();
601 form->IdentifySections(false); 614 form->IdentifySections(false);
602 } 615 }
603 616
604 AutofillMetrics::ServerQueryMetric metric; 617 AutofillMetrics::ServerQueryMetric metric;
605 if (query_response_overrode_heuristics) { 618 if (query_response_overrode_heuristics) {
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
699 bool has_text_field = false; 712 bool has_text_field = false;
700 for (std::vector<AutofillField*>::const_iterator it = begin(); 713 for (std::vector<AutofillField*>::const_iterator it = begin();
701 it != end() && !has_text_field; ++it) { 714 it != end() && !has_text_field; ++it) {
702 has_text_field |= (*it)->form_control_type != "select-one"; 715 has_text_field |= (*it)->form_control_type != "select-one";
703 } 716 }
704 717
705 return has_text_field; 718 return has_text_field;
706 } 719 }
707 720
708 bool FormStructure::ShouldBeCrowdsourced() const { 721 bool FormStructure::ShouldBeCrowdsourced() const {
709 return !has_author_specified_types_ && ShouldBeParsed(); 722 return (has_password_field_ || !has_author_specified_types_) &&
723 ShouldBeParsed();
710 } 724 }
711 725
712 void FormStructure::UpdateFromCache(const FormStructure& cached_form) { 726 void FormStructure::UpdateFromCache(const FormStructure& cached_form) {
713 // Map from field signatures to cached fields. 727 // Map from field signatures to cached fields.
714 std::map<std::string, const AutofillField*> cached_fields; 728 std::map<std::string, const AutofillField*> cached_fields;
715 for (size_t i = 0; i < cached_form.field_count(); ++i) { 729 for (size_t i = 0; i < cached_form.field_count(); ++i) {
716 const AutofillField* field = cached_form.field(i); 730 const AutofillField* field = cached_form.field(i);
717 cached_fields[field->FieldSignature()] = field; 731 cached_fields[field->FieldSignature()] = field;
718 } 732 }
719 733
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 field != fields_.end(); ++field) { 1242 field != fields_.end(); ++field) {
1229 FieldTypeGroup field_type_group = (*field)->Type().group(); 1243 FieldTypeGroup field_type_group = (*field)->Type().group();
1230 if (field_type_group == CREDIT_CARD) 1244 if (field_type_group == CREDIT_CARD)
1231 (*field)->set_section((*field)->section() + "-cc"); 1245 (*field)->set_section((*field)->section() + "-cc");
1232 else 1246 else
1233 (*field)->set_section((*field)->section() + "-default"); 1247 (*field)->set_section((*field)->section() + "-default");
1234 } 1248 }
1235 } 1249 }
1236 1250
1237 } // namespace autofill 1251 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698