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

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

Issue 1670763006: Autofill server-side heuristics for 2 fields password form (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More tests 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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 is_formless_checkout_(form.is_formless_checkout),
309 all_fields_are_passwords_(true) {
309 // Copy the form fields. 310 // Copy the form fields.
310 std::map<base::string16, size_t> unique_names; 311 std::map<base::string16, size_t> unique_names;
311 for (const FormFieldData& field : form.fields) { 312 for (const FormFieldData& field : form.fields) {
312 if (!ShouldSkipField(field)) { 313 if (!ShouldSkipField(field)) {
313 // Add all supported form fields (including with empty names) to the 314 // Add all supported form fields (including with empty names) to the
314 // signature. This is a requirement for Autofill servers. 315 // signature. This is a requirement for Autofill servers.
315 form_signature_field_names_.append("&"); 316 form_signature_field_names_.append("&");
316 form_signature_field_names_.append(StripDigitsIfRequired(field.name)); 317 form_signature_field_names_.append(StripDigitsIfRequired(field.name));
317 318
318 ++active_field_count_; 319 ++active_field_count_;
319 } 320 }
320 321
321 if (field.form_control_type == "password") 322 if (field.form_control_type == "password")
322 has_password_field_ = true; 323 has_password_field_ = true;
324 else
325 all_fields_are_passwords_ = false;
323 326
324 // Generate a unique name for this field by appending a counter to the name. 327 // Generate a unique name for this field by appending a counter to the name.
325 // Make sure to prepend the counter with a non-numeric digit so that we are 328 // Make sure to prepend the counter with a non-numeric digit so that we are
326 // guaranteed to avoid collisions. 329 // guaranteed to avoid collisions.
327 base::string16 unique_name = 330 base::string16 unique_name =
328 field.name + base::ASCIIToUTF16("_") + 331 field.name + base::ASCIIToUTF16("_") +
329 base::SizeTToString16(++unique_names[field.name]); 332 base::SizeTToString16(++unique_names[field.name]);
330 fields_.push_back(new AutofillField(field, unique_name)); 333 fields_.push_back(new AutofillField(field, unique_name));
331 } 334 }
332 335
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
573 576
574 void FormStructure::UpdateAutofillCount() { 577 void FormStructure::UpdateAutofillCount() {
575 autofill_count_ = 0; 578 autofill_count_ = 0;
576 for (const AutofillField* field : *this) { 579 for (const AutofillField* field : *this) {
577 if (field && field->IsFieldFillable()) 580 if (field && field->IsFieldFillable())
578 ++autofill_count_; 581 ++autofill_count_;
579 } 582 }
580 } 583 }
581 584
582 bool FormStructure::ShouldBeParsed() const { 585 bool FormStructure::ShouldBeParsed() const {
583 if (active_field_count() < kRequiredFieldsForPredictionRoutines && 586 if ((active_field_count() <
587 kRequiredFieldsAllPasswordsForUploadAndPrediction ||
Ilya Sherman 2016/02/09 22:33:39 This logic is implicitly assuming that kRequiredFi
dvadym 2016/02/10 11:58:28 Done, I've rewritten it as negation to condition f
588 (!all_fields_are_passwords() &&
589 active_field_count() < kRequiredFieldsForPredictionRoutines)) &&
584 !has_author_specified_types_) { 590 !has_author_specified_types_) {
585 return false; 591 return false;
586 } 592 }
587 593
588 // Rule out http(s)://*/search?... 594 // Rule out http(s)://*/search?...
589 // e.g. http://www.google.com/search?q=... 595 // e.g. http://www.google.com/search?q=...
590 // http://search.yahoo.com/search?p=... 596 // http://search.yahoo.com/search?p=...
591 if (target_url_.path() == "/search") 597 if (target_url_.path() == "/search")
592 return false; 598 return false;
593 599
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 strings[i].at(prefix_len) != strings[0].at(prefix_len)) { 1299 strings[i].at(prefix_len) != strings[0].at(prefix_len)) {
1294 // Mismatch found. 1300 // Mismatch found.
1295 return base::StringPiece16(strings[i].data(), prefix_len); 1301 return base::StringPiece16(strings[i].data(), prefix_len);
1296 } 1302 }
1297 } 1303 }
1298 } 1304 }
1299 return strings[0]; 1305 return strings[0];
1300 } 1306 }
1301 1307
1302 } // namespace autofill 1308 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698