diff options
author | pauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-08 18:17:11 +0000 |
---|---|---|
committer | pauljensen@chromium.org <pauljensen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-02-08 18:17:11 +0000 |
commit | 6bd3007d35fb0ca49c927d32acb4941fe70cb88e (patch) | |
tree | 51b70122c9c6645c26fdeb7736b438ef3c70e2c1 /content | |
parent | 4a4d26d2cf5f584bc347394196bb520030ed68ce (diff) | |
download | chromium_src-6bd3007d35fb0ca49c927d32acb4941fe70cb88e.zip chromium_src-6bd3007d35fb0ca49c927d32acb4941fe70cb88e.tar.gz chromium_src-6bd3007d35fb0ca49c927d32acb4941fe70cb88e.tar.bz2 |
Add StoragePartition's ProtocolHandlers at URLRequestContext construction time.
Previously they were added later which doesn't mesh with pending
URLRequestJobFactory API changes.
BUG=146602,161529
Review URL: https://chromiumcodereview.appspot.com/11308362
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@181519 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content')
18 files changed, 435 insertions, 248 deletions
diff --git a/content/browser/download/download_manager_impl_unittest.cc b/content/browser/download/download_manager_impl_unittest.cc index 41912e4..a923f87 100644 --- a/content/browser/download/download_manager_impl_unittest.cc +++ b/content/browser/download/download_manager_impl_unittest.cc @@ -393,9 +393,6 @@ class MockBrowserContext : public BrowserContext { MOCK_METHOD0(GetRequestContext, net::URLRequestContextGetter*()); MOCK_METHOD1(GetRequestContextForRenderProcess, net::URLRequestContextGetter*(int renderer_child_id)); - MOCK_METHOD2(GetRequestContextForStoragePartition, - net::URLRequestContextGetter*( - const base::FilePath& partition_path, bool in_memory)); MOCK_METHOD0(GetMediaRequestContext, net::URLRequestContextGetter*()); MOCK_METHOD1(GetMediaRequestContextForRenderProcess, diff --git a/content/browser/storage_partition_impl_map.cc b/content/browser/storage_partition_impl_map.cc index 79c6a77..75c4898 100644 --- a/content/browser/storage_partition_impl_map.cc +++ b/content/browser/storage_partition_impl_map.cc @@ -46,28 +46,64 @@ namespace content { namespace { -class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler { +class BlobProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { public: - BlobProtocolHandler( - webkit_blob::BlobStorageController* blob_storage_controller, - fileapi::FileSystemContext* file_system_context, - base::MessageLoopProxy* loop_proxy) - : webkit_blob::BlobProtocolHandler(blob_storage_controller, - file_system_context, - loop_proxy) {} + BlobProtocolHandler(ChromeBlobStorageContext* blob_storage_context, + fileapi::FileSystemContext* file_system_context) + : blob_storage_context_(blob_storage_context), + file_system_context_(file_system_context) {} virtual ~BlobProtocolHandler() {} - private: - virtual scoped_refptr<webkit_blob::BlobData> - LookupBlobData(net::URLRequest* request) const { - const ResourceRequestInfoImpl* info = - ResourceRequestInfoImpl::ForRequest(request); - if (!info) - return NULL; - return info->requested_blob_data(); + virtual net::URLRequestJob* MaybeCreateJob( + net::URLRequest* request, + net::NetworkDelegate* network_delegate) const OVERRIDE { + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); + if (!webkit_blob_protocol_handler_impl_) { + webkit_blob_protocol_handler_impl_.reset( + new WebKitBlobProtocolHandlerImpl(blob_storage_context_->controller(), + file_system_context_)); + } + return webkit_blob_protocol_handler_impl_->MaybeCreateJob(request, + network_delegate); } + private: + // An implementation of webkit_blob::BlobProtocolHandler that gets + // the BlobData from ResourceRequestInfoImpl. + class WebKitBlobProtocolHandlerImpl + : public webkit_blob::BlobProtocolHandler { + public: + WebKitBlobProtocolHandlerImpl( + webkit_blob::BlobStorageController* blob_storage_controller, + fileapi::FileSystemContext* file_system_context) + : webkit_blob::BlobProtocolHandler( + blob_storage_controller, file_system_context, + BrowserThread::GetMessageLoopProxyForThread( + BrowserThread::FILE)) {} + + virtual ~WebKitBlobProtocolHandlerImpl() {} + + private: + // webkit_blob::BlobProtocolHandler implementation. + virtual scoped_refptr<webkit_blob::BlobData> + LookupBlobData(net::URLRequest* request) const OVERRIDE { + const ResourceRequestInfoImpl* info = + ResourceRequestInfoImpl::ForRequest(request); + if (!info) + return NULL; + return info->requested_blob_data(); + } + + DISALLOW_COPY_AND_ASSIGN(WebKitBlobProtocolHandlerImpl); + }; + + const scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; + const scoped_refptr<fileapi::FileSystemContext> file_system_context_; + + mutable scoped_ptr<WebKitBlobProtocolHandlerImpl> + webkit_blob_protocol_handler_impl_; + DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); }; @@ -75,16 +111,16 @@ class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler { // handler because we want to reuse the chrome://scheme (everyone is familiar // with it, and no need to expose the content/chrome separation through our UI). class DeveloperProtocolHandler - : public net::URLRequestJobFactory::Interceptor { + : public net::URLRequestJobFactory::ProtocolHandler { public: DeveloperProtocolHandler( AppCacheService* appcache_service, - BlobStorageController* blob_storage_controller) + ChromeBlobStorageContext* blob_storage_context) : appcache_service_(appcache_service), - blob_storage_controller_(blob_storage_controller) {} + blob_storage_context_(blob_storage_context) {} virtual ~DeveloperProtocolHandler() {} - virtual net::URLRequestJob* MaybeIntercept( + virtual net::URLRequestJob* MaybeCreateJob( net::URLRequest* request, net::NetworkDelegate* network_delegate) const OVERRIDE { // Check for chrome://view-http-cache/*, which uses its own job type. @@ -102,7 +138,7 @@ class DeveloperProtocolHandler // Next check for chrome://blob-internals/, which uses its own job type. if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { return ViewBlobInternalsJobFactory::CreateJobForRequest( - request, network_delegate, blob_storage_controller_); + request, network_delegate, blob_storage_context_->controller()); } #if defined(USE_TCMALLOC) @@ -122,90 +158,11 @@ class DeveloperProtocolHandler return NULL; } - virtual net::URLRequestJob* MaybeInterceptRedirect( - const GURL& location, - net::URLRequest* request, - net::NetworkDelegate* network_delegate) const OVERRIDE { - return NULL; - } - - virtual net::URLRequestJob* MaybeInterceptResponse( - net::URLRequest* request, - net::NetworkDelegate* network_delegate) const OVERRIDE { - return NULL; - } - - virtual bool WillHandleProtocol(const std::string& protocol) const { - return protocol == chrome::kChromeUIScheme; - } - private: AppCacheService* appcache_service_; - BlobStorageController* blob_storage_controller_; + ChromeBlobStorageContext* blob_storage_context_; }; -void InitializeURLRequestContext( - net::URLRequestContextGetter* context_getter, - AppCacheService* appcache_service, - FileSystemContext* file_system_context, - ChromeBlobStorageContext* blob_storage_context, - ResourceContext* resource_context, - bool off_the_record) { - DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); - if (!context_getter) - return; // tests. - - // This code only modifies the URLRequestJobFactory on the context - // to handle blob: URLs, filesystem: URLs, and to let AppCache intercept - // the appropriate requests. This is in addition to the slew of other - // initializtion that is done in during creation of the URLRequestContext. - // We cannot yet centralize this code because URLRequestContext needs - // to be created before the StoragePartition context. - // - // TODO(ajwong): Fix the ordering so all the initialization is in one spot. - net::URLRequestContext* context = context_getter->GetURLRequestContext(); - net::URLRequestJobFactory* job_factory = - const_cast<net::URLRequestJobFactory*>(context->job_factory()); - - // Note: if this is called twice with 2 request contexts that share one job - // factory (as is the case with a media request context and its related - // normal request context) then this will early exit. - if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) - return; // Already initialized this JobFactory. - - bool set_protocol = job_factory->SetProtocolHandler( - chrome::kBlobScheme, - new BlobProtocolHandler( - blob_storage_context->controller(), - file_system_context, - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); - DCHECK(set_protocol); - set_protocol = job_factory->SetProtocolHandler( - chrome::kFileSystemScheme, - CreateFileSystemProtocolHandler(file_system_context)); - DCHECK(set_protocol); - - job_factory->AddInterceptor( - new DeveloperProtocolHandler(appcache_service, - blob_storage_context->controller())); - - set_protocol = job_factory->SetProtocolHandler( - chrome::kChromeUIScheme, - URLDataManagerBackend::CreateProtocolHandler( - GetURLDataManagerForResourceContext(resource_context), - off_the_record)); - DCHECK(set_protocol); - - set_protocol = job_factory->SetProtocolHandler( - chrome::kChromeDevToolsScheme, - CreateDevToolsProtocolHandler( - GetURLDataManagerForResourceContext(resource_context), - off_the_record)); - DCHECK(set_protocol); - - // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! -} - // These constants are used to create the directory structure under the profile // where renderers with a non-default storage partition keep their persistent // state. This will contain a set of directories that partially mirror the @@ -488,12 +445,43 @@ StoragePartitionImpl* StoragePartitionImplMap::Get( partition_path); partitions_[partition_config] = partition; + ChromeBlobStorageContext* blob_storage_context = + ChromeBlobStorageContext::GetFor(browser_context_); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> blob_protocol_handler( + new BlobProtocolHandler(blob_storage_context, + partition->GetFileSystemContext())); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler( + CreateFileSystemProtocolHandler(partition->GetFileSystemContext())); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler( + new DeveloperProtocolHandler(partition->GetAppCacheService(), + blob_storage_context)); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler( + URLDataManagerBackend::CreateProtocolHandler( + browser_context_->GetResourceContext(), + browser_context_->IsOffTheRecord())); + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler( + CreateDevToolsProtocolHandler(browser_context_->GetResourceContext(), + browser_context_->IsOffTheRecord())); + // These calls must happen after StoragePartitionImpl::Create(). - partition->SetURLRequestContext( - partition_domain.empty() ? - browser_context_->GetRequestContext() : - browser_context_->GetRequestContextForStoragePartition( - partition->GetPath(), in_memory)); + if (partition_domain.empty()) { + partition->SetURLRequestContext( + GetContentClient()->browser()->CreateRequestContext(browser_context_, + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass())); + } else { + partition->SetURLRequestContext( + GetContentClient()->browser()->CreateRequestContextForStoragePartition( + browser_context_, partition->GetPath(), in_memory, + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass())); + } partition->SetMediaURLRequestContext( partition_domain.empty() ? browser_context_->GetMediaRequestContext() : @@ -612,19 +600,6 @@ void StoragePartitionImplMap::PostCreateInitialization( make_scoped_refptr( browser_context_->GetSpecialStoragePolicy()))); - // Add content's URLRequestContext's hooks. - BrowserThread::PostTask( - BrowserThread::IO, FROM_HERE, - base::Bind( - &InitializeURLRequestContext, - make_scoped_refptr(partition->GetURLRequestContext()), - make_scoped_refptr(partition->GetAppCacheService()), - make_scoped_refptr(partition->GetFileSystemContext()), - make_scoped_refptr( - ChromeBlobStorageContext::GetFor(browser_context_)), - browser_context_->GetResourceContext(), - browser_context_->IsOffTheRecord())); - // We do not call InitializeURLRequestContext() for media contexts because, // other than the HTTP cache, the media contexts share the same backing // objects as their associated "normal" request context. Thus, the previous diff --git a/content/browser/webui/url_data_manager_backend.cc b/content/browser/webui/url_data_manager_backend.cc index f5fdd6b..3ffc195 100644 --- a/content/browser/webui/url_data_manager_backend.cc +++ b/content/browser/webui/url_data_manager_backend.cc @@ -18,6 +18,7 @@ #include "base/memory/weak_ptr.h" #include "base/message_loop.h" #include "base/string_util.h" +#include "content/browser/resource_context_impl.h" #include "content/browser/webui/shared_resources_data_source.h" #include "content/browser/webui/url_data_source_impl.h" #include "content/public/browser/browser_thread.h" @@ -333,7 +334,7 @@ class ChromeProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { public: // |is_incognito| should be set for incognito profiles. - explicit ChromeProtocolHandler(URLDataManagerBackend* backend, + explicit ChromeProtocolHandler(content::ResourceContext* resource_context, bool is_incognito); ~ChromeProtocolHandler(); @@ -343,7 +344,7 @@ class ChromeProtocolHandler private: // These members are owned by ProfileIOData, which owns this ProtocolHandler. - URLDataManagerBackend* const backend_; + content::ResourceContext* const resource_context_; // True when generated from an incognito profile. const bool is_incognito_; @@ -352,8 +353,8 @@ class ChromeProtocolHandler }; ChromeProtocolHandler::ChromeProtocolHandler( - URLDataManagerBackend* backend, bool is_incognito) - : backend_(backend), is_incognito_(is_incognito) {} + content::ResourceContext* resource_context, bool is_incognito) + : resource_context_(resource_context), is_incognito_(is_incognito) {} ChromeProtocolHandler::~ChromeProtocolHandler() {} @@ -362,8 +363,9 @@ net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob( DCHECK(request); // Fall back to using a custom handler - return new URLRequestChromeJob(request, network_delegate, backend_, - is_incognito_); + return new URLRequestChromeJob( + request, network_delegate, + GetURLDataManagerForResourceContext(resource_context_), is_incognito_); } } // namespace @@ -387,9 +389,9 @@ URLDataManagerBackend::~URLDataManagerBackend() { // static net::URLRequestJobFactory::ProtocolHandler* URLDataManagerBackend::CreateProtocolHandler( - URLDataManagerBackend* backend, bool is_incognito) { - DCHECK(backend); - return new ChromeProtocolHandler(backend, is_incognito); + content::ResourceContext* resource_context, bool is_incognito) { + DCHECK(resource_context); + return new ChromeProtocolHandler(resource_context, is_incognito); } void URLDataManagerBackend::AddDataSource( @@ -521,7 +523,7 @@ class DevToolsJobFactory : public net::URLRequestJobFactory::ProtocolHandler { public: // |is_incognito| should be set for incognito profiles. - DevToolsJobFactory(URLDataManagerBackend* backend, + DevToolsJobFactory(content::ResourceContext* resource_context, bool is_incognito); virtual ~DevToolsJobFactory(); @@ -530,9 +532,9 @@ class DevToolsJobFactory net::NetworkDelegate* network_delegate) const OVERRIDE; private: - // |backend_| and |network_delegate_| are owned by ProfileIOData, which owns - // this ProtocolHandler. - URLDataManagerBackend* const backend_; + // |resource_context_| and |network_delegate_| are owned by ProfileIOData, + // which owns this ProtocolHandler. + content::ResourceContext* const resource_context_; // True when generated from an incognito profile. const bool is_incognito_; @@ -540,11 +542,12 @@ class DevToolsJobFactory DISALLOW_COPY_AND_ASSIGN(DevToolsJobFactory); }; -DevToolsJobFactory::DevToolsJobFactory(URLDataManagerBackend* backend, - bool is_incognito) - : backend_(backend), +DevToolsJobFactory::DevToolsJobFactory( + content::ResourceContext* resource_context, + bool is_incognito) + : resource_context_(resource_context), is_incognito_(is_incognito) { - DCHECK(backend_); + DCHECK(resource_context_); } DevToolsJobFactory::~DevToolsJobFactory() {} @@ -552,16 +555,17 @@ DevToolsJobFactory::~DevToolsJobFactory() {} net::URLRequestJob* DevToolsJobFactory::MaybeCreateJob( net::URLRequest* request, net::NetworkDelegate* network_delegate) const { - return new URLRequestChromeJob(request, network_delegate, backend_, - is_incognito_); + return new URLRequestChromeJob( + request, network_delegate, + GetURLDataManagerForResourceContext(resource_context_), is_incognito_); } } // namespace net::URLRequestJobFactory::ProtocolHandler* -CreateDevToolsProtocolHandler(URLDataManagerBackend* backend, +CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, bool is_incognito) { - return new DevToolsJobFactory(backend, is_incognito); + return new DevToolsJobFactory(resource_context, is_incognito); } } // namespace content diff --git a/content/browser/webui/url_data_manager_backend.h b/content/browser/webui/url_data_manager_backend.h index a6c6fa2..58daa4e 100644 --- a/content/browser/webui/url_data_manager_backend.h +++ b/content/browser/webui/url_data_manager_backend.h @@ -22,6 +22,7 @@ class RefCountedMemory; } namespace content { +class ResourceContext; class URLDataManagerBackend; class URLDataSourceImpl; class URLRequestChromeJob; @@ -37,9 +38,9 @@ class URLDataManagerBackend : public base::SupportsUserData::Data { virtual ~URLDataManagerBackend(); // Invoked to create the protocol handler for chrome://. |is_incognito| should - // be set for incognito profiles. + // be set for incognito profiles. Called on the UI thread. static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler( - URLDataManagerBackend* backend, + content::ResourceContext* resource_context, bool is_incognito); // Adds a DataSource to the collection of data sources. @@ -95,7 +96,7 @@ class URLDataManagerBackend : public base::SupportsUserData::Data { // Creates protocol handler for chrome-devtools://. |is_incognito| should be // set for incognito profiles. net::URLRequestJobFactory::ProtocolHandler* -CreateDevToolsProtocolHandler(URLDataManagerBackend* backend, +CreateDevToolsProtocolHandler(content::ResourceContext* resource_context, bool is_incognito); } // namespace content diff --git a/content/content_shell.gypi b/content/content_shell.gypi index 6c8d3e3..582174a 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -111,8 +111,6 @@ 'shell/shell_network_delegate.h', 'shell/shell_render_process_observer.cc', 'shell/shell_render_process_observer.h', - 'shell/shell_resource_context.cc', - 'shell/shell_resource_context.h', 'shell/shell_resource_dispatcher_host_delegate.cc', 'shell/shell_resource_dispatcher_host_delegate.h', 'shell/shell_switches.cc', diff --git a/content/public/browser/browser_context.h b/content/public/browser/browser_context.h index d82326a..a1b5d7b 100644 --- a/content/public/browser/browser_context.h +++ b/content/public/browser/browser_context.h @@ -116,10 +116,6 @@ class CONTENT_EXPORT BrowserContext : public base::SupportsUserData { virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( int renderer_child_id) = 0; - virtual net::URLRequestContextGetter* GetRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory) = 0; - // Returns the default request context for media resources associated with // this context. // TODO(creis): Remove this version in favor of the one below. diff --git a/content/public/browser/content_browser_client.cc b/content/public/browser/content_browser_client.cc index 6ad2694..2b16e49 100644 --- a/content/public/browser/content_browser_client.cc +++ b/content/public/browser/content_browser_client.cc @@ -36,6 +36,39 @@ bool ContentBrowserClient::ShouldUseProcessPerSite( return false; } +net::URLRequestContextGetter* ContentBrowserClient::CreateRequestContext( + BrowserContext* browser_context, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { + return NULL; +} + +net::URLRequestContextGetter* +ContentBrowserClient::CreateRequestContextForStoragePartition( + BrowserContext* browser_context, + const FilePath& partition_path, + bool in_memory, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { + return NULL; +} + bool ContentBrowserClient::IsHandledURL(const GURL& url) { return false; } diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h index b332073..0e1ed14 100644 --- a/content/public/browser/content_browser_client.h +++ b/content/public/browser/content_browser_client.h @@ -10,12 +10,14 @@ #include <vector> #include "base/callback_forward.h" +#include "base/memory/scoped_ptr.h" #include "content/public/browser/file_descriptor_info.h" #include "content/public/common/socket_permission_request.h" #include "content/public/common/content_client.h" #include "content/public/common/window_container_type.h" #include "net/base/mime_util.h" #include "net/cookies/canonical_cookie.h" +#include "net/url_request/url_request_job_factory.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebNotificationPresenter.h" #if defined(OS_POSIX) && !defined(OS_MACOSX) @@ -49,6 +51,7 @@ class SSLCertRequestInfo; class SSLInfo; class URLRequest; class URLRequestContext; +class URLRequestContextGetter; class X509Certificate; } @@ -135,6 +138,40 @@ class CONTENT_EXPORT ContentBrowserClient { virtual bool ShouldUseProcessPerSite(BrowserContext* browser_context, const GURL& effective_url); + // Creates the main net::URLRequestContextGetter. Should only be called once + // per ContentBrowserClient object. + // TODO(ajwong): Remove once http://crbug.com/159193 is resolved. + virtual net::URLRequestContextGetter* CreateRequestContext( + BrowserContext* browser_context, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); + + // Creates the net::URLRequestContextGetter for a StoragePartition. Should + // only be called once per partition_path per ContentBrowserClient object. + // TODO(ajwong): Remove once http://crbug.com/159193 is resolved. + virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( + BrowserContext* browser_context, + const FilePath& partition_path, + bool in_memory, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); + // Returns whether a specified URL is handled by the embedder's internal // protocol handlers. virtual bool IsHandledURL(const GURL& url); diff --git a/content/public/test/test_browser_context.cc b/content/public/test/test_browser_context.cc index ec47813..b954c70 100644 --- a/content/public/test/test_browser_context.cc +++ b/content/public/test/test_browser_context.cc @@ -82,14 +82,6 @@ TestBrowserContext::GetRequestContextForRenderProcess(int renderer_child_id) { return NULL; } - -net::URLRequestContextGetter* -TestBrowserContext::GetRequestContextForStoragePartition( - const FilePath& partition_path, - bool in_memory) { - return NULL; -} - net::URLRequestContextGetter* TestBrowserContext::GetMediaRequestContext() { return NULL; } diff --git a/content/public/test/test_browser_context.h b/content/public/test/test_browser_context.h index 5a93376..41ddfdd 100644 --- a/content/public/test/test_browser_context.h +++ b/content/public/test/test_browser_context.h @@ -33,9 +33,6 @@ class TestBrowserContext : public BrowserContext { virtual net::URLRequestContextGetter* GetRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* GetRequestContextForRenderProcess( int renderer_child_id) OVERRIDE; - virtual net::URLRequestContextGetter* GetRequestContextForStoragePartition( - const FilePath& partition_path, - bool in_memory) OVERRIDE; virtual net::URLRequestContextGetter* GetMediaRequestContext() OVERRIDE; virtual net::URLRequestContextGetter* GetMediaRequestContextForRenderProcess( int renderer_child_id) OVERRIDE; diff --git a/content/shell/shell_browser_context.cc b/content/shell/shell_browser_context.cc index b464477..1acfa79 100644 --- a/content/shell/shell_browser_context.cc +++ b/content/shell/shell_browser_context.cc @@ -12,11 +12,12 @@ #include "base/path_service.h" #include "base/threading/thread.h" #include "content/public/browser/browser_thread.h" +#include "content/public/browser/resource_context.h" +#include "content/public/browser/storage_partition.h" +#include "content/public/common/content_switches.h" #include "content/shell/shell_download_manager_delegate.h" -#include "content/shell/shell_resource_context.h" #include "content/shell/shell_switches.h" #include "content/shell/shell_url_request_context_getter.h" -#include "content/public/common/content_switches.h" #if defined(OS_WIN) #include "base/base_paths_win.h" @@ -28,9 +29,35 @@ namespace content { +class ShellBrowserContext::ShellResourceContext : public ResourceContext { + public: + ShellResourceContext() : getter_(NULL) {} + virtual ~ShellResourceContext() {} + + // ResourceContext implementation: + virtual net::HostResolver* GetHostResolver() OVERRIDE { + CHECK(getter_); + return getter_->host_resolver(); + } + virtual net::URLRequestContext* GetRequestContext() OVERRIDE { + CHECK(getter_); + return getter_->GetURLRequestContext(); + } + + void set_url_request_context_getter(ShellURLRequestContextGetter* getter) { + getter_ = getter; + } + + private: + ShellURLRequestContextGetter* getter_; + + DISALLOW_COPY_AND_ASSIGN(ShellResourceContext); +}; + ShellBrowserContext::ShellBrowserContext(bool off_the_record) : off_the_record_(off_the_record), - ignore_certificate_errors_(false) { + ignore_certificate_errors_(false), + resource_context_(new ShellResourceContext) { InitWhileIOAllowed(); } @@ -100,14 +127,33 @@ DownloadManagerDelegate* ShellBrowserContext::GetDownloadManagerDelegate() { } net::URLRequestContextGetter* ShellBrowserContext::GetRequestContext() { - if (!url_request_getter_) { - url_request_getter_ = new ShellURLRequestContextGetter( - ignore_certificate_errors_, - GetPath(), - BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), - BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE)); - } - return url_request_getter_; + return GetDefaultStoragePartition(this)->GetURLRequestContext(); +} + +net::URLRequestContextGetter* ShellBrowserContext::CreateRequestContext( + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { + DCHECK(!url_request_getter_); + url_request_getter_ = new ShellURLRequestContextGetter( + ignore_certificate_errors_, + GetPath(), + BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::IO), + BrowserThread::UnsafeGetMessageLoopForThread(BrowserThread::FILE), + blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), + chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); + resource_context_->set_url_request_context_getter(url_request_getter_.get()); + return url_request_getter_.get(); } net::URLRequestContextGetter* @@ -135,17 +181,23 @@ net::URLRequestContextGetter* } net::URLRequestContextGetter* - ShellBrowserContext::GetRequestContextForStoragePartition( + ShellBrowserContext::CreateRequestContextForStoragePartition( const base::FilePath& partition_path, - bool in_memory) { + bool in_memory, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { return NULL; } ResourceContext* ShellBrowserContext::GetResourceContext() { - if (!resource_context_.get()) { - resource_context_.reset(new ShellResourceContext( - static_cast<ShellURLRequestContextGetter*>(GetRequestContext()))); - } return resource_context_.get(); } diff --git a/content/shell/shell_browser_context.h b/content/shell/shell_browser_context.h index 8b82b8a..938c3b8 100644 --- a/content/shell/shell_browser_context.h +++ b/content/shell/shell_browser_context.h @@ -10,12 +10,14 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "content/public/browser/browser_context.h" +#include "net/url_request/url_request_job_factory.h" namespace content { class DownloadManagerDelegate; class ResourceContext; class ShellDownloadManagerDelegate; +class ShellURLRequestContextGetter; class ShellBrowserContext : public BrowserContext { public: @@ -36,9 +38,6 @@ class ShellBrowserContext : public BrowserContext { GetMediaRequestContextForStoragePartition( const base::FilePath& partition_path, bool in_memory) OVERRIDE; - virtual net::URLRequestContextGetter* GetRequestContextForStoragePartition( - const base::FilePath& partition_path, - bool in_memory) OVERRIDE; virtual ResourceContext* GetResourceContext() OVERRIDE; virtual GeolocationPermissionContext* GetGeolocationPermissionContext() OVERRIDE; @@ -46,7 +45,34 @@ class ShellBrowserContext : public BrowserContext { GetSpeechRecognitionPreferences() OVERRIDE; virtual quota::SpecialStoragePolicy* GetSpecialStoragePolicy() OVERRIDE; + net::URLRequestContextGetter* CreateRequestContext( + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); + net::URLRequestContextGetter* CreateRequestContextForStoragePartition( + const FilePath& partition_path, + bool in_memory, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); + private: + class ShellResourceContext; + // Performs initialization of the ShellBrowserContext while IO is still // allowed on the current thread. void InitWhileIOAllowed(); @@ -54,9 +80,9 @@ class ShellBrowserContext : public BrowserContext { bool off_the_record_; bool ignore_certificate_errors_; base::FilePath path_; - scoped_ptr<ResourceContext> resource_context_; + scoped_ptr<ShellResourceContext> resource_context_; scoped_refptr<ShellDownloadManagerDelegate> download_manager_delegate_; - scoped_refptr<net::URLRequestContextGetter> url_request_getter_; + scoped_refptr<ShellURLRequestContextGetter> url_request_getter_; DISALLOW_COPY_AND_ASSIGN(ShellBrowserContext); }; diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc index abc24d1..b2b93aa 100644 --- a/content/shell/shell_content_browser_client.cc +++ b/content/shell/shell_content_browser_client.cc @@ -81,6 +81,50 @@ void ShellContentBrowserClient::RenderProcessHostCreated( host->Send(new ShellViewMsg_SetWebKitSourceDir(webkit_source_dir_)); } +net::URLRequestContextGetter* ShellContentBrowserClient::CreateRequestContext( + BrowserContext* content_browser_context, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { + ShellBrowserContext* shell_browser_context = + ShellBrowserContextForBrowserContext(content_browser_context); + return shell_browser_context->CreateRequestContext( + blob_protocol_handler.Pass(), file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); +} + +net::URLRequestContextGetter* +ShellContentBrowserClient::CreateRequestContextForStoragePartition( + BrowserContext* content_browser_context, + const FilePath& partition_path, + bool in_memory, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) { + ShellBrowserContext* shell_browser_context = + ShellBrowserContextForBrowserContext(content_browser_context); + return shell_browser_context->CreateRequestContextForStoragePartition( + partition_path, in_memory, blob_protocol_handler.Pass(), + file_system_protocol_handler.Pass(), + developer_protocol_handler.Pass(), chrome_protocol_handler.Pass(), + chrome_devtools_protocol_handler.Pass()); +} + void ShellContentBrowserClient::AppendExtraCommandLineSwitches( CommandLine* command_line, int child_process_id) { if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kDumpRenderTree)) @@ -166,4 +210,13 @@ AccessTokenStore* ShellContentBrowserClient::CreateAccessTokenStore() { return new ShellAccessTokenStore(browser_context()->GetRequestContext()); } +ShellBrowserContext* +ShellContentBrowserClient::ShellBrowserContextForBrowserContext( + BrowserContext* content_browser_context) { + if (content_browser_context == browser_context()) + return browser_context(); + DCHECK_EQ(content_browser_context, off_the_record_browser_context()); + return off_the_record_browser_context(); +} + } // namespace content diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h index 91d821e..10933a9 100644 --- a/content/shell/shell_content_browser_client.h +++ b/content/shell/shell_content_browser_client.h @@ -27,6 +27,32 @@ class ShellContentBrowserClient : public ContentBrowserClient { virtual BrowserMainParts* CreateBrowserMainParts( const MainFunctionParams& parameters) OVERRIDE; virtual void RenderProcessHostCreated(RenderProcessHost* host) OVERRIDE; + virtual net::URLRequestContextGetter* CreateRequestContext( + BrowserContext* browser_context, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; + virtual net::URLRequestContextGetter* CreateRequestContextForStoragePartition( + BrowserContext* browser_context, + const FilePath& partition_path, + bool in_memory, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) OVERRIDE; virtual void AppendExtraCommandLineSwitches(CommandLine* command_line, int child_process_id) OVERRIDE; virtual void OverrideWebkitPrefs(RenderViewHost* render_view_host, @@ -62,6 +88,9 @@ class ShellContentBrowserClient : public ContentBrowserClient { } private: + ShellBrowserContext* ShellBrowserContextForBrowserContext( + BrowserContext* content_browser_context); + scoped_ptr<ShellResourceDispatcherHostDelegate> resource_dispatcher_host_delegate_; diff --git a/content/shell/shell_resource_context.cc b/content/shell/shell_resource_context.cc deleted file mode 100644 index 4d247e4..0000000 --- a/content/shell/shell_resource_context.cc +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (c) 2012 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 "content/shell/shell_resource_context.h" -#include "content/shell/shell_url_request_context_getter.h" - -namespace content { - -ShellResourceContext::ShellResourceContext( - ShellURLRequestContextGetter* getter) - : getter_(getter) { -} - -ShellResourceContext::~ShellResourceContext() { -} - -net::HostResolver* ShellResourceContext::GetHostResolver() { - return getter_->host_resolver(); -} - -net::URLRequestContext* ShellResourceContext::GetRequestContext() { - return getter_->GetURLRequestContext(); -} - -} // namespace content diff --git a/content/shell/shell_resource_context.h b/content/shell/shell_resource_context.h deleted file mode 100644 index 046b89a..0000000 --- a/content/shell/shell_resource_context.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2012 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 CONTENT_SHELL_SHELL_RESOURCE_CONTEXT_H_ -#define CONTENT_SHELL_SHELL_RESOURCE_CONTEXT_H_ - -#include "base/compiler_specific.h" -#include "base/memory/ref_counted.h" -#include "content/public/browser/resource_context.h" - -namespace content { - -class ShellURLRequestContextGetter; - -class ShellResourceContext : public ResourceContext { - public: - explicit ShellResourceContext(ShellURLRequestContextGetter* getter); - virtual ~ShellResourceContext(); - - private: - // ResourceContext implementation: - virtual net::HostResolver* GetHostResolver() OVERRIDE; - virtual net::URLRequestContext* GetRequestContext() OVERRIDE; - - scoped_refptr<ShellURLRequestContextGetter> getter_; - - DISALLOW_COPY_AND_ASSIGN(ShellResourceContext); -}; - -} // namespace content - -#endif // CONTENT_SHELL_SHELL_RESOURCE_CONTEXT_H_ diff --git a/content/shell/shell_url_request_context_getter.cc b/content/shell/shell_url_request_context_getter.cc index b085b9e..251bf00 100644 --- a/content/shell/shell_url_request_context_getter.cc +++ b/content/shell/shell_url_request_context_getter.cc @@ -12,6 +12,7 @@ #include "base/threading/worker_pool.h" #include "content/public/browser/browser_thread.h" #include "content/public/common/content_switches.h" +#include "content/public/common/url_constants.h" #include "content/shell/shell_network_delegate.h" #include "content/shell/shell_switches.h" #include "net/base/cert_verifier.h" @@ -26,6 +27,7 @@ #include "net/http/http_network_session.h" #include "net/http/http_server_properties_impl.h" #include "net/proxy/proxy_service.h" +#include "net/url_request/protocol_intercept_job_factory.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" @@ -37,11 +39,27 @@ ShellURLRequestContextGetter::ShellURLRequestContextGetter( bool ignore_certificate_errors, const base::FilePath& base_path, MessageLoop* io_loop, - MessageLoop* file_loop) + MessageLoop* file_loop, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler) : ignore_certificate_errors_(ignore_certificate_errors), base_path_(base_path), io_loop_(io_loop), - file_loop_(file_loop) { + file_loop_(file_loop), + blob_protocol_handler_(blob_protocol_handler.Pass()), + file_system_protocol_handler_(file_system_protocol_handler.Pass()), + developer_protocol_handler_(developer_protocol_handler.Pass()), + chrome_protocol_handler_(chrome_protocol_handler.Pass()), + chrome_devtools_protocol_handler_( + chrome_devtools_protocol_handler.Pass()) { // Must first be created on the UI thread. DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); @@ -151,7 +169,24 @@ net::URLRequestContext* ShellURLRequestContextGetter::GetURLRequestContext() { network_session_params, main_backend); storage_->set_http_transaction_factory(main_cache); - storage_->set_job_factory(new net::URLRequestJobFactoryImpl); + scoped_ptr<net::URLRequestJobFactoryImpl> job_factory( + new net::URLRequestJobFactoryImpl()); + bool set_protocol = job_factory->SetProtocolHandler( + chrome::kBlobScheme, blob_protocol_handler_.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kFileSystemScheme, file_system_protocol_handler_.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kChromeUIScheme, chrome_protocol_handler_.release()); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kChromeDevToolsScheme, + chrome_devtools_protocol_handler_.release()); + DCHECK(set_protocol); + storage_->set_job_factory(new net::ProtocolInterceptJobFactory( + job_factory.PassAs<net::URLRequestJobFactory>(), + developer_protocol_handler_.Pass())); } return url_request_context_.get(); diff --git a/content/shell/shell_url_request_context_getter.h b/content/shell/shell_url_request_context_getter.h index 764a9e6..e631a18 100644 --- a/content/shell/shell_url_request_context_getter.h +++ b/content/shell/shell_url_request_context_getter.h @@ -10,6 +10,7 @@ #include "base/memory/ref_counted.h" #include "base/memory/scoped_ptr.h" #include "net/url_request/url_request_context_getter.h" +#include "net/url_request/url_request_job_factory.h" class MessageLoop; @@ -29,7 +30,17 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { bool ignore_certificate_errors, const base::FilePath& base_path, MessageLoop* io_loop, - MessageLoop* file_loop); + MessageLoop* file_loop, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler, + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler); // net::URLRequestContextGetter implementation. virtual net::URLRequestContext* GetURLRequestContext() OVERRIDE; @@ -51,6 +62,16 @@ class ShellURLRequestContextGetter : public net::URLRequestContextGetter { scoped_ptr<net::NetworkDelegate> network_delegate_; scoped_ptr<net::URLRequestContextStorage> storage_; scoped_ptr<net::URLRequestContext> url_request_context_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + blob_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + file_system_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + developer_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_protocol_handler_; + scoped_ptr<net::URLRequestJobFactory::ProtocolHandler> + chrome_devtools_protocol_handler_; DISALLOW_COPY_AND_ASSIGN(ShellURLRequestContextGetter); }; |