summaryrefslogtreecommitdiffstats
path: root/chrome/browser/webdata
diff options
context:
space:
mode:
authordarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-16 03:53:39 +0000
committerdarin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-16 03:53:39 +0000
commitacca2a1fc734142de039f65405ef259737d7a8fc (patch)
tree6275718b90618e1445cb824e615aeca7c21e6956 /chrome/browser/webdata
parent923bd8b63206d79cdfb0e5eba5b49e5a6f7eee7d (diff)
downloadchromium_src-acca2a1fc734142de039f65405ef259737d7a8fc.zip
chromium_src-acca2a1fc734142de039f65405ef259737d7a8fc.tar.gz
chromium_src-acca2a1fc734142de039f65405ef259737d7a8fc.tar.bz2
Move autofill related WebView{Delegate} methods into the WebKit API.
This CL also changes a bunch of autofill related wstring values to string16. R=jcampan BUG=24595 TEST=none Review URL: http://codereview.chromium.org/279001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29244 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/webdata')
-rw-r--r--chrome/browser/webdata/web_data_service.cc22
-rw-r--r--chrome/browser/webdata/web_data_service.h14
-rw-r--r--chrome/browser/webdata/web_database.cc33
-rw-r--r--chrome/browser/webdata/web_database.h8
-rw-r--r--chrome/browser/webdata/web_database_unittest.cc72
5 files changed, 81 insertions, 68 deletions
diff --git a/chrome/browser/webdata/web_data_service.cc b/chrome/browser/webdata/web_data_service.cc
index d7f3682..cec4e99 100644
--- a/chrome/browser/webdata/web_data_service.cc
+++ b/chrome/browser/webdata/web_data_service.cc
@@ -126,7 +126,7 @@ void WebDataService::AddAutofillFormElements(
}
WebDataService::Handle WebDataService::GetFormValuesForElementName(
- const std::wstring& name, const std::wstring& prefix, int limit,
+ const string16& name, const string16& prefix, int limit,
WebDataServiceConsumer* consumer) {
WebDataRequest* request =
new WebDataRequest(this, GetNextRequestHandle(), consumer);
@@ -142,12 +142,12 @@ WebDataService::Handle WebDataService::GetFormValuesForElementName(
}
void WebDataService::RemoveFormValueForElementName(
- const std::wstring& name, const std::wstring& value) {
- GenericRequest2<std::wstring, std::wstring>* request =
- new GenericRequest2<std::wstring, std::wstring>(this,
- GetNextRequestHandle(),
- NULL,
- name, value);
+ const string16& name, const string16& value) {
+ GenericRequest2<string16, string16>* request =
+ new GenericRequest2<string16, string16>(this,
+ GetNextRequestHandle(),
+ NULL,
+ name, value);
RegisterRequest(request);
ScheduleTask(
NewRunnableMethod(this,
@@ -582,12 +582,12 @@ void WebDataService::AddAutofillFormElementsImpl(
}
void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request,
- const std::wstring& name, const std::wstring& prefix, int limit) {
+ const string16& name, const string16& prefix, int limit) {
if (db_ && !request->IsCancelled()) {
- std::vector<std::wstring> values;
+ std::vector<string16> values;
db_->GetFormValuesForElementName(name, prefix, &values, limit);
request->SetResult(
- new WDResult<std::vector<std::wstring> >(AUTOFILL_VALUE_RESULT,
+ new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT,
values));
}
request->RequestComplete();
@@ -604,7 +604,7 @@ void WebDataService::RemoveFormElementsAddedBetweenImpl(
}
void WebDataService::RemoveFormValueForElementNameImpl(
- GenericRequest2<std::wstring, std::wstring>* request) {
+ GenericRequest2<string16, string16>* request) {
if (db_ && !request->IsCancelled()) {
if (db_->RemoveFormElement(request->GetArgument1(),
request->GetArgument2()))
diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h
index f15911b..03b7766 100644
--- a/chrome/browser/webdata/web_data_service.h
+++ b/chrome/browser/webdata/web_data_service.h
@@ -57,7 +57,7 @@ typedef enum {
PASSWORD_IE7_RESULT, // WDResult<IE7PasswordInfo>
#endif
WEB_APP_IMAGES, // WDResult<WDAppImagesResult>
- AUTOFILL_VALUE_RESULT, // WDResult<std::vector<std::wstring>>
+ AUTOFILL_VALUE_RESULT, // WDResult<std::vector<string16>>
} WDResultType;
// Result from GetWebAppImages.
@@ -382,16 +382,16 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> {
// form input fields named |name|. The method OnWebDataServiceRequestDone of
// |consumer| gets called back when the request is finished, with the vector
// included in the argument |result|.
- Handle GetFormValuesForElementName(const std::wstring& name,
- const std::wstring& prefix,
+ Handle GetFormValuesForElementName(const string16& name,
+ const string16& prefix,
int limit,
WebDataServiceConsumer* consumer);
// Removes form elements recorded for autofill from the database.
void RemoveFormElementsAddedBetween(const base::Time& delete_begin,
const base::Time& delete_end);
- void RemoveFormValueForElementName(const std::wstring& name,
- const std::wstring& value);
+ void RemoveFormValueForElementName(const string16& name,
+ const string16& value);
protected:
friend class TemplateURLModelTest;
@@ -468,11 +468,11 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> {
GenericRequest<std::vector<webkit_glue::AutofillForm::Element> >*
request);
void GetFormValuesForElementNameImpl(WebDataRequest* request,
- const std::wstring& name, const std::wstring& prefix, int limit);
+ const string16& name, const string16& prefix, int limit);
void RemoveFormElementsAddedBetweenImpl(
GenericRequest2<base::Time, base::Time>* request);
void RemoveFormValueForElementNameImpl(
- GenericRequest2<std::wstring, std::wstring>* request);
+ GenericRequest2<string16, string16>* request);
//////////////////////////////////////////////////////////////////////////////
//
diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc
index 98bc76c..a1ba12d 100644
--- a/chrome/browser/webdata/web_database.cc
+++ b/chrome/browser/webdata/web_database.cc
@@ -850,8 +850,8 @@ bool WebDatabase::GetIDAndCountOfFormElement(
return false;
}
- s.BindString(0, WideToUTF8(element.name));
- s.BindString(1, WideToUTF8(element.value));
+ s.BindString(0, UTF16ToUTF8(element.name));
+ s.BindString(1, UTF16ToUTF8(element.value));
*count = 0;
@@ -889,10 +889,9 @@ bool WebDatabase::InsertFormElement(const AutofillForm::Element& element,
return false;
}
- s.BindString(0, WideToUTF8(element.name));
- s.BindString(1, WideToUTF8(element.value));
- s.BindString(2, UTF16ToUTF8(
- l10n_util::ToLower(WideToUTF16Hack(element.value))));
+ s.BindString(0, UTF16ToUTF8(element.name));
+ s.BindString(1, UTF16ToUTF8(element.value));
+ s.BindString(2, UTF16ToUTF8(l10n_util::ToLower(element.value)));
if (!s.Run()) {
NOTREACHED();
@@ -956,9 +955,9 @@ bool WebDatabase::AddAutofillFormElement(const AutofillForm::Element& element) {
InsertPairIDAndDate(pair_id, Time::Now());
}
-bool WebDatabase::GetFormValuesForElementName(const std::wstring& name,
- const std::wstring& prefix,
- std::vector<std::wstring>* values,
+bool WebDatabase::GetFormValuesForElementName(const string16& name,
+ const string16& prefix,
+ std::vector<string16>* values,
int limit) {
DCHECK(values);
sql::Statement s;
@@ -974,10 +973,10 @@ bool WebDatabase::GetFormValuesForElementName(const std::wstring& name,
return false;
}
- s.BindString(0, WideToUTF8(name));
+ s.BindString(0, UTF16ToUTF8(name));
s.BindInt(1, limit);
} else {
- string16 prefix_lower = l10n_util::ToLower(WideToUTF16Hack(prefix));
+ string16 prefix_lower = l10n_util::ToLower(prefix);
string16 next_prefix = prefix_lower;
next_prefix[next_prefix.length() - 1]++;
@@ -993,7 +992,7 @@ bool WebDatabase::GetFormValuesForElementName(const std::wstring& name,
return false;
}
- s.BindString(0, WideToUTF8(name));
+ s.BindString(0, UTF16ToUTF8(name));
s.BindString(1, UTF16ToUTF8(prefix_lower));
s.BindString(2, UTF16ToUTF8(next_prefix));
s.BindInt(3, limit);
@@ -1001,7 +1000,7 @@ bool WebDatabase::GetFormValuesForElementName(const std::wstring& name,
values->clear();
while (s.Step())
- values->push_back(UTF8ToWide(s.ColumnString(0)));
+ values->push_back(UTF8ToUTF16(s.ColumnString(0)));
return s.Succeeded();
}
@@ -1067,8 +1066,8 @@ bool WebDatabase::RemoveFormElementForTimeRange(int64 pair_id,
return result;
}
-bool WebDatabase::RemoveFormElement(const std::wstring& name,
- const std::wstring& value) {
+bool WebDatabase::RemoveFormElement(const string16& name,
+ const string16& value) {
// Find the id for that pair.
sql::Statement s(db_.GetUniqueStatement(
"SELECT pair_id FROM autofill WHERE name = ? AND value= ?"));
@@ -1076,8 +1075,8 @@ bool WebDatabase::RemoveFormElement(const std::wstring& name,
NOTREACHED() << "Statement 1 prepare failed";
return false;
}
- s.BindString(0, WideToUTF8(name));
- s.BindString(1, WideToUTF8(value));
+ s.BindString(0, UTF16ToUTF8(name));
+ s.BindString(1, UTF16ToUTF8(value));
if (s.Step())
return RemoveFormElementForID(s.ColumnInt64(0));
diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h
index acc8fbf..1326c18 100644
--- a/chrome/browser/webdata/web_database.h
+++ b/chrome/browser/webdata/web_database.h
@@ -142,9 +142,9 @@ class WebDatabase {
// Retrieves a vector of all values which have been recorded in the autofill
// table as the value in a form element with name |name| and which start with
// |prefix|. The comparison of the prefix is case insensitive.
- bool GetFormValuesForElementName(const std::wstring& name,
- const std::wstring& prefix,
- std::vector<std::wstring>* values,
+ bool GetFormValuesForElementName(const string16& name,
+ const string16& prefix,
+ std::vector<string16>* values,
int limit);
// Removes rows from autofill_dates if they were created on or after
@@ -191,7 +191,7 @@ class WebDatabase {
bool RemoveFormElementForID(int64 pair_id);
// Removes row from the autofill tables for the given |name| |value| pair.
- bool RemoveFormElement(const std::wstring& name, const std::wstring& value);
+ bool RemoveFormElement(const string16& name, const string16& value);
//////////////////////////////////////////////////////////////////////////////
//
diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc
index 68d56d8..fcfee84 100644
--- a/chrome/browser/webdata/web_database_unittest.cc
+++ b/chrome/browser/webdata/web_database_unittest.cc
@@ -392,19 +392,22 @@ TEST_F(WebDatabaseTest, Autofill) {
// Simulate the submission of a handful of entries in a field called "Name",
// some more often than others.
EXPECT_TRUE(db.AddAutofillFormElement(
- AutofillForm::Element(L"Name", L"Superman")));
- std::vector<std::wstring> v;
+ AutofillForm::Element(ASCIIToUTF16("Name"), ASCIIToUTF16("Superman"))));
+ std::vector<string16> v;
for (int i = 0; i < 5; i++) {
EXPECT_TRUE(db.AddAutofillFormElement(
- AutofillForm::Element(L"Name", L"Clark Kent")));
+ AutofillForm::Element(ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Clark Kent"))));
}
for (int i = 0; i < 3; i++) {
EXPECT_TRUE(db.AddAutofillFormElement(
- AutofillForm::Element(L"Name", L"Clark Sutter")));
+ AutofillForm::Element(ASCIIToUTF16("Name"),
+ ASCIIToUTF16("Clark Sutter"))));
}
for (int i = 0; i < 2; i++) {
EXPECT_TRUE(db.AddAutofillFormElement(
- AutofillForm::Element(L"Favorite Color", L"Green")));
+ AutofillForm::Element(ASCIIToUTF16("Favorite Color"),
+ ASCIIToUTF16("Green"))));
}
int count = 0;
@@ -413,47 +416,54 @@ TEST_F(WebDatabaseTest, Autofill) {
// We have added the name Clark Kent 5 times, so count should be 5 and pair_id
// should be somthing non-zero.
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
- AutofillForm::Element(L"Name", L"Clark Kent"), &pair_id, &count));
+ AutofillForm::Element(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")),
+ &pair_id, &count));
EXPECT_EQ(5, count);
EXPECT_NE(0, pair_id);
// Storing in the data base should be case sensitive, so there should be no
// database entry for clark kent lowercase.
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
- AutofillForm::Element(L"Name", L"clark kent"), &pair_id, &count));
+ AutofillForm::Element(ASCIIToUTF16("Name"), ASCIIToUTF16("clark kent")),
+ &pair_id, &count));
EXPECT_EQ(0, count);
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
- AutofillForm::Element(L"Favorite Color", L"Green"), &pair_id, &count));
+ AutofillForm::Element(ASCIIToUTF16("Favorite Color"),
+ ASCIIToUTF16("Green")),
+ &pair_id, &count));
EXPECT_EQ(2, count);
// This is meant to get a list of suggestions for Name. The empty prefix
// in the second argument means it should return all suggestions for a name
// no matter what they start with. The order that the names occur in the list
// should be decreasing order by count.
- EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", std::wstring(), &v, 6));
+ EXPECT_TRUE(db.GetFormValuesForElementName(
+ ASCIIToUTF16("Name"), string16(), &v, 6));
EXPECT_EQ(3U, v.size());
if (v.size() == 3) {
- EXPECT_EQ(L"Clark Kent", v[0]);
- EXPECT_EQ(L"Clark Sutter", v[1]);
- EXPECT_EQ(L"Superman", v[2]);
+ EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]);
+ EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]);
+ EXPECT_EQ(ASCIIToUTF16("Superman"), v[2]);
}
// If we query again limiting the list size to 1, we should only get the most
// frequent entry.
- EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"", &v, 1));
+ EXPECT_TRUE(db.GetFormValuesForElementName(
+ ASCIIToUTF16("Name"), string16(), &v, 1));
EXPECT_EQ(1U, v.size());
if (v.size() == 1) {
- EXPECT_EQ(L"Clark Kent", v[0]);
+ EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]);
}
// Querying for suggestions given a prefix is case-insensitive, so the prefix
// "cLa" shoud get suggestions for both Clarks.
- EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"cLa", &v, 6));
+ EXPECT_TRUE(db.GetFormValuesForElementName(
+ ASCIIToUTF16("Name"), ASCIIToUTF16("cLa"), &v, 6));
EXPECT_EQ(2U, v.size());
if (v.size() == 2) {
- EXPECT_EQ(L"Clark Kent", v[0]);
- EXPECT_EQ(L"Clark Sutter", v[1]);
+ EXPECT_EQ(ASCIIToUTF16("Clark Kent"), v[0]);
+ EXPECT_EQ(ASCIIToUTF16("Clark Sutter"), v[1]);
}
// Removing all elements since the beginning of this function should remove
@@ -461,33 +471,37 @@ TEST_F(WebDatabaseTest, Autofill) {
EXPECT_TRUE(db.RemoveFormElementsAddedBetween(t1, Time()));
EXPECT_TRUE(db.GetIDAndCountOfFormElement(
- AutofillForm::Element(L"Name", L"Clark Kent"), &pair_id, &count));
+ AutofillForm::Element(ASCIIToUTF16("Name"), ASCIIToUTF16("Clark Kent")),
+ &pair_id, &count));
EXPECT_EQ(0, count);
- EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"", &v, 6));
+ EXPECT_TRUE(
+ db.GetFormValuesForElementName(ASCIIToUTF16("Name"), string16(), &v, 6));
EXPECT_EQ(0U, v.size());
// Now add some values with empty strings.
- const std::wstring kValue = L" toto ";
- EXPECT_TRUE(db.AddAutofillFormElement(AutofillForm::Element(L"blank", L"")));
- EXPECT_TRUE(db.AddAutofillFormElement(AutofillForm::Element(L"blank",
- L" ")));
- EXPECT_TRUE(db.AddAutofillFormElement(AutofillForm::Element(L"blank",
- L" ")));
- EXPECT_TRUE(db.AddAutofillFormElement(AutofillForm::Element(L"blank",
- kValue)));
+ const string16 kValue = ASCIIToUTF16(" toto ");
+ EXPECT_TRUE(db.AddAutofillFormElement(
+ AutofillForm::Element(ASCIIToUTF16("blank"), string16())));
+ EXPECT_TRUE(db.AddAutofillFormElement(
+ AutofillForm::Element(ASCIIToUTF16("blank"), ASCIIToUTF16(" "))));
+ EXPECT_TRUE(db.AddAutofillFormElement(
+ AutofillForm::Element(ASCIIToUTF16("blank"), ASCIIToUTF16(" "))));
+ EXPECT_TRUE(db.AddAutofillFormElement(
+ AutofillForm::Element(ASCIIToUTF16("blank"), kValue)));
// They should be stored normally as the DB layer does not check for empty
// values.
v.clear();
- EXPECT_TRUE(db.GetFormValuesForElementName(L"blank", L"", &v, 10));
+ EXPECT_TRUE(db.GetFormValuesForElementName(
+ ASCIIToUTF16("blank"), string16(), &v, 10));
EXPECT_EQ(4U, v.size());
// Now we'll check that ClearAutofillEmptyValueElements() works as expected.
db.ClearAutofillEmptyValueElements();
v.clear();
- EXPECT_TRUE(db.GetFormValuesForElementName(L"blank", L"", &v, 10));
+ EXPECT_TRUE(db.GetFormValuesForElementName(ASCIIToUTF16("blank"), string16(), &v, 10));
ASSERT_EQ(1U, v.size());
EXPECT_EQ(kValue, v[0]);