diff --git a/brightray/browser/browser_context.cc b/brightray/browser/browser_context.cc index 563ad286bd1..308e733d422 100644 --- a/brightray/browser/browser_context.cc +++ b/brightray/browser/browser_context.cc @@ -20,6 +20,7 @@ #include "content/public/browser/browser_thread.h" #include "content/public/browser/resource_context.h" #include "content/public/browser/storage_partition.h" +#include "net/url_request/url_request_job_factory_impl.h" #if defined(OS_LINUX) #include "base/nix/xdg_util.h" @@ -109,6 +110,7 @@ net::URLRequestContextGetter* BrowserContext::CreateRequestContext( BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), base::Bind(&BrowserContext::CreateNetworkDelegate, base::Unretained(this)), + base::Bind(&BrowserContext::CreateURLRequestJobFactory, base::Unretained(this)), protocol_handlers, protocol_interceptors.Pass()); resource_context_->set_url_request_context_getter(url_request_getter_.get()); @@ -119,6 +121,12 @@ scoped_ptr BrowserContext::CreateNetworkDelegate() { return make_scoped_ptr(new NetworkDelegate).Pass(); } +scoped_ptr BrowserContext::CreateURLRequestJobFactory( + const content::ProtocolHandlerMap& protocol_handlers, + const content::ProtocolHandlerScopedVector& protocol_interceptors) { + return scoped_ptr(); +} + base::FilePath BrowserContext::GetPath() const { return path_; } diff --git a/brightray/browser/browser_context.h b/brightray/browser/browser_context.h index e59c72ab92d..1caa216a7ad 100644 --- a/brightray/browser/browser_context.h +++ b/brightray/browser/browser_context.h @@ -11,6 +11,10 @@ class PrefRegistrySimple; class PrefService; +namespace browser_context { +class URLRequestJobFactory; +} + namespace brightray { class DownloadManagerDelegate; @@ -38,6 +42,12 @@ class BrowserContext : public content::BrowserContext { // implementation. virtual scoped_ptr CreateNetworkDelegate(); + // Subclasses should override this to provide a custom URLRequestJobFactory + // implementation. + virtual scoped_ptr CreateURLRequestJobFactory( + const content::ProtocolHandlerMap& protocol_handlers, + const content::ProtocolHandlerScopedVector& protocol_interceptors); + virtual base::FilePath GetPath() const OVERRIDE; private: diff --git a/brightray/browser/url_request_context_getter.cc b/brightray/browser/url_request_context_getter.cc index 700fe106f6e..80ae8a8e65e 100644 --- a/brightray/browser/url_request_context_getter.cc +++ b/brightray/browser/url_request_context_getter.cc @@ -45,12 +45,14 @@ URLRequestContextGetter::URLRequestContextGetter( base::MessageLoop* io_loop, base::MessageLoop* file_loop, base::Callback(void)> network_delegate_factory, + URLRequestJobFactoryFactory job_factory_factory, content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector protocol_interceptors) : base_path_(base_path), io_loop_(io_loop), file_loop_(file_loop), network_delegate_factory_(network_delegate_factory), + job_factory_factory_(job_factory_factory), protocol_interceptors_(protocol_interceptors.Pass()) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -149,6 +151,14 @@ net::URLRequestContext* URLRequestContextGetter::GetURLRequestContext() { network_session_params, main_backend); storage_->set_http_transaction_factory(main_cache); + // Give user a chance to create their own job factory. + scoped_ptr user_job_factory( + job_factory_factory_.Run(protocol_handlers_, protocol_interceptors_)); + if (user_job_factory) { + storage_->set_job_factory(user_job_factory.release()); + return url_request_context_.get(); + } + scoped_ptr job_factory( new net::URLRequestJobFactoryImpl()); for (auto it = protocol_handlers_.begin(), diff --git a/brightray/browser/url_request_context_getter.h b/brightray/browser/url_request_context_getter.h index ad09e2b409c..3f3dfb1d7b4 100644 --- a/brightray/browser/url_request_context_getter.h +++ b/brightray/browser/url_request_context_getter.h @@ -25,6 +25,10 @@ namespace brightray { class NetworkDelegate; +typedef base::Callback( + const content::ProtocolHandlerMap& protocol_handlers, + const content::ProtocolHandlerScopedVector& protocol_interceptors)> URLRequestJobFactoryFactory; + class URLRequestContextGetter : public net::URLRequestContextGetter { public: URLRequestContextGetter( @@ -32,6 +36,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* io_loop, base::MessageLoop* file_loop, base::Callback(void)>, + URLRequestJobFactoryFactory job_factory_factory, content::ProtocolHandlerMap* protocol_handlers, content::ProtocolHandlerScopedVector protocol_interceptors); virtual ~URLRequestContextGetter(); @@ -48,6 +53,7 @@ class URLRequestContextGetter : public net::URLRequestContextGetter { base::MessageLoop* file_loop_; base::Callback(void)> network_delegate_factory_; + URLRequestJobFactoryFactory job_factory_factory_; scoped_ptr proxy_config_service_; scoped_ptr network_delegate_;