Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Unified Diff: webkit/glue/weburlloader_impl.cc

Issue 5542001: Allow data URLs to trigger downloads, as they do in Firefox.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 10 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/base/data_url.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/weburlloader_impl.cc
===================================================================
--- webkit/glue/weburlloader_impl.cc (revision 68044)
+++ webkit/glue/weburlloader_impl.cc (working copy)
@@ -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 @@
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 @@
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 @@
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;
« no previous file with comments | « net/base/data_url.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698