Index: chrome/browser/profiles/off_the_record_profile_io_data.cc |
diff --git a/chrome/browser/profiles/off_the_record_profile_io_data.cc b/chrome/browser/profiles/off_the_record_profile_io_data.cc |
index 0bdf74d89832b1318b0042906c55d826ad55c3de..6cadb70c6d84945e0ff4211ef3a5cbd1d7be8bd1 100644 |
--- a/chrome/browser/profiles/off_the_record_profile_io_data.cc |
+++ b/chrome/browser/profiles/off_the_record_profile_io_data.cc |
@@ -11,6 +11,8 @@ |
#include "base/threading/worker_pool.h" |
#include "build/build_config.h" |
#include "chrome/browser/browser_process.h" |
+#include "chrome/browser/custom_handlers/protocol_handler_registry.h" |
+#include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
#include "chrome/browser/io_thread.h" |
#include "chrome/browser/net/about_protocol_handler.h" |
#include "chrome/browser/net/chrome_net_log.h" |
@@ -30,8 +32,6 @@ |
#include "net/http/http_cache.h" |
#include "net/http/http_network_session.h" |
#include "net/http/http_server_properties_impl.h" |
-#include "net/url_request/file_protocol_handler.h" |
-#include "net/url_request/ftp_protocol_handler.h" |
#include "net/url_request/url_request_job_factory_impl.h" |
#include "webkit/database/database_tracker.h" |
@@ -128,9 +128,13 @@ OffTheRecordProfileIOData::Handle::GetIsolatedAppRequestContextGetter( |
if (iter != app_request_context_getter_map_.end()) |
return iter->second; |
+ scoped_ptr<net::URLRequestJobFactory::Interceptor> |
+ protocol_handler_interceptor( |
+ ProtocolHandlerRegistryFactory::GetForProfile(profile_)-> |
+ CreateURLInterceptor()); |
ChromeURLRequestContextGetter* context = |
ChromeURLRequestContextGetter::CreateOffTheRecordForIsolatedApp( |
- profile_, io_data_, app_id); |
+ profile_, io_data_, app_id, protocol_handler_interceptor.Pass()); |
app_request_context_getter_map_[app_id] = context; |
return context; |
@@ -229,50 +233,33 @@ void OffTheRecordProfileIOData::LazyInitializeInternal( |
ftp_factory_.reset( |
new net::FtpNetworkLayer(main_context->host_resolver())); |
main_context->set_ftp_transaction_factory(ftp_factory_.get()); |
+ extensions_context->set_ftp_transaction_factory(ftp_factory_.get()); |
#endif // !defined(DISABLE_FTP_SUPPORT) |
main_context->set_chrome_url_data_manager_backend( |
chrome_url_data_manager_backend()); |
- main_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
- extensions_job_factory_.reset(new net::URLRequestJobFactoryImpl); |
+ main_job_factory_.reset(new net::URLRequestJobFactoryImpl()); |
+ extensions_job_factory_.reset(new net::URLRequestJobFactoryImpl()); |
- int set_protocol = main_job_factory_->SetProtocolHandler( |
- chrome::kFileScheme, new net::FileProtocolHandler()); |
- DCHECK(set_protocol); |
- // TODO(shalev): The extension_job_factory_ has a NULL NetworkDelegate. |
+ SetUpJobFactoryDefaults( |
+ main_job_factory_.get(), |
+ profile_params->protocol_handler_interceptor.Pass(), |
+ network_delegate(), |
+ main_context->ftp_transaction_factory(), |
+ main_context->ftp_auth_cache()); |
+ // TODO(shalev): The extensions_job_factory has a NULL NetworkDelegate. |
// Without a network_delegate, this protocol handler will never |
// handle file: requests, but as a side effect it makes |
// job_factory::IsHandledProtocol return true, which prevents attempts to |
- // handle the protocol externally. |
- set_protocol = extensions_job_factory_->SetProtocolHandler( |
- chrome::kFileScheme, new net::FileProtocolHandler()); |
- DCHECK(set_protocol); |
- |
- set_protocol = main_job_factory_->SetProtocolHandler( |
- chrome::kChromeDevToolsScheme, |
- CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), |
- network_delegate())); |
- DCHECK(set_protocol); |
- set_protocol = extensions_job_factory_->SetProtocolHandler( |
- chrome::kChromeDevToolsScheme, |
- CreateDevToolsProtocolHandler(chrome_url_data_manager_backend(), NULL)); |
- DCHECK(set_protocol); |
- |
- net::URLRequestJobFactory* job_factories[2]; |
- job_factories[0] = main_job_factory_.get(); |
- job_factories[1] = extensions_job_factory_.get(); |
- |
- net::FtpAuthCache* ftp_auth_caches[2]; |
- ftp_auth_caches[0] = main_context->ftp_auth_cache(); |
- ftp_auth_caches[1] = extensions_context->ftp_auth_cache(); |
- |
- for (int i = 0; i < 2; i++) { |
- SetUpJobFactoryDefaults(job_factories[i]); |
- job_factories[i]->SetProtocolHandler(chrome::kAboutScheme, |
- new net::AboutProtocolHandler()); |
- CreateFtpProtocolHandler(job_factories[i], ftp_auth_caches[i]); |
- } |
+ // handle the protocol externally. We pass NULL in to |
+ // SetUpJobFactoryDefaults() to get this effect. |
+ SetUpJobFactoryDefaults( |
+ extensions_job_factory_.get(), |
+ scoped_ptr<net::URLRequestJobFactoryImpl::Interceptor>(NULL), |
+ NULL, |
+ extensions_context->ftp_transaction_factory(), |
+ extensions_context->ftp_auth_cache()); |
main_context->set_job_factory(main_job_factory_.get()); |
extensions_context->set_job_factory(extensions_job_factory_.get()); |
@@ -281,7 +268,9 @@ void OffTheRecordProfileIOData::LazyInitializeInternal( |
ChromeURLRequestContext* |
OffTheRecordProfileIOData::InitializeAppRequestContext( |
ChromeURLRequestContext* main_context, |
- const std::string& app_id) const { |
+ const std::string& app_id, |
+ scoped_ptr<net::URLRequestJobFactory::Interceptor> |
+ protocol_handler_interceptor) const { |
AppRequestContext* context = new AppRequestContext(load_time_stats()); |
// Copy most state from the main context. |
@@ -297,10 +286,19 @@ OffTheRecordProfileIOData::InitializeAppRequestContext( |
net::HttpCache::DefaultBackend::InMemory(0); |
net::HttpNetworkSession* main_network_session = |
main_http_factory_->GetSession(); |
- net::HttpCache* app_http_cache = |
- new net::HttpCache(main_network_session, app_backend); |
- |
- context->SetHttpTransactionFactory(app_http_cache); |
+ scoped_ptr<net::HttpTransactionFactory> app_http_cache( |
+ new net::HttpCache(main_network_session, app_backend)); |
+ |
+ context->SetHttpTransactionFactory(app_http_cache.Pass()); |
+ |
+ scoped_ptr<net::URLRequestJobFactory> job_factory( |
+ new net::URLRequestJobFactoryImpl()); |
+ SetUpJobFactoryDefaults(job_factory.get(), |
+ protocol_handler_interceptor.Pass(), |
+ network_delegate(), |
+ context->ftp_transaction_factory(), |
+ context->ftp_auth_cache()); |
+ context->SetJobFactory(job_factory.Pass()); |
return context; |
} |
@@ -321,10 +319,13 @@ OffTheRecordProfileIOData::AcquireMediaRequestContext() const { |
ChromeURLRequestContext* |
OffTheRecordProfileIOData::AcquireIsolatedAppRequestContext( |
ChromeURLRequestContext* main_context, |
- const std::string& app_id) const { |
+ const std::string& app_id, |
+ scoped_ptr<net::URLRequestJobFactory::Interceptor> |
+ protocol_handler_interceptor) const { |
// We create per-app contexts on demand, unlike the others above. |
ChromeURLRequestContext* app_request_context = |
- InitializeAppRequestContext(main_context, app_id); |
+ InitializeAppRequestContext(main_context, app_id, |
+ protocol_handler_interceptor.Pass()); |
DCHECK(app_request_context); |
return app_request_context; |
} |
@@ -337,16 +338,6 @@ OffTheRecordProfileIOData::AcquireIsolatedMediaRequestContext( |
return NULL; |
} |
-void OffTheRecordProfileIOData::CreateFtpProtocolHandler( |
- net::URLRequestJobFactory* job_factory, |
- net::FtpAuthCache* ftp_auth_cache) const { |
-#if !defined(DISABLE_FTP_SUPPORT) |
- job_factory->SetProtocolHandler( |
- chrome::kFtpScheme, |
- new net::FtpProtocolHandler(ftp_factory_.get(), ftp_auth_cache)); |
-#endif // !defined(DISABLE_FTP_SUPPORT) |
-} |
- |
chrome_browser_net::LoadTimeStats* OffTheRecordProfileIOData::GetLoadTimeStats( |
IOThread::Globals* io_thread_globals) const { |
return NULL; |