Index: chrome/renderer/autofill/autofill_agent.cc |
diff --git a/chrome/renderer/autofill/autofill_agent.cc b/chrome/renderer/autofill/autofill_agent.cc |
index 3977caae7a9ab189390c0b0e182b6885247eba68..7f3dc69d05a7f7b3b2a83fd2437404a0ddb91c6e 100644 |
--- a/chrome/renderer/autofill/autofill_agent.cc |
+++ b/chrome/renderer/autofill/autofill_agent.cc |
@@ -54,6 +54,9 @@ const size_t kMaximumTextSizeForAutofill = 1000; |
// via IPC (to prevent long IPC messages). |
const size_t kMaximumDataListSizeForAutofill = 30; |
+// A query counter for requests to show an interactive autocomplete UI. |
+int request_autocomplete_query_id_ = 0; |
+ |
void AppendDataListSuggestions(const WebKit::WebInputElement& element, |
std::vector<string16>* values, |
std::vector<string16>* labels, |
@@ -159,6 +162,8 @@ bool AutofillAgent::OnMessageReceived(const IPC::Message& message) { |
OnAcceptDataListSuggestion) |
IPC_MESSAGE_HANDLER(AutofillMsg_AcceptPasswordAutofillSuggestion, |
OnAcceptPasswordAutofillSuggestion) |
+ IPC_MESSAGE_HANDLER(AutofillMsg_RequestAutocompleteFinished, |
+ OnRequestAutocompleteFinished) |
IPC_MESSAGE_UNHANDLED(handled = false) |
IPC_END_MESSAGE_MAP() |
return handled; |
@@ -213,6 +218,29 @@ void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) { |
Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); |
} |
+void AutofillAgent::RequestAutocomplete(WebKit::WebFrame* frame, |
+ const WebFormElement& form) { |
+ request_autocomplete_query_id_ += 1; |
+ |
+ // Cancel any pending autofill requests. |
+ autofill_query_id_ += 1; |
+ |
+ // Any popup currently showing is obsolete. |
+ HidePopups(); |
+ |
+ FormData form_data; |
+ if (WebFormElementToFormData(form, |
+ WebFormControlElement(), |
+ REQUIRE_AUTOCOMPLETE, |
+ EXTRACT_NONE, |
+ &form_data, |
+ NULL)) { |
+ form_ = form; |
+ Send(new AutofillHostMsg_RequestAutocomplete( |
+ routing_id(), request_autocomplete_query_id_, form_data)); |
+ } |
+} |
+ |
bool AutofillAgent::InputElementClicked(const WebInputElement& element, |
bool was_focused, |
bool is_focused) { |
@@ -582,6 +610,12 @@ void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { |
DCHECK(handled); |
} |
+void AutofillAgent::OnRequestAutocompleteFinished(int query_id, bool success) { |
+ DCHECK_GT(query_id, 0); |
+ if (query_id == request_autocomplete_query_id_) |
+ form_.dispatchAutocompleteEvent(success); |
+} |
+ |
void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
bool autofill_on_empty_values, |
bool requires_caret_at_end, |
@@ -599,10 +633,7 @@ void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
(element.selectionStart() != element.selectionEnd() || |
element.selectionEnd() != static_cast<int>(value.length())))) { |
// Any popup currently showing is obsolete. |
- WebKit::WebView* web_view = render_view()->GetWebView(); |
- if (web_view) |
- web_view->hidePopups(); |
- |
+ HidePopups(); |
return; |
} |
@@ -702,4 +733,11 @@ void AutofillAgent::SetNodeText(const string16& value, |
node->setEditingValue(substring); |
} |
+void AutofillAgent::HidePopups() { |
+ WebKit::WebView* web_view = render_view()->GetWebView(); |
+ if (web_view) |
+ web_view->hidePopups(); |
+} |
+ |
+ |
} // namespace autofill |