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..43807079963877df758fcaf07e6b24e02a618f26 100644 |
--- a/components/autofill/core/browser/form_field.cc |
+++ b/components/autofill/core/browser/form_field.cc |
@@ -40,7 +40,10 @@ bool ShouldBeIgnored(const AutofillField* field) { |
// static |
void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, |
+ bool is_form_tag, |
ServerFieldTypeMap* map) { |
+ DCHECK(map->empty()); |
+ |
// Set up a working copy of the fields to be processed. |
std::vector<AutofillField*> remaining_fields(fields.size()); |
std::copy(fields.begin(), fields.end(), remaining_fields.begin()); |
@@ -50,8 +53,11 @@ void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, |
ShouldBeIgnored), |
remaining_fields.end()); |
+ ServerFieldTypeMap saved_map = *map; |
+ |
// Email pass. |
ParseFormFieldsPass(EmailField::Parse, &remaining_fields, map); |
+ size_t email_count = map->size(); |
// Phone pass. |
ParseFormFieldsPass(PhoneField::Parse, &remaining_fields, map); |
@@ -64,6 +70,16 @@ void FormField::ParseFormFields(const std::vector<AutofillField*>& fields, |
// Name pass. |
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. |
Ilya Sherman
2015/01/28 19:30:23
Why does this apply only for <form> tags? Are acc
Lei Zhang
2015/01/28 19:46:42
Treating email fields uniformly risks more bugs li
|
+ size_t kThreshold = 3; |
+ bool accept_parsing = (map->size() >= kThreshold || |
+ (is_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; |
} |