diff options
author | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-16 11:12:13 +0000 |
---|---|---|
committer | phajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-16 11:12:13 +0000 |
commit | 400d807b0c567a1df1087694627737174a13c8ad (patch) | |
tree | 49250804cbf635a2bb460937ac930d92dcf1b361 /chrome/browser | |
parent | 97f756b5dcf7d1a6ffb4ea4e961ccb5fb12aeae2 (diff) | |
download | chromium_src-400d807b0c567a1df1087694627737174a13c8ad.zip chromium_src-400d807b0c567a1df1087694627737174a13c8ad.tar.gz chromium_src-400d807b0c567a1df1087694627737174a13c8ad.tar.bz2 |
Porting in browser/webdata and template_url.
Review URL: http://codereview.chromium.org/14419
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7052 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser.scons | 2 | ||||
-rw-r--r-- | chrome/browser/browser.vcproj | 4 | ||||
-rw-r--r-- | chrome/browser/template_url.cc | 14 | ||||
-rw-r--r-- | chrome/browser/template_url_model.cc | 14 | ||||
-rw-r--r-- | chrome/browser/template_url_model_unittest.cc | 22 | ||||
-rw-r--r-- | chrome/browser/template_url_parser_unittest.cc | 16 | ||||
-rw-r--r-- | chrome/browser/webdata/web_data_service.h | 12 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.cc | 105 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database.h | 18 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database_unittest.cc | 96 | ||||
-rw-r--r-- | chrome/browser/webdata/web_database_win.cc | 72 |
11 files changed, 173 insertions, 202 deletions
diff --git a/chrome/browser/browser.scons b/chrome/browser/browser.scons index 04f8eac..3848b37 100644 --- a/chrome/browser/browser.scons +++ b/chrome/browser/browser.scons @@ -97,6 +97,7 @@ if env['PLATFORM'] in ('posix', 'win32'): 'template_url_parser.cc', 'url_fetcher_protect.cc', 'user_metrics.cc', + 'webdata/web_database.cc', ]) if env['PLATFORM'] == 'win32': @@ -288,7 +289,6 @@ if env['PLATFORM'] == 'win32': 'web_drag_source.cc', 'web_drop_target.cc', 'webdata/web_data_service.cc', - 'webdata/web_database.cc', 'window_sizer.cc', ]) diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj index 35d90cb..bd6973e 100644 --- a/chrome/browser/browser.vcproj +++ b/chrome/browser/browser.vcproj @@ -1573,6 +1573,10 @@ RelativePath=".\webdata\web_database.h"
>
</File>
+ <File
+ RelativePath=".\webdata\web_database_win.cc"
+ >
+ </File>
</Filter>
<Filter
Name="Importer"
diff --git a/chrome/browser/template_url.cc b/chrome/browser/template_url.cc index ef5fe47..6b56180 100644 --- a/chrome/browser/template_url.cc +++ b/chrome/browser/template_url.cc @@ -102,17 +102,11 @@ bool TemplateURLRef::ParseParameter(size_t start, url->insert(start, kDefaultCount); } else if (parameter == kStartIndexParameter) { if (!optional) { - wchar_t start_string[12]; - if (swprintf_s(start_string, L"%d", index_offset_) <= 0) - return false; - url->insert(start, start_string); + url->insert(start, IntToWString(index_offset_)); } } else if (parameter == kStartPageParameter) { if (!optional) { - wchar_t start_string[12]; - if (swprintf_s(start_string, L"%d", page_offset_) <= 0) - return false; - url->insert(start, start_string); + url->insert(start, IntToWString(page_offset_)); } } else if (parameter == kLanguageParameter) { replacements->push_back(Replacement(LANGUAGE, static_cast<int>(start))); @@ -207,7 +201,7 @@ void TemplateURLRef::ParseHostAndSearchTermKey() const { kGoogleBaseSuggestURLParameterFull, GoogleBaseSuggestURLValue()); - GURL url(url_string); + GURL url(WideToUTF8(url_string)); if (!url.is_valid()) return; @@ -453,7 +447,7 @@ std::wstring TemplateURLRef::GoogleBaseSuggestURLValue() { // Start with the Google base URL. const GURL base_url(google_base_url_ ? - GURL(*google_base_url_) : GoogleURLTracker::GoogleURL()); + GURL(WideToUTF8(*google_base_url_)) : GoogleURLTracker::GoogleURL()); DCHECK(base_url.is_valid()); // Change "www." to "clients1." in the hostname. If no "www." was found, just diff --git a/chrome/browser/template_url_model.cc b/chrome/browser/template_url_model.cc index 587f982..aebc1dd 100644 --- a/chrome/browser/template_url_model.cc +++ b/chrome/browser/template_url_model.cc @@ -32,7 +32,7 @@ using base::Time; static const wchar_t kSearchTermParameter[] = L"{searchTerms}"; // String in Initializer that is replaced with kSearchTermParameter. -static const wchar_t kTemplateParameter[](L"%s"); +static const wchar_t kTemplateParameter[] = L"%s"; // Term used when generating a search url. Use something obscure so that on // the rare case the term replaces the URL it's unlikely another keyword would @@ -173,7 +173,7 @@ std::wstring TemplateURLModel::CleanUserInputKeyword( // Remove the scheme. std::wstring result(l10n_util::ToLower(keyword)); url_parse::Component scheme_component; - if (url_parse::ExtractScheme(keyword.c_str(), + if (url_parse::ExtractScheme(WideToUTF8(keyword).c_str(), static_cast<int>(keyword.length()), &scheme_component)) { // Include trailing ':'. @@ -200,10 +200,12 @@ GURL TemplateURLModel::GenerateSearchURL(const TemplateURL* t_url) { return GURL(); if (!search_ref->SupportsReplacement()) - return GURL(search_ref->url()); + return GURL(WideToUTF8(search_ref->url())); - return GURL(search_ref->ReplaceSearchTerms(*t_url, kReplacementTerm, - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring())); + return search_ref->ReplaceSearchTerms( + *t_url, + kReplacementTerm, + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()); } bool TemplateURLModel::CanReplaceKeyword( @@ -227,7 +229,7 @@ bool TemplateURLModel::CanReplaceKeyword( // be replaced. We do this to ensure that if the user assigns a different // keyword to a generated TemplateURL, we won't regenerate another keyword for // the same host. - GURL gurl(url); + GURL gurl(WideToUTF8(url)); if (gurl.is_valid() && !gurl.host().empty()) return CanReplaceKeywordForHost(gurl.host(), template_url_to_replace); return true; diff --git a/chrome/browser/template_url_model_unittest.cc b/chrome/browser/template_url_model_unittest.cc index ebc00f2..b5198e4 100644 --- a/chrome/browser/template_url_model_unittest.cc +++ b/chrome/browser/template_url_model_unittest.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <windows.h> - #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" @@ -46,7 +44,7 @@ class TemplateURLModelTestingProfile : public TestingProfile { // Create a fresh, empty copy of this directory. file_util::Delete(test_dir_, true); - CreateDirectory(test_dir_.c_str(), NULL); + file_util::CreateDirectory(test_dir_); std::wstring path = test_dir_; file_util::AppendToPath(&path, L"TestDataService.db"); @@ -290,7 +288,7 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { Time month_ago = now - TimeDelta::FromDays(30); // Nothing has been added. - EXPECT_EQ(0, model_->GetTemplateURLs().size()); + EXPECT_EQ(0U, model_->GetTemplateURLs().size()); // Create one with a 0 time. AddKeywordWithDate(L"key1", false, L"http://foo1", L"name1", true, Time()); @@ -305,22 +303,22 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { AddKeywordWithDate(L"key6", false, L"http://foo6", L"name6", false, month_ago); // We just added a few items, validate them. - EXPECT_EQ(6, model_->GetTemplateURLs().size()); + EXPECT_EQ(6U, model_->GetTemplateURLs().size()); // Try removing from current timestamp. This should delete the one in the // future and one very recent one. model_->RemoveAutoGeneratedSince(now); - EXPECT_EQ(4, model_->GetTemplateURLs().size()); + EXPECT_EQ(4U, model_->GetTemplateURLs().size()); // Try removing from two months ago. This should only delete items that are // auto-generated. model_->RemoveAutoGeneratedSince(now - TimeDelta::FromDays(60)); - EXPECT_EQ(3, model_->GetTemplateURLs().size()); + EXPECT_EQ(3U, model_->GetTemplateURLs().size()); // Make sure the right values remain. EXPECT_EQ(L"key1", model_->GetTemplateURLs()[0]->keyword()); EXPECT_TRUE(model_->GetTemplateURLs()[0]->safe_for_autoreplace()); - EXPECT_EQ(0, model_->GetTemplateURLs()[0]->date_created().ToInternalValue()); + EXPECT_EQ(0U, model_->GetTemplateURLs()[0]->date_created().ToInternalValue()); EXPECT_EQ(L"key5", model_->GetTemplateURLs()[1]->keyword()); EXPECT_FALSE(model_->GetTemplateURLs()[1]->safe_for_autoreplace()); @@ -334,7 +332,7 @@ TEST_F(TemplateURLModelTest, ClearBrowsingData_Keywords) { // Try removing from Time=0. This should delete one more. model_->RemoveAutoGeneratedSince(Time()); - EXPECT_EQ(2, model_->GetTemplateURLs().size()); + EXPECT_EQ(2U, model_->GetTemplateURLs().size()); } TEST_F(TemplateURLModelTest, Reset) { @@ -546,7 +544,7 @@ TEST_F(TemplateURLModelTest, BuildQueryTerms) { { "http://blah/foo?x=y&x=z&y=z", true, "x;y", ";z" }, }; - for (size_t i = 0; i < arraysize(data); ++i) { + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { TemplateURLModel::QueryTerms terms; ASSERT_EQ(data[i].result, TemplateURLModel::BuildQueryTerms(GURL(data[i].url), &terms)); @@ -584,7 +582,7 @@ TEST_F(TemplateURLModelTest, UpdateKeywordSearchTermsForURL) { AddKeywordWithDate(L"x", false, L"http://x/foo?q={searchTerms}", L"name", false, Time()); - for (size_t i = 0; i < arraysize(data); ++i) { + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { model_->UpdateKeywordSearchTermsForURL(history::URLRow(GURL(data[i].url))); EXPECT_EQ(data[i].term, GetAndClearSearchTerm()); } @@ -601,7 +599,7 @@ TEST_F(TemplateURLModelTest, DontUpdateKeywordSearchForNonReplaceable) { AddKeywordWithDate(L"x", false, L"http://x/foo", L"name", false, Time()); - for (size_t i = 0; i < arraysize(data); ++i) { + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(data); ++i) { model_->UpdateKeywordSearchTermsForURL(history::URLRow(GURL(data[i].url))); ASSERT_EQ(std::wstring(), GetAndClearSearchTerm()); } diff --git a/chrome/browser/template_url_parser_unittest.cc b/chrome/browser/template_url_parser_unittest.cc index 3a776eb..381eba0 100644 --- a/chrome/browser/template_url_parser_unittest.cc +++ b/chrome/browser/template_url_parser_unittest.cc @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <windows.h> - #include "base/file_util.h" #include "base/logging.h" #include "base/path_service.h" @@ -127,7 +125,7 @@ TEST_F(TemplateURLParserTest, TestWikipedia) { EXPECT_TRUE(template_url_.suggestions_url()->SupportsReplacement()); EXPECT_EQ(template_url_.suggestions_url()->url(), L"http://en.wikipedia.org/w/api.php?action=opensearch&search={searchTerms}"); - ASSERT_EQ(2, template_url_.input_encodings().size()); + ASSERT_EQ(2U, template_url_.input_encodings().size()); EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]); EXPECT_EQ("Shift_JIS", template_url_.input_encodings()[1]); } @@ -148,8 +146,8 @@ class ParamFilterImpl : public TemplateURLParser::ParameterFilter { } bool KeepParameter(const std::string& key, const std::string& value) { - return (name_str_.empty() || key.find(name_str_) == -1) && - (value_str_.empty() || value.find(value_str_) == -1); + return (name_str_.empty() || key.find(name_str_) == std::string::npos) && + (value_str_.empty() || value.find(value_str_) == std::string::npos); } private: @@ -175,7 +173,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxEbay) { L"MfcISAPICommand=GetResult&ht=1&srchdesc=n&maxRecordsReturned=300&" L"maxRecordsPerPage=50&SortProperty=MetaEndSort"; EXPECT_EQ(exp_url, template_url_.url()->url()); - ASSERT_EQ(1, template_url_.input_encodings().size()); + ASSERT_EQ(1U, template_url_.input_encodings().size()); EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]); EXPECT_EQ(GURL("http://search.ebay.com/favicon.ico"), template_url_.GetFavIconURL()); @@ -193,7 +191,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxWebster) { EXPECT_TRUE(template_url_.url()->SupportsReplacement()); EXPECT_EQ(L"http://www.webster.com/cgi-bin/dictionary?va={searchTerms}", template_url_.url()->url()); - ASSERT_EQ(1, template_url_.input_encodings().size()); + ASSERT_EQ(1U, template_url_.input_encodings().size()); EXPECT_EQ("ISO-8859-1", template_url_.input_encodings()[0]); EXPECT_EQ(GURL("http://www.webster.com/favicon.ico"), template_url_.GetFavIconURL()); @@ -214,7 +212,7 @@ TEST_F(TemplateURLParserTest, TestFirefoxYahoo) { template_url_.suggestions_url()->url()); EXPECT_EQ(L"http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", template_url_.url()->url()); - ASSERT_EQ(1, template_url_.input_encodings().size()); + ASSERT_EQ(1U, template_url_.input_encodings().size()); EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]); EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), template_url_.GetFavIconURL()); @@ -235,7 +233,7 @@ TEST_F(TemplateURLParserTest, TestPostSuggestion) { EXPECT_TRUE(template_url_.suggestions_url() == NULL); EXPECT_EQ(L"http://search.yahoo.com/search?p={searchTerms}&ei=UTF-8", template_url_.url()->url()); - ASSERT_EQ(1, template_url_.input_encodings().size()); + ASSERT_EQ(1U, template_url_.input_encodings().size()); EXPECT_EQ("UTF-8", template_url_.input_encodings()[0]); EXPECT_EQ(GURL("http://search.yahoo.com/favicon.ico"), template_url_.GetFavIconURL()); diff --git a/chrome/browser/webdata/web_data_service.h b/chrome/browser/webdata/web_data_service.h index 3002140..053644b 100644 --- a/chrome/browser/webdata/web_data_service.h +++ b/chrome/browser/webdata/web_data_service.h @@ -5,6 +5,8 @@ #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ +#include <map> + #include "base/basictypes.h" #include "base/lock.h" #include "base/message_loop.h" @@ -12,12 +14,10 @@ #include "base/thread.h" #include "chrome/browser/webdata/web_database.h" #include "chrome/common/scoped_vector.h" -#include <map> +#include "webkit/glue/autofill_form.h" -struct AutofillForm::Element; struct IE7PasswordInfo; struct PasswordForm; -class AutofillForm; class GURL; class ShutdownTask; class TemplateURL; @@ -383,7 +383,7 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> { friend class WebDataRequest; // This is invoked by the unit test; path is the path of the Web Data file. - bool WebDataService::InitWithPath(const std::wstring& path); + bool InitWithPath(const std::wstring& path); // Invoked by request implementations when a request has been processed. void RequestCompleted(Handle h); @@ -400,13 +400,13 @@ class WebDataService : public base::RefCountedThreadSafe<WebDataService> { friend class ShutdownTask; typedef GenericRequest2<std::vector<const TemplateURL*>, - std::vector<TemplateURL*>> SetKeywordsRequest; + std::vector<TemplateURL*> > SetKeywordsRequest; // Initialize the database with the provided path. void InitializeDatabase(const std::wstring& path); // Commit any pending transaction and deletes the database. - void WebDataService::ShutdownDatabase(); + void ShutdownDatabase(); // Commit the current transaction and creates a new one. void Commit(); diff --git a/chrome/browser/webdata/web_database.cc b/chrome/browser/webdata/web_database.cc index f17efd1..ced6eb8 100644 --- a/chrome/browser/webdata/web_database.cc +++ b/chrome/browser/webdata/web_database.cc @@ -2,19 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/browser/webdata/web_database.h" + #include <algorithm> #include <limits> #include <vector> -#include "chrome/browser/webdata/web_database.h" - #include "base/gfx/png_decoder.h" #include "base/gfx/png_encoder.h" #include "base/string_util.h" #include "base/time.h" #include "base/values.h" #include "chrome/browser/history/history_database.h" -#include "chrome/browser/ie7_password.h" #include "chrome/browser/template_url.h" #include "chrome/browser/encryptor.h" #include "chrome/common/l10n_util.h" @@ -542,7 +541,7 @@ bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) { s.column_string16(3, &tmp); if (!tmp.empty()) - template_url->SetFavIconURL(GURL(tmp)); + template_url->SetFavIconURL(GURL(WideToUTF8(tmp))); s.column_string16(4, &tmp); template_url->SetURL(tmp, 0, 0); @@ -551,7 +550,7 @@ bool WebDatabase::GetKeywords(std::vector<TemplateURL*>* urls) { s.column_string16(6, &tmp); if (!tmp.empty()) - template_url->set_originating_url(GURL(tmp)); + template_url->set_originating_url(GURL(WideToUTF8(tmp))); template_url->set_date_created(Time::FromTimeT(s.column_int64(7))); @@ -614,40 +613,6 @@ int WebDatabase::GetBuitinKeywordVersion() { return version; } -// Return a new GURL like url, but without any "#foo" bit on the end. -static GURL GURLWithoutRef(const GURL& url) { - url_canon::Replacements<char> replacements; - replacements.ClearRef(); - return url.ReplaceComponents(replacements); -} - -// Convert a list of GUIDs from the in-memory form to the form we keep in -// the database (tab-separated string). -static std::string SerializeGUIDs(const std::vector<std::string>& guids) { - std::string result; - for (size_t i = 0; i < guids.size(); ++i) { - if (!result.empty()) - result.push_back('\t'); - const std::string& guid = guids[i]; - for (size_t j = 0; j < guid.size(); ++j) { - char ch = guid[j]; - // If we have any embedded tabs in the GUID (a pathological case), - // we normalize them to spaces. - if (ch == '\t') - ch = ' '; - result.push_back(ch); - } - } - return result; -} - -// The partner of SerializeGUIDs. Converts a serialized GUIDs string -// back to a vector. -static void DeserializeGUIDs(const std::string& str, - std::vector<std::string>* guids) { - SplitString(str, '\t', guids); -} - bool WebDatabase::AddLogin(const PasswordForm& form) { SQLStatement s; std::string encrypted_password; @@ -684,27 +649,6 @@ bool WebDatabase::AddLogin(const PasswordForm& form) { return true; } -bool WebDatabase::AddIE7Login(const IE7PasswordInfo& info) { - SQLStatement s; - if (s.prepare(db_, - "INSERT OR REPLACE INTO ie7_logins " - "(url_hash, password_value, date_created) " - "VALUES (?, ?, ?)") != SQLITE_OK) { - NOTREACHED() << "Statement prepare failed"; - return false; - } - - s.bind_wstring(0, info.url_hash); - s.bind_blob(1, &info.encrypted_data.front(), - static_cast<int>(info.encrypted_data.size())); - s.bind_int64(2, info.date_created.ToTimeT()); - if (s.step() != SQLITE_DONE) { - NOTREACHED(); - return false; - } - return true; -} - bool WebDatabase::UpdateLogin(const PasswordForm& form) { SQLStatement s; std::string encrypted_password; @@ -769,24 +713,6 @@ bool WebDatabase::RemoveLogin(const PasswordForm& form) { return true; } -bool WebDatabase::RemoveIE7Login(const IE7PasswordInfo& info) { - SQLStatement s; - // Remove a login by UNIQUE-constrained fields. - if (s.prepare(db_, - "DELETE FROM ie7_logins WHERE " - "url_hash = ?") != SQLITE_OK) { - NOTREACHED() << "Statement prepare failed"; - return false; - } - s.bind_wstring(0, info.url_hash); - - if (s.step() != SQLITE_DONE) { - NOTREACHED(); - return false; - } - return true; -} - bool WebDatabase::RemoveLoginsCreatedBetween(const Time delete_begin, const Time delete_end) { SQLStatement s1; @@ -871,29 +797,6 @@ bool WebDatabase::GetLogins(const PasswordForm& form, return result == SQLITE_DONE; } -bool WebDatabase::GetIE7Login(const IE7PasswordInfo& info, - IE7PasswordInfo* result) { - DCHECK(result); - SQLStatement s; - if (s.prepare(db_, - "SELECT password_value, date_created FROM ie7_logins " - "WHERE url_hash == ? ") != SQLITE_OK) { - NOTREACHED() << "Statement prepare failed"; - return false; - } - - s.bind_wstring(0, info.url_hash); - - int64 query_result = s.step(); - if (query_result == SQLITE_ROW) { - s.column_blob_as_vector(0, &result->encrypted_data); - result->date_created = Time::FromTimeT(s.column_int64(1)); - result->url_hash = info.url_hash; - s.step(); - } - return query_result == SQLITE_DONE; -} - bool WebDatabase::GetAllLogins(std::vector<PasswordForm*>* forms, bool include_blacklisted) { DCHECK(forms); diff --git a/chrome/browser/webdata/web_database.h b/chrome/browser/webdata/web_database.h index 4e47168..19059ee 100644 --- a/chrome/browser/webdata/web_database.h +++ b/chrome/browser/webdata/web_database.h @@ -19,7 +19,9 @@ namespace base { class Time; } struct PasswordForm; +#if defined(OS_WIN) struct IE7PasswordInfo; +#endif //////////////////////////////////////////////////////////////////////////////// // @@ -79,18 +81,23 @@ class WebDatabase { // Adds |form| to the list of remembered password forms. bool AddLogin(const PasswordForm& form); +#if defined(OS_WIN) // Adds |info| to the list of imported passwords from ie7/ie8. bool AddIE7Login(const IE7PasswordInfo& info); + // Removes |info| from the list of imported passwords from ie7/ie8. + bool RemoveIE7Login(const IE7PasswordInfo& info); + + // Return the ie7/ie8 login matching |info|. + bool GetIE7Login(const IE7PasswordInfo& info, IE7PasswordInfo* result); +#endif + // Updates remembered password form. bool UpdateLogin(const PasswordForm& form); // Removes |form| from the list of remembered password forms. bool RemoveLogin(const PasswordForm& form); - // Removes |info| from the list of imported passwords from ie7/ie8. - bool RemoveIE7Login(const IE7PasswordInfo& info); - // Removes all logins created from |delete_begin| onwards (inclusive) and // before |delete_end|. You may use a null Time value to do an unbounded // delete in either direction. @@ -102,9 +109,6 @@ class WebDatabase { // including blacklisted matches. bool GetLogins(const PasswordForm& form, std::vector<PasswordForm*>* forms); - // Return the ie7/ie8 login matching |info|. - bool GetIE7Login(const IE7PasswordInfo& info, IE7PasswordInfo* result); - // Loads the complete list of password forms into the specified vector |forms| // if include_blacklisted is true, otherwise only loads those which are // actually autofillable; i.e haven't been blacklisted by the user selecting @@ -205,7 +209,7 @@ class WebDatabase { int transaction_nesting_; MetaTableHelper meta_table_; - DISALLOW_EVIL_CONSTRUCTORS(WebDatabase); + DISALLOW_COPY_AND_ASSIGN(WebDatabase); }; #endif // CHROME_BROWSER_WEBDATA_WEB_DATABASE_H__ diff --git a/chrome/browser/webdata/web_database_unittest.cc b/chrome/browser/webdata/web_database_unittest.cc index 1fe4ce4..349b803 100644 --- a/chrome/browser/webdata/web_database_unittest.cc +++ b/chrome/browser/webdata/web_database_unittest.cc @@ -2,11 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include <windows.h> - #include "base/file_util.h" #include "base/path_service.h" #include "base/string_util.h" +#include "base/time.h" #include "base/values.h" #include "chrome/browser/template_url.h" #include "chrome/browser/webdata/web_database.h" @@ -24,19 +23,16 @@ class WebDatabaseTest : public testing::Test { protected: virtual void SetUp() { - wchar_t b[32]; - _itow_s(static_cast<int>(GetTickCount()), b, arraysize(b), 10); - PathService::Get(chrome::DIR_TEST_DATA, &file_); file_ += FilePath::kSeparators[0]; file_ += L"TestWebDatabase"; - file_ += b; + file_ += Int64ToWString(base::Time::Now().ToInternalValue()); file_ += L".db"; - DeleteFile(file_.c_str()); + file_util::Delete(file_, false); } virtual void TearDown() { - DeleteFile(file_.c_str()); + file_util::Delete(file_, false); } static int GetKeyCount(const DictionaryValue& d) { @@ -111,7 +107,7 @@ TEST_F(WebDatabaseTest, Keywords) { std::vector<TemplateURL*> template_urls; EXPECT_TRUE(db.GetKeywords(&template_urls)); - EXPECT_EQ(1, template_urls.size()); + EXPECT_EQ(1U, template_urls.size()); const TemplateURL* restored_url = template_urls.front(); EXPECT_EQ(template_url.short_name(), restored_url->short_name()); @@ -132,7 +128,7 @@ TEST_F(WebDatabaseTest, Keywords) { EXPECT_EQ(32, restored_url->usage_count()); - ASSERT_EQ(1, restored_url->input_encodings().size()); + ASSERT_EQ(1U, restored_url->input_encodings().size()); EXPECT_EQ("UTF-8", restored_url->input_encodings()[0]); EXPECT_EQ(10, restored_url->prepopulate_id()); @@ -142,7 +138,7 @@ TEST_F(WebDatabaseTest, Keywords) { template_urls.clear(); EXPECT_TRUE(db.GetKeywords(&template_urls)); - EXPECT_EQ(0, template_urls.size()); + EXPECT_EQ(0U, template_urls.size()); delete restored_url; } @@ -192,7 +188,7 @@ TEST_F(WebDatabaseTest, UpdateKeyword) { std::vector<TemplateURL*> template_urls; EXPECT_TRUE(db.GetKeywords(&template_urls)); - EXPECT_EQ(1, template_urls.size()); + EXPECT_EQ(1U, template_urls.size()); const TemplateURL* restored_url = template_urls.front(); EXPECT_EQ(template_url.short_name(), restored_url->short_name()); @@ -211,7 +207,7 @@ TEST_F(WebDatabaseTest, UpdateKeyword) { EXPECT_TRUE(originating_url2 == restored_url->originating_url()); - ASSERT_EQ(1, restored_url->input_encodings().size()); + ASSERT_EQ(1U, restored_url->input_encodings().size()); ASSERT_EQ("Shift_JIS", restored_url->input_encodings()[0]); EXPECT_EQ(template_url.suggestions_url()->url(), @@ -240,7 +236,7 @@ TEST_F(WebDatabaseTest, KeywordWithNoFavicon) { std::vector<TemplateURL*> template_urls; EXPECT_TRUE(db.GetKeywords(&template_urls)); - EXPECT_EQ(1, template_urls.size()); + EXPECT_EQ(1U, template_urls.size()); const TemplateURL* restored_url = template_urls.front(); EXPECT_EQ(template_url.short_name(), restored_url->short_name()); @@ -260,12 +256,12 @@ TEST_F(WebDatabaseTest, Logins) { // Verify the database is empty. EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(0, result.size()); + EXPECT_EQ(0U, result.size()); // Example password form. PasswordForm form; - form.origin = GURL(L"http://www.google.com/accounts/LoginAuth"); - form.action = GURL(L"http://www.google.com/accounts/Login"); + form.origin = GURL("http://www.google.com/accounts/LoginAuth"); + form.action = GURL("http://www.google.com/accounts/Login"); form.username_element = L"Email"; form.username_value = L"test@gmail.com"; form.password_element = L"Passwd"; @@ -279,34 +275,34 @@ TEST_F(WebDatabaseTest, Logins) { // Add it and make sure it is there. EXPECT_TRUE(db.AddLogin(form)); EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); delete result[0]; result.clear(); // Match against an exact copy. EXPECT_TRUE(db.GetLogins(form, &result)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); delete result[0]; result.clear(); // The example site changes... PasswordForm form2(form); - form2.origin = GURL(L"http://www.google.com/new/accounts/LoginAuth"); + form2.origin = GURL("http://www.google.com/new/accounts/LoginAuth"); form2.submit_element = L"reallySignIn"; // Match against an inexact copy EXPECT_TRUE(db.GetLogins(form2, &result)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); delete result[0]; result.clear(); // Uh oh, the site changed origin & action URL's all at once! PasswordForm form3(form2); - form3.action = GURL(L"http://www.google.com/new/accounts/Login"); + form3.action = GURL("http://www.google.com/new/accounts/Login"); // signon_realm is the same, should match. EXPECT_TRUE(db.GetLogins(form3, &result)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); delete result[0]; result.clear(); @@ -317,32 +313,32 @@ TEST_F(WebDatabaseTest, Logins) { // We have only an http record, so no match for this. EXPECT_TRUE(db.GetLogins(form4, &result)); - EXPECT_EQ(0, result.size()); + EXPECT_EQ(0U, result.size()); // Let's imagine the user logs into the secure site. EXPECT_TRUE(db.AddLogin(form4)); EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(2, result.size()); + EXPECT_EQ(2U, result.size()); delete result[0]; delete result[1]; result.clear(); // Now the match works EXPECT_TRUE(db.GetLogins(form4, &result)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); delete result[0]; result.clear(); // The user chose to forget the original but not the new. EXPECT_TRUE(db.RemoveLogin(form)); EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); delete result[0]; result.clear(); // The old form wont match the new site (http vs https). EXPECT_TRUE(db.GetLogins(form, &result)); - EXPECT_EQ(0, result.size()); + EXPECT_EQ(0U, result.size()); // The user's request for the HTTPS site is intercepted // by an attacker who presents an invalid SSL cert. @@ -351,7 +347,7 @@ TEST_F(WebDatabaseTest, Logins) { // It will match in this case. EXPECT_TRUE(db.GetLogins(form5, &result)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); delete result[0]; result.clear(); @@ -365,12 +361,12 @@ TEST_F(WebDatabaseTest, Logins) { EXPECT_TRUE(db.UpdateLogin(form6)); // matches EXPECT_TRUE(db.GetLogins(form5, &result)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); delete result[0]; result.clear(); // Only one record. EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); // password element was updated. EXPECT_EQ(form6.password_value, result[0]->password_value); // Preferred login. @@ -381,7 +377,7 @@ TEST_F(WebDatabaseTest, Logins) { // Make sure everything can disappear. EXPECT_TRUE(db.RemoveLogin(form4)); EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(0, result.size()); + EXPECT_EQ(0U, result.size()); } TEST_F(WebDatabaseTest, Autofill) { @@ -434,7 +430,7 @@ TEST_F(WebDatabaseTest, Autofill) { // 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_EQ(3, v.size()); + EXPECT_EQ(3U, v.size()); if (v.size() == 3) { EXPECT_EQ(L"Clark Kent", v[0]); EXPECT_EQ(L"Clark Sutter", v[1]); @@ -444,7 +440,7 @@ TEST_F(WebDatabaseTest, Autofill) { // 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_EQ(1, v.size()); + EXPECT_EQ(1U, v.size()); if (v.size() == 1) { EXPECT_EQ(L"Clark Kent", v[0]); } @@ -452,7 +448,7 @@ TEST_F(WebDatabaseTest, Autofill) { // 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_EQ(2, v.size()); + EXPECT_EQ(2U, v.size()); if (v.size() == 2) { EXPECT_EQ(L"Clark Kent", v[0]); EXPECT_EQ(L"Clark Sutter", v[1]); @@ -467,7 +463,7 @@ TEST_F(WebDatabaseTest, Autofill) { EXPECT_EQ(0, count); EXPECT_TRUE(db.GetFormValuesForElementName(L"Name", L"", &v, 6)); - EXPECT_EQ(0, v.size()); + EXPECT_EQ(0U, v.size()); } static bool AddTimestampedLogin(WebDatabase* db, std::string url, @@ -500,7 +496,7 @@ TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) { // Verify the database is empty. EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(0, result.size()); + EXPECT_EQ(0U, result.size()); Time now = Time::Now(); TimeDelta one_day = TimeDelta::FromDays(1); @@ -514,7 +510,7 @@ TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) { // Verify inserts worked. EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(4, result.size()); + EXPECT_EQ(4U, result.size()); ClearResults(&result); // Delete everything from today's date and on. @@ -522,7 +518,7 @@ TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) { // Should have deleted half of what we inserted. EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(2, result.size()); + EXPECT_EQ(2U, result.size()); ClearResults(&result); // Delete with 0 date (should delete all). @@ -530,7 +526,7 @@ TEST_F(WebDatabaseTest, ClearPrivateData_SavedPasswords) { // Verify nothing is left. EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(0, result.size()); + EXPECT_EQ(0U, result.size()); } TEST_F(WebDatabaseTest, BlacklistedLogins) { @@ -541,12 +537,12 @@ TEST_F(WebDatabaseTest, BlacklistedLogins) { // Verify the database is empty. EXPECT_TRUE(db.GetAllLogins(&result, true)); - ASSERT_EQ(0, result.size()); + ASSERT_EQ(0U, result.size()); // Save a form as blacklisted. PasswordForm form; - form.origin = GURL(L"http://www.google.com/accounts/LoginAuth"); - form.action = GURL(L"http://www.google.com/accounts/Login"); + form.origin = GURL("http://www.google.com/accounts/LoginAuth"); + form.action = GURL("http://www.google.com/accounts/Login"); form.username_element = L"Email"; form.password_element = L"Passwd"; form.submit_element = L"signIn"; @@ -559,16 +555,16 @@ TEST_F(WebDatabaseTest, BlacklistedLogins) { // Get all non-blacklisted logins (should be none). EXPECT_TRUE(db.GetAllLogins(&result, false)); - ASSERT_EQ(0, result.size()); + ASSERT_EQ(0U, result.size()); // GetLogins should give the blacklisted result. EXPECT_TRUE(db.GetLogins(form, &result)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); ClearResults(&result); // So should GetAll including blacklisted. EXPECT_TRUE(db.GetAllLogins(&result, true)); - EXPECT_EQ(1, result.size()); + EXPECT_EQ(1U, result.size()); ClearResults(&result); } @@ -599,7 +595,7 @@ TEST_F(WebDatabaseTest, WebAppImages) { // Web app should initially have no images. std::vector<SkBitmap> images; ASSERT_TRUE(db.GetWebAppImages(url, &images)); - ASSERT_EQ(0, images.size()); + ASSERT_EQ(0U, images.size()); // Add an image. SkBitmap image; @@ -610,7 +606,7 @@ TEST_F(WebDatabaseTest, WebAppImages) { // Make sure we get the image back. ASSERT_TRUE(db.GetWebAppImages(url, &images)); - ASSERT_EQ(1, images.size()); + ASSERT_EQ(1U, images.size()); ASSERT_EQ(16, images[0].width()); ASSERT_EQ(16, images[0].height()); @@ -623,7 +619,7 @@ TEST_F(WebDatabaseTest, WebAppImages) { ASSERT_TRUE(db.SetWebAppImage(url, image)); images.clear(); ASSERT_TRUE(db.GetWebAppImages(url, &images)); - ASSERT_EQ(1, images.size()); + ASSERT_EQ(1U, images.size()); ASSERT_EQ(16, images[0].width()); ASSERT_EQ(16, images[0].height()); images[0].lockPixels(); @@ -642,7 +638,7 @@ TEST_F(WebDatabaseTest, WebAppImages) { // Make sure we get both images back. images.clear(); ASSERT_TRUE(db.GetWebAppImages(url, &images)); - ASSERT_EQ(2, images.size()); + ASSERT_EQ(2U, images.size()); if (images[0].width() == 16) { ASSERT_EQ(16, images[0].width()); ASSERT_EQ(16, images[0].height()); diff --git a/chrome/browser/webdata/web_database_win.cc b/chrome/browser/webdata/web_database_win.cc new file mode 100644 index 0000000..f5793d4 --- /dev/null +++ b/chrome/browser/webdata/web_database_win.cc @@ -0,0 +1,72 @@ +// Copyright (c) 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/webdata/web_database.h" + +#include "base/logging.h" +#include "base/time.h" +#include "chrome/browser/ie7_password.h" +#include "chrome/common/sqlite_utils.h" + +bool WebDatabase::AddIE7Login(const IE7PasswordInfo& info) { + SQLStatement s; + if (s.prepare(db_, + "INSERT OR REPLACE INTO ie7_logins " + "(url_hash, password_value, date_created) " + "VALUES (?, ?, ?)") != SQLITE_OK) { + NOTREACHED() << "Statement prepare failed"; + return false; + } + + s.bind_wstring(0, info.url_hash); + s.bind_blob(1, &info.encrypted_data.front(), + static_cast<int>(info.encrypted_data.size())); + s.bind_int64(2, info.date_created.ToTimeT()); + if (s.step() != SQLITE_DONE) { + NOTREACHED(); + return false; + } + return true; +} + +bool WebDatabase::RemoveIE7Login(const IE7PasswordInfo& info) { + SQLStatement s; + // Remove a login by UNIQUE-constrained fields. + if (s.prepare(db_, + "DELETE FROM ie7_logins WHERE " + "url_hash = ?") != SQLITE_OK) { + NOTREACHED() << "Statement prepare failed"; + return false; + } + s.bind_wstring(0, info.url_hash); + + if (s.step() != SQLITE_DONE) { + NOTREACHED(); + return false; + } + return true; +} + +bool WebDatabase::GetIE7Login(const IE7PasswordInfo& info, + IE7PasswordInfo* result) { + DCHECK(result); + SQLStatement s; + if (s.prepare(db_, + "SELECT password_value, date_created FROM ie7_logins " + "WHERE url_hash == ? ") != SQLITE_OK) { + NOTREACHED() << "Statement prepare failed"; + return false; + } + + s.bind_wstring(0, info.url_hash); + + int64 query_result = s.step(); + if (query_result == SQLITE_ROW) { + s.column_blob_as_vector(0, &result->encrypted_data); + result->date_created = base::Time::FromTimeT(s.column_int64(1)); + result->url_hash = info.url_hash; + s.step(); + } + return query_result == SQLITE_DONE; +} |