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

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

Issue 753393004: Add flag for single click autofill (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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/autofill_agent.cc
diff --git a/components/autofill/content/renderer/autofill_agent.cc b/components/autofill/content/renderer/autofill_agent.cc
index 6efe69df0e4b526dc435421536787edbc9bc2a20..1b4daba736456c7f7e02d0cd7a6f5b32c068a1da 100644
--- a/components/autofill/content/renderer/autofill_agent.cc
+++ b/components/autofill/content/renderer/autofill_agent.cc
@@ -119,6 +119,15 @@ void TrimStringVectorForIPC(std::vector<base::string16>* strings) {
} // namespace
+AutofillAgent::ShowSuggestionsOptions::ShowSuggestionsOptions()
+ : autofill_on_empty_values(false),
+ requires_caret_at_end(false),
+ display_warning_if_disabled(false),
+ datalist_only(false),
+ show_full_suggestion_list(false),
+ show_password_suggestions_only(false) {
+}
+
AutofillAgent::AutofillAgent(content::RenderView* render_view,
PasswordAutofillAgent* password_autofill_agent,
PasswordGenerationAgent* password_generation_agent)
@@ -264,7 +273,7 @@ void AutofillAgent::didRequestAutocomplete(
render_view()->GetSSLStatusOfFrame(form.document().frame());
bool is_safe = url.SchemeIs(url::kHttpsScheme) &&
!net::IsCertStatusError(ssl_status.cert_status);
- bool allow_unsafe = CommandLine::ForCurrentProcess()->HasSwitch(
+ bool allow_unsafe = base::CommandLine::ForCurrentProcess()->HasSwitch(
::switches::kReduceSecurityForTesting);
FormData form_data;
@@ -316,24 +325,26 @@ void AutofillAgent::FormControlElementClicked(
if (!input_element && !IsTextAreaElement(element))
return;
- bool show_full_suggestion_list = element.isAutofilled() || was_focused;
- bool show_password_suggestions_only = !was_focused;
+ ShowSuggestionsOptions options;
+ options.autofill_on_empty_values = true;
+ options.display_warning_if_disabled = true;
+ options.show_full_suggestion_list = element.isAutofilled();
- // TODO(gcasto): Remove after crbug.com/430318 has been fixed.
- bool show_suggestions = true;
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableSingleClickAutofill)) {
+ // Show full suggestions when clicking on an already-focused form field. On
+ // the initial click (not focused yet), only show password suggestions.
#if defined(OS_ANDROID)
- show_suggestions = was_focused;
+ // TODO(gcasto): Remove after crbug.com/430318 has been fixed.
+ if (!was_focused)
+ return;
#endif
- if (show_suggestions) {
- ShowSuggestions(element,
- true,
- false,
- true,
- false,
- show_full_suggestion_list,
- show_password_suggestions_only);
+ options.show_full_suggestion_list =
+ options.show_full_suggestion_list || was_focused;
+ options.show_password_suggestions_only = !was_focused;
}
+ ShowSuggestions(element, options);
}
void AutofillAgent::textFieldDidEndEditing(const WebInputElement& element) {
@@ -385,7 +396,9 @@ void AutofillAgent::TextFieldDidChangeImpl(
}
}
- ShowSuggestions(element, false, true, false, false, false, false);
+ ShowSuggestionsOptions options;
+ options.requires_caret_at_end = true;
+ ShowSuggestions(element, options);
FormData form;
FormFieldData field;
@@ -406,12 +419,20 @@ void AutofillAgent::textFieldDidReceiveKeyDown(const WebInputElement& element,
}
if (event.windowsKeyCode == ui::VKEY_DOWN ||
- event.windowsKeyCode == ui::VKEY_UP)
- ShowSuggestions(element, true, true, true, false, false, false);
+ event.windowsKeyCode == ui::VKEY_UP) {
+ ShowSuggestionsOptions options;
+ options.autofill_on_empty_values = true;
+ options.requires_caret_at_end = true;
+ options.display_warning_if_disabled = true;
+ ShowSuggestions(element, options);
+ }
}
void AutofillAgent::openTextDataListChooser(const WebInputElement& element) {
- ShowSuggestions(element, true, false, false, true, false, false);
+ ShowSuggestionsOptions options;
+ options.autofill_on_empty_values = true;
+ options.datalist_only = true;
+ ShowSuggestions(element, options);
}
void AutofillAgent::firstUserGestureObserved() {
@@ -562,22 +583,17 @@ void AutofillAgent::OnRequestAutocompleteResult(
}
void AutofillAgent::ShowSuggestions(const WebFormControlElement& element,
- bool autofill_on_empty_values,
- bool requires_caret_at_end,
- bool display_warning_if_disabled,
- bool datalist_only,
- bool show_full_suggestion_list,
- bool show_password_suggestions_only) {
+ const ShowSuggestionsOptions& options) {
if (!element.isEnabled() || element.isReadOnly())
return;
- if (!datalist_only && !element.suggestedValue().isEmpty())
+ if (!options.datalist_only && !element.suggestedValue().isEmpty())
return;
const WebInputElement* input_element = toWebInputElement(&element);
if (input_element) {
if (!input_element->isTextField() || input_element->isPasswordField())
return;
- if (!datalist_only && !input_element->suggestedValue().isEmpty())
+ if (!options.datalist_only && !input_element->suggestedValue().isEmpty())
return;
} else {
DCHECK(IsTextAreaElement(element));
@@ -588,10 +604,10 @@ void AutofillAgent::ShowSuggestions(const WebFormControlElement& element,
// Don't attempt to autofill with values that are too large or if filling
// criteria are not met.
WebString value = element.editingValue();
- if (!datalist_only &&
+ if (!options.datalist_only &&
(value.length() > kMaxDataLength ||
- (!autofill_on_empty_values && value.isEmpty()) ||
- (requires_caret_at_end &&
+ (!options.autofill_on_empty_values && value.isEmpty()) ||
+ (options.requires_caret_at_end &&
(element.selectionStart() != element.selectionEnd() ||
element.selectionEnd() != static_cast<int>(value.length()))))) {
// Any popup currently showing is obsolete.
@@ -601,9 +617,9 @@ void AutofillAgent::ShowSuggestions(const WebFormControlElement& element,
element_ = element;
if (IsAutofillableInputElement(input_element) &&
- (password_autofill_agent_->ShowSuggestions(*input_element,
- show_full_suggestion_list) ||
- show_password_suggestions_only)) {
+ (password_autofill_agent_->ShowSuggestions(
+ *input_element, options.show_full_suggestion_list) ||
+ options.show_password_suggestions_only)) {
is_popup_possibly_visible_ = true;
return;
}
@@ -613,14 +629,15 @@ void AutofillAgent::ShowSuggestions(const WebFormControlElement& element,
// popup. Note that we cannot use the WebKit method element.autoComplete()
// as it does not allow us to distinguish the case where autocomplete is
// disabled for *both* the element and for the form.
- const base::string16 autocomplete_attribute =
- element.getAttribute("autocomplete");
- if (LowerCaseEqualsASCII(autocomplete_attribute, "off"))
- display_warning_if_disabled = false;
-
- QueryAutofillSuggestions(element,
- display_warning_if_disabled,
- datalist_only);
+ bool display_warning = options.display_warning_if_disabled;
+ if (display_warning) {
+ const base::string16 autocomplete_attribute =
+ element.getAttribute("autocomplete");
+ if (LowerCaseEqualsASCII(autocomplete_attribute, "off"))
+ display_warning = false;
+ }
+
+ QueryAutofillSuggestions(element, display_warning, options.datalist_only);
}
void AutofillAgent::QueryAutofillSuggestions(

Powered by Google App Engine
This is Rietveld 408576698