summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorpauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-19 01:56:44 +0000
committerpauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-19 01:56:44 +0000
commit57486fd5b68831b8e3df30becd18c2dc2d4ba7f5 (patch)
tree73dc7e2784b97c1c1d9cbed12a957ea52e1b124c /net
parentc21fcc5b17f1a7234d7649dbc4d24c3b9918605f (diff)
downloadchromium_src-57486fd5b68831b8e3df30becd18c2dc2d4ba7f5.zip
chromium_src-57486fd5b68831b8e3df30becd18c2dc2d4ba7f5.tar.gz
chromium_src-57486fd5b68831b8e3df30becd18c2dc2d4ba7f5.tar.bz2
Removed static factories for data, ftp, file, and about jobs.
Instead add corresponding ProtocolHandlers as needed. Remove URLRequestContext members used by these static factories. Bake FtpAuthCache into FtpProtocolHandler as it was already unique per FtpProtocolHandler. This is a revived version of http://crrev.com/10836206 BUG=142945 Review URL: https://chromiumcodereview.appspot.com/11931024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@188912 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r--net/ftp/ftp_network_session.h3
-rw-r--r--net/proxy/proxy_script_fetcher_impl_unittest.cc5
-rw-r--r--net/url_request/file_protocol_handler.cc4
-rw-r--r--net/url_request/file_protocol_handler.h3
-rw-r--r--net/url_request/ftp_protocol_handler.cc9
-rw-r--r--net/url_request/ftp_protocol_handler.h7
-rw-r--r--net/url_request/protocol_intercept_job_factory.cc5
-rw-r--r--net/url_request/protocol_intercept_job_factory.h3
-rw-r--r--net/url_request/url_request_about_job.cc7
-rw-r--r--net/url_request/url_request_about_job.h2
-rw-r--r--net/url_request/url_request_context.cc7
-rw-r--r--net/url_request/url_request_context.h23
-rw-r--r--net/url_request/url_request_context_builder.cc30
-rw-r--r--net/url_request/url_request_context_builder.h23
-rw-r--r--net/url_request/url_request_context_storage.cc6
-rw-r--r--net/url_request/url_request_context_storage.h3
-rw-r--r--net/url_request/url_request_data_job.cc7
-rw-r--r--net/url_request/url_request_data_job.h2
-rw-r--r--net/url_request/url_request_file_job.cc28
-rw-r--r--net/url_request/url_request_file_job.h2
-rw-r--r--net/url_request/url_request_ftp_job.cc21
-rw-r--r--net/url_request/url_request_ftp_job.h5
-rw-r--r--net/url_request/url_request_ftp_job_unittest.cc20
-rw-r--r--net/url_request/url_request_http_job.cc26
-rw-r--r--net/url_request/url_request_job_factory.cc5
-rw-r--r--net/url_request/url_request_job_factory.h9
-rw-r--r--net/url_request/url_request_job_factory_impl.cc16
-rw-r--r--net/url_request/url_request_job_factory_impl.h1
-rw-r--r--net/url_request/url_request_job_manager.cc10
-rw-r--r--net/url_request/url_request_test_util.cc8
-rw-r--r--net/url_request/url_request_unittest.cc32
31 files changed, 153 insertions, 179 deletions
diff --git a/net/ftp/ftp_network_session.h b/net/ftp/ftp_network_session.h
index c9b3388..e92bb06 100644
--- a/net/ftp/ftp_network_session.h
+++ b/net/ftp/ftp_network_session.h
@@ -7,7 +7,6 @@
#include "base/memory/ref_counted.h"
#include "net/base/net_export.h"
-#include "net/ftp/ftp_auth_cache.h"
namespace net {
@@ -20,7 +19,6 @@ class NET_EXPORT_PRIVATE FtpNetworkSession
explicit FtpNetworkSession(HostResolver* host_resolver);
HostResolver* host_resolver() { return host_resolver_; }
- FtpAuthCache* auth_cache() { return &auth_cache_; }
private:
friend class base::RefCounted<FtpNetworkSession>;
@@ -28,7 +26,6 @@ class NET_EXPORT_PRIVATE FtpNetworkSession
virtual ~FtpNetworkSession();
HostResolver* const host_resolver_;
- FtpAuthCache auth_cache_;
};
} // namespace net
diff --git a/net/proxy/proxy_script_fetcher_impl_unittest.cc b/net/proxy/proxy_script_fetcher_impl_unittest.cc
index e4ea2b9..42117e3 100644
--- a/net/proxy/proxy_script_fetcher_impl_unittest.cc
+++ b/net/proxy/proxy_script_fetcher_impl_unittest.cc
@@ -21,6 +21,7 @@
#include "net/http/http_server_properties_impl.h"
#include "net/ssl/ssl_config_service_defaults.h"
#include "net/test/test_server.h"
+#include "net/url_request/file_protocol_handler.h"
#include "net/url_request/url_request_context_storage.h"
#include "net/url_request/url_request_file_job.h"
#include "net/url_request/url_request_job_factory_impl.h"
@@ -66,7 +67,9 @@ class RequestContext : public URLRequestContext {
storage_.set_http_transaction_factory(new HttpCache(
network_session,
HttpCache::DefaultBackend::InMemory(0)));
- storage_.set_job_factory(new URLRequestJobFactoryImpl());
+ URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl();
+ job_factory->SetProtocolHandler("file", new FileProtocolHandler());
+ storage_.set_job_factory(job_factory);
}
virtual ~RequestContext() {
diff --git a/net/url_request/file_protocol_handler.cc b/net/url_request/file_protocol_handler.cc
index 13a772e..c58c56b 100644
--- a/net/url_request/file_protocol_handler.cc
+++ b/net/url_request/file_protocol_handler.cc
@@ -44,4 +44,8 @@ URLRequestJob* FileProtocolHandler::MaybeCreateJob(
return new URLRequestFileJob(request, network_delegate, file_path);
}
+bool FileProtocolHandler::IsSafeRedirectTarget(const GURL& location) const {
+ return false;
+}
+
} // namespace net
diff --git a/net/url_request/file_protocol_handler.h b/net/url_request/file_protocol_handler.h
index 619227b..8087a6e 100644
--- a/net/url_request/file_protocol_handler.h
+++ b/net/url_request/file_protocol_handler.h
@@ -9,6 +9,8 @@
#include "base/compiler_specific.h"
#include "net/url_request/url_request_job_factory.h"
+class GURL;
+
namespace net {
class NetworkDelegate;
@@ -22,6 +24,7 @@ class NET_EXPORT FileProtocolHandler :
FileProtocolHandler();
virtual URLRequestJob* MaybeCreateJob(
URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE;
+ virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(FileProtocolHandler);
diff --git a/net/url_request/ftp_protocol_handler.cc b/net/url_request/ftp_protocol_handler.cc
index 7d9ba88..08071f3 100644
--- a/net/url_request/ftp_protocol_handler.cc
+++ b/net/url_request/ftp_protocol_handler.cc
@@ -15,12 +15,9 @@
namespace net {
FtpProtocolHandler::FtpProtocolHandler(
- FtpTransactionFactory* ftp_transaction_factory,
- FtpAuthCache* ftp_auth_cache)
- : ftp_transaction_factory_(ftp_transaction_factory),
- ftp_auth_cache_(ftp_auth_cache) {
+ FtpTransactionFactory* ftp_transaction_factory)
+ : ftp_transaction_factory_(ftp_transaction_factory) {
DCHECK(ftp_transaction_factory_);
- DCHECK(ftp_auth_cache_);
}
URLRequestJob* FtpProtocolHandler::MaybeCreateJob(
@@ -34,7 +31,7 @@ URLRequestJob* FtpProtocolHandler::MaybeCreateJob(
return new URLRequestFtpJob(request,
network_delegate,
ftp_transaction_factory_,
- ftp_auth_cache_);
+ &ftp_auth_cache_);
}
} // namespace net
diff --git a/net/url_request/ftp_protocol_handler.h b/net/url_request/ftp_protocol_handler.h
index 871f422..52aea7c 100644
--- a/net/url_request/ftp_protocol_handler.h
+++ b/net/url_request/ftp_protocol_handler.h
@@ -7,11 +7,11 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
+#include "net/ftp/ftp_auth_cache.h"
#include "net/url_request/url_request_job_factory.h"
namespace net {
-class FtpAuthCache;
class FtpTransactionFactory;
class NetworkDelegate;
class URLRequestJob;
@@ -20,14 +20,13 @@ class URLRequestJob;
class NET_EXPORT FtpProtocolHandler :
public URLRequestJobFactory::ProtocolHandler {
public:
- FtpProtocolHandler(FtpTransactionFactory* ftp_transaction_factory,
- FtpAuthCache* ftp_auth_cache);
+ explicit FtpProtocolHandler(FtpTransactionFactory* ftp_transaction_factory);
virtual URLRequestJob* MaybeCreateJob(
URLRequest* request, NetworkDelegate* network_delegate) const OVERRIDE;
private:
FtpTransactionFactory* ftp_transaction_factory_;
- FtpAuthCache* ftp_auth_cache_;
+ mutable FtpAuthCache ftp_auth_cache_;
DISALLOW_COPY_AND_ASSIGN(FtpProtocolHandler);
};
diff --git a/net/url_request/protocol_intercept_job_factory.cc b/net/url_request/protocol_intercept_job_factory.cc
index f72fbf9..d0f92f4 100644
--- a/net/url_request/protocol_intercept_job_factory.cc
+++ b/net/url_request/protocol_intercept_job_factory.cc
@@ -39,4 +39,9 @@ bool ProtocolInterceptJobFactory::IsHandledURL(const GURL& url) const {
return job_factory_->IsHandledURL(url);
}
+bool ProtocolInterceptJobFactory::IsSafeRedirectTarget(
+ const GURL& location) const {
+ return job_factory_->IsSafeRedirectTarget(location);
+}
+
} // namespace net
diff --git a/net/url_request/protocol_intercept_job_factory.h b/net/url_request/protocol_intercept_job_factory.h
index 7deeb30..abc2fb8 100644
--- a/net/url_request/protocol_intercept_job_factory.h
+++ b/net/url_request/protocol_intercept_job_factory.h
@@ -22,6 +22,8 @@ class URLRequestJob;
// given the option of creating a URLRequestJob for each potential URLRequest.
// If |protocol_handler_| does not create a job (i.e. MaybeCreateJob() returns
// NULL) the URLRequest is forwarded to the |job_factory_| to be handled there.
+// Only the MaybeCreateJob() member of |protocol_handler_| is called; the
+// IsSafeRedirectTarget() member is not used.
class NET_EXPORT ProtocolInterceptJobFactory : public URLRequestJobFactory {
public:
ProtocolInterceptJobFactory(scoped_ptr<URLRequestJobFactory> job_factory,
@@ -35,6 +37,7 @@ class NET_EXPORT ProtocolInterceptJobFactory : public URLRequestJobFactory {
NetworkDelegate* network_delegate) const OVERRIDE;
virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE;
virtual bool IsHandledURL(const GURL& url) const OVERRIDE;
+ virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE;
private:
scoped_ptr<URLRequestJobFactory> job_factory_;
diff --git a/net/url_request/url_request_about_job.cc b/net/url_request/url_request_about_job.cc
index 242a735..04ad6d8 100644
--- a/net/url_request/url_request_about_job.cc
+++ b/net/url_request/url_request_about_job.cc
@@ -20,13 +20,6 @@ URLRequestAboutJob::URLRequestAboutJob(URLRequest* request,
ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)) {
}
-// static
-URLRequestJob* URLRequestAboutJob::Factory(URLRequest* request,
- NetworkDelegate* network_delegate,
- const std::string& scheme) {
- return new URLRequestAboutJob(request, network_delegate);
-}
-
void URLRequestAboutJob::Start() {
// Start reading asynchronously so that all error reporting and data
// callbacks happen as they would for network requests.
diff --git a/net/url_request/url_request_about_job.h b/net/url_request/url_request_about_job.h
index ea2b83f..66a888a 100644
--- a/net/url_request/url_request_about_job.h
+++ b/net/url_request/url_request_about_job.h
@@ -17,8 +17,6 @@ class NET_EXPORT URLRequestAboutJob : public URLRequestJob {
public:
URLRequestAboutJob(URLRequest* request, NetworkDelegate* network_delegate);
- static URLRequest::ProtocolFactory Factory;
-
// URLRequestJob:
virtual void Start() OVERRIDE;
virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
diff --git a/net/url_request/url_request_context.cc b/net/url_request/url_request_context.cc
index e88750b..ae3a938 100644
--- a/net/url_request/url_request_context.cc
+++ b/net/url_request/url_request_context.cc
@@ -10,7 +10,6 @@
#include "base/string_util.h"
#include "net/base/host_resolver.h"
#include "net/cookies/cookie_store.h"
-#include "net/ftp/ftp_transaction_factory.h"
#include "net/http/http_transaction_factory.h"
#include "net/url_request/http_user_agent_settings.h"
#include "net/url_request/url_request.h"
@@ -29,11 +28,7 @@ URLRequestContext::URLRequestContext()
http_server_properties_(NULL),
http_user_agent_settings_(NULL),
transport_security_state_(NULL),
-#if !defined(DISABLE_FTP_SUPPORT)
- ftp_auth_cache_(new FtpAuthCache),
-#endif
http_transaction_factory_(NULL),
- ftp_transaction_factory_(NULL),
job_factory_(NULL),
throttler_manager_(NULL),
url_requests_(new std::set<const URLRequest*>) {
@@ -57,9 +52,7 @@ void URLRequestContext::CopyFrom(const URLRequestContext* other) {
set_http_server_properties(other->http_server_properties_);
set_cookie_store(other->cookie_store_);
set_transport_security_state(other->transport_security_state_);
- // FTPAuthCache is unique per context.
set_http_transaction_factory(other->http_transaction_factory_);
- set_ftp_transaction_factory(other->ftp_transaction_factory_);
set_job_factory(other->job_factory_);
set_throttler_manager(other->throttler_manager_);
set_http_user_agent_settings(other->http_user_agent_settings_);
diff --git a/net/url_request/url_request_context.h b/net/url_request/url_request_context.h
index f5dc635..bb26897 100644
--- a/net/url_request/url_request_context.h
+++ b/net/url_request/url_request_context.h
@@ -19,7 +19,6 @@
#include "base/threading/non_thread_safe.h"
#include "net/base/net_export.h"
#include "net/base/net_log.h"
-#include "net/ftp/ftp_auth_cache.h"
#include "net/http/http_network_session.h"
#include "net/http/http_server_properties.h"
#include "net/http/transport_security_state.h"
@@ -30,7 +29,6 @@ namespace net {
class CertVerifier;
class CookieStore;
class FraudulentCertificateReporter;
-class FtpTransactionFactory;
class HostResolver;
class HttpAuthHandlerFactory;
class HttpTransactionFactory;
@@ -131,14 +129,6 @@ class NET_EXPORT URLRequestContext
http_transaction_factory_ = factory;
}
- // Gets the ftp transaction factory for this context.
- FtpTransactionFactory* ftp_transaction_factory() const {
- return ftp_transaction_factory_;
- }
- void set_ftp_transaction_factory(FtpTransactionFactory* factory) {
- ftp_transaction_factory_ = factory;
- }
-
void set_network_delegate(NetworkDelegate* network_delegate) {
network_delegate_ = network_delegate;
}
@@ -165,15 +155,6 @@ class NET_EXPORT URLRequestContext
transport_security_state_ = state;
}
- // Gets the FTP authentication cache for this context.
- FtpAuthCache* ftp_auth_cache() const {
-#if !defined(DISABLE_FTP_SUPPORT)
- return ftp_auth_cache_.get();
-#else
- return NULL;
-#endif
- }
-
// ---------------------------------------------------------------------------
// Legacy accessors that delegate to http_user_agent_settings_.
// TODO(pauljensen): Remove after all clients are updated to directly access
@@ -237,11 +218,7 @@ class NET_EXPORT URLRequestContext
HttpUserAgentSettings* http_user_agent_settings_;
scoped_refptr<CookieStore> cookie_store_;
TransportSecurityState* transport_security_state_;
-#if !defined(DISABLE_FTP_SUPPORT)
- scoped_ptr<FtpAuthCache> ftp_auth_cache_;
-#endif
HttpTransactionFactory* http_transaction_factory_;
- FtpTransactionFactory* ftp_transaction_factory_;
const URLRequestJobFactory* job_factory_;
URLRequestThrottlerManager* throttler_manager_;
diff --git a/net/url_request/url_request_context_builder.cc b/net/url_request/url_request_context_builder.cc
index 498e0ca..4fd9bd9 100644
--- a/net/url_request/url_request_context_builder.cc
+++ b/net/url_request/url_request_context_builder.cc
@@ -26,9 +26,13 @@
#include "net/http/transport_security_state.h"
#include "net/proxy/proxy_service.h"
#include "net/ssl/ssl_config_service_defaults.h"
+#include "net/url_request/data_protocol_handler.h"
+#include "net/url_request/file_protocol_handler.h"
+#include "net/url_request/ftp_protocol_handler.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_context_storage.h"
+#include "net/url_request/url_request_job_factory_impl.h"
namespace net {
@@ -180,7 +184,11 @@ URLRequestContextBuilder::HttpNetworkSessionParams::~HttpNetworkSessionParams()
{}
URLRequestContextBuilder::URLRequestContextBuilder()
- : ftp_enabled_(false),
+ : data_enabled_(false),
+ file_enabled_(false),
+#if !defined(DISABLE_FTP_SUPPORT)
+ ftp_enabled_(false),
+#endif
http_cache_enabled_(true) {}
URLRequestContextBuilder::~URLRequestContextBuilder() {}
@@ -205,11 +213,6 @@ URLRequestContext* URLRequestContextBuilder::Build() {
storage->set_host_resolver(net::HostResolver::CreateDefaultResolver(NULL));
- if (ftp_enabled_) {
- storage->set_ftp_transaction_factory(
- new FtpNetworkLayer(context->host_resolver()));
- }
-
context->StartFileThread();
// TODO(willchan): Switch to using this code when
@@ -290,6 +293,21 @@ URLRequestContext* URLRequestContextBuilder::Build() {
}
storage->set_http_transaction_factory(http_transaction_factory);
+ URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl;
+ if (data_enabled_)
+ job_factory->SetProtocolHandler("data", new DataProtocolHandler);
+ if (file_enabled_)
+ job_factory->SetProtocolHandler("file", new FileProtocolHandler);
+#if !defined(DISABLE_FTP_SUPPORT)
+ if (ftp_enabled_) {
+ ftp_transaction_factory_.reset(
+ new FtpNetworkLayer(context->host_resolver()));
+ job_factory->SetProtocolHandler("ftp",
+ new FtpProtocolHandler(ftp_transaction_factory_.get()));
+ }
+#endif
+ storage->set_job_factory(job_factory);
+
// TODO(willchan): Support sdch.
return context;
diff --git a/net/url_request/url_request_context_builder.h b/net/url_request/url_request_context_builder.h
index 2163ed5..20fc30e 100644
--- a/net/url_request/url_request_context_builder.h
+++ b/net/url_request/url_request_context_builder.h
@@ -25,6 +25,7 @@
namespace net {
+class FtpTransactionFactory;
class HostMappingRules;
class ProxyConfigService;
class URLRequestContext;
@@ -82,10 +83,22 @@ class NET_EXPORT URLRequestContextBuilder {
user_agent_ = user_agent;
}
- // By default it's disabled.
+ // Control support for data:// requests. By default it's disabled.
+ void set_data_enabled(bool enable) {
+ data_enabled_ = enable;
+ }
+
+ // Control support for file:// requests. By default it's disabled.
+ void set_file_enabled(bool enable) {
+ file_enabled_ = enable;
+ }
+
+#if !defined(DISABLE_FTP_SUPPORT)
+ // Control support for ftp:// requests. By default it's disabled.
void set_ftp_enabled(bool enable) {
ftp_enabled_ = enable;
}
+#endif
// Uses BasicNetworkDelegate by default. Note that calling Build will unset
// any custom delegate in builder, so this must be called each time before
@@ -114,7 +127,14 @@ class NET_EXPORT URLRequestContextBuilder {
private:
std::string accept_language_;
std::string user_agent_;
+ // Include support for data:// requests.
+ bool data_enabled_;
+ // Include support for file:// requests.
+ bool file_enabled_;
+#if !defined(DISABLE_FTP_SUPPORT)
+ // Include support for ftp:// requests.
bool ftp_enabled_;
+#endif
bool http_cache_enabled_;
HttpCacheParams http_cache_params_;
HttpNetworkSessionParams http_network_session_params_;
@@ -122,6 +142,7 @@ class NET_EXPORT URLRequestContextBuilder {
scoped_ptr<ProxyConfigService> proxy_config_service_;
#endif // defined(OS_LINUX) || defined(OS_ANDROID)
scoped_ptr<NetworkDelegate> network_delegate_;
+ scoped_ptr<FtpTransactionFactory> ftp_transaction_factory_;
DISALLOW_COPY_AND_ASSIGN(URLRequestContextBuilder);
};
diff --git a/net/url_request/url_request_context_storage.cc b/net/url_request/url_request_context_storage.cc
index e201b8e..7104ab8 100644
--- a/net/url_request/url_request_context_storage.cc
+++ b/net/url_request/url_request_context_storage.cc
@@ -106,12 +106,6 @@ void URLRequestContextStorage::set_http_transaction_factory(
http_transaction_factory_.reset(http_transaction_factory);
}
-void URLRequestContextStorage::set_ftp_transaction_factory(
- FtpTransactionFactory* ftp_transaction_factory) {
- context_->set_ftp_transaction_factory(ftp_transaction_factory);
- ftp_transaction_factory_.reset(ftp_transaction_factory);
-}
-
void URLRequestContextStorage::set_job_factory(
URLRequestJobFactory* job_factory) {
context_->set_job_factory(job_factory);
diff --git a/net/url_request/url_request_context_storage.h b/net/url_request/url_request_context_storage.h
index e08b3c8..0a9d066 100644
--- a/net/url_request/url_request_context_storage.h
+++ b/net/url_request/url_request_context_storage.h
@@ -62,8 +62,6 @@ class NET_EXPORT URLRequestContextStorage {
TransportSecurityState* transport_security_state);
void set_http_transaction_factory(
HttpTransactionFactory* http_transaction_factory);
- void set_ftp_transaction_factory(
- FtpTransactionFactory* ftp_transaction_factory);
void set_job_factory(URLRequestJobFactory* job_factory);
void set_throttler_manager(URLRequestThrottlerManager* throttler_manager);
void set_http_user_agent_settings(
@@ -93,7 +91,6 @@ class NET_EXPORT URLRequestContextStorage {
scoped_ptr<TransportSecurityState> transport_security_state_;
scoped_ptr<HttpTransactionFactory> http_transaction_factory_;
- scoped_ptr<FtpTransactionFactory> ftp_transaction_factory_;
scoped_ptr<URLRequestJobFactory> job_factory_;
scoped_ptr<URLRequestThrottlerManager> throttler_manager_;
diff --git a/net/url_request/url_request_data_job.cc b/net/url_request/url_request_data_job.cc
index 5dffe32..fd248c7 100644
--- a/net/url_request/url_request_data_job.cc
+++ b/net/url_request/url_request_data_job.cc
@@ -16,13 +16,6 @@ URLRequestDataJob::URLRequestDataJob(
: URLRequestSimpleJob(request, network_delegate) {
}
-// static
-URLRequestJob* URLRequestDataJob::Factory(URLRequest* request,
- NetworkDelegate* network_delegate,
- const std::string& scheme) {
- return new URLRequestDataJob(request, network_delegate);
-}
-
int URLRequestDataJob::GetData(std::string* mime_type,
std::string* charset,
std::string* data,
diff --git a/net/url_request/url_request_data_job.h b/net/url_request/url_request_data_job.h
index 7ab6561..d9b2621 100644
--- a/net/url_request/url_request_data_job.h
+++ b/net/url_request/url_request_data_job.h
@@ -18,8 +18,6 @@ class URLRequestDataJob : public URLRequestSimpleJob {
public:
URLRequestDataJob(URLRequest* request, NetworkDelegate* network_delegate);
- static URLRequest::ProtocolFactory Factory;
-
// URLRequestSimpleJob
virtual int GetData(std::string* mime_type,
std::string* charset,
diff --git a/net/url_request/url_request_file_job.cc b/net/url_request/url_request_file_job.cc
index 6b2798b..28dbcd5 100644
--- a/net/url_request/url_request_file_job.cc
+++ b/net/url_request/url_request_file_job.cc
@@ -62,34 +62,6 @@ URLRequestFileJob::URLRequestFileJob(URLRequest* request,
weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
}
-// static
-URLRequestJob* URLRequestFileJob::Factory(URLRequest* request,
- NetworkDelegate* network_delegate,
- const std::string& scheme) {
- base::FilePath file_path;
- const bool is_file = FileURLToFilePath(request->url(), &file_path);
-
- // Check file access permissions.
- if (!network_delegate ||
- !network_delegate->CanAccessFile(*request, file_path)) {
- return new URLRequestErrorJob(request, network_delegate, ERR_ACCESS_DENIED);
- }
- // We need to decide whether to create URLRequestFileJob for file access or
- // URLRequestFileDirJob for directory access. To avoid accessing the
- // filesystem, we only look at the path string here.
- // The code in the URLRequestFileJob::Start() method discovers that a path,
- // which doesn't end with a slash, should really be treated as a directory,
- // and it then redirects to the URLRequestFileDirJob.
- if (is_file &&
- file_util::EndsWithSeparator(file_path) &&
- file_path.IsAbsolute())
- return new URLRequestFileDirJob(request, network_delegate, file_path);
-
- // Use a regular file request job for all non-directories (including invalid
- // file names).
- return new URLRequestFileJob(request, network_delegate, file_path);
-}
-
void URLRequestFileJob::Start() {
FileMetaInfo* meta_info = new FileMetaInfo();
base::WorkerPool::PostTaskAndReply(
diff --git a/net/url_request/url_request_file_job.h b/net/url_request/url_request_file_job.h
index 0d9e192..6fc7fb9 100644
--- a/net/url_request/url_request_file_job.h
+++ b/net/url_request/url_request_file_job.h
@@ -33,8 +33,6 @@ class NET_EXPORT URLRequestFileJob : public URLRequestJob {
NetworkDelegate* network_delegate,
const base::FilePath& file_path);
- static URLRequest::ProtocolFactory Factory;
-
// URLRequestJob:
virtual void Start() OVERRIDE;
virtual void Kill() OVERRIDE;
diff --git a/net/url_request/url_request_ftp_job.cc b/net/url_request/url_request_ftp_job.cc
index 343c4d7..62124e1 100644
--- a/net/url_request/url_request_ftp_job.cc
+++ b/net/url_request/url_request_ftp_job.cc
@@ -12,6 +12,7 @@
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/base/net_util.h"
+#include "net/ftp/ftp_auth_cache.h"
#include "net/ftp/ftp_response_info.h"
#include "net/ftp/ftp_transaction_factory.h"
#include "net/http/http_response_headers.h"
@@ -38,26 +39,6 @@ URLRequestFtpJob::URLRequestFtpJob(
DCHECK(ftp_auth_cache);
}
-// static
-URLRequestJob* URLRequestFtpJob::Factory(URLRequest* request,
- NetworkDelegate* network_delegate,
- const std::string& scheme) {
- DCHECK_EQ(scheme, "ftp");
-
- int port = request->url().IntPort();
- if (request->url().has_port() &&
- !IsPortAllowedByFtp(port) && !IsPortAllowedByOverride(port)) {
- return new URLRequestErrorJob(request,
- network_delegate,
- ERR_UNSAFE_PORT);
- }
-
- return new URLRequestFtpJob(request,
- network_delegate,
- request->context()->ftp_transaction_factory(),
- request->context()->ftp_auth_cache());
-}
-
bool URLRequestFtpJob::IsSafeRedirect(const GURL& location) {
// Disallow all redirects.
return false;
diff --git a/net/url_request/url_request_ftp_job.h b/net/url_request/url_request_ftp_job.h
index 3b053c1..dd16b9a 100644
--- a/net/url_request/url_request_ftp_job.h
+++ b/net/url_request/url_request_ftp_job.h
@@ -32,11 +32,6 @@ class URLRequestFtpJob : public URLRequestJob {
FtpTransactionFactory* ftp_transaction_factory,
FtpAuthCache* ftp_auth_cache);
- // TODO(shalev): get rid of this function in favor of FtpProtocolHandler.
- static URLRequestJob* Factory(URLRequest* request,
- NetworkDelegate* network_delegate,
- const std::string& scheme);
-
// Overridden from URLRequestJob:
virtual bool IsSafeRedirect(const GURL& location) OVERRIDE;
virtual bool GetMimeType(std::string* mime_type) const OVERRIDE;
diff --git a/net/url_request/url_request_ftp_job_unittest.cc b/net/url_request/url_request_ftp_job_unittest.cc
index 61dde753..50f5d05 100644
--- a/net/url_request/url_request_ftp_job_unittest.cc
+++ b/net/url_request/url_request_ftp_job_unittest.cc
@@ -6,10 +6,13 @@
#include "base/run_loop.h"
#include "net/proxy/proxy_config_service.h"
#include "net/socket/socket_test_util.h"
+#include "net/url_request/ftp_protocol_handler.h"
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
+#include "net/url_request/url_request_job_factory_impl.h"
#include "net/url_request/url_request_status.h"
#include "net/url_request/url_request_test_util.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace net {
@@ -49,15 +52,26 @@ class SimpleProxyConfigService : public ProxyConfigService {
Observer* observer_;
};
+class MockFtpTransactionFactory : public FtpTransactionFactory {
+ public:
+ MOCK_METHOD0(CreateTransaction, FtpTransaction*());
+ MOCK_METHOD1(Suspend, void(bool suspend));
+};
+
class FtpTestURLRequestContext : public TestURLRequestContext {
public:
FtpTestURLRequestContext(ClientSocketFactory* socket_factory,
ProxyService* proxy_service,
- NetworkDelegate* network_delegate)
+ NetworkDelegate* network_delegate,
+ FtpTransactionFactory* ftp_transaction_factory)
: TestURLRequestContext(true) {
set_client_socket_factory(socket_factory);
context_storage_.set_proxy_service(proxy_service);
set_network_delegate(network_delegate);
+ URLRequestJobFactoryImpl* job_factory = new URLRequestJobFactoryImpl;
+ job_factory->SetProtocolHandler(
+ "ftp", new FtpProtocolHandler(ftp_transaction_factory));
+ context_storage_.set_job_factory(job_factory);
Init();
}
};
@@ -69,7 +83,8 @@ class URLRequestFtpJobTest : public testing::Test {
new SimpleProxyConfigService, NULL, NULL)),
request_context_(&socket_factory_,
proxy_service_,
- &network_delegate_) {
+ &network_delegate_,
+ &ftp_transaction_factory_) {
}
virtual ~URLRequestFtpJobTest() {
@@ -99,6 +114,7 @@ class URLRequestFtpJobTest : public testing::Test {
ScopedVector<DeterministicSocketData> socket_data_;
DeterministicMockClientSocketFactory socket_factory_;
TestNetworkDelegate network_delegate_;
+ ::testing::StrictMock<MockFtpTransactionFactory> ftp_transaction_factory_;
// Owned by |request_context_|:
ProxyService* proxy_service_;
diff --git a/net/url_request/url_request_http_job.cc b/net/url_request/url_request_http_job.cc
index 716fe4c..5b116b9 100644
--- a/net/url_request/url_request_http_job.cc
+++ b/net/url_request/url_request_http_job.cc
@@ -43,6 +43,7 @@
#include "net/url_request/url_request.h"
#include "net/url_request/url_request_context.h"
#include "net/url_request/url_request_error_job.h"
+#include "net/url_request/url_request_job_factory.h"
#include "net/url_request/url_request_redirect_job.h"
#include "net/url_request/url_request_throttler_header_adapter.h"
#include "net/url_request/url_request_throttler_manager.h"
@@ -1013,25 +1014,16 @@ Filter* URLRequestHttpJob::SetupFilter() const {
}
bool URLRequestHttpJob::IsSafeRedirect(const GURL& location) {
- // We only allow redirects to certain "safe" protocols. This does not
- // restrict redirects to externally handled protocols. Our consumer would
- // need to take care of those.
-
- if (!URLRequest::IsHandledURL(location))
+ // HTTP is always safe.
+ // TODO(pauljensen): Remove once crbug.com/146591 is fixed.
+ if (location.is_valid() &&
+ (location.scheme() == "http" || location.scheme() == "https")) {
return true;
-
- static const char* kSafeSchemes[] = {
- "http",
- "https",
- "ftp"
- };
-
- for (size_t i = 0; i < arraysize(kSafeSchemes); ++i) {
- if (location.SchemeIs(kSafeSchemes[i]))
- return true;
}
-
- return false;
+ // Query URLRequestJobFactory as to whether |location| would be safe to
+ // redirect to.
+ return request_->context()->job_factory() &&
+ request_->context()->job_factory()->IsSafeRedirectTarget(location);
}
bool URLRequestHttpJob::NeedsAuth() {
diff --git a/net/url_request/url_request_job_factory.cc b/net/url_request/url_request_job_factory.cc
index c1f070b..e203cb1 100644
--- a/net/url_request/url_request_job_factory.cc
+++ b/net/url_request/url_request_job_factory.cc
@@ -8,6 +8,11 @@ namespace net {
URLRequestJobFactory::ProtocolHandler::~ProtocolHandler() {}
+bool URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget(
+ const GURL& location) const {
+ return true;
+}
+
URLRequestJobFactory::URLRequestJobFactory() {}
URLRequestJobFactory::~URLRequestJobFactory() {}
diff --git a/net/url_request/url_request_job_factory.h b/net/url_request/url_request_job_factory.h
index bbd1d09..d4cc49e 100644
--- a/net/url_request/url_request_job_factory.h
+++ b/net/url_request/url_request_job_factory.h
@@ -30,6 +30,13 @@ class NET_EXPORT URLRequestJobFactory
virtual URLRequestJob* MaybeCreateJob(
URLRequest* request, NetworkDelegate* network_delegate) const = 0;
+
+ // Indicates if it should be safe to redirect to |location|. Should handle
+ // protocols handled by MaybeCreateJob(). Only called when registered with
+ // URLRequestJobFactoryImpl::SetProtocolHandler() not called when used with
+ // ProtocolInterceptJobFactory.
+ // NOTE(pauljensen): Default implementation returns true.
+ virtual bool IsSafeRedirectTarget(const GURL& location) const;
};
URLRequestJobFactory();
@@ -44,6 +51,8 @@ class NET_EXPORT URLRequestJobFactory
virtual bool IsHandledURL(const GURL& url) const = 0;
+ virtual bool IsSafeRedirectTarget(const GURL& location) const = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(URLRequestJobFactory);
};
diff --git a/net/url_request/url_request_job_factory_impl.cc b/net/url_request/url_request_job_factory_impl.cc
index f4c1d01..84fb951 100644
--- a/net/url_request/url_request_job_factory_impl.cc
+++ b/net/url_request/url_request_job_factory_impl.cc
@@ -64,4 +64,20 @@ bool URLRequestJobFactoryImpl::IsHandledURL(const GURL& url) const {
return IsHandledProtocol(url.scheme());
}
+bool URLRequestJobFactoryImpl::IsSafeRedirectTarget(
+ const GURL& location) const {
+ DCHECK(CalledOnValidThread());
+ if (!location.is_valid()) {
+ // Error cases are safely handled.
+ return true;
+ }
+ ProtocolHandlerMap::const_iterator it = protocol_handler_map_.find(
+ location.scheme());
+ if (it == protocol_handler_map_.end()) {
+ // Unhandled cases are safely handled.
+ return true;
+ }
+ return it->second->IsSafeRedirectTarget(location);
+}
+
} // namespace net
diff --git a/net/url_request/url_request_job_factory_impl.h b/net/url_request/url_request_job_factory_impl.h
index 8f394e2..4f03fb0 100644
--- a/net/url_request/url_request_job_factory_impl.h
+++ b/net/url_request/url_request_job_factory_impl.h
@@ -33,6 +33,7 @@ class NET_EXPORT URLRequestJobFactoryImpl : public URLRequestJobFactory {
NetworkDelegate* network_delegate) const OVERRIDE;
virtual bool IsHandledProtocol(const std::string& scheme) const OVERRIDE;
virtual bool IsHandledURL(const GURL& url) const OVERRIDE;
+ virtual bool IsSafeRedirectTarget(const GURL& location) const OVERRIDE;
private:
typedef std::map<std::string, ProtocolHandler*> ProtocolHandlerMap;
diff --git a/net/url_request/url_request_job_manager.cc b/net/url_request/url_request_job_manager.cc
index 283ee0d..5a64b41 100644
--- a/net/url_request/url_request_job_manager.cc
+++ b/net/url_request/url_request_job_manager.cc
@@ -12,12 +12,8 @@
#include "net/base/load_flags.h"
#include "net/base/net_errors.h"
#include "net/base/network_delegate.h"
-#include "net/url_request/url_request_about_job.h"
#include "net/url_request/url_request_context.h"
-#include "net/url_request/url_request_data_job.h"
#include "net/url_request/url_request_error_job.h"
-#include "net/url_request/url_request_file_job.h"
-#include "net/url_request/url_request_ftp_job.h"
#include "net/url_request/url_request_http_job.h"
#include "net/url_request/url_request_job_factory.h"
@@ -36,12 +32,6 @@ struct SchemeToFactory {
static const SchemeToFactory kBuiltinFactories[] = {
{ "http", URLRequestHttpJob::Factory },
{ "https", URLRequestHttpJob::Factory },
- { "file", URLRequestFileJob::Factory },
-#if !defined(DISABLE_FTP_SUPPORT)
- { "ftp", URLRequestFtpJob::Factory },
-#endif
- { "about", URLRequestAboutJob::Factory },
- { "data", URLRequestDataJob::Factory },
};
// static
diff --git a/net/url_request/url_request_test_util.cc b/net/url_request/url_request_test_util.cc
index e5c0051..5f00999 100644
--- a/net/url_request/url_request_test_util.cc
+++ b/net/url_request/url_request_test_util.cc
@@ -72,14 +72,6 @@ void TestURLRequestContext::Init() {
context_storage_.set_proxy_service(ProxyService::CreateDirect());
if (!cert_verifier())
context_storage_.set_cert_verifier(CertVerifier::CreateDefault());
- if (!ftp_transaction_factory()) {
-#if !defined(DISABLE_FTP_SUPPORT)
- context_storage_.set_ftp_transaction_factory(
- new FtpNetworkLayer(host_resolver()));
-#else
- context_storage_.set_ftp_transaction_factory(NULL);
-#endif // !defined(DISABLE_FTP_SUPPORT)
- }
if (!ssl_config_service())
context_storage_.set_ssl_config_service(new SSLConfigServiceDefaults);
if (!http_auth_handler_factory()) {
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc
index 32b99ac..c7e535a 100644
--- a/net/url_request/url_request_unittest.cc
+++ b/net/url_request/url_request_unittest.cc
@@ -58,6 +58,8 @@
#include "net/socket/ssl_client_socket.h"
#include "net/ssl/ssl_connection_status_flags.h"
#include "net/test/test_server.h"
+#include "net/url_request/data_protocol_handler.h"
+#include "net/url_request/file_protocol_handler.h"
#include "net/url_request/ftp_protocol_handler.h"
#include "net/url_request/static_http_user_agent_settings.h"
#include "net/url_request/url_request.h"
@@ -514,6 +516,9 @@ class URLRequestTest : public PlatformTest {
URLRequestTest() : default_context_(true) {
default_context_.set_network_delegate(&default_network_delegate_);
default_context_.set_net_log(&net_log_);
+ job_factory_.SetProtocolHandler("data", new DataProtocolHandler);
+ job_factory_.SetProtocolHandler("file", new FileProtocolHandler);
+ default_context_.set_job_factory(&job_factory_);
default_context_.Init();
}
virtual ~URLRequestTest() {}
@@ -521,16 +526,14 @@ class URLRequestTest : public PlatformTest {
// Adds the TestJobInterceptor to the default context.
TestJobInterceptor* AddTestInterceptor() {
TestJobInterceptor* protocol_handler_ = new TestJobInterceptor();
- job_factory_.reset(new URLRequestJobFactoryImpl);
- job_factory_->SetProtocolHandler("http", protocol_handler_);
- default_context_.set_job_factory(job_factory_.get());
+ job_factory_.SetProtocolHandler("http", protocol_handler_);
return protocol_handler_;
}
protected:
CapturingNetLog net_log_;
TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
- scoped_ptr<URLRequestJobFactoryImpl> job_factory_;
+ URLRequestJobFactoryImpl job_factory_;
TestURLRequestContext default_context_;
};
@@ -3464,6 +3467,20 @@ TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) {
req.Cancel();
}
+TEST_F(URLRequestTestHTTP, ProtocolHandlerAndFactoryRestrictRedirects) {
+ // Test URLRequestJobFactory::ProtocolHandler::IsSafeRedirectTarget().
+ GURL file_url("file:///foo.txt");
+ GURL data_url("data:,foo");
+ FileProtocolHandler file_protocol_handler;
+ EXPECT_FALSE(file_protocol_handler.IsSafeRedirectTarget(file_url));
+ DataProtocolHandler data_protocol_handler;
+ EXPECT_TRUE(data_protocol_handler.IsSafeRedirectTarget(data_url));
+
+ // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
+ EXPECT_FALSE(job_factory_.IsSafeRedirectTarget(file_url));
+ EXPECT_TRUE(job_factory_.IsSafeRedirectTarget(data_url));
+}
+
TEST_F(URLRequestTestHTTP, RestrictRedirects) {
ASSERT_TRUE(test_server_.Start());
@@ -4983,15 +5000,12 @@ TEST_F(URLRequestTestFTP, UnsafePort) {
ASSERT_TRUE(test_server_.Start());
URLRequestJobFactoryImpl job_factory;
+ FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver());
GURL url("ftp://127.0.0.1:7");
- FtpProtocolHandler ftp_protocol_handler(
- default_context_.ftp_transaction_factory(),
- default_context_.ftp_auth_cache());
job_factory.SetProtocolHandler(
"ftp",
- new FtpProtocolHandler(default_context_.ftp_transaction_factory(),
- default_context_.ftp_auth_cache()));
+ new FtpProtocolHandler(&ftp_transaction_factory));
default_context_.set_job_factory(&job_factory);
TestDelegate d;