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

Unified Diff: chrome/renderer/autofill/autofill_agent.cc

Issue 7514003: Show display warning if the form is autocomplete off. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add comment and change autofill_query_node_ type. Created 9 years, 5 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: chrome/renderer/autofill/autofill_agent.cc
diff --git a/chrome/renderer/autofill/autofill_agent.cc b/chrome/renderer/autofill/autofill_agent.cc
index 72110d0e41d54f1471a36c24144eaf555e7287ba..17d7a0c7c2daa5d1d7fdfa01f5cbba0266d8bc5e 100644
--- a/chrome/renderer/autofill/autofill_agent.cc
+++ b/chrome/renderer/autofill/autofill_agent.cc
@@ -234,7 +234,13 @@ void AutofillAgent::OnSuggestionsReturned(int query_id,
std::vector<int> ids(unique_ids);
int separator_index = -1;
- if (ids[0] < 0 && ids.size() > 1) {
+ if (!autofill_query_node_.isNull() && !autofill_query_node_.autoComplete()) {
+ // If autofill is disabled and we had suggestions, show a warning instead.
+ v.assign(1, l10n_util::GetStringUTF16(IDS_AUTOFILL_WARNING_FORM_DISABLED));
+ l.assign(1, string16());
+ i.assign(1, string16());
+ ids.assign(1, -1);
+ } else if (ids[0] < 0 && ids.size() > 1) {
// If we received a warning instead of suggestions from autofill but regular
// suggestions from autocomplete, don't show the autofill warning.
v.erase(v.begin());
@@ -320,7 +326,14 @@ void AutofillAgent::ShowSuggestions(const WebInputElement& element,
bool autofill_on_empty_values,
bool requires_caret_at_end,
bool display_warning_if_disabled) {
- if (!element.isEnabled() || element.isReadOnly() || !element.autoComplete() ||
+ // If autocomplete is disabled at the form level, then we might want to show
+ // a warning in place of suggestions. However, if autocomplete is disabled
+ // specifically for this field, we never want to show a warning. Otherwise,
+ // we might interfere with custom popups (e.g. search suggestions) used by
+ // the website.
+ const WebFormElement form = element.form();
+ if (!element.isEnabled() || element.isReadOnly() ||
+ (!element.autoComplete() && form.autoComplete()) ||
!element.isTextField() || element.isPasswordField() ||
!element.suggestedValue().isEmpty())
return;
@@ -345,21 +358,21 @@ void AutofillAgent::ShowSuggestions(const WebInputElement& element,
QueryAutofillSuggestions(element, display_warning_if_disabled);
}
-void AutofillAgent::QueryAutofillSuggestions(const WebNode& node,
+void AutofillAgent::QueryAutofillSuggestions(const WebInputElement& element,
bool display_warning_if_disabled) {
static int query_counter = 0;
autofill_query_id_ = query_counter++;
- autofill_query_node_ = node;
+ autofill_query_node_ = element;
display_warning_if_disabled_ = display_warning_if_disabled;
webkit_glue::FormData form;
webkit_glue::FormField field;
- if (!FindFormAndFieldForNode(node, &form, &field)) {
+ if (!FindFormAndFieldForNode(element, &form, &field)) {
// If we didn't find the cached form, at least let autocomplete have a shot
// at providing suggestions.
- FormManager::WebFormControlElementToFormField(
- node.toConst<WebFormControlElement>(), FormManager::EXTRACT_VALUE,
- &field);
+ FormManager::WebFormControlElementToFormField(element,
+ FormManager::EXTRACT_VALUE,
+ &field);
}
Send(new AutofillHostMsg_QueryFormFieldAutofill(
« chrome/renderer/autofill/autofill_agent.h ('K') | « chrome/renderer/autofill/autofill_agent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698