diff options
21 files changed, 217 insertions, 164 deletions
diff --git a/chrome/browser/DEPS b/chrome/browser/DEPS index d7ac476..b822492 100644 --- a/chrome/browser/DEPS +++ b/chrome/browser/DEPS @@ -34,7 +34,6 @@ include_rules = [ # TODO(jam): Need to remove all these and use only content/public. BUG=98716 # DO NOT ADD ANY MORE ITEMS TO THE LIST BELOW! "+content/browser/geolocation/wifi_data_provider_common.h", - "+content/browser/renderer_host/resource_request_info_impl.h", # TODO(asanka): see http://codereview.chromium.org/9141031 "+content/browser/download/download_state_info.h", # TODO(ben): http://crbug.com/118410 will fix the following: diff --git a/chrome/browser/download/download_browsertest.cc b/chrome/browser/download/download_browsertest.cc index 412e41f..f3c42a2 100644 --- a/chrome/browser/download/download_browsertest.cc +++ b/chrome/browser/download/download_browsertest.cc @@ -60,9 +60,8 @@ #include "content/test/test_file_error_injector.h" #include "content/test/test_navigation_observer.h" #include "net/base/net_util.h" +#include "net/test/test_server.h" #include "testing/gtest/include/gtest/gtest.h" -#include "webkit/blob/blob_data.h" -#include "webkit/blob/blob_storage_controller.h" using content::BrowserThread; using content::DownloadItem; @@ -2431,8 +2430,7 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadErrorReadonlyFolder) { // downloaded through a blob: URL. IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousBlobData) { ASSERT_TRUE(InitialSetup(false)); - const char kBlobUrl[] = "blob:test-download-url"; - GURL blob_url(kBlobUrl); + #if defined(OS_WIN) // On Windows, if SafeBrowsing is enabled, certain file types (.exe, .cab, // .msi) will be handled by the DownloadProtectionService. However, if the URL @@ -2443,25 +2441,19 @@ IN_PROC_BROWSER_TEST_F(DownloadTest, DownloadDangerousBlobData) { #else const char kFilename[] = "foo.jar"; #endif - std::string content_disposition = "attachment; filename="; - content_disposition += kFilename; - - webkit_blob::BlobStorageController* blob_controller = - content::ResourceContext::GetBlobStorageController( - DownloadManagerForBrowser(browser())->GetBrowserContext()-> - GetResourceContext()); - scoped_refptr<webkit_blob::BlobData> blob_data(new webkit_blob::BlobData()); - blob_data->AppendData("foo"); - blob_controller->AddFinishedBlob(blob_url, blob_data.get()); - blob_data = blob_controller->GetBlobDataFromUrl(blob_url); - blob_data->set_content_type("application/octet-stream"); - blob_data->set_content_disposition(content_disposition); + + std::string path("files/downloads/download-dangerous-blob.html?filename="); + path += kFilename; + + // Need to use http urls because the blob js doesn't work on file urls for + // security reasons. + ASSERT_TRUE(test_server()->Start()); + GURL url(test_server()->GetURL(path)); DownloadTestObserver* observer(DangerousDownloadWaiter( browser(), 1, DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT)); - ui_test_utils::NavigateToURL(browser(), blob_url); + ui_test_utils::NavigateToURL(browser(), url); observer->WaitForFinished(); - blob_controller->RemoveBlob(blob_url); EXPECT_EQ(1u, observer->NumDownloadsSeenInState(DownloadItem::COMPLETE)); EXPECT_EQ(1u, observer->NumDangerousDownloadsSeen()); diff --git a/chrome/browser/profiles/profile_io_data.cc b/chrome/browser/profiles/profile_io_data.cc index 75ac696..ca6c90b 100644 --- a/chrome/browser/profiles/profile_io_data.cc +++ b/chrome/browser/profiles/profile_io_data.cc @@ -41,7 +41,6 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" -#include "content/browser/renderer_host/resource_request_info_impl.h" #include "content/public/browser/browser_thread.h" #include "content/public/browser/host_zoom_map.h" #include "content/public/browser/notification_service.h" @@ -54,9 +53,6 @@ #include "net/proxy/proxy_script_fetcher_impl.h" #include "net/proxy/proxy_service.h" #include "net/url_request/url_request.h" -#include "webkit/blob/blob_data.h" -#include "webkit/blob/blob_url_request_job_factory.h" -#include "webkit/fileapi/file_system_url_request_job_factory.h" #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/gview_request_interceptor.h" @@ -67,7 +63,6 @@ using content::BrowserContext; using content::BrowserThread; using content::ResourceContext; using content::ResourceDispatcherHost; -using content::ResourceRequestInfoImpl; namespace { @@ -149,30 +144,6 @@ class ProtocolHandlerRegistryInterceptor DISALLOW_COPY_AND_ASSIGN(ProtocolHandlerRegistryInterceptor); }; -// TODO(darin): Move this class to src/content -class ChromeBlobProtocolHandler : public webkit_blob::BlobProtocolHandler { - public: - ChromeBlobProtocolHandler( - webkit_blob::BlobStorageController* blob_storage_controller, - base::MessageLoopProxy* loop_proxy) - : webkit_blob::BlobProtocolHandler(blob_storage_controller, - loop_proxy) {} - - virtual ~ChromeBlobProtocolHandler() {} - - 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(); - } - - DISALLOW_COPY_AND_ASSIGN(ChromeBlobProtocolHandler); -}; - Profile* GetProfileOnUI(ProfileManager* profile_manager, Profile* profile) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); DCHECK(profile); @@ -488,26 +459,12 @@ void ProfileIOData::LazyInitialize() const { set_protocol = job_factory_->SetProtocolHandler( chrome::kChromeUIScheme, ChromeURLDataManagerBackend::CreateProtocolHandler( - chrome_url_data_manager_backend_.get(), - ResourceContext::GetAppCacheService(&resource_context_), - ResourceContext::GetBlobStorageController(&resource_context_))); + chrome_url_data_manager_backend_.get())); DCHECK(set_protocol); set_protocol = job_factory_->SetProtocolHandler( chrome::kChromeDevToolsScheme, CreateDevToolsProtocolHandler(chrome_url_data_manager_backend_.get())); DCHECK(set_protocol); - set_protocol = job_factory_->SetProtocolHandler( - chrome::kBlobScheme, - new ChromeBlobProtocolHandler( - ResourceContext::GetBlobStorageController(&resource_context_), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); - DCHECK(set_protocol); - set_protocol = job_factory_->SetProtocolHandler( - chrome::kFileSystemScheme, - CreateFileSystemProtocolHandler( - ResourceContext::GetFileSystemContext(&resource_context_), - BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); - DCHECK(set_protocol); #if defined(OS_CHROMEOS) && !defined(GOOGLE_CHROME_BUILD) // Install the GView request interceptor that will redirect requests // of compatible documents (PDF, etc) to the GView document viewer. diff --git a/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc b/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc index fe6bfa7..638adb5 100644 --- a/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc +++ b/chrome/browser/ui/webui/chrome_url_data_manager_backend.cc @@ -18,8 +18,6 @@ #include "base/path_service.h" #include "base/string_util.h" #include "chrome/browser/net/chrome_url_request_context.h" -#include "chrome/browser/net/view_blob_internals_job_factory.h" -#include "chrome/browser/net/view_http_cache_job_factory.h" #include "chrome/browser/ui/webui/shared_resources_data_source.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/chrome_switches.h" @@ -34,8 +32,6 @@ #include "net/url_request/url_request_file_job.h" #include "net/url_request/url_request_job.h" #include "net/url_request/url_request_job_factory.h" -#include "webkit/appcache/appcache_service.h" -#include "webkit/appcache/view_appcache_internals_job.h" using content::BrowserThread; @@ -319,18 +315,10 @@ void URLRequestChromeJob::StartAsync() { namespace { -bool IsViewAppCacheInternalsURL(const GURL& url) { - return url.SchemeIs(chrome::kChromeUIScheme) && - url.host() == chrome::kChromeUIAppCacheInternalsHost; -} - class ChromeProtocolHandler : public net::URLRequestJobFactory::ProtocolHandler { public: - ChromeProtocolHandler( - ChromeURLDataManagerBackend* backend, - appcache::AppCacheService* appcache_service, - webkit_blob::BlobStorageController* blob_storage_controller); + explicit ChromeProtocolHandler(ChromeURLDataManagerBackend* backend); ~ChromeProtocolHandler(); virtual net::URLRequestJob* MaybeCreateJob( @@ -339,19 +327,13 @@ class ChromeProtocolHandler private: // These members are owned by ProfileIOData, which owns this ProtocolHandler. ChromeURLDataManagerBackend* const backend_; - appcache::AppCacheService* const appcache_service_; - webkit_blob::BlobStorageController* const blob_storage_controller_; DISALLOW_COPY_AND_ASSIGN(ChromeProtocolHandler); }; ChromeProtocolHandler::ChromeProtocolHandler( - ChromeURLDataManagerBackend* backend, - appcache::AppCacheService* appcache_service, - webkit_blob::BlobStorageController* blob_storage_controller) - : backend_(backend), - appcache_service_(appcache_service), - blob_storage_controller_(blob_storage_controller) {} + ChromeURLDataManagerBackend* backend) + : backend_(backend) {} ChromeProtocolHandler::~ChromeProtocolHandler() {} @@ -359,20 +341,6 @@ net::URLRequestJob* ChromeProtocolHandler::MaybeCreateJob( net::URLRequest* request) const { DCHECK(request); - // Next check for chrome://view-http-cache/*, which uses its own job type. - if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) - return ViewHttpCacheJobFactory::CreateJobForRequest(request); - - // Next check for chrome://appcache-internals/, which uses its own job type. - if (IsViewAppCacheInternalsURL(request->url())) - return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( - request, appcache_service_); - - // Next check for chrome://blob-internals/, which uses its own job type. - if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) - return ViewBlobInternalsJobFactory::CreateJobForRequest( - request, blob_storage_controller_); - // Fall back to using a custom handler return new URLRequestChromeJob(request, backend_); } @@ -395,14 +363,9 @@ ChromeURLDataManagerBackend::~ChromeURLDataManagerBackend() { // static net::URLRequestJobFactory::ProtocolHandler* ChromeURLDataManagerBackend::CreateProtocolHandler( - ChromeURLDataManagerBackend* backend, - appcache::AppCacheService* appcache_service, - webkit_blob::BlobStorageController* blob_storage_controller) { - DCHECK(appcache_service); - DCHECK(blob_storage_controller); + ChromeURLDataManagerBackend* backend) { DCHECK(backend); - return new ChromeProtocolHandler( - backend, appcache_service, blob_storage_controller); + return new ChromeProtocolHandler(backend); } void ChromeURLDataManagerBackend::AddDataSource( diff --git a/chrome/browser/ui/webui/chrome_url_data_manager_backend.h b/chrome/browser/ui/webui/chrome_url_data_manager_backend.h index 073fdc1..5fa7772 100644 --- a/chrome/browser/ui/webui/chrome_url_data_manager_backend.h +++ b/chrome/browser/ui/webui/chrome_url_data_manager_backend.h @@ -20,17 +20,10 @@ class GURL; class RefCountedMemory; class URLRequestChromeJob; -namespace appcache { -class AppCacheService; -} - namespace net { class URLRequest; class URLRequestJob; } -namespace webkit_blob { -class BlobStorageController; -} // ChromeURLDataManagerBackend is used internally by ChromeURLDataManager on the // IO thread. In most cases you can use the API in ChromeURLDataManager and @@ -45,9 +38,7 @@ class ChromeURLDataManagerBackend { // Invoked to create the protocol handler for chrome://. static net::URLRequestJobFactory::ProtocolHandler* CreateProtocolHandler( - ChromeURLDataManagerBackend* backend, - appcache::AppCacheService* appcache_service, - webkit_blob::BlobStorageController* blob_storage_controller); + ChromeURLDataManagerBackend* backend); // Adds a DataSource to the collection of data sources. void AddDataSource(ChromeURLDataManager::DataSource* source); diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 7e038ab..c8cc165 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -1431,10 +1431,6 @@ 'browser/net/url_request_mock_link_doctor_job.h', 'browser/net/url_request_mock_util.cc', 'browser/net/url_request_mock_util.h', - 'browser/net/view_blob_internals_job_factory.cc', - 'browser/net/view_blob_internals_job_factory.h', - 'browser/net/view_http_cache_job_factory.cc', - 'browser/net/view_http_cache_job_factory.h', 'browser/notifications/balloon.cc', 'browser/notifications/balloon.h', 'browser/notifications/balloon_collection.cc', diff --git a/chrome/common/url_constants.cc b/chrome/common/url_constants.cc index faf46b3..7305690 100644 --- a/chrome/common/url_constants.cc +++ b/chrome/common/url_constants.cc @@ -56,7 +56,6 @@ const char kChromeUIKeyboardURL[] = "chrome://keyboard/"; const char kChromeUIMemoryRedirectURL[] = "chrome://memory-redirect/"; const char kChromeUIMemoryURL[] = "chrome://memory/"; const char kChromeUINetInternalsURL[] = "chrome://net-internals/"; -const char kChromeUINetworkViewCacheURL[] = "chrome://view-http-cache/"; const char kChromeUINewProfile[] = "chrome://newprofile/"; const char kChromeUINewTabURL[] = "chrome://newtab/"; const char kChromeUIOmniboxURL[] = "chrome://omnibox/"; @@ -113,9 +112,7 @@ const char kChromeUITabModalConfirmDialogURL[] = // Add hosts to kChromePaths in browser_about_handler.cc to be listed by // chrome://chrome-urls (about:about) and the built-in AutocompleteProvider. const char kChromeUIAboutHost[] = "about"; -const char kChromeUIAppCacheInternalsHost[] = "appcache-internals"; const char kChromeUIBlankHost[] = "blank"; -const char kChromeUIBlobInternalsHost[] = "blob-internals"; const char kChromeUIBookmarksHost[] = "bookmarks"; const char kChromeUICacheHost[] = "cache"; const char kChromeUICertificateViewerHost[] = "view-cert"; @@ -160,7 +157,6 @@ const char kChromeUIMemoryHost[] = "memory"; const char kChromeUIMemoryRedirectHost[] = "memory-redirect"; const char kChromeUINetInternalsHost[] = "net-internals"; const char kChromeUINetworkActionPredictorHost[] = "network-action-predictor"; -const char kChromeUINetworkViewCacheHost[] = "view-http-cache"; const char kChromeUINewTabHost[] = "newtab"; const char kChromeUIOmniboxHost[] = "omnibox"; const char kChromeUIPluginsHost[] = "plugins"; diff --git a/chrome/common/url_constants.h b/chrome/common/url_constants.h index c1b984b..1b5c4a7 100644 --- a/chrome/common/url_constants.h +++ b/chrome/common/url_constants.h @@ -50,7 +50,6 @@ extern const char kChromeUIKeyboardURL[]; extern const char kChromeUIMemoryRedirectURL[]; extern const char kChromeUIMemoryURL[]; extern const char kChromeUINetInternalsURL[]; -extern const char kChromeUINetworkViewCacheURL[]; extern const char kChromeUINewProfile[]; extern const char kChromeUINewTabURL[]; extern const char kChromeUIOmniboxURL[]; @@ -104,9 +103,7 @@ extern const char kChromeUITabModalConfirmDialogURL[]; // chrome components of URLs. Should be kept in sync with the full URLs above. extern const char kChromeUIAboutHost[]; extern const char kChromeUIAboutPageFrameHost[]; -extern const char kChromeUIAppCacheInternalsHost[]; extern const char kChromeUIBlankHost[]; -extern const char kChromeUIBlobInternalsHost[]; extern const char kChromeUIBookmarksHost[]; extern const char kChromeUICacheHost[]; extern const char kChromeUICertificateViewerHost[]; @@ -151,7 +148,6 @@ extern const char kChromeUIMemoryHost[]; extern const char kChromeUIMemoryRedirectHost[]; extern const char kChromeUINetInternalsHost[]; extern const char kChromeUINetworkActionPredictorHost[]; -extern const char kChromeUINetworkViewCacheHost[]; extern const char kChromeUINewTabHost[]; extern const char kChromeUIOmniboxHost[]; extern const char kChromeUIPluginsHost[]; diff --git a/chrome/test/data/downloads/download-dangerous-blob.html b/chrome/test/data/downloads/download-dangerous-blob.html new file mode 100644 index 0000000..8f26b3b --- /dev/null +++ b/chrome/test/data/downloads/download-dangerous-blob.html @@ -0,0 +1,15 @@ +<html> +<body> +<a download="foo.exe" href="">link</a> +<script> + bb = new WebKitBlobBuilder + bb.append('foo') + b = bb.getBlob() + document.querySelector('a[download]').href = webkitURL.createObjectURL(b) + + url = window.location.href + document.querySelector('a[download]').download = url.substr(url.indexOf('=') + 1) + document.querySelector('a[download]').click() +</script> +</body> +</html> diff --git a/chrome/browser/net/view_blob_internals_job_factory.cc b/content/browser/net/view_blob_internals_job_factory.cc index ed9a109..32dbd99 100644 --- a/chrome/browser/net/view_blob_internals_job_factory.cc +++ b/content/browser/net/view_blob_internals_job_factory.cc @@ -2,12 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/net/view_blob_internals_job_factory.h" +#include "content/browser/net/view_blob_internals_job_factory.h" #include "base/memory/scoped_ptr.h" #include "base/string_util.h" -#include "chrome/browser/net/chrome_url_request_context.h" -#include "chrome/common/url_constants.h" +#include "content/public/common/url_constants.h" #include "net/url_request/url_request.h" #include "webkit/blob/view_blob_internals_job.h" diff --git a/chrome/browser/net/view_blob_internals_job_factory.h b/content/browser/net/view_blob_internals_job_factory.h index 7cb8fbc..11eb48f 100644 --- a/chrome/browser/net/view_blob_internals_job_factory.h +++ b/content/browser/net/view_blob_internals_job_factory.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_NET_VIEW_BLOB_INTERNALS_JOB_FACTORY_H_ -#define CHROME_BROWSER_NET_VIEW_BLOB_INTERNALS_JOB_FACTORY_H_ +#ifndef CONTENT_BROWSER_NET_VIEW_BLOB_INTERNALS_JOB_FACTORY_H_ +#define CONTENT_BROWSER_NET_VIEW_BLOB_INTERNALS_JOB_FACTORY_H_ #pragma once namespace net { @@ -24,4 +24,4 @@ class ViewBlobInternalsJobFactory { webkit_blob::BlobStorageController* blob_storage_controller); }; -#endif // CHROME_BROWSER_NET_VIEW_BLOB_INTERNALS_JOB_FACTORY_H_ +#endif // CONTENT_BROWSER_NET_VIEW_BLOB_INTERNALS_JOB_FACTORY_H_ diff --git a/chrome/browser/net/view_http_cache_job_factory.cc b/content/browser/net/view_http_cache_job_factory.cc index 8802601..738524f 100644 --- a/chrome/browser/net/view_http_cache_job_factory.cc +++ b/content/browser/net/view_http_cache_job_factory.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/net/view_http_cache_job_factory.h" +#include "content/browser/net/view_http_cache_job_factory.h" #include "base/bind.h" #include "base/bind_helpers.h" @@ -11,7 +11,7 @@ #include "base/memory/weak_ptr.h" #include "base/message_loop.h" #include "base/string_util.h" -#include "chrome/common/url_constants.h" +#include "content/public/common/url_constants.h" #include "net/base/completion_callback.h" #include "net/base/net_errors.h" #include "net/url_request/url_request.h" diff --git a/chrome/browser/net/view_http_cache_job_factory.h b/content/browser/net/view_http_cache_job_factory.h index eb164c5..5e0c322 100644 --- a/chrome/browser/net/view_http_cache_job_factory.h +++ b/content/browser/net/view_http_cache_job_factory.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_NET_VIEW_HTTP_CACHE_JOB_FACTORY_H_ -#define CHROME_BROWSER_NET_VIEW_HTTP_CACHE_JOB_FACTORY_H_ +#ifndef CONTENT_BROWSER_NET_VIEW_HTTP_CACHE_JOB_FACTORY_H_ +#define CONTENT_BROWSER_NET_VIEW_HTTP_CACHE_JOB_FACTORY_H_ #pragma once namespace net { @@ -19,4 +19,4 @@ class ViewHttpCacheJobFactory { static net::URLRequestJob* CreateJobForRequest(net::URLRequest* request); }; -#endif // CHROME_BROWSER_NET_VIEW_HTTP_CACHE_JOB_FACTORY_H_ +#endif // CONTENT_BROWSER_NET_VIEW_HTTP_CACHE_JOB_FACTORY_H_ diff --git a/content/browser/renderer_host/resource_dispatcher_host_impl.cc b/content/browser/renderer_host/resource_dispatcher_host_impl.cc index 4fc859a..d7ea8ad 100644 --- a/content/browser/renderer_host/resource_dispatcher_host_impl.cc +++ b/content/browser/renderer_host/resource_dispatcher_host_impl.cc @@ -43,6 +43,7 @@ #include "content/browser/renderer_host/resource_request_info_impl.h" #include "content/browser/renderer_host/sync_resource_handler.h" #include "content/browser/renderer_host/throttling_resource_handler.h" +#include "content/browser/resource_context_impl.h" #include "content/browser/ssl/ssl_client_auth_handler.h" #include "content/browser/ssl/ssl_manager.h" #include "content/browser/worker_host/worker_service_impl.h" @@ -55,7 +56,6 @@ #include "content/public/browser/global_request_id.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/render_view_host_delegate.h" -#include "content/public/browser/resource_context.h" #include "content/public/browser/resource_dispatcher_host_delegate.h" #include "content/public/browser/resource_dispatcher_host_login_delegate.h" #include "content/public/browser/resource_throttle.h" @@ -743,7 +743,7 @@ void ResourceDispatcherHostImpl::BeginRequest( // Might need to resolve the blob references in the upload data. if (request_data.upload_data) { - ResourceContext::GetBlobStorageController(resource_context)-> + GetBlobStorageControllerForResourceContext(resource_context)-> ResolveBlobReferencesInUploadData(request_data.upload_data.get()); } @@ -914,7 +914,7 @@ void ResourceDispatcherHostImpl::BeginRequest( // Hang on to a reference to ensure the blob is not released prior // to the job being started. webkit_blob::BlobStorageController* controller = - ResourceContext::GetBlobStorageController(resource_context); + GetBlobStorageControllerForResourceContext(resource_context); extra_info->set_requested_blob_data( controller->GetBlobDataFromUrl(request->url())); } diff --git a/content/browser/resource_context_impl.cc b/content/browser/resource_context_impl.cc index 5a856fc..a3768db 100644 --- a/content/browser/resource_context_impl.cc +++ b/content/browser/resource_context_impl.cc @@ -4,14 +4,27 @@ #include "content/browser/resource_context_impl.h" +#include "base/logging.h" #include "content/browser/appcache/chrome_appcache_service.h" #include "content/browser/fileapi/browser_file_system_helper.h" #include "content/browser/fileapi/chrome_blob_storage_context.h" #include "content/browser/host_zoom_map_impl.h" #include "content/browser/in_process_webkit/indexed_db_context_impl.h" +#include "content/browser/net/view_blob_internals_job_factory.h" +#include "content/browser/net/view_http_cache_job_factory.h" +#include "content/browser/renderer_host/resource_request_info_impl.h" #include "content/public/browser/browser_context.h" #include "content/public/browser/browser_thread.h" +#include "content/public/common/url_constants.h" +#include "net/url_request/url_request.h" +#include "net/url_request/url_request_context.h" +#include "net/url_request/url_request_context_getter.h" +#include "webkit/appcache/appcache_service.h" +#include "webkit/appcache/view_appcache_internals_job.h" +#include "webkit/blob/blob_data.h" +#include "webkit/blob/blob_url_request_job_factory.h" #include "webkit/database/database_tracker.h" +#include "webkit/fileapi/file_system_url_request_job_factory.h" // Key names on ResourceContext. static const char* kAppCacheServicKeyName = "content_appcache_service_tracker"; @@ -30,6 +43,8 @@ using webkit_database::DatabaseTracker; namespace content { +namespace { + class NonOwningZoomData : public base::SupportsUserData::Data { public: explicit NonOwningZoomData(HostZoomMap* hzm) : host_zoom_map_(hzm) {} @@ -39,18 +54,118 @@ class NonOwningZoomData : public base::SupportsUserData::Data { HostZoomMap* host_zoom_map_; }; +class BlobProtocolHandler : public webkit_blob::BlobProtocolHandler { + public: + BlobProtocolHandler( + webkit_blob::BlobStorageController* blob_storage_controller, + base::MessageLoopProxy* loop_proxy) + : webkit_blob::BlobProtocolHandler(blob_storage_controller, + loop_proxy) {} + + 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(); + } + + DISALLOW_COPY_AND_ASSIGN(BlobProtocolHandler); +}; + +// Adds a bunch of debugging urls. We use an interceptor instead of a protocol +// 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: + DeveloperProtocolHandler( + AppCacheService* appcache_service, + BlobStorageController* blob_storage_controller) + : appcache_service_(appcache_service), + blob_storage_controller_(blob_storage_controller) {} + virtual ~DeveloperProtocolHandler() {} + + virtual net::URLRequestJob* MaybeIntercept( + net::URLRequest* request) const OVERRIDE { + // Check for chrome://view-http-cache/*, which uses its own job type. + if (ViewHttpCacheJobFactory::IsSupportedURL(request->url())) + return ViewHttpCacheJobFactory::CreateJobForRequest(request); + + // Next check for chrome://appcache-internals/, which uses its own job type. + if (request->url().SchemeIs(chrome::kChromeUIScheme) && + request->url().host() == chrome::kChromeUIAppCacheInternalsHost) { + return appcache::ViewAppCacheInternalsJobFactory::CreateJobForRequest( + request, appcache_service_); + } + + // Next check for chrome://blob-internals/, which uses its own job type. + if (ViewBlobInternalsJobFactory::IsSupportedURL(request->url())) { + return ViewBlobInternalsJobFactory::CreateJobForRequest( + request, blob_storage_controller_); + } + return NULL; + } + + virtual net::URLRequestJob* MaybeInterceptRedirect( + const GURL& location, + net::URLRequest* request) const OVERRIDE { + return NULL; + } + + virtual net::URLRequestJob* MaybeInterceptResponse( + net::URLRequest* request) const OVERRIDE { + return NULL; + } + + private: + AppCacheService* appcache_service_; + BlobStorageController* blob_storage_controller_; +}; + +void InitializeRequestContext( + ResourceContext* resource_context, + scoped_refptr<net::URLRequestContextGetter> context_getter) { + if (!context_getter) + return; // tests. + net::URLRequestContext* context = context_getter->GetURLRequestContext(); + net::URLRequestJobFactory* job_factory = + const_cast<net::URLRequestJobFactory*>(context->job_factory()); + if (job_factory->IsHandledProtocol(chrome::kBlobScheme)) + return; // Already initialized this RequestContext. + + bool set_protocol = job_factory->SetProtocolHandler( + chrome::kBlobScheme, + new BlobProtocolHandler( + GetBlobStorageControllerForResourceContext(resource_context), + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); + DCHECK(set_protocol); + set_protocol = job_factory->SetProtocolHandler( + chrome::kFileSystemScheme, + CreateFileSystemProtocolHandler( + GetFileSystemContextForResourceContext(resource_context), + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE))); + DCHECK(set_protocol); + + job_factory->AddInterceptor(new DeveloperProtocolHandler( + ResourceContext::GetAppCacheService(resource_context), + GetBlobStorageControllerForResourceContext(resource_context))); + + // TODO(jam): Add the ProtocolHandlerRegistryIntercepter here! +} + +} // namespace + AppCacheService* ResourceContext::GetAppCacheService(ResourceContext* context) { return UserDataAdapter<ChromeAppCacheService>::Get( context, kAppCacheServicKeyName); } -FileSystemContext* ResourceContext::GetFileSystemContext( - ResourceContext* resource_context) { - return UserDataAdapter<FileSystemContext>::Get( - resource_context, kFileSystemContextKeyName); -} - -BlobStorageController* ResourceContext::GetBlobStorageController( +BlobStorageController* GetBlobStorageControllerForResourceContext( ResourceContext* resource_context) { return GetChromeBlobStorageContextForResourceContext(resource_context)-> controller(); @@ -62,6 +177,12 @@ DatabaseTracker* GetDatabaseTrackerForResourceContext( resource_context, kDatabaseTrackerKeyName); } +FileSystemContext* GetFileSystemContextForResourceContext( + ResourceContext* resource_context) { + return UserDataAdapter<FileSystemContext>::Get( + resource_context, kFileSystemContextKeyName); +} + IndexedDBContextImpl* GetIndexedDBContextForResourceContext( ResourceContext* resource_context) { return UserDataAdapter<IndexedDBContextImpl>::Get( @@ -112,6 +233,22 @@ void InitializeResourceContext(BrowserContext* browser_context) { kHostZoomMapKeyName, new NonOwningZoomData( HostZoomMap::GetForBrowserContext(browser_context))); + + // Add content's URLRequestContext's hooks. + // Check first to avoid memory leak in unittests. + if (BrowserThread::IsMessageLoopValid(BrowserThread::IO)) { + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&InitializeRequestContext, + resource_context, + make_scoped_refptr(browser_context->GetRequestContext()))); + BrowserThread::PostTask( + BrowserThread::IO, FROM_HERE, + base::Bind(&InitializeRequestContext, + resource_context, + make_scoped_refptr( + browser_context->GetRequestContextForMedia()))); + } } } // namespace content diff --git a/content/browser/resource_context_impl.h b/content/browser/resource_context_impl.h index 946ba24..a3bbf95 100644 --- a/content/browser/resource_context_impl.h +++ b/content/browser/resource_context_impl.h @@ -10,6 +10,14 @@ class IndexedDBContextImpl; class ChromeBlobStorageContext; +namespace fileapi { +class FileSystemContext; +} + +namespace webkit_blob { +class BlobStorageController; +} + namespace webkit_database { class DatabaseTracker; } @@ -22,8 +30,12 @@ class HostZoomMap; // Getters for objects that are part of BrowserContext which are also used on // the IO thread. These are only accessed by content so they're not on the // public API. +webkit_blob::BlobStorageController* GetBlobStorageControllerForResourceContext( + ResourceContext* resource_context); webkit_database::DatabaseTracker* GetDatabaseTrackerForResourceContext( ResourceContext* resource_context); +fileapi::FileSystemContext* GetFileSystemContextForResourceContext( + ResourceContext* resource_context); IndexedDBContextImpl* GetIndexedDBContextForResourceContext( ResourceContext* resource_context); ChromeBlobStorageContext* GetChromeBlobStorageContextForResourceContext( diff --git a/content/browser/worker_host/worker_process_host.cc b/content/browser/worker_host/worker_process_host.cc index dc38359..35dc452 100644 --- a/content/browser/worker_host/worker_process_host.cc +++ b/content/browser/worker_host/worker_process_host.cc @@ -92,7 +92,7 @@ void WorkerCrashCallback(int render_process_unique_id, int render_view_id) { host->GetDelegate()->WorkerCrashed(); } -WorkerProcessHost::WorkerProcessHost(content::ResourceContext* resource_context) +WorkerProcessHost::WorkerProcessHost(ResourceContext* resource_context) : resource_context_(resource_context) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(resource_context); @@ -198,7 +198,7 @@ bool WorkerProcessHost::Init(int render_process_id) { cmd_line); fileapi::FileSystemContext* file_system_context = - ResourceContext::GetFileSystemContext(resource_context_); + GetFileSystemContextForResourceContext(resource_context_); ChildProcessSecurityPolicyImpl::GetInstance()->AddWorker( process_->GetData().id, render_process_id); if (!CommandLine::ForCurrentProcess()->HasSwitch( @@ -266,7 +266,7 @@ void WorkerProcessHost::CreateMessageFilters(int render_process_id) { process_->GetHost()->AddFilter(new FileAPIMessageFilter( process_->GetData().id, request_context, - ResourceContext::GetFileSystemContext(resource_context_), + GetFileSystemContextForResourceContext(resource_context_), content::GetChromeBlobStorageContextForResourceContext( resource_context_))); process_->GetHost()->AddFilter(new FileUtilitiesMessageFilter( diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 758d277..3295f43 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -405,6 +405,10 @@ 'browser/mime_registry_message_filter.h', 'browser/net/browser_online_state_observer.cc', 'browser/net/browser_online_state_observer.h', + 'browser/net/view_blob_internals_job_factory.cc', + 'browser/net/view_blob_internals_job_factory.h', + 'browser/net/view_http_cache_job_factory.cc', + 'browser/net/view_http_cache_job_factory.h', 'browser/notification_service_impl.cc', 'browser/notification_service_impl.h', 'browser/plugin_data_remover_impl.cc', diff --git a/content/public/browser/resource_context.h b/content/public/browser/resource_context.h index af28f92..817578f 100644 --- a/content/public/browser/resource_context.h +++ b/content/public/browser/resource_context.h @@ -12,19 +12,11 @@ namespace appcache { class AppCacheService; } -namespace fileapi { -class FileSystemContext; -} - namespace net { class HostResolver; class URLRequestContext; } -namespace webkit_blob { -class BlobStorageController; -} - namespace content { class MediaObserver; @@ -36,10 +28,6 @@ class CONTENT_EXPORT ResourceContext : public base::SupportsUserData { public: static appcache::AppCacheService* GetAppCacheService( ResourceContext* resource_context); - static fileapi::FileSystemContext* GetFileSystemContext( - ResourceContext* resource_context); - static webkit_blob::BlobStorageController* GetBlobStorageController( - ResourceContext* resource_context); virtual ~ResourceContext() {} virtual net::HostResolver* GetHostResolver() = 0; diff --git a/content/public/common/url_constants.cc b/content/public/common/url_constants.cc index 49f9711..26dee8e 100644 --- a/content/public/common/url_constants.cc +++ b/content/public/common/url_constants.cc @@ -45,13 +45,17 @@ const char kViewSourceScheme[] = "view-source"; const char kStandardSchemeSeparator[] = "://"; const char kAboutBlankURL[] = "about:blank"; +const char kChromeUIAppCacheInternalsHost[] = "appcache-internals"; +const char kChromeUIBlobInternalsHost[] = "blob-internals"; const char kChromeUIBrowserCrashHost[] = "inducebrowsercrashforrealz"; +const char kChromeUINetworkViewCacheHost[] = "view-http-cache"; const char kChromeUICrashURL[] = "chrome://crash"; const char kChromeUIGpuCleanURL[] = "chrome://gpuclean"; const char kChromeUIGpuCrashURL[] = "chrome://gpucrash"; const char kChromeUIGpuHangURL[] = "chrome://gpuhang"; const char kChromeUIHangURL[] = "chrome://hang"; const char kChromeUIKillURL[] = "chrome://kill"; +const char kChromeUINetworkViewCacheURL[] = "chrome://view-http-cache/"; const char kChromeUIShorthangURL[] = "chrome://shorthang"; // This error URL is loaded in normal web renderer processes, so it should not diff --git a/content/public/common/url_constants.h b/content/public/common/url_constants.h index 2df75c8..dcf69d5 100644 --- a/content/public/common/url_constants.h +++ b/content/public/common/url_constants.h @@ -39,13 +39,17 @@ CONTENT_EXPORT extern const char kStandardSchemeSeparator[]; // About URLs (including schemes). CONTENT_EXPORT extern const char kAboutBlankURL[]; +CONTENT_EXPORT extern const char kChromeUIAppCacheInternalsHost[]; +CONTENT_EXPORT extern const char kChromeUIBlobInternalsHost[]; CONTENT_EXPORT extern const char kChromeUIBrowserCrashHost[]; +CONTENT_EXPORT extern const char kChromeUINetworkViewCacheHost[]; CONTENT_EXPORT extern const char kChromeUICrashURL[]; CONTENT_EXPORT extern const char kChromeUIGpuCleanURL[]; CONTENT_EXPORT extern const char kChromeUIGpuCrashURL[]; CONTENT_EXPORT extern const char kChromeUIGpuHangURL[]; CONTENT_EXPORT extern const char kChromeUIHangURL[]; CONTENT_EXPORT extern const char kChromeUIKillURL[]; +CONTENT_EXPORT extern const char kChromeUINetworkViewCacheURL[]; CONTENT_EXPORT extern const char kChromeUIShorthangURL[]; // Special URL used to start a navigation to an error page. |