summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--net/base/data_url.cc4
-rw-r--r--net/base/data_url.h3
-rw-r--r--webkit/glue/weburlloader_impl.cc28
3 files changed, 34 insertions, 1 deletions
diff --git a/net/base/data_url.cc b/net/base/data_url.cc
index e30f7da..e387cd1 100644
--- a/net/base/data_url.cc
+++ b/net/base/data_url.cc
@@ -60,6 +60,10 @@ bool DataURL::Parse(const GURL& url, std::string* mime_type,
if (charset->empty())
charset->assign("US-ASCII");
+ // The caller may not be interested in receiving the data.
+ if (!data)
+ return true;
+
// Preserve spaces if dealing with text or xml input, same as mozilla:
// https://bugzilla.mozilla.org/show_bug.cgi?id=138052
// but strip them otherwise:
diff --git a/net/base/data_url.h b/net/base/data_url.h
index b40878a..65a211a 100644
--- a/net/base/data_url.h
+++ b/net/base/data_url.h
@@ -37,6 +37,9 @@ class DataURL {
// If the URL is malformed, then this method will return false, and its
// output variables will remain unchanged. On success, true is returned.
//
+ // OPTIONAL: If |data| is NULL, then the <data> section will not be parsed
+ // or validated.
+ //
static bool Parse(const GURL& url,
std::string* mime_type,
std::string* charset,
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;