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

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

Issue 1671753004: [Autofill] Fill fields that have an autocomplete attributes even if not in a form. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added IPC Trait for new attribute Created 4 years, 10 months 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 <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
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
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 we are dealing with either a
346 // proper <form> or a <form>-less checkout, run the heuristics and server
347 // prediction routines.
348 if (active_field_count() >= kRequiredFieldsForPredictionRoutines &&
349 (is_form_tag_ || is_formless_checkout_)) {
347 ServerFieldTypeMap field_type_map; 350 ServerFieldTypeMap field_type_map;
348 FormField::ParseFormFields(fields_.get(), is_form_tag_, &field_type_map); 351 FormField::ParseFormFields(fields_.get(), is_form_tag_, &field_type_map);
349 for (size_t i = 0; i < field_count(); ++i) { 352 for (size_t i = 0; i < field_count(); ++i) {
350 AutofillField* field = fields_[i]; 353 AutofillField* field = fields_[i];
351 ServerFieldTypeMap::iterator iter = 354 ServerFieldTypeMap::iterator iter =
352 field_type_map.find(field->unique_name()); 355 field_type_map.find(field->unique_name());
353 if (iter != field_type_map.end()) 356 if (iter != field_type_map.end())
354 field->set_heuristic_type(iter->second); 357 field->set_heuristic_type(iter->second);
355 } 358 }
356 } 359 }
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1290 strings[i].at(prefix_len) != strings[0].at(prefix_len)) { 1293 strings[i].at(prefix_len) != strings[0].at(prefix_len)) {
1291 // Mismatch found. 1294 // Mismatch found.
1292 return base::StringPiece16(strings[i].data(), prefix_len); 1295 return base::StringPiece16(strings[i].data(), prefix_len);
1293 } 1296 }
1294 } 1297 }
1295 } 1298 }
1296 return strings[0]; 1299 return strings[0];
1297 } 1300 }
1298 1301
1299 } // namespace autofill 1302 } // 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