summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autofill_manager.cc
diff options
context:
space:
mode:
authorpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-05 20:26:28 +0000
committerpetersont@google.com <petersont@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-11-05 20:26:28 +0000
commit6f2ff8526c54090bf6afe9c80f2d63551231e997 (patch)
tree2cacbf423441a4f442e8ec01a176c519154c7112 /chrome/browser/autofill_manager.cc
parent2b481f8d533c08824d3aeeeb9a0407b596077c16 (diff)
downloadchromium_src-6f2ff8526c54090bf6afe9c80f2d63551231e997.zip
chromium_src-6f2ff8526c54090bf6afe9c80f2d63551231e997.tar.gz
chromium_src-6f2ff8526c54090bf6afe9c80f2d63551231e997.tar.bz2
Added functions to WebDatabase and WebDataService for recording frequent entries in text input elements in forms. Also added the class AutofillManager which gets instantiated once per WebContents and provides an API from which the database can be easily accessed to provide a list of possible desired values to be entered in a text field given what the user has already typed there.
Review URL: http://codereview.chromium.org/8845 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@4809 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill_manager.cc')
-rw-r--r--chrome/browser/autofill_manager.cc81
1 files changed, 81 insertions, 0 deletions
diff --git a/chrome/browser/autofill_manager.cc b/chrome/browser/autofill_manager.cc
new file mode 100644
index 0000000..af8589b
--- /dev/null
+++ b/chrome/browser/autofill_manager.cc
@@ -0,0 +1,81 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/autofill_manager.h"
+
+#include "base/string_util.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/web_contents.h"
+
+AutofillManager::~AutofillManager() {
+ ClearPendingQuery();
+}
+
+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) {
+ NOTREACHED();
+ return;
+ }
+ web_data_service->CancelRequest(pending_query_handle_);
+ }
+ pending_query_handle_ = 0;
+ query_is_pending_ = false;
+}
+
+void AutofillManager::AutofillFormSubmitted(const AutofillForm& form) {
+ StoreFormEntriesInWebDatabase(form);
+}
+
+void AutofillManager::FetchValuesForName(const std::wstring& name,
+ const std::wstring& prefix,
+ int limit) {
+ WebDataService* web_data_service =
+ profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ if (!web_data_service) {
+ NOTREACHED();
+ return;
+ }
+
+ 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(query_is_pending_);
+
+ DCHECK(result);
+ if (!result)
+ return;
+
+ switch (result->GetType()) {
+ case AUTOFILL_VALUE_RESULT: {
+ break;
+ }
+ default:
+ NOTREACHED();
+ break;
+ }
+
+ ClearPendingQuery();
+}
+
+void AutofillManager::StoreFormEntriesInWebDatabase(
+ const AutofillForm& form) {
+ if (profile()->IsOffTheRecord())
+ return;
+
+ profile()->GetWebDataService(Profile::EXPLICIT_ACCESS)->
+ AddAutofillFormElements(form.elements);
+}