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

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

Issue 11270018: [autofill] Adding new API to request an interactive autocomplete UI flow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: newest Created 8 years, 2 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 3977caae7a9ab189390c0b0e182b6885247eba68..51c83e9da6e6e63f5b10c99b21cf1127fde12feb 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"
@@ -54,6 +55,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;
Ilya Sherman 2012/10/27 07:44:11 This should be a private member of the class. Als
Dan Beam 2012/10/29 19:17:05 I don't think this is relevant any more.
+
void AppendDataListSuggestions(const WebKit::WebInputElement& element,
std::vector<string16>* values,
std::vector<string16>* labels,
@@ -159,6 +163,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 +219,29 @@ void AutofillAgent::DidChangeScrollOffset(WebKit::WebFrame*) {
Send(new AutofillHostMsg_HideAutofillPopup(routing_id()));
}
+void AutofillAgent::didRequestAutocomplete(WebKit::WebFrame* frame,
+ const WebFormElement& form) {
+ request_autocomplete_query_id_ += 1;
Evan Stade 2012/10/29 17:54:28 ++
Dan Beam 2012/10/29 19:17:05 Done.
+
+ // 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 +611,20 @@ void AutofillAgent::OnAcceptPasswordAutofillSuggestion(const string16& value) {
DCHECK(handled);
}
+void AutofillAgent::OnRequestAutocompleteFinished(int query_id, int result) {
+ DCHECK_GT(query_id, 0);
+ if (query_id != request_autocomplete_query_id_)
+ return;
+
+ if (result == WebFormElement::AutocompleteSuccess ||
+ result == WebFormElement::AutocompleteError) {
+ form_.finishRequestAutocomplete(
+ static_cast<WebFormElement::AutocompleteResult>(result));
+ } else {
+ NOTREACHED() << "Unknown autocomplete result.";
Ilya Sherman 2012/10/27 07:44:11 nit: Please remove the logged text; you can add it
Dan Beam 2012/10/29 19:17:05 Done.
+ }
+}
+
void AutofillAgent::ShowSuggestions(const WebInputElement& element,
bool autofill_on_empty_values,
bool requires_caret_at_end,
@@ -599,10 +642,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 +742,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();
Ilya Sherman 2012/10/27 07:44:11 You should also hide any popups that might be show
Dan Beam 2012/10/29 19:17:05 The code wasn't doing this before and I'm simply p
Ilya Sherman 2012/10/29 21:27:47 Feel free to file a bug against csharp@ and annota
Dan Beam 2012/10/29 23:08:23 https://chromiumcodereview.appspot.com/11273096/
+}
+
Evan Stade 2012/10/29 17:54:28 extra newline
Dan Beam 2012/10/29 19:17:05 Done.
+
} // namespace autofill

Powered by Google App Engine
This is Rietveld 408576698