diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-20 19:25:42 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-20 19:25:42 +0000 |
commit | 00e3f152083aea092353b3d284c368b48136f33c (patch) | |
tree | 081df57119ba9301bebd7c7091efc4acab5accc9 /chrome/browser/password_manager | |
parent | 4e6f2f037e6d1956bc431ac37a72d8e6871586d8 (diff) | |
download | chromium_src-00e3f152083aea092353b3d284c368b48136f33c.zip chromium_src-00e3f152083aea092353b3d284c368b48136f33c.tar.gz chromium_src-00e3f152083aea092353b3d284c368b48136f33c.tar.bz2 |
Convert some structures in webkit/glue to string16.
R=yaar
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/305002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29549 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/password_manager')
9 files changed, 85 insertions, 83 deletions
diff --git a/chrome/browser/password_manager/login_database.cc b/chrome/browser/password_manager/login_database.cc index c948db2..ac6540c 100644 --- a/chrome/browser/password_manager/login_database.cc +++ b/chrome/browser/password_manager/login_database.cc @@ -139,13 +139,13 @@ bool LoginDatabase::AddLogin(const PasswordForm& form) { s.bind_string(COLUMN_ORIGIN_URL, form.origin.spec()); s.bind_string(COLUMN_ACTION_URL, form.action.spec()); - s.bind_wstring(COLUMN_USERNAME_ELEMENT, form.username_element); - s.bind_wstring(COLUMN_USERNAME_VALUE, form.username_value); - s.bind_wstring(COLUMN_PASSWORD_ELEMENT, form.password_element); + s.bind_string16(COLUMN_USERNAME_ELEMENT, form.username_element); + s.bind_string16(COLUMN_USERNAME_VALUE, form.username_value); + s.bind_string16(COLUMN_PASSWORD_ELEMENT, form.password_element); std::string encrypted_password = EncryptedString(form.password_value); s.bind_blob(COLUMN_PASSWORD_VALUE, encrypted_password.data(), static_cast<int>(encrypted_password.length())); - s.bind_wstring(COLUMN_SUBMIT_ELEMENT, form.submit_element); + s.bind_string16(COLUMN_SUBMIT_ELEMENT, form.submit_element); s.bind_string(COLUMN_SIGNON_REALM, form.signon_realm); s.bind_int(COLUMN_SSL_VALID, form.ssl_valid); s.bind_int(COLUMN_PREFERRED, form.preferred); @@ -182,9 +182,9 @@ bool LoginDatabase::UpdateLogin(const PasswordForm& form, int* items_changed) { s.bind_int(2, form.ssl_valid); s.bind_int(3, form.preferred); s.bind_string(4, form.origin.spec()); - s.bind_wstring(5, form.username_element); - s.bind_wstring(6, form.username_value); - s.bind_wstring(7, form.password_element); + s.bind_string16(5, form.username_element); + s.bind_string16(6, form.username_value); + s.bind_string16(7, form.password_element); s.bind_string(8, form.signon_realm); if (s.step() != SQLITE_DONE) { @@ -213,10 +213,10 @@ bool LoginDatabase::RemoveLogin(const PasswordForm& form) { } s.bind_string(0, form.origin.spec()); - s.bind_wstring(1, form.username_element); - s.bind_wstring(2, form.username_value); - s.bind_wstring(3, form.password_element); - s.bind_wstring(4, form.submit_element); + s.bind_string16(1, form.username_element); + s.bind_string16(2, form.username_value); + s.bind_string16(3, form.password_element); + s.bind_string16(4, form.submit_element); s.bind_string(5, form.signon_realm); if (s.step() != SQLITE_DONE) { @@ -249,13 +249,13 @@ void LoginDatabase::InitPasswordFormFromStatement(PasswordForm* form, form->origin = GURL(tmp); s->column_string(COLUMN_ACTION_URL, &tmp); form->action = GURL(tmp); - s->column_wstring(COLUMN_USERNAME_ELEMENT, &form->username_element); - s->column_wstring(COLUMN_USERNAME_VALUE, &form->username_value); - s->column_wstring(COLUMN_PASSWORD_ELEMENT, &form->password_element); + s->column_string16(COLUMN_USERNAME_ELEMENT, &form->username_element); + s->column_string16(COLUMN_USERNAME_VALUE, &form->username_value); + s->column_string16(COLUMN_PASSWORD_ELEMENT, &form->password_element); std::string encrypted_password; s->column_blob_as_string(COLUMN_PASSWORD_VALUE, &encrypted_password); form->password_value = DecryptedString(encrypted_password); - s->column_wstring(COLUMN_SUBMIT_ELEMENT, &form->submit_element); + s->column_string16(COLUMN_SUBMIT_ELEMENT, &form->submit_element); s->column_string(COLUMN_SIGNON_REALM, &tmp); form->signon_realm = tmp; form->ssl_valid = (s->column_int(COLUMN_SSL_VALID) > 0); diff --git a/chrome/browser/password_manager/login_database.h b/chrome/browser/password_manager/login_database.h index 9e34192..3db5ce3 100644 --- a/chrome/browser/password_manager/login_database.h +++ b/chrome/browser/password_manager/login_database.h @@ -8,6 +8,7 @@ #include <string> #include <vector> +#include "base/string16.h" #include "chrome/browser/meta_table_helper.h" #include "webkit/glue/password_form.h" @@ -61,10 +62,10 @@ class LoginDatabase { protected: // Returns an encrypted version of plain_text. - virtual std::string EncryptedString(const std::wstring& plain_text) const = 0; + virtual std::string EncryptedString(const string16& plain_text) const = 0; // Returns a decrypted version of cipher_text. - virtual std::wstring DecryptedString(const std::string& cipher_text) + virtual string16 DecryptedString(const std::string& cipher_text) const = 0; bool InitLoginsTable(); diff --git a/chrome/browser/password_manager/login_database_mac.cc b/chrome/browser/password_manager/login_database_mac.cc index fbef3ac..731f114 100644 --- a/chrome/browser/password_manager/login_database_mac.cc +++ b/chrome/browser/password_manager/login_database_mac.cc @@ -4,12 +4,12 @@ #include "chrome/browser/password_manager/login_database_mac.h" -std::string LoginDatabaseMac::EncryptedString(const std::wstring& plain_text) +std::string LoginDatabaseMac::EncryptedString(const string16& plain_text) const { return std::string(); } -std::wstring LoginDatabaseMac::DecryptedString(const std::string& cipher_text) +string16 LoginDatabaseMac::DecryptedString(const std::string& cipher_text) const { - return std::wstring(); + return string16(); } diff --git a/chrome/browser/password_manager/login_database_mac.h b/chrome/browser/password_manager/login_database_mac.h index 8683179..9c6e93e 100644 --- a/chrome/browser/password_manager/login_database_mac.h +++ b/chrome/browser/password_manager/login_database_mac.h @@ -19,8 +19,8 @@ class LoginDatabaseMac : public LoginDatabase { protected: // Stub implementations that always return an empty string. - virtual std::string EncryptedString(const std::wstring& plain_text) const; - virtual std::wstring DecryptedString(const std::string& cipher_text) const; + virtual std::string EncryptedString(const string16& plain_text) const; + virtual string16 DecryptedString(const std::string& cipher_text) const; }; diff --git a/chrome/browser/password_manager/login_database_unittest.cc b/chrome/browser/password_manager/login_database_unittest.cc index 201c93f..beb439a 100644 --- a/chrome/browser/password_manager/login_database_unittest.cc +++ b/chrome/browser/password_manager/login_database_unittest.cc @@ -63,11 +63,11 @@ TEST_F(LoginDatabaseTest, Logins) { PasswordForm form; 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"; - form.password_value = L"test"; - form.submit_element = L"signIn"; + form.username_element = ASCIIToUTF16("Email"); + form.username_value = ASCIIToUTF16("test@gmail.com"); + form.password_element = ASCIIToUTF16("Passwd"); + form.password_value = ASCIIToUTF16("test"); + form.submit_element = ASCIIToUTF16("signIn"); form.signon_realm = "http://www.google.com/"; form.ssl_valid = false; form.preferred = false; @@ -89,7 +89,7 @@ TEST_F(LoginDatabaseTest, Logins) { // The example site changes... PasswordForm form2(form); form2.origin = GURL("http://www.google.com/new/accounts/LoginAuth"); - form2.submit_element = L"reallySignIn"; + form2.submit_element = ASCIIToUTF16("reallySignIn"); // Match against an inexact copy EXPECT_TRUE(db->GetLogins(form2, &result)); @@ -154,7 +154,7 @@ TEST_F(LoginDatabaseTest, Logins) { // User changes his password. PasswordForm form6(form5); - form6.password_value = L"test6"; + form6.password_value = ASCIIToUTF16("test6"); form6.preferred = true; // We update, and check to make sure it matches the @@ -173,7 +173,7 @@ TEST_F(LoginDatabaseTest, Logins) { // Password element was updated. #if defined(OS_MACOSX) // On the Mac we should never be storing passwords in the database. - EXPECT_EQ(L"", result[0]->password_value); + EXPECT_EQ(string16(), result[0]->password_value); #else EXPECT_EQ(form6.password_value, result[0]->password_value); #endif @@ -189,15 +189,15 @@ TEST_F(LoginDatabaseTest, Logins) { } static bool AddTimestampedLogin(LoginDatabase* db, std::string url, - std::wstring unique_string, + const std::string& unique_string, const base::Time& time) { // Example password form. PasswordForm form; form.origin = GURL(url + std::string("/LoginAuth")); - form.username_element = unique_string.c_str(); - form.username_value = unique_string.c_str(); - form.password_element = unique_string.c_str(); - form.submit_element = L"signIn"; + form.username_element = ASCIIToUTF16(unique_string); + form.username_value = ASCIIToUTF16(unique_string); + form.password_element = ASCIIToUTF16(unique_string); + form.submit_element = ASCIIToUTF16("signIn"); form.signon_realm = url; form.date_created = time; return db->AddLogin(form); @@ -227,11 +227,11 @@ TEST_F(LoginDatabaseTest, ClearPrivateData_SavedPasswords) { base::TimeDelta one_day = base::TimeDelta::FromDays(1); // Create one with a 0 time. - EXPECT_TRUE(AddTimestampedLogin(db.get(), "1", L"foo1", base::Time())); + EXPECT_TRUE(AddTimestampedLogin(db.get(), "1", "foo1", base::Time())); // Create one for now and +/- 1 day. - EXPECT_TRUE(AddTimestampedLogin(db.get(), "2", L"foo2", now - one_day)); - EXPECT_TRUE(AddTimestampedLogin(db.get(), "3", L"foo3", now)); - EXPECT_TRUE(AddTimestampedLogin(db.get(), "4", L"foo4", now + one_day)); + EXPECT_TRUE(AddTimestampedLogin(db.get(), "2", "foo2", now - one_day)); + EXPECT_TRUE(AddTimestampedLogin(db.get(), "3", "foo3", now)); + EXPECT_TRUE(AddTimestampedLogin(db.get(), "4", "foo4", now + one_day)); // Verify inserts worked. EXPECT_TRUE(db->GetAutofillableLogins(&result)); @@ -270,9 +270,9 @@ TEST_F(LoginDatabaseTest, BlacklistedLogins) { PasswordForm form; 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"; + form.username_element = ASCIIToUTF16("Email"); + form.password_element = ASCIIToUTF16("Passwd"); + form.submit_element = ASCIIToUTF16("signIn"); form.signon_realm = "http://www.google.com/"; form.ssl_valid = false; form.preferred = true; diff --git a/chrome/browser/password_manager/password_form_manager_unittest.cc b/chrome/browser/password_manager/password_form_manager_unittest.cc index 30c4faa..b3f4bb6 100644 --- a/chrome/browser/password_manager/password_form_manager_unittest.cc +++ b/chrome/browser/password_manager/password_form_manager_unittest.cc @@ -19,17 +19,17 @@ class PasswordFormManagerTest : public testing::Test { virtual void SetUp() { observed_form_.origin = GURL("http://www.google.com/a/LoginAuth"); observed_form_.action = GURL("http://www.google.com/a/Login"); - observed_form_.username_element = L"Email"; - observed_form_.password_element = L"Passwd"; - observed_form_.submit_element = L"signIn"; + observed_form_.username_element = ASCIIToUTF16("Email"); + observed_form_.password_element = ASCIIToUTF16("Passwd"); + observed_form_.submit_element = ASCIIToUTF16("signIn"); observed_form_.signon_realm = "http://www.google.com"; saved_match_ = observed_form_; saved_match_.origin = GURL("http://www.google.com/a/ServiceLoginAuth"); saved_match_.action = GURL("http://www.google.com/a/ServiceLogin"); saved_match_.preferred = true; - saved_match_.username_value = L"test@gmail.com"; - saved_match_.password_value = L"test1"; + saved_match_.username_value = ASCIIToUTF16("test@gmail.com"); + saved_match_.password_value = ASCIIToUTF16("test1"); profile_ = new TestingProfile(); } @@ -65,7 +65,6 @@ class PasswordFormManagerTest : public testing::Test { private: PasswordForm observed_form_; PasswordForm saved_match_; - std::wstring test_dir_; Profile* profile_; }; @@ -100,8 +99,8 @@ TEST_F(PasswordFormManagerTest, TestNewLogin) { // will yield the previously saved login. SimulateMatchingPhase(manager, true); // Set up the new login. - std::wstring new_user = L"newuser"; - std::wstring new_pass = L"newpass"; + string16 new_user = ASCIIToUTF16("newuser"); + string16 new_pass = ASCIIToUTF16("newpass"); credentials.username_value = new_user; credentials.password_value = new_pass; manager->ProvisionallySave(credentials); @@ -134,7 +133,7 @@ TEST_F(PasswordFormManagerTest, TestUpdatePassword) { // origin URL (as it does in this case) than the saved_match, but we want to // make sure the updated password is reflected in saved_match, because that is // what we autofilled. - std::wstring new_pass = L"newpassword"; + string16 new_pass = ASCIIToUTF16("newpassword"); PasswordForm credentials = *observed_form(); credentials.username_value = saved_match()->username_value; credentials.password_value = new_pass; diff --git a/chrome/browser/password_manager/password_manager.cc b/chrome/browser/password_manager/password_manager.cc index 58c4afd..da00ed7 100644 --- a/chrome/browser/password_manager/password_manager.cc +++ b/chrome/browser/password_manager/password_manager.cc @@ -240,8 +240,9 @@ void PasswordManager::Autofill( } default: if (observer_) { - observer_->OnAutofillDataAvailable(preferred_match->username_value, - preferred_match->password_value); + observer_->OnAutofillDataAvailable( + UTF16ToWideHack(preferred_match->username_value), + UTF16ToWideHack(preferred_match->password_value)); } } } diff --git a/chrome/browser/password_manager/password_store_mac.cc b/chrome/browser/password_manager/password_store_mac.cc index 594478a..3102938 100644 --- a/chrome/browser/password_manager/password_store_mac.cc +++ b/chrome/browser/password_manager/password_store_mac.cc @@ -258,8 +258,8 @@ bool FillPasswordFormFromKeychainItem(const MacKeychain& keychain, return false; } - UTF8ToWide(static_cast<const char *>(password_data), password_length, - &(form->password_value)); + UTF8ToUTF16(static_cast<const char *>(password_data), password_length, + &(form->password_value)); int port = kAnyPort; std::string server; @@ -272,8 +272,8 @@ bool FillPasswordFormFromKeychainItem(const MacKeychain& keychain, } switch (attr.tag) { case kSecAccountItemAttr: - UTF8ToWide(static_cast<const char *>(attr.data), attr.length, - &(form->username_value)); + UTF8ToUTF16(static_cast<const char *>(attr.data), attr.length, + &(form->username_value)); break; case kSecServerItemAttr: server.assign(static_cast<const char *>(attr.data), attr.length); @@ -321,7 +321,7 @@ bool FillPasswordFormFromKeychainItem(const MacKeychain& keychain, // kSecNegativeItemAttr doesn't seem to actually be in widespread use. In // practice, other browsers seem to use a "" or " " password (and a special // user name) to indicated blacklist entries. - if (form->password_value.empty() || form->password_value == L" ") { + if (form->password_value.empty() || EqualsASCII(form->password_value, " ")) { form->blacklisted_by_user = true; } @@ -477,7 +477,7 @@ std::vector<PasswordForm*> std::vector<PasswordForm*> MacKeychainPasswordFormAdapter::PasswordsMergeableWithForm( const PasswordForm& query_form) { - std::string username = WideToUTF8(query_form.username_value); + std::string username = UTF16ToUTF8(query_form.username_value); std::vector<SecKeychainItemRef> keychain_items = MatchingKeychainItems(query_form.signon_realm, query_form.scheme, NULL, username.c_str()); @@ -530,8 +530,8 @@ bool MacKeychainPasswordFormAdapter::AddPassword(const PasswordForm& form) { &is_secure, &security_domain)) { return false; } - std::string username = WideToUTF8(form.username_value); - std::string password = WideToUTF8(form.password_value); + std::string username = UTF16ToUTF8(form.username_value); + std::string password = UTF16ToUTF8(form.password_value); std::string path = form.origin.path(); SecProtocolType protocol = is_secure ? kSecProtocolTypeHTTPS : kSecProtocolTypeHTTP; @@ -601,7 +601,7 @@ SecKeychainItemRef MacKeychainPasswordFormAdapter::KeychainItemForForm( } std::string path = form.origin.path(); - std::string username = WideToUTF8(form.username_value); + std::string username = UTF16ToUTF8(form.username_value); std::vector<SecKeychainItemRef> matches = MatchingKeychainItems( form.signon_realm, form.scheme, path.c_str(), username.c_str()); diff --git a/chrome/browser/password_manager/password_store_mac_unittest.cc b/chrome/browser/password_manager/password_store_mac_unittest.cc index 6eeeac7..8591b86 100644 --- a/chrome/browser/password_manager/password_store_mac_unittest.cc +++ b/chrome/browser/password_manager/password_store_mac_unittest.cc @@ -6,6 +6,7 @@ #include "base/basictypes.h" #include "base/stl_util-inl.h" +#include "base/string_util.h" #include "chrome/browser/keychain_mock_mac.h" #include "chrome/browser/password_manager/password_store_mac.h" #include "chrome/browser/password_manager/password_store_mac_internal.h" @@ -123,15 +124,15 @@ static PasswordForm* CreatePasswordFormFromData( if (form_data.action) form->action = GURL(form_data.action); if (form_data.submit_element) - form->submit_element = std::wstring(form_data.submit_element); + form->submit_element = WideToUTF16(form_data.submit_element); if (form_data.username_element) - form->username_element = std::wstring(form_data.username_element); + form->username_element = WideToUTF16(form_data.username_element); if (form_data.password_element) - form->password_element = std::wstring(form_data.password_element); + form->password_element = WideToUTF16(form_data.password_element); if (form_data.username_value) { - form->username_value = std::wstring(form_data.username_value); + form->username_value = WideToUTF16(form_data.username_value); if (form_data.password_value) - form->password_value = std::wstring(form_data.password_value); + form->password_value = WideToUTF16(form_data.password_value); } else { form->blacklisted_by_user = true; } @@ -168,16 +169,16 @@ static void CheckFormsAgainstExpectations( << test_label; EXPECT_EQ(GURL(expectation->origin), form->origin) << test_label; EXPECT_EQ(GURL(expectation->action), form->action) << test_label; - EXPECT_EQ(std::wstring(expectation->submit_element), form->submit_element) + EXPECT_EQ(WideToUTF16(expectation->submit_element), form->submit_element) << test_label; - EXPECT_EQ(std::wstring(expectation->username_element), + EXPECT_EQ(WideToUTF16(expectation->username_element), form->username_element) << test_label; - EXPECT_EQ(std::wstring(expectation->password_element), + EXPECT_EQ(WideToUTF16(expectation->password_element), form->password_element) << test_label; if (expectation->username_value) { - EXPECT_EQ(std::wstring(expectation->username_value), + EXPECT_EQ(WideToUTF16(expectation->username_value), form->username_value) << test_label; - EXPECT_EQ(std::wstring(expectation->password_value), + EXPECT_EQ(WideToUTF16(expectation->password_value), form->password_value) << test_label; } else { EXPECT_TRUE(form->blacklisted_by_user) << test_label; @@ -255,9 +256,9 @@ TEST_F(PasswordStoreMacTest, TestKeychainToFormTranslation) { EXPECT_EQ(std::string(expected[i].signon_realm), form.signon_realm) << "In iteration " << i; if (expected[i].username) { - EXPECT_EQ(std::wstring(expected[i].username), form.username_value) + EXPECT_EQ(WideToUTF16(expected[i].username), form.username_value) << "In iteration " << i; - EXPECT_EQ(std::wstring(expected[i].password), form.password_value) + EXPECT_EQ(WideToUTF16(expected[i].password), form.password_value) << "In iteration " << i; EXPECT_FALSE(form.blacklisted_by_user) << "In iteration " << i; } else { @@ -423,7 +424,7 @@ TEST_F(PasswordStoreMacTest, TestKeychainExactSearch) { std::vector<PasswordForm*> modified_forms; modified_forms.push_back(new PasswordForm(*base_form)); - modified_forms.back()->username_value = std::wstring(L"wrong_user"); + modified_forms.back()->username_value = ASCIIToUTF16("wrong_user"); modified_forms.push_back(new PasswordForm(*base_form)); SetPasswordFormPath(modified_forms.back(), "elsewhere.html"); @@ -565,15 +566,15 @@ TEST_F(PasswordStoreMacTest, TestFormMatch) { PasswordForm base_form; base_form.signon_realm = std::string("http://some.domain.com/"); base_form.origin = GURL("http://some.domain.com/page.html"); - base_form.username_value = std::wstring(L"joe_user"); + base_form.username_value = ASCIIToUTF16("joe_user"); { // Check that everything unimportant can be changed. PasswordForm different_form(base_form); - different_form.username_element = std::wstring(L"username"); - different_form.submit_element = std::wstring(L"submit"); - different_form.username_element = std::wstring(L"password"); - different_form.password_value = std::wstring(L"sekrit"); + different_form.username_element = ASCIIToUTF16("username"); + different_form.submit_element = ASCIIToUTF16("submit"); + different_form.username_element = ASCIIToUTF16("password"); + different_form.password_value = ASCIIToUTF16("sekrit"); different_form.action = GURL("http://some.domain.com/action.cgi"); different_form.ssl_valid = true; different_form.preferred = true; @@ -602,7 +603,7 @@ TEST_F(PasswordStoreMacTest, TestFormMatch) { } { PasswordForm different_form(base_form); - different_form.username_value = std::wstring(L"john.doe"); + different_form.username_value = ASCIIToUTF16("john.doe"); EXPECT_FALSE(internal_keychain_helpers::FormsMatchForMerge(base_form, different_form)); } @@ -813,8 +814,8 @@ TEST_F(PasswordStoreMacTest, TestPasswordBulkLookup) { &database_forms); EXPECT_EQ(2U, database_forms.size()); ASSERT_EQ(3U, merged_forms.size()); - EXPECT_EQ(std::wstring(L"sekrit"), merged_forms[0]->password_value); - EXPECT_EQ(std::wstring(L"sekrit"), merged_forms[1]->password_value); + EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[0]->password_value); + EXPECT_EQ(ASCIIToUTF16("sekrit"), merged_forms[1]->password_value); EXPECT_EQ(true, merged_forms[2]->blacklisted_by_user); STLDeleteElements(&database_forms); |