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..b5229d1665b645be481868fa55cb1e56171ce5c6 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) { |
Evan Stade
2015/01/22 23:43:44
DCHECK(map->empty())?
Lei Zhang
2015/01/22 23:58:12
Done.
|
// Set up a working copy of the fields to be processed. |
std::vector<AutofillField*> remaining_fields(fields.size()); |
@@ -50,8 +51,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 +68,17 @@ 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. |
+ size_t count = map->size(); |
Evan Stade
2015/01/22 23:43:44
nit: no need for this variable
Lei Zhang
2015/01/22 23:58:12
Done.
|
+ 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 +145,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; |
} |