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 <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 Loading... | |
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 Loading... | |
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 |
586 // If |form->has_author_specified_types| only password fields should be | |
587 // updated. | |
588 if (form->has_author_specified_types_ && | |
589 (*field)->form_control_type != "password") { | |
590 ++current_info; | |
Ilya Sherman
2014/10/25 00:36:18
Oh, sorry, I had not noticed that "++current_info;
| |
591 continue; | |
592 } | |
593 | |
582 // UNKNOWN_TYPE is reserved for use by the client. | 594 // UNKNOWN_TYPE is reserved for use by the client. |
583 DCHECK_NE(current_info->field_type, UNKNOWN_TYPE); | 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; |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
699 bool has_text_field = false; | 711 bool has_text_field = false; |
700 for (std::vector<AutofillField*>::const_iterator it = begin(); | 712 for (std::vector<AutofillField*>::const_iterator it = begin(); |
701 it != end() && !has_text_field; ++it) { | 713 it != end() && !has_text_field; ++it) { |
702 has_text_field |= (*it)->form_control_type != "select-one"; | 714 has_text_field |= (*it)->form_control_type != "select-one"; |
703 } | 715 } |
704 | 716 |
705 return has_text_field; | 717 return has_text_field; |
706 } | 718 } |
707 | 719 |
708 bool FormStructure::ShouldBeCrowdsourced() const { | 720 bool FormStructure::ShouldBeCrowdsourced() const { |
709 return !has_author_specified_types_ && ShouldBeParsed(); | 721 return (has_password_field_ || !has_author_specified_types_) && |
722 ShouldBeParsed(); | |
710 } | 723 } |
711 | 724 |
712 void FormStructure::UpdateFromCache(const FormStructure& cached_form) { | 725 void FormStructure::UpdateFromCache(const FormStructure& cached_form) { |
713 // Map from field signatures to cached fields. | 726 // Map from field signatures to cached fields. |
714 std::map<std::string, const AutofillField*> cached_fields; | 727 std::map<std::string, const AutofillField*> cached_fields; |
715 for (size_t i = 0; i < cached_form.field_count(); ++i) { | 728 for (size_t i = 0; i < cached_form.field_count(); ++i) { |
716 const AutofillField* field = cached_form.field(i); | 729 const AutofillField* field = cached_form.field(i); |
717 cached_fields[field->FieldSignature()] = field; | 730 cached_fields[field->FieldSignature()] = field; |
718 } | 731 } |
719 | 732 |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1228 field != fields_.end(); ++field) { | 1241 field != fields_.end(); ++field) { |
1229 FieldTypeGroup field_type_group = (*field)->Type().group(); | 1242 FieldTypeGroup field_type_group = (*field)->Type().group(); |
1230 if (field_type_group == CREDIT_CARD) | 1243 if (field_type_group == CREDIT_CARD) |
1231 (*field)->set_section((*field)->section() + "-cc"); | 1244 (*field)->set_section((*field)->section() + "-cc"); |
1232 else | 1245 else |
1233 (*field)->set_section((*field)->section() + "-default"); | 1246 (*field)->set_section((*field)->section() + "-default"); |
1234 } | 1247 } |
1235 } | 1248 } |
1236 | 1249 |
1237 } // namespace autofill | 1250 } // namespace autofill |
OLD | NEW |