Chromium Code Reviews| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 : form_name_(form.name), | 297 : form_name_(form.name), |
| 298 source_url_(form.origin), | 298 source_url_(form.origin), |
| 299 target_url_(form.action), | 299 target_url_(form.action), |
| 300 autofill_count_(0), | 300 autofill_count_(0), |
| 301 active_field_count_(0), | 301 active_field_count_(0), |
| 302 upload_required_(USE_UPLOAD_RATES), | 302 upload_required_(USE_UPLOAD_RATES), |
| 303 has_author_specified_types_(false), | 303 has_author_specified_types_(false), |
| 304 has_author_specified_sections_(false), | 304 has_author_specified_sections_(false), |
| 305 was_parsed_for_autocomplete_attributes_(false), | 305 was_parsed_for_autocomplete_attributes_(false), |
| 306 has_password_field_(false), | 306 has_password_field_(false), |
| 307 is_form_tag_(form.is_form_tag) { | 307 is_form_tag_(form.is_form_tag), |
| 308 is_formless_checkout_(form.is_formless_checkout) { | |
| 308 // Copy the form fields. | 309 // Copy the form fields. |
| 309 std::map<base::string16, size_t> unique_names; | 310 std::map<base::string16, size_t> unique_names; |
| 310 for (const FormFieldData& field : form.fields) { | 311 for (const FormFieldData& field : form.fields) { |
| 311 if (!ShouldSkipField(field)) { | 312 if (!ShouldSkipField(field)) { |
| 312 // Add all supported form fields (including with empty names) to the | 313 // Add all supported form fields (including with empty names) to the |
| 313 // signature. This is a requirement for Autofill servers. | 314 // signature. This is a requirement for Autofill servers. |
| 314 form_signature_field_names_.append("&"); | 315 form_signature_field_names_.append("&"); |
| 315 form_signature_field_names_.append(StripDigitsIfRequired(field.name)); | 316 form_signature_field_names_.append(StripDigitsIfRequired(field.name)); |
| 316 | 317 |
| 317 ++active_field_count_; | 318 ++active_field_count_; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 330 } | 331 } |
| 331 | 332 |
| 332 // Do further processing on the fields, as needed. | 333 // Do further processing on the fields, as needed. |
| 333 ProcessExtractedFields(); | 334 ProcessExtractedFields(); |
| 334 } | 335 } |
| 335 | 336 |
| 336 FormStructure::~FormStructure() {} | 337 FormStructure::~FormStructure() {} |
| 337 | 338 |
| 338 void FormStructure::DetermineHeuristicTypes() { | 339 void FormStructure::DetermineHeuristicTypes() { |
| 339 // First, try to detect field types based on each field's |autocomplete| | 340 // First, try to detect field types based on each field's |autocomplete| |
| 340 // attribute value. If there is at least one form field that specifies an | 341 // attribute value. |
| 341 // autocomplete type hint, don't try to apply other heuristics to match fields | |
| 342 // in this form. | |
| 343 if (!was_parsed_for_autocomplete_attributes_) | 342 if (!was_parsed_for_autocomplete_attributes_) |
| 344 ParseFieldTypesFromAutocompleteAttributes(); | 343 ParseFieldTypesFromAutocompleteAttributes(); |
| 345 | 344 |
| 346 if (active_field_count() >= kRequiredFieldsForPredictionRoutines) { | 345 // Then, if there are enough active fields and if the form is not a synthetic |
|
Mathieu
2016/02/05 22:36:45
// Then if there are enough active fields, and if
sebsg
2016/02/09 01:13:57
Done.
| |
| 346 // non checkout form, run the heuristics and server prediction routines. | |
| 347 if (active_field_count() >= kRequiredFieldsForPredictionRoutines && | |
| 348 (is_form_tag_ || is_formless_checkout_)) { | |
| 347 ServerFieldTypeMap field_type_map; | 349 ServerFieldTypeMap field_type_map; |
| 348 FormField::ParseFormFields(fields_.get(), is_form_tag_, &field_type_map); | 350 FormField::ParseFormFields(fields_.get(), is_form_tag_, &field_type_map); |
| 349 for (size_t i = 0; i < field_count(); ++i) { | 351 for (size_t i = 0; i < field_count(); ++i) { |
| 350 AutofillField* field = fields_[i]; | 352 AutofillField* field = fields_[i]; |
| 351 ServerFieldTypeMap::iterator iter = | 353 ServerFieldTypeMap::iterator iter = |
| 352 field_type_map.find(field->unique_name()); | 354 field_type_map.find(field->unique_name()); |
| 353 if (iter != field_type_map.end()) | 355 if (iter != field_type_map.end()) |
| 354 field->set_heuristic_type(iter->second); | 356 field->set_heuristic_type(iter->second); |
| 355 } | 357 } |
| 356 } | 358 } |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1290 strings[i].at(prefix_len) != strings[0].at(prefix_len)) { | 1292 strings[i].at(prefix_len) != strings[0].at(prefix_len)) { |
| 1291 // Mismatch found. | 1293 // Mismatch found. |
| 1292 return base::StringPiece16(strings[i].data(), prefix_len); | 1294 return base::StringPiece16(strings[i].data(), prefix_len); |
| 1293 } | 1295 } |
| 1294 } | 1296 } |
| 1295 } | 1297 } |
| 1296 return strings[0]; | 1298 return strings[0]; |
| 1297 } | 1299 } |
| 1298 | 1300 |
| 1299 } // namespace autofill | 1301 } // namespace autofill |
| OLD | NEW |