summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/autofill_manager.cc58
-rw-r--r--chrome/browser/autofill_manager.h12
-rw-r--r--chrome/browser/renderer_host/render_view_host.cc22
-rw-r--r--chrome/browser/renderer_host/render_view_host.h12
-rw-r--r--chrome/browser/renderer_host/render_view_host_delegate.h8
-rw-r--r--chrome/common/render_messages_internal.h10
-rw-r--r--chrome/renderer/render_view.cc19
-rw-r--r--chrome/renderer/render_view.h7
8 files changed, 72 insertions, 76 deletions
diff --git a/chrome/browser/autofill_manager.cc b/chrome/browser/autofill_manager.cc
index 99b55bde..ee274df 100644
--- a/chrome/browser/autofill_manager.cc
+++ b/chrome/browser/autofill_manager.cc
@@ -23,7 +23,6 @@ void AutofillManager::RegisterUserPrefs(PrefService* prefs) {
AutofillManager::AutofillManager(TabContents* tab_contents)
: tab_contents_(tab_contents),
pending_query_handle_(0),
- node_id_(0),
request_id_(0) {
form_autofill_enabled_.Init(prefs::kFormAutofillEnabled,
profile()->GetPrefs(), NULL);
@@ -35,6 +34,7 @@ AutofillManager::~AutofillManager() {
void AutofillManager::CancelPendingQuery() {
if (pending_query_handle_) {
+ SendSuggestions(NULL);
WebDataService* web_data_service =
profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
if (!web_data_service) {
@@ -55,27 +55,26 @@ void AutofillManager::AutofillFormSubmitted(
StoreFormEntriesInWebDatabase(form);
}
-void AutofillManager::GetAutofillSuggestions(const std::wstring& name,
- const std::wstring& prefix,
- int64 node_id,
- int request_id) {
+bool AutofillManager::GetAutofillSuggestions(int request_id,
+ const std::wstring& name,
+ const std::wstring& prefix) {
if (!*form_autofill_enabled_)
- return;
+ return false;
WebDataService* web_data_service =
profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
if (!web_data_service) {
NOTREACHED();
- return;
+ return false;
}
CancelPendingQuery();
- node_id_ = node_id;
request_id_ = request_id;
pending_query_handle_ = web_data_service->GetFormValuesForElementName(
name, prefix, kMaxAutofillMenuItems, this);
+ return true;
}
void AutofillManager::RemoveAutofillEntry(const std::wstring& name,
@@ -95,28 +94,11 @@ void AutofillManager::OnWebDataServiceRequestDone(WebDataService::Handle h,
DCHECK(pending_query_handle_);
pending_query_handle_ = 0;
- if (!*form_autofill_enabled_)
- return;
-
- DCHECK(result);
- if (!result)
- return;
-
- switch (result->GetType()) {
- case AUTOFILL_VALUE_RESULT: {
- RenderViewHost* host = tab_contents_->render_view_host();
- if (!host)
- return;
- const WDResult<std::vector<std::wstring> >* r =
- static_cast<const WDResult<std::vector<std::wstring> >*>(result);
- std::vector<std::wstring> suggestions = r->GetValue();
- host->AutofillSuggestionsReturned(suggestions, node_id_, request_id_, -1);
- break;
- }
-
- default:
- NOTREACHED();
- break;
+ if (*form_autofill_enabled_) {
+ DCHECK(result);
+ SendSuggestions(result);
+ } else {
+ SendSuggestions(NULL);
}
}
@@ -131,3 +113,19 @@ void AutofillManager::StoreFormEntriesInWebDatabase(
profile()->GetWebDataService(Profile::EXPLICIT_ACCESS)->
AddAutofillFormElements(form.elements);
}
+
+void AutofillManager::SendSuggestions(const WDTypedResult* result) {
+ RenderViewHost* host = tab_contents_->render_view_host();
+ if (!host)
+ return;
+ if (result) {
+ DCHECK(result->GetType() == AUTOFILL_VALUE_RESULT);
+ const WDResult<std::vector<std::wstring> >* autofill_result =
+ static_cast<const WDResult<std::vector<std::wstring> >*>(result);
+ host->AutofillSuggestionsReturned(
+ request_id_, autofill_result->GetValue(), -1);
+ } else {
+ host->AutofillSuggestionsReturned(
+ request_id_, std::vector<std::wstring>(), -1);
+ }
+}
diff --git a/chrome/browser/autofill_manager.h b/chrome/browser/autofill_manager.h
index 8fa241e..acea4d7 100644
--- a/chrome/browser/autofill_manager.h
+++ b/chrome/browser/autofill_manager.h
@@ -26,16 +26,13 @@ class AutofillManager : public RenderViewHostDelegate::Autofill,
explicit AutofillManager(TabContents* tab_contents);
virtual ~AutofillManager();
- void CancelPendingQuery();
-
Profile* profile();
// RenderViewHostDelegate::Autofill implementation.
virtual void AutofillFormSubmitted(const webkit_glue::AutofillForm& form);
- virtual void GetAutofillSuggestions(const std::wstring& name,
- const std::wstring& prefix,
- int64 node_id,
- int request_id);
+ virtual bool GetAutofillSuggestions(int request_id,
+ const std::wstring& name,
+ const std::wstring& prefix);
virtual void RemoveAutofillEntry(const std::wstring& name,
const std::wstring& value);
@@ -46,7 +43,9 @@ class AutofillManager : public RenderViewHostDelegate::Autofill,
static void RegisterUserPrefs(PrefService* prefs);
private:
+ void CancelPendingQuery();
void StoreFormEntriesInWebDatabase(const webkit_glue::AutofillForm& form);
+ void SendSuggestions(const WDTypedResult* suggestions);
TabContents* tab_contents_;
@@ -56,7 +55,6 @@ class AutofillManager : public RenderViewHostDelegate::Autofill,
// is queried on another thread, we record the query handle until we
// get called back.
WebDataService::Handle pending_query_handle_;
- int64 node_id_;
int request_id_;
DISALLOW_COPY_AND_ASSIGN(AutofillManager);
diff --git a/chrome/browser/renderer_host/render_view_host.cc b/chrome/browser/renderer_host/render_view_host.cc
index cd9eb26..ff6adce 100644
--- a/chrome/browser/renderer_host/render_view_host.cc
+++ b/chrome/browser/renderer_host/render_view_host.cc
@@ -1550,16 +1550,18 @@ void RenderViewHost::OnMsgShouldCloseACK(bool proceed) {
}
}
-void RenderViewHost::OnQueryFormFieldAutofill(const std::wstring& field_name,
- const std::wstring& user_text,
- int64 node_id,
- int request_id) {
+void RenderViewHost::OnQueryFormFieldAutofill(int request_id,
+ const std::wstring& field_name,
+ const std::wstring& user_text) {
RenderViewHostDelegate::Autofill* autofill_delegate =
delegate_->GetAutofillDelegate();
+ bool ok = false;
if (autofill_delegate) {
- autofill_delegate->GetAutofillSuggestions(field_name, user_text,
- node_id, request_id);
+ ok = autofill_delegate->GetAutofillSuggestions(
+ request_id, field_name, user_text);
}
+ if (!ok)
+ AutofillSuggestionsReturned(request_id, std::vector<std::wstring>(), 0);
}
void RenderViewHost::OnRemoveAutofillEntry(const std::wstring& field_name,
@@ -1571,10 +1573,10 @@ void RenderViewHost::OnRemoveAutofillEntry(const std::wstring& field_name,
}
void RenderViewHost::AutofillSuggestionsReturned(
- const std::vector<std::wstring>& suggestions,
- int64 node_id, int request_id, int default_suggestion_index) {
- Send(new ViewMsg_AutofillSuggestions(routing_id(), node_id,
- request_id, suggestions, -1));
+ int request_id, const std::vector<std::wstring>& suggestions,
+ int default_suggestion_index) {
+ Send(new ViewMsg_QueryFormFieldAutofill_ACK(
+ routing_id(), request_id, suggestions, -1));
// Default index -1 means no default suggestion.
}
diff --git a/chrome/browser/renderer_host/render_view_host.h b/chrome/browser/renderer_host/render_view_host.h
index c903ad6..52eb6b0 100644
--- a/chrome/browser/renderer_host/render_view_host.h
+++ b/chrome/browser/renderer_host/render_view_host.h
@@ -394,9 +394,8 @@ class RenderViewHost : public RenderWidgetHost,
void PopupNotificationVisibilityChanged(bool visible);
// Called by the AutofillManager when the list of suggestions is ready.
- void AutofillSuggestionsReturned(const std::vector<std::wstring>& suggestions,
- int64 node_id,
- int request_id,
+ void AutofillSuggestionsReturned(int request_id,
+ const std::vector<std::wstring>& suggestions,
int default_suggestion_index);
// Notifies the Renderer that a move or resize of its containing window has
@@ -571,10 +570,9 @@ class RenderViewHost : public RenderWidgetHost,
void OnDidGetApplicationInfo(int32 page_id,
const webkit_glue::WebApplicationInfo& info);
void OnMsgShouldCloseACK(bool proceed);
- void OnQueryFormFieldAutofill(const std::wstring& field_name,
- const std::wstring& user_text,
- int64 node_id,
- int request_id);
+ void OnQueryFormFieldAutofill(int request_id,
+ const std::wstring& field_name,
+ const std::wstring& user_text);
void OnRemoveAutofillEntry(const std::wstring& field_name,
const std::wstring& value);
diff --git a/chrome/browser/renderer_host/render_view_host_delegate.h b/chrome/browser/renderer_host/render_view_host_delegate.h
index 0f853c3..617c48c 100644
--- a/chrome/browser/renderer_host/render_view_host_delegate.h
+++ b/chrome/browser/renderer_host/render_view_host_delegate.h
@@ -352,10 +352,10 @@ class RenderViewHostDelegate {
// query. When the database thread is finished, the autofill manager
// retrieves the calling RenderViewHost and then passes the vector of
// suggestions to RenderViewHost::AutofillSuggestionsReturned.
- virtual void GetAutofillSuggestions(const std::wstring& field_name,
- const std::wstring& user_text,
- int64 node_id,
- int request_id) = 0;
+ // Return true to indicate that AutofillSuggestionsReturned will be called.
+ virtual bool GetAutofillSuggestions(int request_id,
+ const std::wstring& field_name,
+ const std::wstring& user_text) = 0;
// Called when the user has indicated that she wants to remove the specified
// autofill suggestion from the database.
diff --git a/chrome/common/render_messages_internal.h b/chrome/common/render_messages_internal.h
index 8a48182..824a773 100644
--- a/chrome/common/render_messages_internal.h
+++ b/chrome/common/render_messages_internal.h
@@ -591,8 +591,7 @@ IPC_BEGIN_MESSAGES(View)
// Reply to the ViewHostMsg_QueryFormFieldAutofill message with the autofill
// suggestions.
- IPC_MESSAGE_ROUTED4(ViewMsg_AutofillSuggestions,
- int64 /* id of the text input field */,
+ IPC_MESSAGE_ROUTED3(ViewMsg_QueryFormFieldAutofill_ACK,
int /* id of the request message */,
std::vector<std::wstring> /* suggestions */,
int /* index of default suggestion */)
@@ -1601,11 +1600,10 @@ IPC_BEGIN_MESSAGES(ViewHost)
gfx::Rect /* Out: Window location */)
// Queries the browser for suggestion for autofill in a form input field.
- IPC_MESSAGE_ROUTED4(ViewHostMsg_QueryFormFieldAutofill,
+ IPC_MESSAGE_ROUTED3(ViewHostMsg_QueryFormFieldAutofill,
+ int /* id of this message */,
std::wstring /* field name */,
- std::wstring /* user entered text */,
- int64 /* id of the text input field */,
- int /* id of this message */)
+ std::wstring /* user entered text */)
// Instructs the browser to remove the specified autofill-entry from the
// database.
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc
index 816b19a..83e98a0 100644
--- a/chrome/renderer/render_view.cc
+++ b/chrome/renderer/render_view.cc
@@ -224,6 +224,7 @@ RenderView::RenderView(RenderThreadBase* render_thread,
has_unload_listener_(false),
decrement_shared_popup_at_destruction_(false),
form_field_autofill_request_id_(0),
+ form_field_autofill_node_id_(0),
popup_notification_visible_(false),
spelling_panel_visible_(false),
delay_seconds_for_form_state_sync_(kDefaultDelaySecondsForFormStateSync),
@@ -465,8 +466,8 @@ void RenderView::OnMessageReceived(const IPC::Message& message) {
OnMessageFromExternalHost)
IPC_MESSAGE_HANDLER(ViewMsg_DisassociateFromPopupCount,
OnDisassociateFromPopupCount)
- IPC_MESSAGE_HANDLER(ViewMsg_AutofillSuggestions,
- OnReceivedAutofillSuggestions)
+ IPC_MESSAGE_HANDLER(ViewMsg_QueryFormFieldAutofill_ACK,
+ OnQueryFormFieldAutofillAck)
IPC_MESSAGE_HANDLER(ViewMsg_PopupNotificationVisibilityChanged,
OnPopupNotificationVisibilityChanged)
IPC_MESSAGE_HANDLER(ViewMsg_MoveOrResizeStarted, OnMoveOrResizeStarted)
@@ -1237,10 +1238,9 @@ void RenderView::QueryFormFieldAutofill(const std::wstring& field_name,
int64 node_id) {
static int message_id_counter = 0;
form_field_autofill_request_id_ = message_id_counter++;
- Send(new ViewHostMsg_QueryFormFieldAutofill(routing_id_,
- field_name, text,
- node_id,
- form_field_autofill_request_id_));
+ form_field_autofill_node_id_ = node_id;
+ Send(new ViewHostMsg_QueryFormFieldAutofill(
+ routing_id_, form_field_autofill_request_id_, field_name, text));
}
void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
@@ -1248,16 +1248,15 @@ void RenderView::RemoveStoredAutofillEntry(const std::wstring& name,
Send(new ViewHostMsg_RemoveAutofillEntry(routing_id_, name, value));
}
-void RenderView::OnReceivedAutofillSuggestions(
- int64 node_id,
+void RenderView::OnQueryFormFieldAutofillAck(
int request_id,
const std::vector<std::wstring>& suggestions,
int default_suggestion_index) {
if (!webview() || request_id != form_field_autofill_request_id_)
return;
- webview()->AutofillSuggestionsForNode(node_id, suggestions,
- default_suggestion_index);
+ webview()->AutofillSuggestionsForNode(
+ form_field_autofill_node_id_, suggestions, default_suggestion_index);
}
void RenderView::OnPopupNotificationVisibilityChanged(bool visible) {
diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h
index 8a5b2cc..43d1643 100644
--- a/chrome/renderer/render_view.h
+++ b/chrome/renderer/render_view.h
@@ -635,8 +635,7 @@ class RenderView : public RenderWidget,
void OnThemeChanged();
// Notification that we have received autofill suggestion.
- void OnReceivedAutofillSuggestions(
- int64 node_id,
+ void OnQueryFormFieldAutofillAck(
int request_id,
const std::vector<std::wstring>& suggestions,
int default_suggestions_index);
@@ -874,6 +873,10 @@ class RenderView : public RenderWidget,
// out of date responses.
int form_field_autofill_request_id_;
+ // The id of the node corresponding to the last request sent for form field
+ // autofill.
+ int64 form_field_autofill_node_id_;
+
// We need to prevent windows from closing themselves with a window.close()
// call while a blocked popup notification is being displayed. We cannot
// synchronously query the Browser process. We cannot wait for the Browser