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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 source_url_(form.origin), | 356 source_url_(form.origin), |
357 target_url_(form.action), | 357 target_url_(form.action), |
358 autofill_count_(0), | 358 autofill_count_(0), |
359 active_field_count_(0), | 359 active_field_count_(0), |
360 upload_required_(USE_UPLOAD_RATES), | 360 upload_required_(USE_UPLOAD_RATES), |
361 has_author_specified_types_(false), | 361 has_author_specified_types_(false), |
362 has_password_field_(false), | 362 has_password_field_(false), |
363 is_form_tag_(form.is_form_tag) { | 363 is_form_tag_(form.is_form_tag) { |
364 // Copy the form fields. | 364 // Copy the form fields. |
365 std::map<base::string16, size_t> unique_names; | 365 std::map<base::string16, size_t> unique_names; |
366 for (std::vector<FormFieldData>::const_iterator field = | 366 for (const FormFieldData& field : form.fields) { |
367 form.fields.begin(); | 367 if (!ShouldSkipField(field)) { |
368 field != form.fields.end(); ++field) { | |
369 if (!ShouldSkipField(*field)) { | |
370 // Add all supported form fields (including with empty names) to the | 368 // Add all supported form fields (including with empty names) to the |
371 // signature. This is a requirement for Autofill servers. | 369 // signature. This is a requirement for Autofill servers. |
372 form_signature_field_names_.append("&"); | 370 form_signature_field_names_.append("&"); |
373 form_signature_field_names_.append(StripDigitsIfRequired(field->name)); | 371 form_signature_field_names_.append(StripDigitsIfRequired(field.name)); |
374 | 372 |
375 ++active_field_count_; | 373 ++active_field_count_; |
376 } | 374 } |
377 | 375 |
378 if (field->form_control_type == "password") | 376 if (field.form_control_type == "password") |
379 has_password_field_ = true; | 377 has_password_field_ = true; |
380 | 378 |
381 // Generate a unique name for this field by appending a counter to the name. | 379 // Generate a unique name for this field by appending a counter to the name. |
382 // Make sure to prepend the counter with a non-numeric digit so that we are | 380 // Make sure to prepend the counter with a non-numeric digit so that we are |
383 // guaranteed to avoid collisions. | 381 // guaranteed to avoid collisions. |
384 if (!unique_names.count(field->name)) | 382 base::string16 unique_name = |
385 unique_names[field->name] = 1; | 383 field.name + base::ASCIIToUTF16("_") + |
386 else | 384 base::IntToString16(++unique_names[field.name]); |
387 ++unique_names[field->name]; | 385 fields_.push_back(new AutofillField(field, unique_name)); |
388 base::string16 unique_name = field->name + base::ASCIIToUTF16("_") + | |
389 base::IntToString16(unique_names[field->name]); | |
390 fields_.push_back(new AutofillField(*field, unique_name)); | |
391 } | 386 } |
392 } | 387 } |
393 | 388 |
394 FormStructure::~FormStructure() {} | 389 FormStructure::~FormStructure() {} |
395 | 390 |
396 void FormStructure::DetermineHeuristicTypes() { | 391 void FormStructure::DetermineHeuristicTypes() { |
397 // First, try to detect field types based on each field's |autocomplete| | 392 // First, try to detect field types based on each field's |autocomplete| |
398 // attribute value. If there is at least one form field that specifies an | 393 // attribute value. If there is at least one form field that specifies an |
399 // autocomplete type hint, don't try to apply other heuristics to match fields | 394 // autocomplete type hint, don't try to apply other heuristics to match fields |
400 // in this form. | 395 // in this form. |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1287 for (AutofillField* field : fields_) { | 1282 for (AutofillField* field : fields_) { |
1288 FieldTypeGroup field_type_group = field->Type().group(); | 1283 FieldTypeGroup field_type_group = field->Type().group(); |
1289 if (field_type_group == CREDIT_CARD) | 1284 if (field_type_group == CREDIT_CARD) |
1290 field->set_section(field->section() + "-cc"); | 1285 field->set_section(field->section() + "-cc"); |
1291 else | 1286 else |
1292 field->set_section(field->section() + "-default"); | 1287 field->set_section(field->section() + "-default"); |
1293 } | 1288 } |
1294 } | 1289 } |
1295 | 1290 |
1296 } // namespace autofill | 1291 } // namespace autofill |
OLD | NEW |