diff options
author | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-03 21:11:20 +0000 |
---|---|---|
committer | darin@chromium.org <darin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-12-03 21:11:20 +0000 |
commit | 2d8099cf56475b6989911ea8e573cbeb26724f3d (patch) | |
tree | 05b33ac2edbaf2bddddf7f75f904b3c9949ccab7 /webkit/glue/weburlloader_impl.cc | |
parent | 9df79fddac6dc70909ac16207c9e63f2660ca5d1 (diff) | |
download | chromium_src-2d8099cf56475b6989911ea8e573cbeb26724f3d.zip chromium_src-2d8099cf56475b6989911ea8e573cbeb26724f3d.tar.gz chromium_src-2d8099cf56475b6989911ea8e573cbeb26724f3d.tar.bz2 |
Allow data URLs to trigger downloads, as they do in Firefox.
Unfortunately, many of our tests rely on being able to use WebURLLoader to load
data: URLs when there is no ResourceLoaderBridge implementation. In those tests,
we would crash if we try to use the ResourceLoaderBridge. To workaround that,
and because it probably a good optimization anyways, I decided to check if the
data URL has a supported MIME type, and if it does, then I let it load directly
as before.
Since data URLs may be very large, I modified DataURL::Parse to skip parsing the
'data' section of the URL if the corresponding out param is null.
R=tony
BUG=38546
TEST=none (I would like to add a download test, but they are all disabled or flaky.)
Review URL: http://codereview.chromium.org/5542001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68212 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/weburlloader_impl.cc')
-rw-r--r-- | webkit/glue/weburlloader_impl.cc | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/webkit/glue/weburlloader_impl.cc b/webkit/glue/weburlloader_impl.cc index a7f219d..d134382 100644 --- a/webkit/glue/weburlloader_impl.cc +++ b/webkit/glue/weburlloader_impl.cc @@ -14,6 +14,7 @@ #include "base/time.h" #include "net/base/data_url.h" #include "net/base/load_flags.h" +#include "net/base/mime_util.h" #include "net/base/net_errors.h" #include "net/base/net_util.h" #include "net/http/http_response_headers.h" @@ -302,6 +303,8 @@ class WebURLLoaderImpl::Context : public base::RefCounted<Context>, friend class base::RefCounted<Context>; ~Context() {} + // We can optimize the handling of data URLs in most cases. + bool CanHandleDataURL(const GURL& url) const; void HandleDataURL(); WebURLLoaderImpl* loader_; @@ -350,7 +353,7 @@ void WebURLLoaderImpl::Context::Start( request_ = request; // Save the request. GURL url = request.url(); - if (url.SchemeIs("data")) { + if (url.SchemeIs("data") && CanHandleDataURL(url)) { if (sync_load_response) { // This is a sync load. Do the work now. sync_load_response->url = url; @@ -662,6 +665,29 @@ void WebURLLoaderImpl::Context::OnCompletedRequest( Release(); } +bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { + DCHECK(url.SchemeIs("data")); + + // Optimize for the case where we can handle a data URL locally. We must + // skip this for data URLs targetted at frames since those could trigger a + // download. + // + // NOTE: We special case MIME types we can render both for performance + // reasons as well as to support unit tests, which do not have an underlying + // ResourceLoaderBridge implementation. + + if (request_.targetType() != WebURLRequest::TargetIsMainFrame && + request_.targetType() != WebURLRequest::TargetIsSubframe) + return true; + + std::string mime_type, unused_charset; + if (net::DataURL::Parse(url, &mime_type, &unused_charset, NULL) && + net::IsSupportedMimeType(mime_type)) + return true; + + return false; +} + void WebURLLoaderImpl::Context::HandleDataURL() { ResourceResponseInfo info; URLRequestStatus status; |