summaryrefslogtreecommitdiffstats
path: root/chrome/browser/autocomplete_history_manager.cc
diff options
context:
space:
mode:
authorthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-08 14:40:53 +0000
committerthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-08 14:40:53 +0000
commitce0a501326e20c17e76796f550179a49be67bc0f (patch)
treea620ad1268f1313da9fda613ef1c2822087d4c82 /chrome/browser/autocomplete_history_manager.cc
parenta39aa53a7acabb03a86a5be5c663d6ae47215440 (diff)
downloadchromium_src-ce0a501326e20c17e76796f550179a49be67bc0f.zip
chromium_src-ce0a501326e20c17e76796f550179a49be67bc0f.tar.gz
chromium_src-ce0a501326e20c17e76796f550179a49be67bc0f.tar.bz2
Putting this back in since it didn't solve the failures.
Revert 49164 - Backing this out to see if it fixes the failures on the two windows bots (landed about when they started). Revert 49030 AutoFill: Don't save credit card numbers from Autocomplete to the WebDB. BUG=8026 TEST=AutocompleteHistoryManagerTest Review URL: http://codereview.chromium.org/2676003 TBR=jhawkins@chromium.org Review URL: http://codereview.chromium.org/2748002 TBR=thomasvl@chromium.org Review URL: http://codereview.chromium.org/2770001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49165 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autocomplete_history_manager.cc')
-rw-r--r--chrome/browser/autocomplete_history_manager.cc95
1 files changed, 50 insertions, 45 deletions
diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc
index e5d96a7..d94f920 100644
--- a/chrome/browser/autocomplete_history_manager.cc
+++ b/chrome/browser/autocomplete_history_manager.cc
@@ -6,7 +6,9 @@
#include <vector>
+#include "base/string16.h"
#include "base/string_util.h"
+#include "chrome/browser/autofill/credit_card.h"
#include "chrome/browser/pref_service.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
@@ -16,38 +18,34 @@
using webkit_glue::FormData;
+namespace {
+
// Limit on the number of suggestions to appear in the pop-up menu under an
// text input element in a form.
-static const int kMaxAutofillMenuItems = 6;
+const int kMaxAutocompleteMenuItems = 6;
+
+// The separator characters for credit card values.
+const string16 kCreditCardSeparators = ASCIIToUTF16(" -");
+
+} // namespace
AutocompleteHistoryManager::AutocompleteHistoryManager(
TabContents* tab_contents) : tab_contents_(tab_contents),
pending_query_handle_(0),
query_id_(0) {
- form_autofill_enabled_.Init(prefs::kAutoFillEnabled,
- profile()->GetPrefs(), NULL);
-}
+ DCHECK(tab_contents);
-AutocompleteHistoryManager::~AutocompleteHistoryManager() {
- CancelPendingQuery();
-}
+ profile_ = tab_contents_->profile();
+ DCHECK(profile_);
-void AutocompleteHistoryManager::CancelPendingQuery() {
- if (pending_query_handle_) {
- SendSuggestions(NULL);
- 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;
+ web_data_service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ DCHECK(web_data_service_);
+
+ autofill_enabled_.Init(prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL);
}
-Profile* AutocompleteHistoryManager::profile() {
- return tab_contents_->profile();
+AutocompleteHistoryManager::~AutocompleteHistoryManager() {
+ CancelPendingQuery();
}
void AutocompleteHistoryManager::FormSubmitted(const FormData& form) {
@@ -56,35 +54,20 @@ void AutocompleteHistoryManager::FormSubmitted(const FormData& form) {
bool AutocompleteHistoryManager::GetAutocompleteSuggestions(
int query_id, const string16& name, const string16& prefix) {
- if (!*form_autofill_enabled_)
+ if (!*autofill_enabled_)
return false;
- WebDataService* web_data_service =
- profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!web_data_service) {
- NOTREACHED();
- return false;
- }
-
CancelPendingQuery();
query_id_ = query_id;
-
- pending_query_handle_ = web_data_service->GetFormValuesForElementName(
- name, prefix, kMaxAutofillMenuItems, this);
+ pending_query_handle_ = web_data_service_->GetFormValuesForElementName(
+ name, prefix, kMaxAutocompleteMenuItems, this);
return true;
}
void AutocompleteHistoryManager::RemoveAutocompleteEntry(
const string16& name, const string16& value) {
- WebDataService* web_data_service =
- profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
- if (!web_data_service) {
- NOTREACHED();
- return;
- }
-
- web_data_service->RemoveFormValueForElementName(name, value);
+ web_data_service_->RemoveFormValueForElementName(name, value);
}
void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
@@ -93,7 +76,7 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
DCHECK(pending_query_handle_);
pending_query_handle_ = 0;
- if (*form_autofill_enabled_) {
+ if (*autofill_enabled_) {
DCHECK(result);
SendSuggestions(result);
} else {
@@ -101,35 +84,57 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
}
}
+AutocompleteHistoryManager::AutocompleteHistoryManager(
+ Profile* profile, WebDataService* wds) : tab_contents_(NULL),
+ profile_(profile),
+ web_data_service_(wds),
+ pending_query_handle_(0),
+ query_id_(0) {
+ autofill_enabled_.Init(
+ prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL);
+}
+
+void AutocompleteHistoryManager::CancelPendingQuery() {
+ if (pending_query_handle_) {
+ SendSuggestions(NULL);
+ web_data_service_->CancelRequest(pending_query_handle_);
+ }
+ pending_query_handle_ = 0;
+}
+
void AutocompleteHistoryManager::StoreFormEntriesInWebDatabase(
const FormData& form) {
- if (!*form_autofill_enabled_)
+ if (!*autofill_enabled_)
return;
- if (profile()->IsOffTheRecord())
+ if (profile_->IsOffTheRecord())
return;
// We put the following restriction on stored FormFields:
// - non-empty name
// - non-empty value
// - text field
+ // - value is not a credit card number
std::vector<webkit_glue::FormField> values;
for (std::vector<webkit_glue::FormField>::const_iterator iter =
form.fields.begin();
iter != form.fields.end(); ++iter) {
if (!iter->value().empty() &&
!iter->name().empty() &&
- iter->form_control_type() == ASCIIToUTF16("text"))
+ iter->form_control_type() == ASCIIToUTF16("text") &&
+ !CreditCard::IsCreditCardNumber(iter->value()))
values.push_back(*iter);
}
- profile()->GetWebDataService(Profile::EXPLICIT_ACCESS)->AddFormFields(values);
+ if (!values.empty())
+ web_data_service_->AddFormFields(values);
}
void AutocompleteHistoryManager::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<string16> >* autofill_result =