diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-29 06:15:44 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-29 06:15:44 +0000 |
commit | 13c8a0903376ff406151679d8673a6452d721290 (patch) | |
tree | dbb5b8e9503f8d0ee447863089f3e6f23692910f | |
parent | 6b55570f03236557b8b966b08dfbdda1ea91aadc (diff) | |
download | chromium_src-13c8a0903376ff406151679d8673a6452d721290.zip chromium_src-13c8a0903376ff406151679d8673a6452d721290.tar.gz chromium_src-13c8a0903376ff406151679d8673a6452d721290.tar.bz2 |
Net: Convert username and password to string16.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3040016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54101 0039d316-1c4b-4281-b951-d872f2087c98
67 files changed, 555 insertions, 456 deletions
diff --git a/chrome/browser/login_prompt.cc b/chrome/browser/login_prompt.cc index 37677b5..0061e9c 100644 --- a/chrome/browser/login_prompt.cc +++ b/chrome/browser/login_prompt.cc @@ -319,7 +319,7 @@ void LoginHandler::SetAuthDeferred(const std::wstring& username, DCHECK(ChromeThread::CurrentlyOn(ChromeThread::IO)); if (request_) { - request_->SetAuth(username, password); + request_->SetAuth(WideToUTF16Hack(username), WideToUTF16Hack(password)); ResetLoginHandlerForRequest(request_); } } diff --git a/net/base/auth.h b/net/base/auth.h index 3050a4c5..20c4f5c 100644 --- a/net/base/auth.h +++ b/net/base/auth.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -9,6 +9,7 @@ #include <string> #include "base/ref_counted.h" +#include "base/string16.h" namespace net { @@ -51,8 +52,8 @@ class AuthData : public base::RefCountedThreadSafe<AuthData> { public: AuthState state; // whether we need, have, or gave up on authentication. std::wstring scheme; // the authentication scheme. - std::wstring username; // the username supplied to us for auth. - std::wstring password; // the password supplied to us for auth. + string16 username; // the username supplied to us for auth. + string16 password; // the password supplied to us for auth. // We wouldn't instantiate this class if we didn't need authentication. AuthData() : state(AUTH_STATE_NEED_AUTH) {} diff --git a/net/base/net_util.cc b/net/base/net_util.cc index 73df8c6..7ba8a10 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -1338,14 +1338,12 @@ std::string GetHostName() { } void GetIdentityFromURL(const GURL& url, - std::wstring* username, - std::wstring* password) { + string16* username, + string16* password) { UnescapeRule::Type flags = UnescapeRule::SPACES | UnescapeRule::URL_SPECIAL_CHARS; - *username = UTF16ToWideHack(UnescapeAndDecodeUTF8URLComponent(url.username(), - flags, NULL)); - *password = UTF16ToWideHack(UnescapeAndDecodeUTF8URLComponent(url.password(), - flags, NULL)); + *username = UnescapeAndDecodeUTF8URLComponent(url.username(), flags, NULL); + *password = UnescapeAndDecodeUTF8URLComponent(url.password(), flags, NULL); } std::string GetHostOrSpecFromURL(const GURL& url) { diff --git a/net/base/net_util.h b/net/base/net_util.h index 7b2ed36..44bda41 100644 --- a/net/base/net_util.h +++ b/net/base/net_util.h @@ -106,8 +106,8 @@ std::string GetHostName(); // Extracts the unescaped username/password from |url|, saving the results // into |*username| and |*password|. void GetIdentityFromURL(const GURL& url, - std::wstring* username, - std::wstring* password); + string16* username, + string16* password); // Returns either the host from |url|, or, if the host is empty, the full spec. std::string GetHostOrSpecFromURL(const GURL& url); diff --git a/net/base/net_util_unittest.cc b/net/base/net_util_unittest.cc index 2c62089..84cb4f4 100644 --- a/net/base/net_util_unittest.cc +++ b/net/base/net_util_unittest.cc @@ -575,54 +575,54 @@ TEST(NetUtilTest, FileURLConversion) { TEST(NetUtilTest, GetIdentityFromURL) { struct { const char* input_url; - const wchar_t* expected_username; - const wchar_t* expected_password; + const char* expected_username; + const char* expected_password; } tests[] = { { "http://username:password@google.com", - L"username", - L"password", + "username", + "password", }, { // Test for http://crbug.com/19200 "http://username:p@ssword@google.com", - L"username", - L"p@ssword", + "username", + "p@ssword", }, { // Special URL characters should be unescaped. "http://username:p%3fa%26s%2fs%23@google.com", - L"username", - L"p?a&s/s#", + "username", + "p?a&s/s#", }, { // Username contains %20. "http://use rname:password@google.com", - L"use rname", - L"password", + "use rname", + "password", }, { // Keep %00 as is. "http://use%00rname:password@google.com", - L"use%00rname", - L"password", + "use%00rname", + "password", }, { // Use a '+' in the username. "http://use+rname:password@google.com", - L"use+rname", - L"password", + "use+rname", + "password", }, { // Use a '&' in the password. "http://username:p&ssword@google.com", - L"username", - L"p&ssword", + "username", + "p&ssword", }, }; for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { SCOPED_TRACE(StringPrintf("Test[%" PRIuS "]: %s", i, tests[i].input_url)); GURL url(tests[i].input_url); - std::wstring username, password; + string16 username, password; net::GetIdentityFromURL(url, &username, &password); - EXPECT_EQ(tests[i].expected_username, username); - EXPECT_EQ(tests[i].expected_password, password); + EXPECT_EQ(ASCIIToUTF16(tests[i].expected_username), username); + EXPECT_EQ(ASCIIToUTF16(tests[i].expected_password), password); } } @@ -634,12 +634,12 @@ TEST(NetUtilTest, GetIdentityFromURL_UTF8) { EXPECT_EQ("%E4%BD%A0%E5%A5%BD", url.password()); // Extract the unescaped identity. - std::wstring username, password; + string16 username, password; net::GetIdentityFromURL(url, &username, &password); // Verify that it was decoded as UTF8. - EXPECT_EQ(L"foo", username); - EXPECT_EQ(L"\x4f60\x597d", password); + EXPECT_EQ(ASCIIToUTF16("foo"), username); + EXPECT_EQ(WideToUTF16(L"\x4f60\x597d"), password); } // Just a bunch of fake headers. diff --git a/net/ftp/ftp_auth_cache.cc b/net/ftp/ftp_auth_cache.cc index d3bff90..caa2b8a 100644 --- a/net/ftp/ftp_auth_cache.cc +++ b/net/ftp/ftp_auth_cache.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -20,8 +20,8 @@ FtpAuthCache::Entry* FtpAuthCache::Lookup(const GURL& origin) { return NULL; } -void FtpAuthCache::Add(const GURL& origin, const std::wstring& username, - const std::wstring& password) { +void FtpAuthCache::Add(const GURL& origin, const string16& username, + const string16& password) { DCHECK(origin.SchemeIs("ftp")); DCHECK_EQ(origin.GetOrigin(), origin); @@ -38,8 +38,8 @@ void FtpAuthCache::Add(const GURL& origin, const std::wstring& username, } } -void FtpAuthCache::Remove(const GURL& origin, const std::wstring& username, - const std::wstring& password) { +void FtpAuthCache::Remove(const GURL& origin, const string16& username, + const string16& password) { for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { if (it->origin == origin && it->username == username && it->password == password) { diff --git a/net/ftp/ftp_auth_cache.h b/net/ftp/ftp_auth_cache.h index d541b8e..36156da 100644 --- a/net/ftp/ftp_auth_cache.h +++ b/net/ftp/ftp_auth_cache.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// 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. @@ -7,8 +7,8 @@ #pragma once #include <list> -#include <string> +#include "base/string16.h" #include "googleurl/src/gurl.h" namespace net { @@ -27,16 +27,16 @@ class FtpAuthCache { static const size_t kMaxEntries; struct Entry { - Entry(const GURL& origin, const std::wstring& username, - const std::wstring& password) + Entry(const GURL& origin, const string16& username, + const string16& password) : origin(origin), username(username), password(password) { } const GURL origin; - std::wstring username; - std::wstring password; + string16 username; + string16 password; }; FtpAuthCache() {} @@ -48,13 +48,13 @@ class FtpAuthCache { // Add an entry for |origin| to the cache (consisting of |username| and // |password|). If there is already an entry for |origin|, it will be // overwritten. - void Add(const GURL& origin, const std::wstring& username, - const std::wstring& password); + void Add(const GURL& origin, const string16& username, + const string16& password); // Remove the entry for |origin| from the cache, if one exists and matches // |username| and |password|. - void Remove(const GURL& origin, const std::wstring& username, - const std::wstring& password); + void Remove(const GURL& origin, const string16& username, + const string16& password); private: typedef std::list<Entry> EntryList; diff --git a/net/ftp/ftp_auth_cache_unittest.cc b/net/ftp/ftp_auth_cache_unittest.cc index b23781e..005de89 100644 --- a/net/ftp/ftp_auth_cache_unittest.cc +++ b/net/ftp/ftp_auth_cache_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -10,6 +10,22 @@ using net::FtpAuthCache; +namespace { + +const string16 kBogus(ASCIIToUTF16("bogus")); +const string16 kOthername(ASCIIToUTF16("othername")); +const string16 kOtherword(ASCIIToUTF16("otherword")); +const string16 kPassword(ASCIIToUTF16("password")); +const string16 kPassword1(ASCIIToUTF16("password1")); +const string16 kPassword2(ASCIIToUTF16("password2")); +const string16 kPassword3(ASCIIToUTF16("password3")); +const string16 kUsername(ASCIIToUTF16("username")); +const string16 kUsername1(ASCIIToUTF16("username1")); +const string16 kUsername2(ASCIIToUTF16("username2")); +const string16 kUsername3(ASCIIToUTF16("username3")); + +} // namespace + TEST(FtpAuthCacheTest, LookupAddRemove) { FtpAuthCache cache; @@ -20,38 +36,38 @@ TEST(FtpAuthCacheTest, LookupAddRemove) { EXPECT_TRUE(cache.Lookup(origin1) == NULL); // Add entry for origin1. - cache.Add(origin1, L"username1", L"password1"); + cache.Add(origin1, kUsername1, kPassword1); FtpAuthCache::Entry* entry1 = cache.Lookup(origin1); ASSERT_TRUE(entry1); EXPECT_EQ(origin1, entry1->origin); - EXPECT_EQ(L"username1", entry1->username); - EXPECT_EQ(L"password1", entry1->password); + EXPECT_EQ(kUsername1, entry1->username); + EXPECT_EQ(kPassword1, entry1->password); // Add an entry for origin2. - cache.Add(origin2, L"username2", L"password2"); + cache.Add(origin2, kUsername2, kPassword2); FtpAuthCache::Entry* entry2 = cache.Lookup(origin2); ASSERT_TRUE(entry2); EXPECT_EQ(origin2, entry2->origin); - EXPECT_EQ(L"username2", entry2->username); - EXPECT_EQ(L"password2", entry2->password); + EXPECT_EQ(kUsername2, entry2->username); + EXPECT_EQ(kPassword2, entry2->password); // The original entry1 should still be there. EXPECT_EQ(entry1, cache.Lookup(origin1)); // Overwrite the entry for origin1. - cache.Add(origin1, L"username3", L"password3"); + cache.Add(origin1, kUsername3, kPassword3); FtpAuthCache::Entry* entry3 = cache.Lookup(origin1); ASSERT_TRUE(entry3); EXPECT_EQ(origin1, entry3->origin); - EXPECT_EQ(L"username3", entry3->username); - EXPECT_EQ(L"password3", entry3->password); + EXPECT_EQ(kUsername3, entry3->username); + EXPECT_EQ(kPassword3, entry3->password); // Remove entry of origin1. - cache.Remove(origin1, L"username3", L"password3"); + cache.Remove(origin1, kUsername3, kPassword3); EXPECT_TRUE(cache.Lookup(origin1) == NULL); // Remove non-existent entry. - cache.Remove(origin1, L"username3", L"password3"); + cache.Remove(origin1, kUsername3, kPassword3); EXPECT_TRUE(cache.Lookup(origin1) == NULL); } @@ -63,8 +79,8 @@ TEST(FtpAuthCacheTest, LookupWithPort) { GURL origin1("ftp://foo:80"); GURL origin2("ftp://foo:21"); - cache.Add(origin1, L"username", L"password"); - cache.Add(origin2, L"username", L"password"); + cache.Add(origin1, kUsername, kPassword); + cache.Add(origin2, kUsername, kPassword); EXPECT_NE(cache.Lookup(origin1), cache.Lookup(origin2)); } @@ -77,7 +93,7 @@ TEST(FtpAuthCacheTest, NormalizedKey) { FtpAuthCache cache; // Add. - cache.Add(GURL("ftp://HoSt:21"), L"username", L"password"); + cache.Add(GURL("ftp://HoSt:21"), kUsername, kPassword); // Lookup. FtpAuthCache::Entry* entry1 = cache.Lookup(GURL("ftp://HoSt:21")); @@ -86,30 +102,30 @@ TEST(FtpAuthCacheTest, NormalizedKey) { EXPECT_EQ(entry1, cache.Lookup(GURL("ftp://host"))); // Overwrite. - cache.Add(GURL("ftp://host"), L"othername", L"otherword"); + cache.Add(GURL("ftp://host"), kOthername, kOtherword); FtpAuthCache::Entry* entry2 = cache.Lookup(GURL("ftp://HoSt:21")); ASSERT_TRUE(entry2); EXPECT_EQ(GURL("ftp://host"), entry2->origin); - EXPECT_EQ(L"othername", entry2->username); - EXPECT_EQ(L"otherword", entry2->password); + EXPECT_EQ(kOthername, entry2->username); + EXPECT_EQ(kOtherword, entry2->password); // Remove - cache.Remove(GURL("ftp://HOsT"), L"othername", L"otherword"); + cache.Remove(GURL("ftp://HOsT"), kOthername, kOtherword); EXPECT_TRUE(cache.Lookup(GURL("ftp://host")) == NULL); } TEST(FtpAuthCacheTest, OnlyRemoveMatching) { FtpAuthCache cache; - cache.Add(GURL("ftp://host"), L"username", L"password"); + cache.Add(GURL("ftp://host"), kUsername, kPassword); EXPECT_TRUE(cache.Lookup(GURL("ftp://host"))); // Auth data doesn't match, shouldn't remove. - cache.Remove(GURL("ftp://host"), L"bogus", L"bogus"); + cache.Remove(GURL("ftp://host"), kBogus, kBogus); EXPECT_TRUE(cache.Lookup(GURL("ftp://host"))); // Auth data matches, should remove. - cache.Remove(GURL("ftp://host"), L"username", L"password"); + cache.Remove(GURL("ftp://host"), kUsername, kPassword); EXPECT_TRUE(cache.Lookup(GURL("ftp://host")) == NULL); } @@ -117,7 +133,7 @@ TEST(FtpAuthCacheTest, EvictOldEntries) { FtpAuthCache cache; for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) - cache.Add(GURL("ftp://host" + IntToString(i)), L"username", L"password"); + cache.Add(GURL("ftp://host" + IntToString(i)), kUsername, kPassword); // No entries should be evicted before reaching the limit. for (size_t i = 0; i < FtpAuthCache::kMaxEntries; i++) { @@ -125,7 +141,7 @@ TEST(FtpAuthCacheTest, EvictOldEntries) { } // Adding one entry should cause eviction of the first entry. - cache.Add(GURL("ftp://last_host"), L"username", L"password"); + cache.Add(GURL("ftp://last_host"), kUsername, kPassword); EXPECT_TRUE(cache.Lookup(GURL("ftp://host0")) == NULL); // Remaining entries should not get evicted. diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc index 471e8c9..85cac4b 100644 --- a/net/ftp/ftp_network_transaction.cc +++ b/net/ftp/ftp_network_transaction.cc @@ -212,8 +212,8 @@ int FtpNetworkTransaction::Start(const FtpRequestInfo* request_info, if (request_->url.has_username()) { GetIdentityFromURL(request_->url, &username_, &password_); } else { - username_ = L"anonymous"; - password_ = L"chrome@example.com"; + username_ = ASCIIToUTF16("anonymous"); + password_ = ASCIIToUTF16("chrome@example.com"); } DetectTypecode(); @@ -234,8 +234,8 @@ int FtpNetworkTransaction::Stop(int error) { return OK; } -int FtpNetworkTransaction::RestartWithAuth(const std::wstring& username, - const std::wstring& password, +int FtpNetworkTransaction::RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback) { ResetStateForRestart(); @@ -653,7 +653,7 @@ int FtpNetworkTransaction::DoCtrlReadComplete(int result) { // Some servers (for example Pure-FTPd) apparently close the control // connection when anonymous login is not permitted. For more details // see http://crbug.com/25023. - if (command_sent_ == COMMAND_USER && username_ == L"anonymous") + if (command_sent_ == COMMAND_USER && username_ == ASCIIToUTF16("anonymous")) response_.needs_auth = true; return Stop(ERR_EMPTY_RESPONSE); } @@ -700,7 +700,7 @@ int FtpNetworkTransaction::DoCtrlWriteComplete(int result) { // USER Command. int FtpNetworkTransaction::DoCtrlWriteUSER() { - std::string command = "USER " + WideToUTF8(username_); + std::string command = "USER " + UTF16ToUTF8(username_); if (!IsValidFTPCommandString(command)) return Stop(ERR_MALFORMED_IDENTITY); @@ -732,7 +732,7 @@ int FtpNetworkTransaction::ProcessResponseUSER( // PASS command. int FtpNetworkTransaction::DoCtrlWritePASS() { - std::string command = "PASS " + WideToUTF8(password_); + std::string command = "PASS " + UTF16ToUTF8(password_); if (!IsValidFTPCommandString(command)) return Stop(ERR_MALFORMED_IDENTITY); diff --git a/net/ftp/ftp_network_transaction.h b/net/ftp/ftp_network_transaction.h index 6b2a1f8..3732157 100644 --- a/net/ftp/ftp_network_transaction.h +++ b/net/ftp/ftp_network_transaction.h @@ -6,13 +6,14 @@ #define NET_FTP_FTP_NETWORK_TRANSACTION_H_ #pragma once -#include <string> #include <queue> +#include <string> #include <utility> #include <vector> #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "net/base/address_list.h" #include "net/base/host_resolver.h" #include "net/base/net_log.h" @@ -37,8 +38,8 @@ class FtpNetworkTransaction : public FtpTransaction { CompletionCallback* callback, const BoundNetLog& net_log); virtual int Stop(int error); - virtual int RestartWithAuth(const std::wstring& username, - const std::wstring& password, + virtual int RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback); virtual int RestartIgnoringLastError(CompletionCallback* callback); virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); @@ -201,10 +202,8 @@ class FtpNetworkTransaction : public FtpTransaction { // EPSV fail, we fall back to PASV for the duration of connection. bool use_epsv_; - // We get username and password as wstrings in RestartWithAuth, so they are - // also kept as wstrings here. - std::wstring username_; - std::wstring password_; + string16 username_; + string16 password_; // Current directory on the remote server, as returned by last PWD command, // with any trailing slash removed. diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc index c5aed0d..5745ae7 100644 --- a/net/ftp/ftp_network_transaction_unittest.cc +++ b/net/ftp/ftp_network_transaction_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -7,6 +7,7 @@ #include "build/build_config.h" #include "base/ref_counted.h" +#include "base/string_util.h" #include "net/base/io_buffer.h" #include "net/base/mock_host_resolver.h" #include "net/base/net_util.h" @@ -81,8 +82,8 @@ class FtpSocketDataProvider : public DynamicSocketDataProvider { return Verify("EPSV\r\n", data, PRE_SIZE, "227 Entering Extended Passive Mode (|||31744|)\r\n"); case PRE_NOPASV: - // Use unallocated 599 FTP error code to make sure it falls into the generic - // ERR_FTP_FAILED bucket. + // Use unallocated 599 FTP error code to make sure it falls into the + // generic ERR_FTP_FAILED bucket. return Verify("PASV\r\n", data, PRE_QUIT, "599 fail\r\n"); case PRE_QUIT: @@ -1045,9 +1046,10 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartUser) { StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads), ctrl_writes, arraysize(ctrl_writes)); mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); - ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"foo\nownz0red", - L"innocent", - &callback_)); + ASSERT_EQ(ERR_IO_PENDING, + transaction_.RestartWithAuth(ASCIIToUTF16("foo\nownz0red"), + ASCIIToUTF16("innocent"), + &callback_)); EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); } @@ -1077,9 +1079,10 @@ TEST_F(FtpNetworkTransactionTest, EvilRestartPassword) { StaticSocketDataProvider ctrl_socket2(ctrl_reads, arraysize(ctrl_reads), ctrl_writes, arraysize(ctrl_writes)); mock_socket_factory_.AddSocketDataProvider(&ctrl_socket2); - ASSERT_EQ(ERR_IO_PENDING, transaction_.RestartWithAuth(L"innocent", - L"foo\nownz0red", - &callback_)); + ASSERT_EQ(ERR_IO_PENDING, + transaction_.RestartWithAuth(ASCIIToUTF16("innocent"), + ASCIIToUTF16("foo\nownz0red"), + &callback_)); EXPECT_EQ(ERR_MALFORMED_IDENTITY, callback_.WaitForResult()); } diff --git a/net/ftp/ftp_transaction.h b/net/ftp/ftp_transaction.h index b4d1f76..b1f1add 100644 --- a/net/ftp/ftp_transaction.h +++ b/net/ftp/ftp_transaction.h @@ -1,11 +1,12 @@ -// 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. +// 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. #ifndef NET_FTP_FTP_TRANSACTION_H_ #define NET_FTP_FTP_TRANSACTION_H_ #pragma once +#include "base/string16.h" #include "net/base/completion_callback.h" #include "net/base/io_buffer.h" #include "net/base/load_states.h" @@ -42,8 +43,8 @@ class FtpTransaction { const BoundNetLog& net_log) = 0; // Restarts the FTP transaction with authentication credentials. - virtual int RestartWithAuth(const std::wstring& username, - const std::wstring& password, + virtual int RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback) = 0; // Once response info is available for the transaction, response data may be diff --git a/net/http/http_auth.h b/net/http/http_auth.h index 1a752a0..542165c 100644 --- a/net/http/http_auth.h +++ b/net/http/http_auth.h @@ -7,8 +7,10 @@ #pragma once #include <set> +#include <string> #include "base/scoped_ptr.h" +#include "base/string16.h" #include "net/http/http_util.h" template <class T> class scoped_refptr; @@ -68,9 +70,8 @@ class HttpAuth { IdentitySource source; bool invalid; - // TODO(wtc): |username| and |password| should be string16. - std::wstring username; - std::wstring password; + string16 username; + string16 password; }; // Get the name of the header containing the auth challenge diff --git a/net/http/http_auth_cache.cc b/net/http/http_auth_cache.cc index 21db55d..58a90f1 100644 --- a/net/http/http_auth_cache.cc +++ b/net/http/http_auth_cache.cc @@ -48,14 +48,14 @@ void CheckOriginIsValid(const GURL& origin) { // Functor used by remove_if. struct IsEnclosedBy { - IsEnclosedBy(const std::string& path) : path(path) { } + explicit IsEnclosedBy(const std::string& path) : path(path) { } bool operator() (const std::string& x) { return IsEnclosingPath(path, x); } const std::string& path; }; -} // namespace +} // namespace namespace net { @@ -71,7 +71,7 @@ HttpAuthCache::Entry* HttpAuthCache::Lookup(const GURL& origin, it->scheme() == scheme) return &(*it); } - return NULL; // No realm entry found. + return NULL; // No realm entry found. } // Performance: O(n*m), where n is the number of realm entries, m is the number @@ -93,15 +93,15 @@ HttpAuthCache::Entry* HttpAuthCache::LookupByPath(const GURL& origin, if (it->origin() == origin && it->HasEnclosingPath(parent_dir)) return &(*it); } - return NULL; // No entry found. + return NULL; // No entry found. } HttpAuthCache::Entry* HttpAuthCache::Add(const GURL& origin, const std::string& realm, const std::string& scheme, const std::string& auth_challenge, - const std::wstring& username, - const std::wstring& password, + const string16& username, + const string16& password, const std::string& path) { CheckOriginIsValid(origin); CheckPathIsValid(path); @@ -165,8 +165,8 @@ bool HttpAuthCache::Entry::HasEnclosingPath(const std::string& dir) { bool HttpAuthCache::Remove(const GURL& origin, const std::string& realm, const std::string& scheme, - const std::wstring& username, - const std::wstring& password) { + const string16& username, + const string16& password) { for (EntryList::iterator it = entries_.begin(); it != entries_.end(); ++it) { if (it->origin() == origin && it->realm() == realm && it->scheme() == scheme) { @@ -180,4 +180,4 @@ bool HttpAuthCache::Remove(const GURL& origin, return false; } -} // namespace net +} // namespace net diff --git a/net/http/http_auth_cache.h b/net/http/http_auth_cache.h index 297457d..dc82107 100644 --- a/net/http/http_auth_cache.h +++ b/net/http/http_auth_cache.h @@ -10,6 +10,7 @@ #include <string> #include "base/ref_counted.h" +#include "base/string16.h" #include "googleurl/src/gurl.h" // This is needed for the FRIEND_TEST() macro. #include "testing/gtest/include/gtest/gtest_prod.h" @@ -62,8 +63,8 @@ class HttpAuthCache { const std::string& realm, const std::string& scheme, const std::string& auth_challenge, - const std::wstring& username, - const std::wstring& password, + const string16& username, + const string16& password, const std::string& path); // Remove entry on server |origin| for realm |realm| and scheme |scheme| @@ -77,8 +78,8 @@ class HttpAuthCache { bool Remove(const GURL& origin, const std::string& realm, const std::string& scheme, - const std::wstring& username, - const std::wstring& password); + const string16& username, + const string16& password); // Prevent unbounded memory growth. These are safeguards for abuse; it is // not expected that the limits will be reached in ordinary usage. @@ -115,12 +116,12 @@ class HttpAuthCache::Entry { } // The login username. - const std::wstring username() const { + const string16 username() const { return username_; } // The login password. - const std::wstring password() const { + const string16 password() const { return password_; } @@ -149,8 +150,8 @@ class HttpAuthCache::Entry { // Identity. std::string auth_challenge_; - std::wstring username_; - std::wstring password_; + string16 username_; + string16 password_; int nonce_count_; @@ -159,6 +160,6 @@ class HttpAuthCache::Entry { PathList paths_; }; -} // namespace net +} // namespace net #endif // NET_HTTP_HTTP_AUTH_CACHE_H_ diff --git a/net/http/http_auth_cache_unittest.cc b/net/http/http_auth_cache_unittest.cc index 4e2af9d..b5d7175 100644 --- a/net/http/http_auth_cache_unittest.cc +++ b/net/http/http_auth_cache_unittest.cc @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <string> + +#include "base/string16.h" #include "base/string_util.h" #include "net/base/net_errors.h" #include "net/http/http_auth_cache.h" @@ -30,8 +33,8 @@ class MockAuthHandler : public HttpAuthHandler { return false; // Unused. } - virtual int GenerateAuthTokenImpl(const std::wstring*, - const std::wstring*, + virtual int GenerateAuthTokenImpl(const string16*, + const string16*, const HttpRequestInfo*, CompletionCallback* callback, std::string* auth_token) { @@ -44,6 +47,22 @@ class MockAuthHandler : public HttpAuthHandler { ~MockAuthHandler() {} }; +const char* kBasic = "basic"; +const char* kDigest = "digest"; +const char* kRealm1 = "Realm1"; +const char* kRealm2 = "Realm2"; +const char* kRealm3 = "Realm3"; +const char* kRealm4 = "Realm4"; +const string16 k123(ASCIIToUTF16("123")); +const string16 k1234(ASCIIToUTF16("1234")); +const string16 kAdmin(ASCIIToUTF16("admin")); +const string16 kAlice(ASCIIToUTF16("alice")); +const string16 kAlice2(ASCIIToUTF16("alice2")); +const string16 kPassword(ASCIIToUTF16("password")); +const string16 kRoot(ASCIIToUTF16("root")); +const string16 kUsername(ASCIIToUTF16("username")); +const string16 kWileCoyote(ASCIIToUTF16("wilecoyote")); + } // namespace // Test adding and looking-up cache entries (both by realm and by path). @@ -55,73 +74,74 @@ TEST(HttpAuthCacheTest, Basic) { // Add cache entries for 3 realms: "Realm1", "Realm2", "Realm3" scoped_ptr<HttpAuthHandler> realm1_handler( - new MockAuthHandler("basic", "Realm1", HttpAuth::AUTH_SERVER)); + new MockAuthHandler(kBasic, kRealm1, HttpAuth::AUTH_SERVER)); cache.Add(origin, realm1_handler->realm(), realm1_handler->scheme(), - "Basic realm=Realm1", L"realm1-user", L"realm1-password", - "/foo/bar/index.html"); + "Basic realm=Realm1", ASCIIToUTF16("realm1-user"), + ASCIIToUTF16("realm1-password"), "/foo/bar/index.html"); scoped_ptr<HttpAuthHandler> realm2_handler( - new MockAuthHandler("basic", "Realm2", HttpAuth::AUTH_SERVER)); + new MockAuthHandler(kBasic, kRealm2, HttpAuth::AUTH_SERVER)); cache.Add(origin, realm2_handler->realm(), realm2_handler->scheme(), - "Basic realm=Realm2", L"realm2-user", L"realm2-password", - "/foo2/index.html"); + "Basic realm=Realm2", ASCIIToUTF16("realm2-user"), + ASCIIToUTF16("realm2-password"), "/foo2/index.html"); scoped_ptr<HttpAuthHandler> realm3_basic_handler( - new MockAuthHandler("basic", "Realm3", HttpAuth::AUTH_PROXY)); + new MockAuthHandler(kBasic, kRealm3, HttpAuth::AUTH_PROXY)); cache.Add(origin, realm3_basic_handler->realm(), realm3_basic_handler->scheme(), "Basic realm=Realm3", - L"realm3-basic-user", L"realm3-basic-password", ""); + ASCIIToUTF16("realm3-basic-user"), + ASCIIToUTF16("realm3-basic-password"), ""); scoped_ptr<HttpAuthHandler> realm3_digest_handler( - new MockAuthHandler("digest", "Realm3", HttpAuth::AUTH_PROXY)); + new MockAuthHandler(kDigest, kRealm3, HttpAuth::AUTH_PROXY)); cache.Add(origin, realm3_digest_handler->realm(), realm3_digest_handler->scheme(), "Digest realm=Realm3", - L"realm3-digest-user", L"realm3-digest-password", - "/baz/index.html"); + ASCIIToUTF16("realm3-digest-user"), + ASCIIToUTF16("realm3-digest-password"), "/baz/index.html"); // There is no Realm4 - entry = cache.Lookup(origin, "Realm4", "basic"); + entry = cache.Lookup(origin, kRealm4, kBasic); EXPECT_TRUE(NULL == entry); // While Realm3 does exist, the origin scheme is wrong. - entry = cache.Lookup(GURL("https://www.google.com"), "Realm3", - "basic"); + entry = cache.Lookup(GURL("https://www.google.com"), kRealm3, + kBasic); EXPECT_TRUE(NULL == entry); // Realm, origin scheme ok, authentication scheme wrong - entry = cache.Lookup(GURL("http://www.google.com"), "Realm1", "digest"); + entry = cache.Lookup(GURL("http://www.google.com"), kRealm1, kDigest); EXPECT_TRUE(NULL == entry); // Valid lookup by origin, realm, scheme. - entry = cache.Lookup(GURL("http://www.google.com:80"), "Realm3", "basic"); + entry = cache.Lookup(GURL("http://www.google.com:80"), kRealm3, kBasic); ASSERT_FALSE(NULL == entry); - EXPECT_EQ("basic", entry->scheme()); - EXPECT_EQ("Realm3", entry->realm()); + EXPECT_EQ(kBasic, entry->scheme()); + EXPECT_EQ(kRealm3, entry->realm()); EXPECT_EQ("Basic realm=Realm3", entry->auth_challenge()); - EXPECT_EQ(L"realm3-basic-user", entry->username()); - EXPECT_EQ(L"realm3-basic-password", entry->password()); + EXPECT_EQ(ASCIIToUTF16("realm3-basic-user"), entry->username()); + EXPECT_EQ(ASCIIToUTF16("realm3-basic-password"), entry->password()); // Valid lookup by origin, realm, scheme when there's a duplicate // origin, realm in the cache - entry = cache.Lookup(GURL("http://www.google.com:80"), "Realm3", "digest"); + entry = cache.Lookup(GURL("http://www.google.com:80"), kRealm3, kDigest); ASSERT_FALSE(NULL == entry); - EXPECT_EQ("digest", entry->scheme()); - EXPECT_EQ("Realm3", entry->realm()); + EXPECT_EQ(kDigest, entry->scheme()); + EXPECT_EQ(kRealm3, entry->realm()); EXPECT_EQ("Digest realm=Realm3", entry->auth_challenge()); - EXPECT_EQ(L"realm3-digest-user", entry->username()); - EXPECT_EQ(L"realm3-digest-password", entry->password()); + EXPECT_EQ(ASCIIToUTF16("realm3-digest-user"), entry->username()); + EXPECT_EQ(ASCIIToUTF16("realm3-digest-password"), entry->password()); // Valid lookup by realm. - entry = cache.Lookup(origin, "Realm2", "basic"); + entry = cache.Lookup(origin, kRealm2, kBasic); ASSERT_FALSE(NULL == entry); - EXPECT_EQ("basic", entry->scheme()); - EXPECT_EQ("Realm2", entry->realm()); + EXPECT_EQ(kBasic, entry->scheme()); + EXPECT_EQ(kRealm2, entry->realm()); EXPECT_EQ("Basic realm=Realm2", entry->auth_challenge()); - EXPECT_EQ(L"realm2-user", entry->username()); - EXPECT_EQ(L"realm2-password", entry->password()); + EXPECT_EQ(ASCIIToUTF16("realm2-user"), entry->username()); + EXPECT_EQ(ASCIIToUTF16("realm2-password"), entry->password()); // Check that subpaths are recognized. - HttpAuthCache::Entry* realm2_entry = cache.Lookup(origin, "Realm2", "basic"); + HttpAuthCache::Entry* realm2_entry = cache.Lookup(origin, kRealm2, kBasic); EXPECT_FALSE(NULL == realm2_entry); // Positive tests: entry = cache.LookupByPath(origin, "/foo2/index.html"); @@ -145,7 +165,7 @@ TEST(HttpAuthCacheTest, Basic) { // Confirm we find the same realm, different auth scheme by path lookup HttpAuthCache::Entry* realm3_digest_entry = - cache.Lookup(origin, "Realm3", "digest"); + cache.Lookup(origin, kRealm3, kDigest); EXPECT_FALSE(NULL == realm3_digest_entry); entry = cache.LookupByPath(origin, "/baz/index.html"); EXPECT_TRUE(realm3_digest_entry == entry); @@ -156,7 +176,7 @@ TEST(HttpAuthCacheTest, Basic) { // Confirm we find the same realm, different auth scheme by path lookup HttpAuthCache::Entry* realm3DigestEntry = - cache.Lookup(origin, "Realm3", "digest"); + cache.Lookup(origin, kRealm3, kDigest); EXPECT_FALSE(NULL == realm3DigestEntry); entry = cache.LookupByPath(origin, "/baz/index.html"); EXPECT_TRUE(realm3DigestEntry == entry); @@ -168,8 +188,8 @@ TEST(HttpAuthCacheTest, Basic) { // Lookup using empty path (may be used for proxy). entry = cache.LookupByPath(origin, ""); EXPECT_FALSE(NULL == entry); - EXPECT_EQ("basic", entry->scheme()); - EXPECT_EQ("Realm3", entry->realm()); + EXPECT_EQ(kBasic, entry->scheme()); + EXPECT_EQ(kRealm3, entry->realm()); } TEST(HttpAuthCacheTest, AddPath) { @@ -212,21 +232,21 @@ TEST(HttpAuthCacheTest, AddToExistingEntry) { const std::string auth_challenge = "Basic realm=MyRealm"; scoped_ptr<HttpAuthHandler> handler( - new MockAuthHandler("basic", "MyRealm", HttpAuth::AUTH_SERVER)); + new MockAuthHandler(kBasic, "MyRealm", HttpAuth::AUTH_SERVER)); HttpAuthCache::Entry* orig_entry = cache.Add( origin, handler->realm(), handler->scheme(), auth_challenge, - L"user1", L"password1", "/x/y/z/"); + ASCIIToUTF16("user1"), ASCIIToUTF16("password1"), "/x/y/z/"); cache.Add(origin, handler->realm(), handler->scheme(), auth_challenge, - L"user2", L"password2", "/z/y/x/"); + ASCIIToUTF16("user2"), ASCIIToUTF16("password2"), "/z/y/x/"); cache.Add(origin, handler->realm(), handler->scheme(), auth_challenge, - L"user3", L"password3", "/z/y"); + ASCIIToUTF16("user3"), ASCIIToUTF16("password3"), "/z/y"); - HttpAuthCache::Entry* entry = cache.Lookup(origin, "MyRealm", "basic"); + HttpAuthCache::Entry* entry = cache.Lookup(origin, "MyRealm", kBasic); EXPECT_TRUE(entry == orig_entry); - EXPECT_EQ(L"user3", entry->username()); - EXPECT_EQ(L"password3", entry->password()); + EXPECT_EQ(ASCIIToUTF16("user3"), entry->username()); + EXPECT_EQ(ASCIIToUTF16("password3"), entry->password()); EXPECT_EQ(2U, entry->paths_.size()); EXPECT_EQ("/z/", entry->paths_.front()); @@ -237,63 +257,64 @@ TEST(HttpAuthCacheTest, Remove) { GURL origin("http://foobar2.com"); scoped_ptr<HttpAuthHandler> realm1_handler( - new MockAuthHandler("basic", "Realm1", HttpAuth::AUTH_SERVER)); + new MockAuthHandler(kBasic, kRealm1, HttpAuth::AUTH_SERVER)); scoped_ptr<HttpAuthHandler> realm2_handler( - new MockAuthHandler("basic", "Realm2", HttpAuth::AUTH_SERVER)); + new MockAuthHandler(kBasic, kRealm2, HttpAuth::AUTH_SERVER)); scoped_ptr<HttpAuthHandler> realm3_basic_handler( - new MockAuthHandler("basic", "Realm3", HttpAuth::AUTH_SERVER)); + new MockAuthHandler(kBasic, kRealm3, HttpAuth::AUTH_SERVER)); scoped_ptr<HttpAuthHandler> realm3_digest_handler( - new MockAuthHandler("digest", "Realm3", HttpAuth::AUTH_SERVER)); + new MockAuthHandler(kDigest, kRealm3, HttpAuth::AUTH_SERVER)); HttpAuthCache cache; cache.Add(origin, realm1_handler->realm(), realm1_handler->scheme(), - "basic realm=Realm1", L"alice", L"123", "/"); + "basic realm=Realm1", kAlice, k123, "/"); cache.Add(origin, realm2_handler->realm(), realm2_handler->scheme(), - "basic realm=Realm2", L"bob", L"princess", "/"); + "basic realm=Realm2", ASCIIToUTF16("bob"), ASCIIToUTF16("princess"), + "/"); cache.Add(origin, realm3_basic_handler->realm(), - realm3_basic_handler->scheme(), "basic realm=Realm3", L"admin", - L"password", "/"); + realm3_basic_handler->scheme(), "basic realm=Realm3", + kAdmin, kPassword, "/"); cache.Add(origin, realm3_digest_handler->realm(), - realm3_digest_handler->scheme(), "digest realm=Realm3", L"root", - L"wilecoyote", "/"); + realm3_digest_handler->scheme(), "digest realm=Realm3", + kRoot, kWileCoyote, "/"); // Fails, because there is no realm "Realm4". - EXPECT_FALSE(cache.Remove(origin, "Realm4", "basic", L"alice", L"123")); + EXPECT_FALSE(cache.Remove(origin, kRealm4, kBasic, kAlice, k123)); // Fails because the origin is wrong. EXPECT_FALSE(cache.Remove( - GURL("http://foobar2.com:100"), "Realm1", "basic", L"alice", L"123")); + GURL("http://foobar2.com:100"), kRealm1, kBasic, kAlice, k123)); // Fails because the username is wrong. - EXPECT_FALSE(cache.Remove(origin, "Realm1", "basic", L"alice2", L"123")); + EXPECT_FALSE(cache.Remove(origin, kRealm1, kBasic, kAlice2, k123)); // Fails because the password is wrong. - EXPECT_FALSE(cache.Remove(origin, "Realm1", "basic", L"alice", L"1234")); + EXPECT_FALSE(cache.Remove(origin, kRealm1, kBasic, kAlice, k1234)); // Fails because the authentication type is wrong. - EXPECT_FALSE(cache.Remove(origin, "Realm1", "digest", L"alice", L"123")); + EXPECT_FALSE(cache.Remove(origin, kRealm1, kDigest, kAlice, k123)); // Succeeds. - EXPECT_TRUE(cache.Remove(origin, "Realm1", "basic", L"alice", L"123")); + EXPECT_TRUE(cache.Remove(origin, kRealm1, kBasic, kAlice, k123)); // Fails because we just deleted the entry! - EXPECT_FALSE(cache.Remove(origin, "Realm1", "basic", L"alice", L"123")); + EXPECT_FALSE(cache.Remove(origin, kRealm1, kBasic, kAlice, k123)); // Succeed when there are two authentication types for the same origin,realm. - EXPECT_TRUE(cache.Remove(origin, "Realm3", "digest", L"root", L"wilecoyote")); + EXPECT_TRUE(cache.Remove(origin, kRealm3, kDigest, kRoot, kWileCoyote)); // Succeed as above, but when entries were added in opposite order cache.Add(origin, realm3_digest_handler->realm(), - realm3_digest_handler->scheme(), "digest realm=Realm3", L"root", - L"wilecoyote", "/"); - EXPECT_TRUE(cache.Remove(origin, "Realm3", "basic", L"admin", L"password")); + realm3_digest_handler->scheme(), "digest realm=Realm3", + kRoot, kWileCoyote, "/"); + EXPECT_TRUE(cache.Remove(origin, kRealm3, kBasic, kAdmin, kPassword)); // Make sure that removing one entry still leaves the other available for // lookup. - HttpAuthCache::Entry* entry = cache.Lookup(origin, "Realm3", "digest"); + HttpAuthCache::Entry* entry = cache.Lookup(origin, kRealm3, kDigest); EXPECT_FALSE(NULL == entry); } @@ -316,13 +337,13 @@ class HttpAuthCacheEvictionTest : public testing::Test { } void AddPathToRealm(int realm_i, int path_i) { - cache_.Add(origin_, GenerateRealm(realm_i), "basic", "", - L"username", L"password", GeneratePath(realm_i, path_i)); + cache_.Add(origin_, GenerateRealm(realm_i), kBasic, "", + kUsername, kPassword, GeneratePath(realm_i, path_i)); } void CheckRealmExistence(int realm_i, bool exists) { const HttpAuthCache::Entry* entry = - cache_.Lookup(origin_, GenerateRealm(realm_i), "basic"); + cache_.Lookup(origin_, GenerateRealm(realm_i), kBasic); if (exists) { EXPECT_FALSE(entry == NULL); EXPECT_EQ(GenerateRealm(realm_i), entry->realm()); diff --git a/net/http/http_auth_controller.cc b/net/http/http_auth_controller.cc index c077ee8..3f2d688 100644 --- a/net/http/http_auth_controller.cc +++ b/net/http/http_auth_controller.cc @@ -73,8 +73,8 @@ int HttpAuthController::MaybeGenerateAuthToken(const HttpRequestInfo* request, bool needs_auth = HaveAuth() || SelectPreemptiveAuth(net_log); if (!needs_auth) return OK; - const std::wstring* username = NULL; - const std::wstring* password = NULL; + const string16* username = NULL; + const string16* password = NULL; if (identity_.source != HttpAuth::IDENT_SRC_DEFAULT_CREDENTIALS) { username = &identity_.username; password = &identity_.password; @@ -219,8 +219,8 @@ int HttpAuthController::HandleAuthChallenge( return OK; } -void HttpAuthController::ResetAuth(const std::wstring& username, - const std::wstring& password) { +void HttpAuthController::ResetAuth(const string16& username, + const string16& password) { DCHECK(identity_.invalid || (username.empty() && password.empty())); if (identity_.invalid) { diff --git a/net/http/http_auth_controller.h b/net/http/http_auth_controller.h index 098adb8..be335ba 100644 --- a/net/http/http_auth_controller.h +++ b/net/http/http_auth_controller.h @@ -12,6 +12,7 @@ #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "googleurl/src/gurl.h" #include "net/base/completion_callback.h" #include "net/base/net_log.h" @@ -55,8 +56,8 @@ class HttpAuthController : public base::RefCounted<HttpAuthController> { const BoundNetLog& net_log); // Store the supplied credentials and prepare to restart the auth. - virtual void ResetAuth(const std::wstring& username, - const std::wstring& password); + virtual void ResetAuth(const string16& username, + const string16& password); virtual bool HaveAuthHandler() const { return handler_.get() != NULL; diff --git a/net/http/http_auth_gssapi_posix.cc b/net/http/http_auth_gssapi_posix.cc index 5c88375..444f882 100644 --- a/net/http/http_auth_gssapi_posix.cc +++ b/net/http/http_auth_gssapi_posix.cc @@ -721,8 +721,8 @@ bool HttpAuthGSSAPI::ParseChallenge(HttpAuth::ChallengeTokenizer* tok) { return true; } -int HttpAuthGSSAPI::GenerateAuthToken(const std::wstring* username, - const std::wstring* password, +int HttpAuthGSSAPI::GenerateAuthToken(const string16* username, + const string16* password, const std::wstring& spn, std::string* auth_token) { DCHECK(auth_token); @@ -757,8 +757,8 @@ int HttpAuthGSSAPI::GenerateAuthToken(const std::wstring* username, return OK; } -int HttpAuthGSSAPI::OnFirstRound(const std::wstring* username, - const std::wstring* password) { +int HttpAuthGSSAPI::OnFirstRound(const string16* username, + const string16* password) { // TODO(cbentzel): Acquire credentials? DCHECK((username == NULL) == (password == NULL)); username_.clear(); diff --git a/net/http/http_auth_gssapi_posix.h b/net/http/http_auth_gssapi_posix.h index 746ce59..094a784 100644 --- a/net/http/http_auth_gssapi_posix.h +++ b/net/http/http_auth_gssapi_posix.h @@ -10,6 +10,7 @@ #include "base/gtest_prod_util.h" #include "base/native_library.h" +#include "base/string16.h" #include "net/http/http_auth.h" #define GSS_USE_FUNCTION_POINTERS @@ -201,7 +202,7 @@ class GSSAPISharedLibrary : public GSSAPILibrary { // scope. class ScopedSecurityContext { public: - ScopedSecurityContext(GSSAPILibrary* gssapi_lib); + explicit ScopedSecurityContext(GSSAPILibrary* gssapi_lib); ~ScopedSecurityContext(); const gss_ctx_id_t get() const { return security_context_; } @@ -238,21 +239,21 @@ class HttpAuthGSSAPI { // If this is the first round of a multiple round scheme, credentials are // obtained using |*username| and |*password|. If |username| and |password| // are NULL, the default credentials are used instead. - int GenerateAuthToken(const std::wstring* username, - const std::wstring* password, + int GenerateAuthToken(const string16* username, + const string16* password, const std::wstring& spn, std::string* auth_token); private: - int OnFirstRound(const std::wstring* username, - const std::wstring* password); + int OnFirstRound(const string16* username, + const string16* password); int GetNextSecurityToken(const std::wstring& spn, gss_buffer_t in_token, gss_buffer_t out_token); std::string scheme_; - std::wstring username_; - std::wstring password_; + string16 username_; + string16 password_; gss_OID gss_oid_; GSSAPILibrary* library_; std::string decoded_server_auth_token_; diff --git a/net/http/http_auth_handler.cc b/net/http/http_auth_handler.cc index 0bb017b..4858658 100644 --- a/net/http/http_auth_handler.cc +++ b/net/http/http_auth_handler.cc @@ -76,8 +76,8 @@ NetLog::EventType EventTypeFromAuthTarget(HttpAuth::Target target) { } // namespace -int HttpAuthHandler::GenerateAuthToken(const std::wstring* username, - const std::wstring* password, +int HttpAuthHandler::GenerateAuthToken(const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token) { diff --git a/net/http/http_auth_handler.h b/net/http/http_auth_handler.h index 179ed25..9b092cf 100644 --- a/net/http/http_auth_handler.h +++ b/net/http/http_auth_handler.h @@ -8,6 +8,7 @@ #include <string> +#include "base/string16.h" #include "base/time.h" #include "net/base/completion_callback.h" #include "net/base/net_log.h" @@ -57,8 +58,8 @@ class HttpAuthHandler { // call. // Otherwise, there was a problem generating a token synchronously, and the // value of |*auth_token| is unspecified. - int GenerateAuthToken(const std::wstring* username, - const std::wstring* password, + int GenerateAuthToken(const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token); @@ -137,8 +138,8 @@ class HttpAuthHandler { // |GenerateAuthTokenImpl()} is the auth-scheme specific implementation // of generating the next auth token. Callers sohuld use |GenerateAuthToken()| // which will in turn call |GenerateAuthTokenImpl()| - virtual int GenerateAuthTokenImpl(const std::wstring* username, - const std::wstring* password, + virtual int GenerateAuthTokenImpl(const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token) = 0; diff --git a/net/http/http_auth_handler_basic.cc b/net/http/http_auth_handler_basic.cc index efd8c5e..31edf23 100644 --- a/net/http/http_auth_handler_basic.cc +++ b/net/http/http_auth_handler_basic.cc @@ -42,14 +42,14 @@ bool HttpAuthHandlerBasic::Init(HttpAuth::ChallengeTokenizer* challenge) { } int HttpAuthHandlerBasic::GenerateAuthTokenImpl( - const std::wstring* username, - const std::wstring* password, + const string16* username, + const string16* password, const HttpRequestInfo*, CompletionCallback*, std::string* auth_token) { // TODO(eroman): is this the right encoding of username/password? std::string base64_username_password; - if (!base::Base64Encode(WideToUTF8(*username) + ":" + WideToUTF8(*password), + if (!base::Base64Encode(UTF16ToUTF8(*username) + ":" + UTF16ToUTF8(*password), &base64_username_password)) { LOG(ERROR) << "Unexpected problem Base64 encoding."; return ERR_UNEXPECTED; diff --git a/net/http/http_auth_handler_basic.h b/net/http/http_auth_handler_basic.h index a4cb28e..3204e94 100644 --- a/net/http/http_auth_handler_basic.h +++ b/net/http/http_auth_handler_basic.h @@ -6,6 +6,9 @@ #define NET_HTTP_HTTP_AUTH_HANDLER_BASIC_H_ #pragma once +#include <string> + +#include "base/string16.h" #include "net/http/http_auth_handler.h" #include "net/http/http_auth_handler_factory.h" @@ -31,8 +34,8 @@ class HttpAuthHandlerBasic : public HttpAuthHandler { protected: virtual bool Init(HttpAuth::ChallengeTokenizer* challenge); - virtual int GenerateAuthTokenImpl(const std::wstring* username, - const std::wstring* password, + virtual int GenerateAuthTokenImpl(const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token); diff --git a/net/http/http_auth_handler_basic_unittest.cc b/net/http/http_auth_handler_basic_unittest.cc index 12e8830..a758887 100644 --- a/net/http/http_auth_handler_basic_unittest.cc +++ b/net/http/http_auth_handler_basic_unittest.cc @@ -2,28 +2,30 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "testing/gtest/include/gtest/gtest.h" +#include <string> #include "base/basictypes.h" +#include "base/string_util.h" #include "net/base/net_errors.h" #include "net/http/http_auth_handler_basic.h" #include "net/http/http_request_info.h" +#include "testing/gtest/include/gtest/gtest.h" namespace net { TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) { static const struct { - const wchar_t* username; - const wchar_t* password; + const char* username; + const char* password; const char* expected_credentials; } tests[] = { - { L"foo", L"bar", "Basic Zm9vOmJhcg==" }, + { "foo", "bar", "Basic Zm9vOmJhcg==" }, // Empty username - { L"", L"foobar", "Basic OmZvb2Jhcg==" }, + { "", "foobar", "Basic OmZvb2Jhcg==" }, // Empty password - { L"anon", L"", "Basic YW5vbjo=" }, + { "anon", "", "Basic YW5vbjo=" }, // Empty username and empty password. - { L"", L"", "Basic Og==" }, + { "", "", "Basic Og==" }, }; GURL origin("http://www.example.com"); HttpAuthHandlerBasic::Factory factory; @@ -32,8 +34,8 @@ TEST(HttpAuthHandlerBasicTest, GenerateAuthToken) { scoped_ptr<HttpAuthHandler> basic; EXPECT_EQ(OK, factory.CreateAuthHandlerFromString( challenge, HttpAuth::AUTH_SERVER, origin, BoundNetLog(), &basic)); - std::wstring username(tests[i].username); - std::wstring password(tests[i].password); + string16 username(ASCIIToUTF16(tests[i].username)); + string16 password(ASCIIToUTF16(tests[i].password)); HttpRequestInfo request_info; std::string auth_token; int rv = basic->GenerateAuthToken(&username, &password, &request_info, @@ -77,4 +79,4 @@ TEST(HttpAuthHandlerBasicTest, InitFromChallenge) { } } -} // namespace net +} // namespace net diff --git a/net/http/http_auth_handler_digest.cc b/net/http/http_auth_handler_digest.cc index 90090a6..c0d04d5 100644 --- a/net/http/http_auth_handler_digest.cc +++ b/net/http/http_auth_handler_digest.cc @@ -4,6 +4,8 @@ #include "net/http/http_auth_handler_digest.h" +#include <string> + #include "base/logging.h" #include "base/md5.h" #include "base/rand_util.h" @@ -86,8 +88,8 @@ std::string HttpAuthHandlerDigest::AlgorithmToString(int algorithm) { } int HttpAuthHandlerDigest::GenerateAuthTokenImpl( - const std::wstring* username, - const std::wstring* password, + const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token) { @@ -101,9 +103,8 @@ int HttpAuthHandlerDigest::GenerateAuthTokenImpl( GetRequestMethodAndPath(request, &method, &path); *auth_token = AssembleCredentials(method, path, - // TODO(eroman): is this the right encoding? - WideToUTF8(*username), - WideToUTF8(*password), + *username, + *password, cnonce, nonce_count_); return OK; } @@ -128,12 +129,14 @@ void HttpAuthHandlerDigest::GetRequestMethodAndPath( std::string HttpAuthHandlerDigest::AssembleResponseDigest( const std::string& method, const std::string& path, - const std::string& username, - const std::string& password, + const string16& username, + const string16& password, const std::string& cnonce, const std::string& nc) const { // ha1 = MD5(A1) - std::string ha1 = MD5String(username + ":" + realm_ + ":" + password); + // TODO(eroman): is this the right encoding? + std::string ha1 = MD5String(UTF16ToUTF8(username) + ":" + realm_ + ":" + + UTF16ToUTF8(password)); if (algorithm_ == HttpAuthHandlerDigest::ALGORITHM_MD5_SESS) ha1 = MD5String(ha1 + ":" + nonce_ + ":" + cnonce); @@ -152,15 +155,16 @@ std::string HttpAuthHandlerDigest::AssembleResponseDigest( std::string HttpAuthHandlerDigest::AssembleCredentials( const std::string& method, const std::string& path, - const std::string& username, - const std::string& password, + const string16& username, + const string16& password, const std::string& cnonce, int nonce_count) const { // the nonce-count is an 8 digit hex string. std::string nc = StringPrintf("%08x", nonce_count); + // TODO(eroman): is this the right encoding? std::string authorization = std::string("Digest username=") + - HttpUtil::Quote(username); + HttpUtil::Quote(UTF16ToUTF8(username)); authorization += ", realm=" + HttpUtil::Quote(realm_); authorization += ", nonce=" + HttpUtil::Quote(nonce_); authorization += ", uri=" + HttpUtil::Quote(path); @@ -219,7 +223,7 @@ bool HttpAuthHandlerDigest::ParseChallenge( if (!challenge->valid() || !LowerCaseEqualsASCII(challenge->scheme(), "digest")) - return false; // FAIL -- Couldn't match auth-scheme. + return false; // FAIL -- Couldn't match auth-scheme. // Loop through all the properties. while (challenge->GetNext()) { @@ -229,16 +233,16 @@ bool HttpAuthHandlerDigest::ParseChallenge( } if (!ParseChallengeProperty(challenge->name(), challenge->unquoted_value())) - return false; // FAIL -- couldn't parse a property. + return false; // FAIL -- couldn't parse a property. } // Check if tokenizer failed. if (!challenge->valid()) - return false; // FAIL + return false; // FAIL // Check that a minimum set of properties were provided. if (nonce_.empty()) - return false; // FAIL + return false; // FAIL return true; } @@ -264,7 +268,7 @@ bool HttpAuthHandlerDigest::ParseChallengeProperty(const std::string& name, algorithm_ = ALGORITHM_MD5_SESS; } else { DLOG(INFO) << "Unknown value of algorithm"; - return false; // FAIL -- unsupported value of algorithm. + return false; // FAIL -- unsupported value of algorithm. } } else if (LowerCaseEqualsASCII(name, "qop")) { // Parse the comma separated list of qops. diff --git a/net/http/http_auth_handler_digest.h b/net/http/http_auth_handler_digest.h index bf3aa77..1b03d17 100644 --- a/net/http/http_auth_handler_digest.h +++ b/net/http/http_auth_handler_digest.h @@ -6,6 +6,9 @@ #define NET_HTTP_HTTP_AUTH_HANDLER_DIGEST_H_ #pragma once +#include <string> + +#include "base/string16.h" #include "net/http/http_auth_handler.h" #include "net/http/http_auth_handler_factory.h" @@ -36,8 +39,8 @@ class HttpAuthHandlerDigest : public HttpAuthHandler { return ParseChallenge(challenge); } - virtual int GenerateAuthTokenImpl(const std::wstring* username, - const std::wstring* password, + virtual int GenerateAuthTokenImpl(const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token); @@ -97,16 +100,16 @@ class HttpAuthHandlerDigest : public HttpAuthHandler { // Build up the 'response' production. std::string AssembleResponseDigest(const std::string& method, const std::string& path, - const std::string& username, - const std::string& password, + const string16& username, + const string16& password, const std::string& cnonce, const std::string& nc) const; // Build up the value for (Authorization/Proxy-Authorization). std::string AssembleCredentials(const std::string& method, const std::string& path, - const std::string& username, - const std::string& password, + const string16& username, + const string16& password, const std::string& cnonce, int nonce_count) const; @@ -121,7 +124,7 @@ class HttpAuthHandlerDigest : public HttpAuthHandler { std::string opaque_; bool stale_; DigestAlgorithm algorithm_; - int qop_; // Bitfield of QualityOfProtection + int qop_; // Bitfield of QualityOfProtection int nonce_count_; diff --git a/net/http/http_auth_handler_digest_unittest.cc b/net/http/http_auth_handler_digest_unittest.cc index b1782f6..c563aae 100644 --- a/net/http/http_auth_handler_digest_unittest.cc +++ b/net/http/http_auth_handler_digest_unittest.cc @@ -2,11 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "testing/gtest/include/gtest/gtest.h" +#include <string> #include "base/basictypes.h" +#include "base/string_util.h" #include "net/base/net_errors.h" #include "net/http/http_auth_handler_digest.h" +#include "testing/gtest/include/gtest/gtest.h" namespace net { @@ -276,12 +278,13 @@ TEST(HttpAuthHandlerDigestTest, AssembleCredentials) { HttpAuthHandlerDigest* digest = static_cast<HttpAuthHandlerDigest*>(handler.get()); - std::string creds = digest->AssembleCredentials(tests[i].req_method, - tests[i].req_path, - tests[i].username, - tests[i].password, - tests[i].cnonce, - tests[i].nonce_count); + std::string creds = + digest->AssembleCredentials(tests[i].req_method, + tests[i].req_path, + ASCIIToUTF16(tests[i].username), + ASCIIToUTF16(tests[i].password), + tests[i].cnonce, + tests[i].nonce_count); EXPECT_STREQ(tests[i].expected_creds, creds.c_str()); } diff --git a/net/http/http_auth_handler_mock.cc b/net/http/http_auth_handler_mock.cc index 09a03561..983105b 100644 --- a/net/http/http_auth_handler_mock.cc +++ b/net/http/http_auth_handler_mock.cc @@ -76,8 +76,8 @@ bool HttpAuthHandlerMock::Init(HttpAuth::ChallengeTokenizer* challenge) { return true; } -int HttpAuthHandlerMock::GenerateAuthTokenImpl(const std::wstring* username, - const std::wstring* password, +int HttpAuthHandlerMock::GenerateAuthTokenImpl(const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token) { diff --git a/net/http/http_auth_handler_mock.h b/net/http/http_auth_handler_mock.h index c99092a..f9a676c 100644 --- a/net/http/http_auth_handler_mock.h +++ b/net/http/http_auth_handler_mock.h @@ -8,6 +8,7 @@ #include <string> +#include "base/string16.h" #include "base/task.h" #include "net/http/http_auth_handler.h" #include "net/http/http_auth_handler_factory.h" @@ -69,8 +70,8 @@ class HttpAuthHandlerMock : public HttpAuthHandler { protected: virtual bool Init(HttpAuth::ChallengeTokenizer* challenge); - virtual int GenerateAuthTokenImpl(const std::wstring* username, - const std::wstring* password, + virtual int GenerateAuthTokenImpl(const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token); diff --git a/net/http/http_auth_handler_negotiate.cc b/net/http/http_auth_handler_negotiate.cc index d7a9c50..889dea2 100644 --- a/net/http/http_auth_handler_negotiate.cc +++ b/net/http/http_auth_handler_negotiate.cc @@ -44,8 +44,8 @@ HttpAuthHandlerNegotiate::~HttpAuthHandlerNegotiate() { } int HttpAuthHandlerNegotiate::GenerateAuthTokenImpl( - const std::wstring* username, - const std::wstring* password, + const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token) { @@ -223,8 +223,8 @@ int HttpAuthHandlerNegotiate::DoResolveCanonicalNameComplete(int rv) { int HttpAuthHandlerNegotiate::DoGenerateAuthToken() { next_state_ = STATE_GENERATE_AUTH_TOKEN_COMPLETE; - std::wstring* username = has_username_and_password_ ? &username_ : NULL; - std::wstring* password = has_username_and_password_ ? &password_ : NULL; + string16* username = has_username_and_password_ ? &username_ : NULL; + string16* password = has_username_and_password_ ? &password_ : NULL; // TODO(cbentzel): This should possibly be done async. return auth_system_.GenerateAuthToken(username, password, spn_, auth_token_); } diff --git a/net/http/http_auth_handler_negotiate.h b/net/http/http_auth_handler_negotiate.h index abc18ef..005e665 100644 --- a/net/http/http_auth_handler_negotiate.h +++ b/net/http/http_auth_handler_negotiate.h @@ -8,8 +8,7 @@ #include <string> -#include "build/build_config.h" - +#include "base/string16.h" #include "build/build_config.h" #include "net/base/address_list.h" #include "net/http/http_auth_handler.h" @@ -119,8 +118,8 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler { protected: virtual bool Init(HttpAuth::ChallengeTokenizer* challenge); - virtual int GenerateAuthTokenImpl(const std::wstring* username, - const std::wstring* password, + virtual int GenerateAuthTokenImpl(const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token); @@ -156,8 +155,8 @@ class HttpAuthHandlerNegotiate : public HttpAuthHandler { // Things which should be consistent after first call to GenerateAuthToken. bool already_called_; bool has_username_and_password_; - std::wstring username_; - std::wstring password_; + string16 username_; + string16 password_; std::wstring spn_; // Things which vary each round. diff --git a/net/http/http_auth_handler_negotiate_unittest.cc b/net/http/http_auth_handler_negotiate_unittest.cc index 4fcdad1..75063ca 100644 --- a/net/http/http_auth_handler_negotiate_unittest.cc +++ b/net/http/http_auth_handler_negotiate_unittest.cc @@ -4,6 +4,7 @@ #include "net/http/http_auth_handler_negotiate.h" +#include "base/string_util.h" #include "net/base/mock_host_resolver.h" #include "net/base/net_errors.h" #include "net/base/test_completion_callback.h" @@ -225,8 +226,8 @@ TEST_F(HttpAuthHandlerNegotiateTest, DisableCname) { TestCompletionCallback callback; HttpRequestInfo request_info; std::string token; - std::wstring username = L"foo"; - std::wstring password = L"bar"; + string16 username = ASCIIToUTF16("foo"); + string16 password = ASCIIToUTF16("bar"); EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, &request_info, &callback, &token)); @@ -246,8 +247,8 @@ TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameStandardPort) { TestCompletionCallback callback; HttpRequestInfo request_info; std::string token; - std::wstring username = L"foo"; - std::wstring password = L"bar"; + string16 username = ASCIIToUTF16("foo"); + string16 password = ASCIIToUTF16("bar"); EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, &request_info, &callback, &token)); @@ -267,8 +268,8 @@ TEST_F(HttpAuthHandlerNegotiateTest, DisableCnameNonstandardPort) { TestCompletionCallback callback; HttpRequestInfo request_info; std::string token; - std::wstring username = L"foo"; - std::wstring password = L"bar"; + string16 username = ASCIIToUTF16("foo"); + string16 password = ASCIIToUTF16("bar"); EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, &request_info, &callback, &token)); @@ -288,8 +289,8 @@ TEST_F(HttpAuthHandlerNegotiateTest, CnameSync) { TestCompletionCallback callback; HttpRequestInfo request_info; std::string token; - std::wstring username = L"foo"; - std::wstring password = L"bar"; + string16 username = ASCIIToUTF16("foo"); + string16 password = ASCIIToUTF16("bar"); EXPECT_EQ(OK, auth_handler->GenerateAuthToken(&username, &password, &request_info, &callback, &token)); @@ -309,8 +310,8 @@ TEST_F(HttpAuthHandlerNegotiateTest, CnameAsync) { TestCompletionCallback callback; HttpRequestInfo request_info; std::string token; - std::wstring username = L"foo"; - std::wstring password = L"bar"; + string16 username = ASCIIToUTF16("foo"); + string16 password = ASCIIToUTF16("bar"); EXPECT_EQ(ERR_IO_PENDING, auth_handler->GenerateAuthToken( &username, &password, &request_info, &callback, &token)); EXPECT_EQ(OK, callback.WaitForResult()); diff --git a/net/http/http_auth_handler_ntlm.cc b/net/http/http_auth_handler_ntlm.cc index d8e8a75..3191df6 100644 --- a/net/http/http_auth_handler_ntlm.cc +++ b/net/http/http_auth_handler_ntlm.cc @@ -14,8 +14,8 @@ namespace net { int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( - const std::wstring* username, - const std::wstring* password, + const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token) { @@ -36,8 +36,8 @@ int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( // |username| may be in the form "DOMAIN\user". Parse it into the two // components. - std::wstring domain; - std::wstring user; + string16 domain; + string16 user; size_t backslash_idx = username->find(L'\\'); if (backslash_idx == std::wstring::npos) { user = *username; @@ -45,9 +45,9 @@ int HttpAuthHandlerNTLM::GenerateAuthTokenImpl( domain = username->substr(0, backslash_idx); user = username->substr(backslash_idx + 1); } - domain_ = WideToUTF16(domain); - username_ = WideToUTF16(user); - password_ = WideToUTF16(*password); + domain_ = domain; + username_ = user; + password_ = *password; // Initial challenge. if (auth_data_.empty()) { diff --git a/net/http/http_auth_handler_ntlm.h b/net/http/http_auth_handler_ntlm.h index 3cefc56..00d6905 100644 --- a/net/http/http_auth_handler_ntlm.h +++ b/net/http/http_auth_handler_ntlm.h @@ -117,8 +117,8 @@ class HttpAuthHandlerNTLM : public HttpAuthHandler { return ParseChallenge(tok); } - virtual int GenerateAuthTokenImpl(const std::wstring* username, - const std::wstring* password, + virtual int GenerateAuthTokenImpl(const string16* username, + const string16* password, const HttpRequestInfo* request, CompletionCallback* callback, std::string* auth_token); diff --git a/net/http/http_auth_handler_unittest.cc b/net/http/http_auth_handler_unittest.cc index 2516745..62ecf22 100644 --- a/net/http/http_auth_handler_unittest.cc +++ b/net/http/http_auth_handler_unittest.cc @@ -4,6 +4,7 @@ #include "net/http/http_auth_handler.h" +#include "base/string_util.h" #include "net/base/capturing_net_log.h" #include "net/base/net_errors.h" #include "net/base/net_log_unittest.h" @@ -18,8 +19,8 @@ TEST(HttpAuthHandlerTest, NetLog) { NetLog::Source source; GURL origin("http://www.example.com"); std::string challenge = "Mock asdf"; - std::wstring username = L"user"; - std::wstring password = L"pass"; + string16 username = ASCIIToUTF16("user"); + string16 password = ASCIIToUTF16("pass"); std::string auth_token; HttpRequestInfo request; diff --git a/net/http/http_auth_sspi_win.cc b/net/http/http_auth_sspi_win.cc index 221acf1..9c195df 100644 --- a/net/http/http_auth_sspi_win.cc +++ b/net/http/http_auth_sspi_win.cc @@ -11,6 +11,7 @@ #include "base/logging.h" #include "base/singleton.h" #include "base/string_util.h" +#include "base/utf_string_conversions.h" #include "net/base/net_errors.h" #include "net/http/http_auth.h" @@ -43,9 +44,9 @@ int MapAcquireCredentialsStatusToError(SECURITY_STATUS status, int AcquireExplicitCredentials(SSPILibrary* library, const SEC_WCHAR* package, - const std::wstring& domain, - const std::wstring& user, - const std::wstring& password, + const string16& domain, + const string16& user, + const string16& password, CredHandle* cred) { SEC_WINNT_AUTH_IDENTITY identity; identity.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE; @@ -159,8 +160,8 @@ bool HttpAuthSSPI::ParseChallenge(HttpAuth::ChallengeTokenizer* tok) { return true; } -int HttpAuthSSPI::GenerateAuthToken(const std::wstring* username, - const std::wstring* password, +int HttpAuthSSPI::GenerateAuthToken(const string16* username, + const string16* password, const std::wstring& spn, std::string* auth_token) { DCHECK((username == NULL) == (password == NULL)); @@ -199,14 +200,14 @@ int HttpAuthSSPI::GenerateAuthToken(const std::wstring* username, return OK; } -int HttpAuthSSPI::OnFirstRound(const std::wstring* username, - const std::wstring* password) { +int HttpAuthSSPI::OnFirstRound(const string16* username, + const string16* password) { DCHECK((username == NULL) == (password == NULL)); DCHECK(!SecIsValidHandle(&cred_)); int rv = OK; if (username) { - std::wstring domain; - std::wstring user; + string16 domain; + string16 user; SplitDomainAndUser(*username, &domain, &user); rv = AcquireExplicitCredentials(library_, security_package_, domain, user, *password, &cred_); @@ -300,14 +301,14 @@ int HttpAuthSSPI::GetNextSecurityToken( return OK; } -void SplitDomainAndUser(const std::wstring& combined, - std::wstring* domain, - std::wstring* user) { +void SplitDomainAndUser(const string16& combined, + string16* domain, + string16* user) { // |combined| may be in the form "user" or "DOMAIN\user". - // Separatethe two parts if they exist. + // Separate the two parts if they exist. // TODO(cbentzel): I believe user@domain is also a valid form. size_t backslash_idx = combined.find(L'\\'); - if (backslash_idx == std::wstring::npos) { + if (backslash_idx == string16::npos) { domain->clear(); *user = combined; } else { diff --git a/net/http/http_auth_sspi_win.h b/net/http/http_auth_sspi_win.h index 95775ae..bf1778f 100644 --- a/net/http/http_auth_sspi_win.h +++ b/net/http/http_auth_sspi_win.h @@ -17,6 +17,7 @@ #include <string> +#include "base/string16.h" #include "net/http/http_auth.h" namespace net { @@ -93,14 +94,14 @@ class HttpAuthSSPI { // obtained using |*username| and |*password|. If |username| and |password| // are both NULL, the credentials for the currently logged in user are used // instead. - int GenerateAuthToken(const std::wstring* username, - const std::wstring* password, + int GenerateAuthToken(const string16* username, + const string16* password, const std::wstring& spn, std::string* auth_token); private: - int OnFirstRound(const std::wstring* username, - const std::wstring* password); + int OnFirstRound(const string16* username, + const string16* password); int GetNextSecurityToken( const std::wstring& spn, @@ -126,9 +127,9 @@ class HttpAuthSSPI { // If |combined| is of form "bar", |domain| will be empty and |user| will // contain "bar". // |domain| and |user| must be non-NULL. -void SplitDomainAndUser(const std::wstring& combined, - std::wstring* domain, - std::wstring* user); +void SplitDomainAndUser(const string16& combined, + string16* domain, + string16* user); // Determines the maximum token length in bytes for a particular SSPI package. // diff --git a/net/http/http_cache_transaction.cc b/net/http/http_cache_transaction.cc index 2ea08b8..bbd42f8 100644 --- a/net/http/http_cache_transaction.cc +++ b/net/http/http_cache_transaction.cc @@ -4,12 +4,15 @@ #include "net/http/http_cache_transaction.h" -#include "base/compiler_specific.h" +#include "build/build_config.h" #if defined(OS_POSIX) #include <unistd.h> #endif +#include <string> + +#include "base/compiler_specific.h" #include "base/histogram.h" #include "base/ref_counted.h" #include "base/string_util.h" @@ -223,8 +226,8 @@ int HttpCache::Transaction::RestartWithCertificate( } int HttpCache::Transaction::RestartWithAuth( - const std::wstring& username, - const std::wstring& password, + const string16& username, + const string16& password, CompletionCallback* callback) { DCHECK(auth_response_.headers); DCHECK(callback); @@ -1497,8 +1500,8 @@ int HttpCache::Transaction::RestartNetworkRequestWithCertificate( } int HttpCache::Transaction::RestartNetworkRequestWithAuth( - const std::wstring& username, - const std::wstring& password) { + const string16& username, + const string16& password) { DCHECK(mode_ & WRITE || mode_ == NONE); DCHECK(network_trans_.get()); DCHECK_EQ(STATE_NONE, next_state_); diff --git a/net/http/http_cache_transaction.h b/net/http/http_cache_transaction.h index bd9dc75..05a8484 100644 --- a/net/http/http_cache_transaction.h +++ b/net/http/http_cache_transaction.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. +// 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. @@ -9,8 +9,11 @@ #define NET_HTTP_HTTP_CACHE_TRANSACTION_H_ #pragma once -#include "net/base/net_log.h" +#include <string> + +#include "base/string16.h" #include "base/time.h" +#include "net/base/net_log.h" #include "net/http/http_cache.h" #include "net/http/http_response_info.h" #include "net/http/http_transaction.h" @@ -33,8 +36,8 @@ class HttpCache::Transaction : public HttpTransaction { virtual int RestartIgnoringLastError(CompletionCallback* callback); virtual int RestartWithCertificate(X509Certificate* client_cert, CompletionCallback* callback); - virtual int RestartWithAuth(const std::wstring& username, - const std::wstring& password, + virtual int RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback); virtual bool IsReadyToRestartForAuth(); virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); @@ -250,8 +253,8 @@ class HttpCache::Transaction : public HttpTransaction { // Called to restart a network transaction with authentication credentials. // Returns network error code. - int RestartNetworkRequestWithAuth(const std::wstring& username, - const std::wstring& password); + int RestartNetworkRequestWithAuth(const string16& username, + const string16& password); // Called to determine if we need to validate the cache entry before using it. bool RequiresValidation(); diff --git a/net/http/http_network_transaction.cc b/net/http/http_network_transaction.cc index 789170a..3fa59bf 100644 --- a/net/http/http_network_transaction.cc +++ b/net/http/http_network_transaction.cc @@ -318,8 +318,8 @@ int HttpNetworkTransaction::RestartWithCertificate( } int HttpNetworkTransaction::RestartWithAuth( - const std::wstring& username, - const std::wstring& password, + const string16& username, + const string16& password, CompletionCallback* callback) { HttpAuth::Target target = pending_auth_target_; if (target == HttpAuth::AUTH_NONE) { diff --git a/net/http/http_network_transaction.h b/net/http/http_network_transaction.h index ec35ced..3fa0e67 100644 --- a/net/http/http_network_transaction.h +++ b/net/http/http_network_transaction.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "base/time.h" #include "net/base/address_list.h" #include "net/base/io_buffer.h" @@ -68,8 +69,8 @@ class HttpNetworkTransaction : public HttpTransaction { virtual int RestartIgnoringLastError(CompletionCallback* callback); virtual int RestartWithCertificate(X509Certificate* client_cert, CompletionCallback* callback); - virtual int RestartWithAuth(const std::wstring& username, - const std::wstring& password, + virtual int RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback); virtual bool IsReadyToRestartForAuth() { return pending_auth_target_ != HttpAuth::AUTH_NONE && diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc index 11c3965..09b0029 100644 --- a/net/http/http_network_transaction_unittest.cc +++ b/net/http/http_network_transaction_unittest.cc @@ -44,6 +44,23 @@ //----------------------------------------------------------------------------- +namespace { + +const string16 kBar(ASCIIToUTF16("bar")); +const string16 kBar2(ASCIIToUTF16("bar2")); +const string16 kBar3(ASCIIToUTF16("bar3")); +const string16 kBaz(ASCIIToUTF16("baz")); +const string16 kFirst(ASCIIToUTF16("first")); +const string16 kFoo(ASCIIToUTF16("foo")); +const string16 kFoo2(ASCIIToUTF16("foo2")); +const string16 kFoo3(ASCIIToUTF16("foo3")); +const string16 kFou(ASCIIToUTF16("fou")); +const string16 kSecond(ASCIIToUTF16("second")); +const string16 kTestingNTLM(ASCIIToUTF16("testing-ntlm")); +const string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); + +} // namespace + namespace net { class HttpNetworkSessionPeer { @@ -945,7 +962,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuth) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -1061,7 +1078,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -1134,7 +1151,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -1215,7 +1232,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -1306,7 +1323,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -1404,7 +1421,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAlive) { TestCompletionCallback callback2; // Wrong password (should be "bar"). - rv = trans->RestartWithAuth(L"foo", L"baz", &callback2); + rv = trans->RestartWithAuth(kFoo, kBaz, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -1842,7 +1859,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -1858,7 +1875,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { TestCompletionCallback callback3; - rv = trans->RestartWithAuth(L"foo2", L"bar2", &callback3); + rv = trans->RestartWithAuth(kFoo2, kBar2, &callback3); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback3.WaitForResult(); @@ -1972,7 +1989,7 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { EXPECT_TRUE(trans->IsReadyToRestartForAuth()); TestCompletionCallback callback2; - rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); + rv = trans->RestartWithAuth(string16(), string16(), &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); EXPECT_EQ(OK, rv); @@ -1991,7 +2008,7 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth1) { TestCompletionCallback callback3; - rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback3); + rv = trans->RestartWithAuth(kTestingNTLM, kTestingNTLM, &callback3); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback3.WaitForResult(); @@ -2150,7 +2167,7 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { EXPECT_TRUE(trans->IsReadyToRestartForAuth()); TestCompletionCallback callback2; - rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); + rv = trans->RestartWithAuth(string16(), string16(), &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); EXPECT_EQ(OK, rv); @@ -2169,7 +2186,7 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { TestCompletionCallback callback3; // Enter the wrong password. - rv = trans->RestartWithAuth(L"testing-ntlm", L"wrongpassword", &callback3); + rv = trans->RestartWithAuth(kTestingNTLM, kWrongPassword, &callback3); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback3.WaitForResult(); @@ -2177,7 +2194,7 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { EXPECT_TRUE(trans->IsReadyToRestartForAuth()); TestCompletionCallback callback4; - rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback4); + rv = trans->RestartWithAuth(string16(), string16(), &callback4); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback4.WaitForResult(); EXPECT_EQ(OK, rv); @@ -2196,7 +2213,7 @@ TEST_F(HttpNetworkTransactionTest, NTLMAuth2) { TestCompletionCallback callback5; // Now enter the right password. - rv = trans->RestartWithAuth(L"testing-ntlm", L"testing-ntlm", &callback5); + rv = trans->RestartWithAuth(kTestingNTLM, kTestingNTLM, &callback5); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback5.WaitForResult(); @@ -2569,7 +2586,7 @@ TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { EXPECT_TRUE(trans->IsReadyToRestartForAuth()); TestCompletionCallback callback2; - rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); + rv = trans->RestartWithAuth(string16(), string16(), &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); EXPECT_EQ(OK, rv); @@ -2667,7 +2684,7 @@ TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { EXPECT_TRUE(trans->IsReadyToRestartForAuth()); TestCompletionCallback callback2; - rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); + rv = trans->RestartWithAuth(string16(), string16(), &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); EXPECT_EQ(OK, rv); @@ -2683,7 +2700,7 @@ TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { EXPECT_EQ(L"basic", response->auth_challenge->scheme); TestCompletionCallback callback3; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback3); + rv = trans->RestartWithAuth(kFoo, kBar, &callback3); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback3.WaitForResult(); EXPECT_EQ(OK, rv); @@ -2771,7 +2788,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -2856,7 +2873,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo2", L"bar2", &callback2); + rv = trans->RestartWithAuth(kFoo2, kBar2, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -2972,7 +2989,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { EXPECT_TRUE(trans->IsReadyToRestartForAuth()); TestCompletionCallback callback2; - rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); + rv = trans->RestartWithAuth(string16(), string16(), &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); EXPECT_EQ(OK, rv); @@ -3061,7 +3078,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { EXPECT_TRUE(trans->IsReadyToRestartForAuth()); TestCompletionCallback callback2; - rv = trans->RestartWithAuth(std::wstring(), std::wstring(), &callback2); + rv = trans->RestartWithAuth(string16(), string16(), &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); EXPECT_EQ(OK, rv); @@ -3080,7 +3097,7 @@ TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { TestCompletionCallback callback3; - rv = trans->RestartWithAuth(L"foo3", L"bar3", &callback3); + rv = trans->RestartWithAuth(kFoo3, kBar3, &callback3); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback3.WaitForResult(); @@ -3167,7 +3184,7 @@ TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -4528,7 +4545,7 @@ TEST_F(HttpNetworkTransactionTest, DrainResetOK) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -4796,7 +4813,7 @@ TEST_F(HttpNetworkTransactionTest, UnreadableUploadFileAfterAuthRestart) { TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"foo", L"bar", &callback2); + rv = trans->RestartWithAuth(kFoo, kBar, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); @@ -4915,7 +4932,7 @@ TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { // password prompt for second_realm waiting to be filled in after the // transaction completes. TestCompletionCallback callback2; - rv = trans->RestartWithAuth(L"first", L"baz", &callback2); + rv = trans->RestartWithAuth(kFirst, kBaz, &callback2); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback2.WaitForResult(); EXPECT_EQ(OK, rv); @@ -4931,7 +4948,7 @@ TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { // prompt is not present, it indicates that the HttpAuthCacheEntry for // first_realm was not correctly removed. TestCompletionCallback callback3; - rv = trans->RestartWithAuth(L"second", L"fou", &callback3); + rv = trans->RestartWithAuth(kSecond, kFou, &callback3); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback3.WaitForResult(); EXPECT_EQ(OK, rv); @@ -4944,7 +4961,7 @@ TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { // Issue the fourth request with the correct password and username. TestCompletionCallback callback4; - rv = trans->RestartWithAuth(L"first", L"bar", &callback4); + rv = trans->RestartWithAuth(kFirst, kBar, &callback4); EXPECT_EQ(ERR_IO_PENDING, rv); rv = callback4.WaitForResult(); EXPECT_EQ(OK, rv); @@ -5896,7 +5913,7 @@ TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { if (round == 0) { rv = trans->Start(&request, &callback, BoundNetLog()); } else { - rv = trans->RestartWithAuth(L"foo", L"bar", &callback); + rv = trans->RestartWithAuth(kFoo, kBar, &callback); } if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); @@ -6008,7 +6025,7 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { // Second round auth_handler->SetGenerateExpectation(false, OK); - rv = trans->RestartWithAuth(L"foo", L"bar", &callback); + rv = trans->RestartWithAuth(kFoo, kBar, &callback); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(OK, rv); @@ -6018,7 +6035,7 @@ TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { // Third round auth_handler->SetGenerateExpectation(false, OK); - rv = trans->RestartWithAuth(L"", L"", &callback); + rv = trans->RestartWithAuth(string16(), string16(), &callback); if (rv == ERR_IO_PENDING) rv = callback.WaitForResult(); EXPECT_EQ(OK, rv); diff --git a/net/http/http_transaction.h b/net/http/http_transaction.h index 9e7d028..690d521 100644 --- a/net/http/http_transaction.h +++ b/net/http/http_transaction.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// 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. @@ -6,8 +6,7 @@ #define NET_HTTP_HTTP_TRANSACTION_H_ #pragma once -#include <string> - +#include "base/string16.h" #include "net/base/completion_callback.h" #include "net/base/load_states.h" @@ -62,8 +61,8 @@ class HttpTransaction { CompletionCallback* callback) = 0; // Restarts the HTTP transaction with authentication credentials. - virtual int RestartWithAuth(const std::wstring& username, - const std::wstring& password, + virtual int RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback) = 0; // Returns true if auth is ready to be continued. Callers should check diff --git a/net/http/http_transaction_unittest.h b/net/http/http_transaction_unittest.h index 6b8d428..47629b5 100644 --- a/net/http/http_transaction_unittest.h +++ b/net/http/http_transaction_unittest.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// 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. @@ -14,6 +14,7 @@ #include "base/callback.h" #include "base/compiler_specific.h" #include "base/message_loop.h" +#include "base/string16.h" #include "base/string_util.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" @@ -260,8 +261,8 @@ class MockNetworkTransaction : public net::HttpTransaction { return net::ERR_FAILED; } - virtual int RestartWithAuth(const std::wstring& username, - const std::wstring& password, + virtual int RestartWithAuth(const string16& username, + const string16& password, net::CompletionCallback* callback) { return net::ERR_FAILED; } diff --git a/net/socket/socket_test_util.cc b/net/socket/socket_test_util.cc index 0d75516..8ff6ace 100644 --- a/net/socket/socket_test_util.cc +++ b/net/socket/socket_test_util.cc @@ -920,8 +920,8 @@ int MockHttpAuthController::HandleAuthChallenge( return OK; } -void MockHttpAuthController::ResetAuth(const std::wstring& username, - const std::wstring& password) { +void MockHttpAuthController::ResetAuth(const string16& username, + const string16& password) { data_index_++; } diff --git a/net/socket/socket_test_util.h b/net/socket/socket_test_util.h index d2dd31a..1a0ab11 100644 --- a/net/socket/socket_test_util.h +++ b/net/socket/socket_test_util.h @@ -16,6 +16,7 @@ #include "base/logging.h" #include "base/scoped_ptr.h" #include "base/scoped_vector.h" +#include "base/string16.h" #include "net/base/address_list.h" #include "net/base/io_buffer.h" #include "net/base/net_errors.h" @@ -636,8 +637,8 @@ class MockTCPClientSocketPool : public TCPClientSocketPool { const scoped_refptr<ClientSocketPoolHistograms>& histograms, ClientSocketFactory* socket_factory); - int release_count() const { return release_count_; }; - int cancel_count() const { return cancel_count_; }; + int release_count() const { return release_count_; } + int cancel_count() const { return cancel_count_; } // TCPClientSocketPool methods. virtual int RequestSocket(const std::string& group_name, @@ -695,7 +696,8 @@ class MockSOCKSClientSocketPool : public SOCKSClientSocketPool { }; struct MockHttpAuthControllerData { - MockHttpAuthControllerData(std::string header) : auth_header(header) {} + explicit MockHttpAuthControllerData(std::string header) + : auth_header(header) {} std::string auth_header; }; @@ -716,8 +718,8 @@ class MockHttpAuthController : public HttpAuthController { bool do_not_send_server_auth, bool establishing_tunnel, const BoundNetLog& net_log); - virtual void ResetAuth(const std::wstring& username, - const std::wstring& password); + virtual void ResetAuth(const string16& username, + const string16& password); virtual bool HaveAuthHandler() const; virtual bool HaveAuth() const; diff --git a/net/socket/ssl_client_socket_pool_unittest.cc b/net/socket/ssl_client_socket_pool_unittest.cc index 64cae4c..d8b6339 100644 --- a/net/socket/ssl_client_socket_pool_unittest.cc +++ b/net/socket/ssl_client_socket_pool_unittest.cc @@ -77,7 +77,6 @@ class SSLClientSocketPoolTest : public ClientSocketPoolTest { scoped_refptr<SSLSocketParams> SSLParams( ProxyServer::Scheme proxy, struct MockHttpAuthControllerData* auth_data, size_t auth_data_len, bool want_spdy_over_ssl, bool want_spdy_over_npn) { - scoped_refptr<HttpProxySocketParams> http_proxy_params; if (proxy == ProxyServer::SCHEME_HTTP) { scoped_refptr<MockHttpAuthController> auth_controller = @@ -641,8 +640,8 @@ TEST_F(SSLClientSocketPoolTest, DoProxyAuth) { const HttpResponseInfo& tunnel_info = handle.ssl_error_response_info(); EXPECT_EQ(tunnel_info.headers->response_code(), 407); - params->http_proxy_params()->auth_controller()->ResetAuth(std::wstring(), - std::wstring()); + params->http_proxy_params()->auth_controller()->ResetAuth(string16(), + string16()); rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); @@ -710,8 +709,8 @@ TEST_F(SSLClientSocketPoolTest, DoProxyAuthNoKeepAlive) { const HttpResponseInfo& tunnel_info = handle.ssl_error_response_info(); EXPECT_EQ(tunnel_info.headers->response_code(), 407); - params->http_proxy_params()->auth_controller()->ResetAuth(std::wstring(), - std::wstring()); + params->http_proxy_params()->auth_controller()->ResetAuth(string16(), + string16()); rv = handle.Init("a", params, MEDIUM, &callback, pool_, BoundNetLog()); EXPECT_EQ(ERR_IO_PENDING, rv); EXPECT_FALSE(handle.is_initialized()); diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index c1216d7..6e7f270 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -196,7 +196,7 @@ void SocketStream::Close() { } void SocketStream::RestartWithAuth( - const std::wstring& username, const std::wstring& password) { + const string16& username, const string16& password) { DCHECK(MessageLoop::current()) << "The current MessageLoop must exist"; DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index 74b87cf..860f785 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -14,6 +14,7 @@ #include "base/linked_ptr.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "base/task.h" #include "net/base/address_list.h" #include "net/base/completion_callback.h" @@ -133,8 +134,8 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { // Restarts with authentication info. // Should be used for response of OnAuthRequired. virtual void RestartWithAuth( - const std::wstring& username, - const std::wstring& password); + const string16& username, + const string16& password); // Detach delegate. Call before delegate is deleted. // Once delegate is detached, close the socket stream and never call delegate diff --git a/net/socket_stream/socket_stream_job.h b/net/socket_stream/socket_stream_job.h index 086aa79..89e0c36 100644 --- a/net/socket_stream/socket_stream_job.h +++ b/net/socket_stream/socket_stream_job.h @@ -9,6 +9,7 @@ #include <string> #include "base/ref_counted.h" +#include "base/string16.h" #include "net/socket_stream/socket_stream.h" class GURL; @@ -65,8 +66,8 @@ class SocketStreamJob : public base::RefCountedThreadSafe<SocketStreamJob> { } virtual void RestartWithAuth( - const std::wstring& username, - const std::wstring& password) { + const string16& username, + const string16& password) { socket_->RestartWithAuth(username, password); } diff --git a/net/socket_stream/socket_stream_unittest.cc b/net/socket_stream/socket_stream_unittest.cc index d32654a..def766c 100644 --- a/net/socket_stream/socket_stream_unittest.cc +++ b/net/socket_stream/socket_stream_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -119,8 +119,8 @@ class SocketStreamEventRecorder : public net::SocketStream::Delegate { << " password=" << password_; event->socket->RestartWithAuth(username_, password_); } - void SetAuthInfo(const std::wstring& username, - const std::wstring& password) { + void SetAuthInfo(const string16& username, + const string16& password) { username_ = username; password_ = password; } @@ -138,8 +138,8 @@ class SocketStreamEventRecorder : public net::SocketStream::Delegate { Callback1<SocketStreamEvent*>::Type* on_auth_required_; net::CompletionCallback* callback_; - std::wstring username_; - std::wstring password_; + string16 username_; + string16 password_; DISALLOW_COPY_AND_ASSIGN(SocketStreamEventRecorder); }; @@ -318,9 +318,7 @@ TEST_F(SocketStreamTest, BasicAuthProxy) { new SocketStreamEventRecorder(&callback)); delegate->SetOnConnected(NewCallback(delegate.get(), &SocketStreamEventRecorder::DoClose)); - const std::wstring kUsername = L"foo"; - const std::wstring kPassword = L"bar"; - delegate->SetAuthInfo(kUsername, kPassword); + delegate->SetAuthInfo(ASCIIToUTF16("foo"), ASCIIToUTF16("bar")); delegate->SetOnAuthRequired( NewCallback(delegate.get(), &SocketStreamEventRecorder::DoRestartWithAuth)); diff --git a/net/spdy/spdy_network_transaction.cc b/net/spdy/spdy_network_transaction.cc index 6e0c930..e575ad0 100644 --- a/net/spdy/spdy_network_transaction.cc +++ b/net/spdy/spdy_network_transaction.cc @@ -1,9 +1,11 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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 "net/spdy/spdy_network_transaction.h" +#include <string> + #include "base/compiler_specific.h" #include "base/logging.h" #include "base/scoped_ptr.h" @@ -78,8 +80,8 @@ int SpdyNetworkTransaction::RestartWithCertificate( } int SpdyNetworkTransaction::RestartWithAuth( - const std::wstring& username, - const std::wstring& password, + const string16& username, + const string16& password, CompletionCallback* callback) { // TODO(mbelshe): implement me. NOTIMPLEMENTED(); diff --git a/net/spdy/spdy_network_transaction.h b/net/spdy/spdy_network_transaction.h index 92357ac..7df2e64 100644 --- a/net/spdy/spdy_network_transaction.h +++ b/net/spdy/spdy_network_transaction.h @@ -1,17 +1,17 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. -#ifndef NET_SPDY_NETWORK_TRANSACTION_H_ -#define NET_SPDY_NETWORK_TRANSACTION_H_ +#ifndef NET_SPDY_SPDY_NETWORK_TRANSACTION_H_ +#define NET_SPDY_SPDY_NETWORK_TRANSACTION_H_ #pragma once -#include <string> #include <deque> #include "base/basictypes.h" #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "base/time.h" #include "net/base/completion_callback.h" #include "net/base/load_states.h" @@ -43,8 +43,8 @@ class SpdyNetworkTransaction : public HttpTransaction { virtual int RestartIgnoringLastError(CompletionCallback* callback); virtual int RestartWithCertificate(X509Certificate* client_cert, CompletionCallback* callback); - virtual int RestartWithAuth(const std::wstring& username, - const std::wstring& password, + virtual int RestartWithAuth(const string16& username, + const string16& password, CompletionCallback* callback); virtual bool IsReadyToRestartForAuth() { return false; } virtual int Read(IOBuffer* buf, int buf_len, CompletionCallback* callback); @@ -121,4 +121,4 @@ class SpdyNetworkTransaction : public HttpTransaction { } // namespace net -#endif // NET_SPDY_NETWORK_TRANSACTION_H_ +#endif // NET_SPDY_SPDY_NETWORK_TRANSACTION_H_ diff --git a/net/url_request/url_request.cc b/net/url_request/url_request.cc index 9f226c2..3ed7d92 100644 --- a/net/url_request/url_request.cc +++ b/net/url_request/url_request.cc @@ -1,4 +1,4 @@ -// Copyright (c) 20010 The Chromium Authors. All rights reserved. +// 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. @@ -23,7 +23,6 @@ using base::Time; using net::UploadData; using std::string; -using std::wstring; namespace { @@ -395,7 +394,7 @@ void URLRequest::FollowDeferredRedirect() { job_->FollowDeferredRedirect(); } -void URLRequest::SetAuth(const wstring& username, const wstring& password) { +void URLRequest::SetAuth(const string16& username, const string16& password) { DCHECK(job_); DCHECK(job_->NeedsAuth()); diff --git a/net/url_request/url_request.h b/net/url_request/url_request.h index e5a644e..a6ef386 100644 --- a/net/url_request/url_request.h +++ b/net/url_request/url_request.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// 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. @@ -15,6 +15,7 @@ #include "base/logging.h" #include "base/non_thread_safe.h" #include "base/ref_counted.h" +#include "base/string16.h" #include "googleurl/src/gurl.h" #include "net/base/load_states.h" #include "net/base/net_log.h" @@ -504,7 +505,7 @@ class URLRequest : public NonThreadSafe { // OnAuthRequired() callback (and only then). // SetAuth will reissue the request with the given credentials. // CancelAuth will give up and display the error page. - void SetAuth(const std::wstring& username, const std::wstring& password); + void SetAuth(const string16& username, const string16& password); void CancelAuth(); // This method can be called after the user selects a client certificate to diff --git a/net/url_request/url_request_ftp_job.cc b/net/url_request/url_request_ftp_job.cc index f8746fc..e59f79f 100644 --- a/net/url_request/url_request_ftp_job.cc +++ b/net/url_request/url_request_ftp_job.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -90,8 +90,8 @@ void URLRequestFtpJob::GetAuthChallengeInfo( result->swap(auth_info); } -void URLRequestFtpJob::SetAuth(const std::wstring& username, - const std::wstring& password) { +void URLRequestFtpJob::SetAuth(const string16& username, + const string16& password) { DCHECK(NeedsAuth()); server_auth_->state = net::AUTH_STATE_HAVE_AUTH; server_auth_->username = username; diff --git a/net/url_request/url_request_ftp_job.h b/net/url_request/url_request_ftp_job.h index 02a034d..c614554 100644 --- a/net/url_request/url_request_ftp_job.h +++ b/net/url_request/url_request_ftp_job.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// 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. @@ -8,6 +8,7 @@ #include <string> +#include "base/string16.h" #include "net/base/auth.h" #include "net/base/completion_callback.h" #include "net/ftp/ftp_request_info.h" @@ -42,8 +43,8 @@ class URLRequestFtpJob : public URLRequestJob { virtual bool NeedsAuth(); virtual void GetAuthChallengeInfo( scoped_refptr<net::AuthChallengeInfo>* auth_info); - virtual void SetAuth(const std::wstring& username, - const std::wstring& password); + virtual void SetAuth(const string16& username, + const string16& password); virtual void CancelAuth(); // TODO(ibrar): Yet to give another look at this function. diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc index 9a03213..cbccff2 100644 --- a/net/url_request/url_request_http_job.cc +++ b/net/url_request/url_request_http_job.cc @@ -310,8 +310,8 @@ void URLRequestHttpJob::GetAuthChallengeInfo( *result = response_info_->auth_challenge; } -void URLRequestHttpJob::SetAuth(const std::wstring& username, - const std::wstring& password) { +void URLRequestHttpJob::SetAuth(const string16& username, + const string16& password) { DCHECK(transaction_.get()); // Proxy gets set first, then WWW. @@ -326,8 +326,8 @@ void URLRequestHttpJob::SetAuth(const std::wstring& username, } void URLRequestHttpJob::RestartTransactionWithAuth( - const std::wstring& username, - const std::wstring& password) { + const string16& username, + const string16& password) { username_ = username; password_ = password; @@ -596,7 +596,7 @@ void URLRequestHttpJob::NotifyHeadersComplete() { // notified of the headers completion so that we can update the cookie store. if (transaction_->IsReadyToRestartForAuth()) { DCHECK(!response_info_->auth_challenge.get()); - RestartTransactionWithAuth(std::wstring(), std::wstring()); + RestartTransactionWithAuth(string16(), string16()); return; } diff --git a/net/url_request/url_request_http_job.h b/net/url_request/url_request_http_job.h index 223edf8..ea2e544 100644 --- a/net/url_request/url_request_http_job.h +++ b/net/url_request/url_request_http_job.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// 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. @@ -11,6 +11,7 @@ #include <vector> #include "base/scoped_ptr.h" +#include "base/string16.h" #include "net/base/auth.h" #include "net/base/completion_callback.h" #include "net/http/http_request_info.h" @@ -50,8 +51,8 @@ class URLRequestHttpJob : public URLRequestJob { virtual bool IsSafeRedirect(const GURL& location); virtual bool NeedsAuth(); virtual void GetAuthChallengeInfo(scoped_refptr<net::AuthChallengeInfo>*); - virtual void SetAuth(const std::wstring& username, - const std::wstring& password); + virtual void SetAuth(const string16& username, + const string16& password); virtual void CancelAuth(); virtual void ContinueWithCertificate(net::X509Certificate* client_cert); virtual void ContinueDespiteLastError(); @@ -80,8 +81,8 @@ class URLRequestHttpJob : public URLRequestJob { bool ShouldTreatAsCertificateError(int result); - void RestartTransactionWithAuth(const std::wstring& username, - const std::wstring& password); + void RestartTransactionWithAuth(const string16& username, + const string16& password); // Keep a reference to the url request context to be sure it's not deleted // before us. @@ -97,8 +98,8 @@ class URLRequestHttpJob : public URLRequestJob { net::AuthState proxy_auth_state_; net::AuthState server_auth_state_; - std::wstring username_; - std::wstring password_; + string16 username_; + string16 password_; net::CompletionCallbackImpl<URLRequestHttpJob> can_get_cookies_callback_; net::CompletionCallbackImpl<URLRequestHttpJob> can_set_cookie_callback_; diff --git a/net/url_request/url_request_job.cc b/net/url_request/url_request_job.cc index 7ce60c3..11fc46d5 100644 --- a/net/url_request/url_request_job.cc +++ b/net/url_request/url_request_job.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// 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. @@ -110,8 +110,8 @@ void URLRequestJob::GetAuthChallengeInfo( NOTREACHED(); } -void URLRequestJob::SetAuth(const std::wstring& username, - const std::wstring& password) { +void URLRequestJob::SetAuth(const string16& username, + const string16& password) { // This will only be called if NeedsAuth() returns true, in which // case the derived class should implement this! NOTREACHED(); diff --git a/net/url_request/url_request_job.h b/net/url_request/url_request_job.h index 7cd496b..05f55bc 100644 --- a/net/url_request/url_request_job.h +++ b/net/url_request/url_request_job.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// 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. @@ -11,6 +11,7 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" +#include "base/string16.h" #include "base/time.h" #include "googleurl/src/gurl.h" #include "net/base/filter.h" @@ -171,8 +172,8 @@ class URLRequestJob : public base::RefCountedThreadSafe<URLRequestJob>, scoped_refptr<net::AuthChallengeInfo>* auth_info); // Resend the request with authentication credentials. - virtual void SetAuth(const std::wstring& username, - const std::wstring& password); + virtual void SetAuth(const string16& username, + const string16& password); // Display the error page without asking for credentials again. virtual void CancelAuth(); diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index 8c842fe..bfbd290 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. +// 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. @@ -51,6 +51,10 @@ using base::Time; namespace { +const string16 kChrome(ASCIIToUTF16("chrome")); +const string16 kSecret(ASCIIToUTF16("secret")); +const string16 kUser(ASCIIToUTF16("user")); + base::StringPiece TestNetResourceProvider(int key) { return "header"; } @@ -1165,8 +1169,8 @@ TEST_F(URLRequestTestHTTP, BasicAuth) { // populate the cache { TestDelegate d; - d.set_username(L"user"); - d.set_password(L"secret"); + d.set_username(kUser); + d.set_password(kSecret); URLRequest r(server_->TestServerPage("auth-basic"), &d); r.set_context(context); @@ -1182,8 +1186,8 @@ TEST_F(URLRequestTestHTTP, BasicAuth) { // response should be fetched from the cache. { TestDelegate d; - d.set_username(L"user"); - d.set_password(L"secret"); + d.set_username(kUser); + d.set_password(kSecret); URLRequest r(server_->TestServerPage("auth-basic"), &d); r.set_context(context); @@ -1212,8 +1216,8 @@ TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { { scoped_refptr<URLRequestContext> context = new TestURLRequestContext(); TestDelegate d; - d.set_username(L"user"); - d.set_password(L"secret"); + d.set_username(kUser); + d.set_password(kSecret); URLRequest r(url_requiring_auth, &d); r.set_context(context); @@ -1771,7 +1775,7 @@ class RestartTestJob : public URLRequestTestJob { this->NotifyRestartRequired(); } private: - ~RestartTestJob() {} + ~RestartTestJob() {} }; class CancelTestJob : public URLRequestTestJob { @@ -2335,8 +2339,8 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongPasswordRestart) { TestDelegate d; // Set correct login credentials. The delegate will be asked for them when // the initial login with wrong credentials will fail. - d.set_username(L"chrome"); - d.set_password(L"chrome"); + d.set_username(kChrome); + d.set_password(kChrome); { TestURLRequest r(server_->TestServerPage("/LICENSE", "chrome", "wrong_password"), &d); @@ -2388,8 +2392,8 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCheckWrongUserRestart) { TestDelegate d; // Set correct login credentials. The delegate will be asked for them when // the initial login with wrong credentials will fail. - d.set_username(L"chrome"); - d.set_password(L"chrome"); + d.set_username(kChrome); + d.set_password(kChrome); { TestURLRequest r(server_->TestServerPage("/LICENSE", "wrong_user", "chrome"), &d); @@ -2464,8 +2468,8 @@ TEST_F(URLRequestTestFTP, FLAKY_FTPCacheLoginBoxCredentials) { scoped_ptr<TestDelegate> d(new TestDelegate); // Set correct login credentials. The delegate will be asked for them when // the initial login with wrong credentials will fail. - d->set_username(L"chrome"); - d->set_password(L"chrome"); + d->set_username(kChrome); + d->set_password(kChrome); { TestURLRequest r(server_->TestServerPage("/LICENSE", "chrome", "wrong_password"), diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h index 39dc5bf..92f527f 100644 --- a/net/url_request/url_request_unittest.h +++ b/net/url_request/url_request_unittest.h @@ -18,6 +18,7 @@ #include "base/message_loop.h" #include "base/path_service.h" #include "base/process_util.h" +#include "base/string16.h" #include "base/thread.h" #include "base/time.h" #include "base/utf_string_conversions.h" @@ -346,8 +347,8 @@ class TestDelegate : public URLRequest::Delegate { void set_allow_certificate_errors(bool val) { allow_certificate_errors_ = val; } - void set_username(const std::wstring& u) { username_ = u; } - void set_password(const std::wstring& p) { password_ = p; } + void set_username(const string16& u) { username_ = u; } + void set_password(const string16& p) { password_ = p; } // query state const std::string& data_received() const { return data_received_; } @@ -376,8 +377,8 @@ class TestDelegate : public URLRequest::Delegate { bool quit_on_redirect_; bool allow_certificate_errors_; - std::wstring username_; - std::wstring password_; + string16 username_; + string16 password_; // tracks status of callbacks int response_started_count_; diff --git a/net/websockets/websocket_job.cc b/net/websockets/websocket_job.cc index 17dc54b..ba79c44 100644 --- a/net/websockets/websocket_job.cc +++ b/net/websockets/websocket_job.cc @@ -134,8 +134,8 @@ void WebSocketJob::Close() { } void WebSocketJob::RestartWithAuth( - const std::wstring& username, - const std::wstring& password) { + const string16& username, + const string16& password) { state_ = CONNECTING; socket_->RestartWithAuth(username, password); } diff --git a/net/websockets/websocket_job.h b/net/websockets/websocket_job.h index d1dae8d..f19653d 100644 --- a/net/websockets/websocket_job.h +++ b/net/websockets/websocket_job.h @@ -9,6 +9,7 @@ #include <string> #include <vector> +#include "base/string16.h" #include "net/base/address_list.h" #include "net/base/completion_callback.h" #include "net/socket_stream/socket_stream_job.h" @@ -47,8 +48,8 @@ class WebSocketJob : public SocketStreamJob, public SocketStream::Delegate { virtual bool SendData(const char* data, int len); virtual void Close(); virtual void RestartWithAuth( - const std::wstring& username, - const std::wstring& password); + const string16& username, + const string16& password); virtual void DetachDelegate(); // SocketStream::Delegate methods. diff --git a/net/websockets/websocket_job_unittest.cc b/net/websockets/websocket_job_unittest.cc index f33b42c..0136759 100644 --- a/net/websockets/websocket_job_unittest.cc +++ b/net/websockets/websocket_job_unittest.cc @@ -35,7 +35,7 @@ class MockSocketStream : public SocketStream { virtual void Close() {} virtual void RestartWithAuth( - const std::wstring& username, const std::wstring& password) {} + const string16& username, const string16& password) {} virtual void DetachDelegate() { delegate_ = NULL; } |