From 6d81b488e8cc5e10eaeca0a4ee4819dc3f469a24 Mon Sep 17 00:00:00 2001 From: "bryner@chromium.org" Date: Tue, 22 Feb 2011 19:47:19 +0000 Subject: Propagate the remote socket address to URLRequest and to ViewHostMsg_FrameNavigate. This will be used to run pre-classification checks for client-side phishing detection, and will also enable the socket address to be exposed via the webRequest extension API. This is adapted from the original patch by pmarks on http://codereview.chromium.org/6369003/ . BUG=51663 TEST=added socket address checks to various unittests Review URL: http://codereview.chromium.org/6488010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75620 0039d316-1c4b-4281-b951-d872f2087c98 --- net/ftp/ftp_network_transaction.cc | 12 ++++++++++-- net/ftp/ftp_network_transaction_unittest.cc | 7 +++++++ net/ftp/ftp_response_info.h | 4 ++++ 3 files changed, 21 insertions(+), 2 deletions(-) (limited to 'net/ftp') diff --git a/net/ftp/ftp_network_transaction.cc b/net/ftp/ftp_network_transaction.cc index d012818..3f35c83 100644 --- a/net/ftp/ftp_network_transaction.cc +++ b/net/ftp/ftp_network_transaction.cc @@ -9,6 +9,7 @@ #include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "net/base/address_list.h" #include "net/base/connection_type_histograms.h" #include "net/base/escape.h" #include "net/base/net_errors.h" @@ -620,8 +621,15 @@ int FtpNetworkTransaction::DoCtrlConnect() { } int FtpNetworkTransaction::DoCtrlConnectComplete(int result) { - if (result == OK) - next_state_ = STATE_CTRL_READ; + if (result == OK) { + // Put the peer's IP address and port into the response. + AddressList address; + result = ctrl_socket_->GetPeerAddress(&address); + if (result == OK) { + response_.socket_address = HostPortPair::FromAddrInfo(address.head()); + next_state_ = STATE_CTRL_READ; + } + } return result; } diff --git a/net/ftp/ftp_network_transaction_unittest.cc b/net/ftp/ftp_network_transaction_unittest.cc index 8da3baf..1d86fba 100644 --- a/net/ftp/ftp_network_transaction_unittest.cc +++ b/net/ftp/ftp_network_transaction_unittest.cc @@ -9,6 +9,7 @@ #include "base/ref_counted.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" +#include "net/base/host_port_pair.h" #include "net/base/io_buffer.h" #include "net/base/mock_host_resolver.h" #include "net/base/net_util.h" @@ -831,6 +832,9 @@ TEST_F(FtpNetworkTransactionTest, DirectoryTransaction) { EXPECT_TRUE(transaction_.GetResponseInfo()->is_directory_listing); EXPECT_EQ(-1, transaction_.GetResponseInfo()->expected_content_size); + EXPECT_EQ("192.0.2.33", + transaction_.GetResponseInfo()->socket_address.host()); + EXPECT_EQ(0, transaction_.GetResponseInfo()->socket_address.port()); } TEST_F(FtpNetworkTransactionTest, DirectoryTransactionWithPasvFallback) { @@ -904,6 +908,9 @@ TEST_F(FtpNetworkTransactionTest, DownloadTransaction) { // We pass an artificial value of 18 as a response to the SIZE command. EXPECT_EQ(18, transaction_.GetResponseInfo()->expected_content_size); + EXPECT_EQ("192.0.2.33", + transaction_.GetResponseInfo()->socket_address.host()); + EXPECT_EQ(0, transaction_.GetResponseInfo()->socket_address.port()); } TEST_F(FtpNetworkTransactionTest, DownloadTransactionWithPasvFallback) { diff --git a/net/ftp/ftp_response_info.h b/net/ftp/ftp_response_info.h index 0c8884c..9db9018 100644 --- a/net/ftp/ftp_response_info.h +++ b/net/ftp/ftp_response_info.h @@ -7,6 +7,7 @@ #pragma once #include "base/time.h" +#include "net/base/host_port_pair.h" namespace net { @@ -36,6 +37,9 @@ class FtpResponseInfo { // True if the response data is of a directory listing. bool is_directory_listing; + + // Remote address of the socket which fetched this resource. + HostPortPair socket_address; }; } // namespace net -- cgit v1.1