summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-08 02:38:04 +0000
committerpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-08 02:38:04 +0000
commitf0961cfdecddaaac9c89fb65c67ba3377d066043 (patch)
tree61ad1f994b2130b8fbc67555d08319c14fa5793b /chrome/browser
parentd893ab9643e5284db08087bc7514f59e37d6b319 (diff)
downloadchromium_src-f0961cfdecddaaac9c89fb65c67ba3377d066043.zip
chromium_src-f0961cfdecddaaac9c89fb65c67ba3377d066043.tar.gz
chromium_src-f0961cfdecddaaac9c89fb65c67ba3377d066043.tar.bz2
Review URL: http://codereview.chromium.org/10237
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5059 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autofill_manager.cc56
-rw-r--r--chrome/browser/autofill_manager.h28
-rw-r--r--chrome/browser/render_view_host.cc38
-rw-r--r--chrome/browser/render_view_host.h6
-rw-r--r--chrome/browser/render_view_host_delegate.h14
-rw-r--r--chrome/browser/web_contents.cc11
-rw-r--r--chrome/browser/web_contents.h2
7 files changed, 57 insertions, 98 deletions
diff --git a/chrome/browser/autofill_manager.cc b/chrome/browser/autofill_manager.cc
index 9493992..af8589b 100644
--- a/chrome/browser/autofill_manager.cc
+++ b/chrome/browser/autofill_manager.cc
@@ -8,21 +8,15 @@
#include "chrome/browser/profile.h"
#include "chrome/browser/web_contents.h"
-AutofillManager::AutofillManager(WebContents* web_contents) :
- web_contents_(web_contents),
- pending_query_handle_(0),
- node_id_(0),
- request_id_(0) {
- form_autofill_enabled_.Init(prefs::kFormAutofillEnabled,
- profile()->GetPrefs(), NULL);
-}
-
AutofillManager::~AutofillManager() {
- CancelPendingQuery();
+ ClearPendingQuery();
}
-void AutofillManager::CancelPendingQuery() {
- if (pending_query_handle_) {
+void AutofillManager::ClearPendingQuery() {
+ pending_query_name_.clear();
+ pending_query_prefix_.clear();
+
+ if (query_is_pending_) {
WebDataService* web_data_service =
profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
if (!web_data_service) {
@@ -32,10 +26,7 @@ void AutofillManager::CancelPendingQuery() {
web_data_service->CancelRequest(pending_query_handle_);
}
pending_query_handle_ = 0;
-}
-
-Profile* AutofillManager::profile() {
- return web_contents_->profile();
+ query_is_pending_ = false;
}
void AutofillManager::AutofillFormSubmitted(const AutofillForm& form) {
@@ -44,12 +35,7 @@ void AutofillManager::AutofillFormSubmitted(const AutofillForm& form) {
void AutofillManager::FetchValuesForName(const std::wstring& name,
const std::wstring& prefix,
- int limit,
- int64 node_id,
- int request_id) {
- if (!*form_autofill_enabled_)
- return;
-
+ int limit) {
WebDataService* web_data_service =
profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
if (!web_data_service) {
@@ -57,22 +43,17 @@ void AutofillManager::FetchValuesForName(const std::wstring& name,
return;
}
- CancelPendingQuery();
-
- node_id_ = node_id;
- request_id_ = request_id;
+ ClearPendingQuery();
pending_query_handle_ = web_data_service->
GetFormValuesForElementName(name, prefix, limit, this);
+ pending_query_name_ = name;
+ pending_query_prefix_ = prefix;
}
void AutofillManager::OnWebDataServiceRequestDone(WebDataService::Handle h,
const WDTypedResult* result) {
- DCHECK(pending_query_handle_);
- pending_query_handle_ = 0;
-
- if (!*form_autofill_enabled_)
- return;
+ DCHECK(query_is_pending_);
DCHECK(result);
if (!result)
@@ -80,27 +61,18 @@ void AutofillManager::OnWebDataServiceRequestDone(WebDataService::Handle h,
switch (result->GetType()) {
case AUTOFILL_VALUE_RESULT: {
- RenderViewHost* host = web_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;
}
+
+ ClearPendingQuery();
}
void AutofillManager::StoreFormEntriesInWebDatabase(
const AutofillForm& form) {
- if (!*form_autofill_enabled_)
- return;
-
if (profile()->IsOffTheRecord())
return;
diff --git a/chrome/browser/autofill_manager.h b/chrome/browser/autofill_manager.h
index 72a04d4..fac533f 100644
--- a/chrome/browser/autofill_manager.h
+++ b/chrome/browser/autofill_manager.h
@@ -9,22 +9,22 @@
#include <string>
#include "chrome/browser/webdata/web_data_service.h"
-#include "chrome/common/pref_member.h"
+#include "chrome/browser/web_contents.h"
#include "webkit/glue/autofill_form.h"
class Profile;
-class WebContents;
// Per-tab autofill manager. Handles receiving form data from the renderer and
// the storing and retrieving of form data through WebDataService.
class AutofillManager : public WebDataServiceConsumer {
public:
- explicit AutofillManager(WebContents* web_contents);
+ explicit AutofillManager(WebContents* web_contents)
+ : query_is_pending_(false), web_contents_(web_contents) {}
virtual ~AutofillManager();
- void CancelPendingQuery();
+ void ClearPendingQuery();
- Profile* profile();
+ Profile* profile() { return web_contents_->profile(); }
// Called when a form is submitted (i.e. when the user hits the submit button)
// to store the form entries in the profile's sql database.
@@ -32,11 +32,8 @@ class AutofillManager : public WebDataServiceConsumer {
// Starts a query into the database for the values corresponding to name.
// OnWebDataServiceRequestDone gets called when the query completes.
- void FetchValuesForName(const std::wstring& name,
- const std::wstring& prefix,
- int limit,
- int64 node_id,
- int request_id);
+ void FetchValuesForName(const std::wstring& name, const std::wstring& prefix,
+ int limit);
// WebDataServiceConsumer implementation.
virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
@@ -46,15 +43,14 @@ class AutofillManager : public WebDataServiceConsumer {
void StoreFormEntriesInWebDatabase(const AutofillForm& form);
WebContents* web_contents_;
-
- BooleanPrefMember form_autofill_enabled_;
-
+
// When the manager makes a request from WebDataService, the database
- // is queried on another thread, we record the query handle until we
+ // is queried on another thread, we record the query in this map until we
// get called back.
+ bool query_is_pending_;
WebDataService::Handle pending_query_handle_;
- int64 node_id_;
- int request_id_;
+ std::wstring pending_query_name_;
+ std::wstring pending_query_prefix_;
DISALLOW_COPY_AND_ASSIGN(AutofillManager);
};
diff --git a/chrome/browser/render_view_host.cc b/chrome/browser/render_view_host.cc
index d6b7f74..71c9574 100644
--- a/chrome/browser/render_view_host.cc
+++ b/chrome/browser/render_view_host.cc
@@ -1233,15 +1233,37 @@ void RenderViewHost::OnQueryFormFieldAutofill(const std::wstring& field_name,
const std::wstring& user_text,
int64 node_id,
int request_id) {
- delegate_->GetAutofillSuggestions(field_name, user_text, node_id, request_id);
-}
+ // TODO(jcampan): this is where the suggestions should be queried from the
+ // database. The sample code commented below is left here in the meantime for
+ // testing purpose.
+#ifndef TEST_AUTOFILL
+ static std::vector<std::wstring>* suggestions = NULL;
+ if (!suggestions) {
+ suggestions = new std::vector<std::wstring>();
+ suggestions->push_back(L"Alice");
+ suggestions->push_back(L"Jay");
+ suggestions->push_back(L"Jason");
+ suggestions->push_back(L"Jasmine");
+ suggestions->push_back(L"Jamel");
+ suggestions->push_back(L"Jamelo");
+ suggestions->push_back(L"Volvo");
+ suggestions->push_back(L"Volswagen");
+ }
+
-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));
- // Default index -1 means no default suggestion.
+ std::vector<std::wstring> result;
+ for (std::vector<std::wstring>::iterator iter = suggestions->begin();
+ iter != suggestions->end(); ++iter) {
+ if (StartsWith(*iter, user_text, false))
+ result.push_back(*iter);
+ }
+ Send(new ViewMsg_AutofillSuggestions(routing_id_,
+ node_id, request_id, result, 0));
+#else
+ Send(new ViewMsg_AutofillSuggestions(routing_id_,
+ node_id, request_id,
+ std::vector<std::wstring>(), 0));
+#endif
}
void RenderViewHost::NotifyRendererUnresponsive() {
diff --git a/chrome/browser/render_view_host.h b/chrome/browser/render_view_host.h
index 3638f9b..6c9fede 100644
--- a/chrome/browser/render_view_host.h
+++ b/chrome/browser/render_view_host.h
@@ -392,12 +392,6 @@ class RenderViewHost : public RenderWidgetHost {
// as a popup.
void DisassociateFromPopupCount();
- // 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,
- int default_suggestion_index);
-
protected:
// Overridden from RenderWidgetHost:
virtual void UnhandledInputEvent(const WebInputEvent& event);
diff --git a/chrome/browser/render_view_host_delegate.h b/chrome/browser/render_view_host_delegate.h
index 63e2eaa..4230438 100644
--- a/chrome/browser/render_view_host_delegate.h
+++ b/chrome/browser/render_view_host_delegate.h
@@ -9,7 +9,6 @@
#include <vector>
#include "base/basictypes.h"
-#include "chrome/browser/autofill_manager.h"
#include "chrome/common/render_messages.h"
#include "webkit/glue/webpreferences.h"
@@ -284,21 +283,10 @@ class RenderViewHostDelegate {
// Password forms have been detected in the page.
virtual void PasswordFormsSeen(const std::vector<PasswordForm>& forms) { }
-
+
// Forms fillable by autofill have been detected in the page.
virtual void AutofillFormSubmitted(const AutofillForm& form) { }
- // Called to retrieve a list of suggestions from the web database given
- // the name of the field |field_name| and what the user has already typed in
- // the field |user_text|. Appeals to the database thead to perform the 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) { }
-
// Notification that the page has an OpenSearch description document.
virtual void PageHasOSDD(RenderViewHost* render_view_host,
int32 page_id, const GURL& doc_url,
diff --git a/chrome/browser/web_contents.cc b/chrome/browser/web_contents.cc
index acd9338..0c37ae0 100644
--- a/chrome/browser/web_contents.cc
+++ b/chrome/browser/web_contents.cc
@@ -134,13 +134,8 @@ const wchar_t* kPrefsToObserve[] = {
// no font is specified or a CSS generic family (serif or sans-serif)
// is not specified.
};
-
const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
-// Limit on the number of suggestions to appear in the pop-up menu under an
-// text input element in a form.
-const int kMaxAutofillMenuItems = 6;
-
void InitWebContentsClass() {
static bool web_contents_class_initialized = false;
if (!web_contents_class_initialized) {
@@ -1136,12 +1131,6 @@ void WebContents::AutofillFormSubmitted(
GetAutofillManager()->AutofillFormSubmitted(form);
}
-void WebContents::GetAutofillSuggestions(const std::wstring& field_name,
- const std::wstring& user_text, int64 node_id, int request_id) {
- GetAutofillManager()->FetchValuesForName(field_name, user_text,
- kMaxAutofillMenuItems, node_id, request_id);
-}
-
// Checks to see if we should generate a keyword based on the OSDD, and if
// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
void WebContents::PageHasOSDD(RenderViewHost* render_view_host,
diff --git a/chrome/browser/web_contents.h b/chrome/browser/web_contents.h
index 8b59d6b..8e06a1a 100644
--- a/chrome/browser/web_contents.h
+++ b/chrome/browser/web_contents.h
@@ -290,8 +290,6 @@ class WebContents : public TabContents,
IPC::Message* reply_msg);
virtual void PasswordFormsSeen(const std::vector<PasswordForm>& forms);
virtual void AutofillFormSubmitted(const AutofillForm& form);
- virtual void GetAutofillSuggestions(const std::wstring& field_name,
- const std::wstring& user_text, int64 node_id, int request_id);
virtual void PageHasOSDD(RenderViewHost* render_view_host,
int32 page_id, const GURL& url, bool autodetected);
virtual void InspectElementReply(int num_resources);