Chromium Code Reviews| Index: chrome/renderer/autofill/autofill_agent.cc |
| diff --git a/chrome/renderer/autofill/autofill_agent.cc b/chrome/renderer/autofill/autofill_agent.cc |
| index 8af890ab029926c37efce9cfb7d83c3699cd94ca..aa9eddbb7431d5521234fa9591a6272d9e82b98f 100644 |
| --- a/chrome/renderer/autofill/autofill_agent.cc |
| +++ b/chrome/renderer/autofill/autofill_agent.cc |
| @@ -24,6 +24,7 @@ |
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebFormControlElement.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebFormElement.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
| @@ -130,6 +131,7 @@ AutofillAgent::AutofillAgent( |
| was_query_node_autofilled_(false), |
| has_shown_autofill_popup_for_current_edit_(false), |
| did_set_node_text_(false), |
| + has_requested_autocomplete_(false), |
| ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| render_view->GetWebView()->setAutofillClient(this); |
| } |
| @@ -157,6 +159,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; |
| @@ -211,6 +215,30 @@ void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) { |
| Send(new AutofillHostMsg_HideAutofillPopup(routing_id())); |
| } |
| +void AutofillAgent::didRequestAutocomplete(WebKit::WebFrame* frame, |
| + const WebFormElement& form) { |
| + if (has_requested_autocomplete_) |
| + return; |
| + |
| + // Cancel any pending autofill requests. |
|
Ilya Sherman
2012/10/29 21:27:47
nit: "autofill" -> "Autofill"
Dan Beam
2012/10/29 23:08:24
D'oh, sorry, done.
|
| + ++autofill_query_id_; |
| + |
| + // Any popup currently showing is obsolete. |
| + HidePopups(); |
| + |
| + FormData form_data; |
| + if (WebFormElementToFormData(form, |
| + WebFormControlElement(), |
| + REQUIRE_AUTOCOMPLETE, |
| + EXTRACT_NONE, |
| + &form_data, |
| + NULL)) { |
| + form_ = form; |
| + has_requested_autocomplete_ = true; |
| + Send(new AutofillHostMsg_RequestAutocomplete(routing_id(), form_data)); |
| + } |
| +} |
| + |
| bool AutofillAgent::InputElementClicked(const WebInputElement& element, |
| bool was_focused, |
| bool is_focused) { |
| @@ -574,6 +602,21 @@ void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) { |
| DCHECK(handled); |
| } |
| +void AutofillAgent::OnRequestAutocompleteFinished(int result) { |
| + if (!has_requested_autocomplete_) |
| + return; |
|
Ilya Sherman
2012/10/29 21:27:47
nit: Can this be a DCHECK instead?
Dan Beam
2012/10/29 23:08:24
Done.
|
| + |
| + has_requested_autocomplete_ = false; |
| + |
| + if (result == WebFormElement::AutocompleteSuccess || |
| + result == WebFormElement::AutocompleteError) { |
| + form_.finishRequestAutocomplete( |
| + static_cast<WebFormElement::AutocompleteResult>(result)); |
| + } else { |
| + NOTREACHED(); |
| + } |
|
Ilya Sherman
2012/10/29 21:27:47
Optional nit: Maybe write this as a DCHECK() + rem
Dan Beam
2012/10/29 23:08:24
Done.
|
| +} |
| + |
| void AutofillAgent::ShowSuggestions(const WebInputElement& element, |
| bool autofill_on_empty_values, |
| bool requires_caret_at_end, |
| @@ -591,10 +634,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; |
| } |
| @@ -694,4 +734,10 @@ 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 |