summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-08 13:43:51 +0000
committerthomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-08 13:43:51 +0000
commita39aa53a7acabb03a86a5be5c663d6ae47215440 (patch)
treee304aa2f39c6103bf75d151c41730f43d9111b1a /chrome/browser
parenta5e04eafb781ce5739ab08398bc7ded7ed512116 (diff)
downloadchromium_src-a39aa53a7acabb03a86a5be5c663d6ae47215440.zip
chromium_src-a39aa53a7acabb03a86a5be5c663d6ae47215440.tar.gz
chromium_src-a39aa53a7acabb03a86a5be5c663d6ae47215440.tar.bz2
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 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49164 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/autocomplete_history_manager.cc95
-rw-r--r--chrome/browser/autocomplete_history_manager.h14
-rw-r--r--chrome/browser/autocomplete_history_manager_unittest.cc86
-rw-r--r--chrome/browser/autofill/credit_card.cc52
-rw-r--r--chrome/browser/autofill/credit_card.h7
-rw-r--r--chrome/browser/webdata/web_data_service.h2
6 files changed, 81 insertions, 175 deletions
diff --git a/chrome/browser/autocomplete_history_manager.cc b/chrome/browser/autocomplete_history_manager.cc
index d94f920..e5d96a7 100644
--- a/chrome/browser/autocomplete_history_manager.cc
+++ b/chrome/browser/autocomplete_history_manager.cc
@@ -6,9 +6,7 @@
#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"
@@ -18,56 +16,75 @@
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.
-const int kMaxAutocompleteMenuItems = 6;
-
-// The separator characters for credit card values.
-const string16 kCreditCardSeparators = ASCIIToUTF16(" -");
-
-} // namespace
+static const int kMaxAutofillMenuItems = 6;
AutocompleteHistoryManager::AutocompleteHistoryManager(
TabContents* tab_contents) : tab_contents_(tab_contents),
pending_query_handle_(0),
query_id_(0) {
- DCHECK(tab_contents);
-
- profile_ = tab_contents_->profile();
- DCHECK(profile_);
-
- web_data_service_ = profile_->GetWebDataService(Profile::EXPLICIT_ACCESS);
- DCHECK(web_data_service_);
-
- autofill_enabled_.Init(prefs::kAutoFillEnabled, profile_->GetPrefs(), NULL);
+ form_autofill_enabled_.Init(prefs::kAutoFillEnabled,
+ profile()->GetPrefs(), NULL);
}
AutocompleteHistoryManager::~AutocompleteHistoryManager() {
CancelPendingQuery();
}
+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;
+}
+
+Profile* AutocompleteHistoryManager::profile() {
+ return tab_contents_->profile();
+}
+
void AutocompleteHistoryManager::FormSubmitted(const FormData& form) {
StoreFormEntriesInWebDatabase(form);
}
bool AutocompleteHistoryManager::GetAutocompleteSuggestions(
int query_id, const string16& name, const string16& prefix) {
- if (!*autofill_enabled_)
+ if (!*form_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, kMaxAutocompleteMenuItems, this);
+
+ pending_query_handle_ = web_data_service->GetFormValuesForElementName(
+ name, prefix, kMaxAutofillMenuItems, this);
return true;
}
void AutocompleteHistoryManager::RemoveAutocompleteEntry(
const string16& name, const string16& value) {
- web_data_service_->RemoveFormValueForElementName(name, value);
+ WebDataService* web_data_service =
+ profile()->GetWebDataService(Profile::EXPLICIT_ACCESS);
+ if (!web_data_service) {
+ NOTREACHED();
+ return;
+ }
+
+ web_data_service->RemoveFormValueForElementName(name, value);
}
void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
@@ -76,7 +93,7 @@ void AutocompleteHistoryManager::OnWebDataServiceRequestDone(
DCHECK(pending_query_handle_);
pending_query_handle_ = 0;
- if (*autofill_enabled_) {
+ if (*form_autofill_enabled_) {
DCHECK(result);
SendSuggestions(result);
} else {
@@ -84,57 +101,35 @@ 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 (!*autofill_enabled_)
+ if (!*form_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") &&
- !CreditCard::IsCreditCardNumber(iter->value()))
+ iter->form_control_type() == ASCIIToUTF16("text"))
values.push_back(*iter);
}
- if (!values.empty())
- web_data_service_->AddFormFields(values);
+ profile()->GetWebDataService(Profile::EXPLICIT_ACCESS)->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 =
diff --git a/chrome/browser/autocomplete_history_manager.h b/chrome/browser/autocomplete_history_manager.h
index 4e87bd6..2f8fe5e 100644
--- a/chrome/browser/autocomplete_history_manager.h
+++ b/chrome/browser/autocomplete_history_manager.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_
#define CHROME_BROWSER_AUTOCOMPLETE_HISTORY_MANAGER_H_
+#include <string>
+
#include "chrome/browser/pref_member.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
#include "chrome/browser/webdata/web_data_service.h"
@@ -25,6 +27,8 @@ class AutocompleteHistoryManager
explicit AutocompleteHistoryManager(TabContents* tab_contents);
virtual ~AutocompleteHistoryManager();
+ Profile* profile();
+
// RenderViewHostDelegate::Autocomplete implementation.
virtual void FormSubmitted(const webkit_glue::FormData& form);
virtual bool GetAutocompleteSuggestions(int query_id,
@@ -37,22 +41,14 @@ class AutocompleteHistoryManager
virtual void OnWebDataServiceRequestDone(WebDataService::Handle h,
const WDTypedResult* result);
- protected:
- friend class AutocompleteHistoryManagerTest;
-
- // For tests.
- AutocompleteHistoryManager(Profile* profile, WebDataService* wds);
-
private:
void CancelPendingQuery();
void StoreFormEntriesInWebDatabase(const webkit_glue::FormData& form);
void SendSuggestions(const WDTypedResult* suggestions);
TabContents* tab_contents_;
- Profile* profile_;
- scoped_refptr<WebDataService> web_data_service_;
- BooleanPrefMember autofill_enabled_;
+ 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
diff --git a/chrome/browser/autocomplete_history_manager_unittest.cc b/chrome/browser/autocomplete_history_manager_unittest.cc
deleted file mode 100644
index 49a473c..0000000
--- a/chrome/browser/autocomplete_history_manager_unittest.cc
+++ /dev/null
@@ -1,86 +0,0 @@
-// Copyright (c) 2010 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 <vector>
-
-#include "base/ref_counted.h"
-#include "base/string16.h"
-#include "base/task.h"
-#include "chrome/browser/autocomplete_history_manager.h"
-#include "chrome/browser/webdata/web_data_service.h"
-#include "chrome/test/testing_profile.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "webkit/glue/form_data.h"
-
-using testing::_;
-using webkit_glue::FormData;
-
-class MockWebDataService : public WebDataService {
- public:
- MOCK_METHOD1(AddFormFields,
- void(const std::vector<webkit_glue::FormField>&)); // NOLINT
-};
-
-class AutocompleteHistoryManagerTest : public testing::Test {
- protected:
- AutocompleteHistoryManagerTest()
- : ui_thread_(ChromeThread::UI, &message_loop_) {
- }
-
- virtual void SetUp() {
- web_data_service_ = new MockWebDataService();
- autocomplete_manager_.reset(
- new AutocompleteHistoryManager(&profile_, web_data_service_));
- }
-
- MessageLoopForUI message_loop_;
- ChromeThread ui_thread_;
-
- TestingProfile profile_;
- scoped_refptr<MockWebDataService> web_data_service_;
- scoped_ptr<AutocompleteHistoryManager> autocomplete_manager_;
-};
-
-// Tests that credit card numbers are not sent to the WebDatabase to be saved.
-TEST_F(AutocompleteHistoryManagerTest, CreditCardNumberValue) {
- FormData form;
- form.name = ASCIIToUTF16("MyForm");
- form.method = ASCIIToUTF16("POST");
- form.origin = GURL("http://myform.com/form.html");
- form.action = GURL("http://myform.com/submit.html");
-
- // Valid Visa credit card number pulled from the paypal help site.
- webkit_glue::FormField valid_cc(ASCIIToUTF16("Credit Card"),
- ASCIIToUTF16("ccnum"),
- ASCIIToUTF16("4012888888881881"),
- ASCIIToUTF16("text"),
- 20);
- form.fields.push_back(valid_cc);
-
- EXPECT_CALL(*web_data_service_, AddFormFields(_)).Times(0);
- autocomplete_manager_->FormSubmitted(form);
-}
-
-// Contrary test to AutocompleteHistoryManagerTest.CreditCardNumberValue. The
-// value being submitted is not a valid credit card number, so it will be sent
-// to the WebDatabase to be saved.
-TEST_F(AutocompleteHistoryManagerTest, NonCreditCardNumberValue) {
- FormData form;
- form.name = ASCIIToUTF16("MyForm");
- form.method = ASCIIToUTF16("POST");
- form.origin = GURL("http://myform.com/form.html");
- form.action = GURL("http://myform.com/submit.html");
-
- // Invalid credit card number.
- webkit_glue::FormField invalid_cc(ASCIIToUTF16("Credit Card"),
- ASCIIToUTF16("ccnum"),
- ASCIIToUTF16("4580123456789012"),
- ASCIIToUTF16("text"),
- 20);
- form.fields.push_back(invalid_cc);
-
- EXPECT_CALL(*(web_data_service_.get()), AddFormFields(_)).Times(1);
- autocomplete_manager_->FormSubmitted(form);
-}
diff --git a/chrome/browser/autofill/credit_card.cc b/chrome/browser/autofill/credit_card.cc
index 7f41b5e..fefab77 100644
--- a/chrome/browser/autofill/credit_card.cc
+++ b/chrome/browser/autofill/credit_card.cc
@@ -281,31 +281,6 @@ bool CreditCard::operator!=(const CreditCard& creditcard) const {
return !operator==(creditcard);
}
-// Use the Luhn formula to validate the number.
-bool CreditCard::IsCreditCardNumber(const string16& text) {
- string16 number;
- RemoveChars(text, kCreditCardSeparators.c_str(), &number);
-
- int sum = 0;
- bool odd = false;
- string16::reverse_iterator iter;
- for (iter = number.rbegin(); iter != number.rend(); ++iter) {
- if (!IsAsciiDigit(*iter))
- return false;
-
- int digit = *iter - '0';
- if (odd) {
- digit *= 2;
- sum += digit / 10 + digit % 10;
- } else {
- sum += digit;
- }
- odd = !odd;
- }
-
- return (sum % 10) == 0;
-}
-
string16 CreditCard::ExpirationMonthAsString() const {
if (expiration_month_ == 0)
return string16();
@@ -434,6 +409,33 @@ bool CreditCard::IsNameOnCard(const string16& text) const {
return StringToLowerASCII(text) == StringToLowerASCII(name_on_card_);
}
+bool CreditCard::IsCreditCardNumber(const string16& text) {
+ string16 number;
+ TrimString(text, kCreditCardSeparators.c_str(), &number);
+
+ // We use the Luhn formula to validate the number; see
+ // http://www.beachnet.com/~hstiles/cardtype.html and
+ // http://www.webopedia.com/TERM/L/Luhn_formula.html.
+ int sum = 0;
+ bool odd = false;
+ string16::reverse_iterator iter;
+ for (iter = number.rbegin(); iter != number.rend(); ++iter) {
+ if (!IsAsciiDigit(*iter))
+ return false;
+
+ int digit = *iter - '0';
+ if (odd) {
+ digit *= 2;
+ sum += digit / 10 + digit % 10;
+ } else {
+ sum += digit;
+ }
+ odd = !odd;
+ }
+
+ return (sum % 10) == 0;
+}
+
bool CreditCard::IsVerificationCode(const string16& text) const {
return StringToLowerASCII(text) == StringToLowerASCII(verification_code_);
}
diff --git a/chrome/browser/autofill/credit_card.h b/chrome/browser/autofill/credit_card.h
index 50bfa3a..4c16ec7 100644
--- a/chrome/browser/autofill/credit_card.h
+++ b/chrome/browser/autofill/credit_card.h
@@ -58,10 +58,6 @@ class CreditCard : public FormGroup {
bool operator!=(const CreditCard& creditcard) const;
void set_label(const string16& label) { label_ = label; }
- // Returns true if |value| is a credit card number. Uses the Luhn formula to
- // validate the number.
- static bool IsCreditCardNumber(const string16& text);
-
private:
// The month and year are zero if not present.
int Expiration4DigitYear() const { return expiration_year_; }
@@ -111,6 +107,9 @@ class CreditCard : public FormGroup {
// case-insensitive.
bool IsNameOnCard(const string16& text) const;
+ // Uses the Luhn formula to validate the credit card number in |text|.
+ static bool IsCreditCardNumber(const string16& text);
+
// Returns true if |text| matches the expiration month of the card.
bool IsExpirationMonth(const string16& text) const;
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index 5e35728..a5105b2 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -395,7 +395,7 @@ class WebDataService
//////////////////////////////////////////////////////////////////////////////
// Schedules a task to add form fields to the web database.
- virtual void AddFormFields(const std::vector<webkit_glue::FormField>& fields);
+ void AddFormFields(const std::vector<webkit_glue::FormField>& fields);
// Initiates the request for a vector of values which have been entered in
// form input fields named |name|. The method OnWebDataServiceRequestDone of