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

Unified Diff: components/autofill/content/renderer/form_cache.cc

Issue 1411363003: [Autofill] Always show available data when encountering autocomplete attributes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 1 month 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/content/renderer/form_cache.cc
diff --git a/components/autofill/content/renderer/form_cache.cc b/components/autofill/content/renderer/form_cache.cc
index 81ddf83574d53c6727ecbf50714fb6ef93bf38c9..c2f52ea0c4d1b9633de5520e8f708e04cc2ddb1d 100644
--- a/components/autofill/content/renderer/form_cache.cc
+++ b/components/autofill/content/renderer/form_cache.cc
@@ -64,8 +64,7 @@ void LogDeprecationMessages(const WebFormControlElement& element) {
// is imposed by WebFormElementToFormData().
Evan Stade 2015/11/04 17:15:18 I think this comment needs further updating becaus
sebsg 2015/11/10 19:04:50 As I read the code more I realized that num_editab
bool ShouldIgnoreForm(size_t num_editable_elements,
size_t num_control_elements) {
- return (num_editable_elements < kRequiredAutofillFields &&
- num_control_elements > 0);
Evan Stade 2015/11/04 17:15:18 prefer this way of checking against 0 rather than
sebsg 2015/11/10 19:04:50 Done.
+ return (!num_editable_elements && num_control_elements);
Evan Stade 2015/11/04 17:15:18 nit: remove excess parens
sebsg 2015/11/10 19:04:50 Done.
}
} // namespace
@@ -117,8 +116,7 @@ std::vector<FormData> FormCache::ExtractNewForms() {
if (num_fields_seen > form_util::kMaxParseableFields)
return forms;
- if (form.fields.size() >= kRequiredAutofillFields &&
- !ContainsKey(parsed_forms_, form)) {
+ if (!ContainsKey(parsed_forms_, form) && IsFormInteresting(form)) {
for (auto it = parsed_forms_.begin(); it != parsed_forms_.end(); ++it) {
if (it->SameFormAs(form)) {
parsed_forms_.erase(it);
@@ -155,8 +153,8 @@ std::vector<FormData> FormCache::ExtractNewForms() {
if (num_fields_seen > form_util::kMaxParseableFields)
return forms;
- if (synthetic_form.fields.size() >= kRequiredAutofillFields &&
- !parsed_forms_.count(synthetic_form)) {
+ if (!parsed_forms_.count(synthetic_form) &&
+ IsFormInteresting(synthetic_form)) {
SaveInitialValues(control_elements);
forms.push_back(synthetic_form);
parsed_forms_.insert(synthetic_form);
@@ -305,6 +303,23 @@ bool FormCache::ShowPredictions(const FormDataPredictions& form) {
return true;
}
+// static
+bool FormCache::IsFormInteresting(FormData form) {
+ if (form.fields.empty())
+ return false;
+
+ // If the form has at least one field with an autocomplete attribute,
+ // autocomplete suggestions will be shown.
Evan Stade 2015/11/04 17:15:18 this comment is misleading, we don't know if sugge
sebsg 2015/11/10 19:04:50 Done.
+ for (auto field : form.fields) {
+ if (!field.autocomplete_attribute.empty())
+ return true;
+ }
+
+ // If there are no autocomplete attributes, the form needs to have at least
+ // the required number of fields to be a candidate for autofill.
+ return form.fields.size() >= kRequiredAutofillFields;
+}
+
size_t FormCache::ScanFormControlElements(
const std::vector<WebFormControlElement>& control_elements,
bool log_deprecation_messages) {

Powered by Google App Engine
This is Rietveld 408576698