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

Unified Diff: components/autofill/core/browser/form_field.cc

Issue 853523004: Autofill: Set requirements for number of recognized fields in an autofillable form (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: components/autofill/core/browser/form_field.cc
diff --git a/components/autofill/core/browser/form_field.cc b/components/autofill/core/browser/form_field.cc
index 191be8d62f4d80459c572f0179a930c0afde2e18..e3813937dae02cc0150953d41d74d6204b5a8a51 100644
--- a/components/autofill/core/browser/form_field.cc
+++ b/components/autofill/core/browser/form_field.cc
@@ -40,6 +40,7 @@ bool ShouldBeIgnored(const AutofillField* field) {
// static
void FormField::ParseFormFields(const std::vector<AutofillField*>& fields,
+ bool is_in_form_tag,
ServerFieldTypeMap* map) {
// Set up a working copy of the fields to be processed.
std::vector<AutofillField*> remaining_fields(fields.size());
@@ -50,20 +51,35 @@ void FormField::ParseFormFields(const std::vector<AutofillField*>& fields,
ShouldBeIgnored),
remaining_fields.end());
+ ServerFieldTypeMap saved_map = *map;
+ size_t email_count = 0;
+ size_t count = 0;
+
// Email pass.
- ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map);
+ email_count += ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map);
+ count += email_count;
// Phone pass.
- ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map);
+ count += ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map);
// Address pass.
- ParseFormFieldsPass(AddressField::Parse, &remaining_fields, map);
+ count += ParseFormFieldsPass(AddressField::Parse, &remaining_fields, map);
// Credit card pass.
- ParseFormFieldsPass(CreditCardField::Parse, &remaining_fields, map);
+ count += ParseFormFieldsPass(CreditCardField::Parse, &remaining_fields, map);
// Name pass.
- ParseFormFieldsPass(NameField::Parse, &remaining_fields, map);
+ count += ParseFormFieldsPass(NameField::Parse, &remaining_fields, map);
+
+ // Do not autofill a form if there are less than 3 recognized fields.
+ // Otherwise it is very easy to have false positives. http://crbug.com/447332
+ // For <form> tags, make an exception for email fields, which are commonly the
+ // only recognized field on account registration sites.
+ size_t kThreshold = 3;
+ bool accept_parsing = (count >= kThreshold ||
+ (is_in_form_tag && email_count > 0));
+ if (!accept_parsing)
+ *map = saved_map;
}
// static
@@ -130,17 +146,17 @@ bool FormField::Match(const AutofillField* field,
const base::string16& pattern,
int match_type) {
if ((match_type & FormField::MATCH_LABEL) &&
- autofill::MatchesPattern(field->label, pattern)) {
+ MatchesPattern(field->label, pattern)) {
return true;
}
if ((match_type & FormField::MATCH_NAME) &&
- autofill::MatchesPattern(field->name, pattern)) {
+ MatchesPattern(field->name, pattern)) {
return true;
}
if ((match_type & FormField::MATCH_VALUE) &&
- autofill::MatchesPattern(field->value, pattern)) {
+ MatchesPattern(field->value, pattern)) {
return true;
}
@@ -148,12 +164,13 @@ bool FormField::Match(const AutofillField* field,
}
// static
-void FormField::ParseFormFieldsPass(ParseFunction parse,
- std::vector<AutofillField*>* fields,
- ServerFieldTypeMap* map) {
+size_t FormField::ParseFormFieldsPass(ParseFunction parse,
+ std::vector<AutofillField*>* fields,
+ ServerFieldTypeMap* map) {
// Store unmatched fields for further processing by the caller.
std::vector<AutofillField*> remaining_fields;
+ size_t initial_field_count = map->size();
AutofillScanner scanner(*fields);
while (!scanner.IsEnd()) {
scoped_ptr<FormField> form_field(parse(&scanner));
@@ -169,6 +186,9 @@ void FormField::ParseFormFieldsPass(ParseFunction parse,
}
std::swap(*fields, remaining_fields);
+
+ DCHECK_GE(map->size(), initial_field_count);
+ return map->size() - initial_field_count;
Evan Stade 2015/01/22 23:17:04 this doesn't need to be part of ParseFormFieldsPas
Lei Zhang 2015/01/22 23:32:04 Done.
}
bool FormField::MatchesFormControlType(const std::string& type,
« no previous file with comments | « components/autofill/core/browser/form_field.h ('k') | components/autofill/core/browser/form_field_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698