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

Unified Diff: content/child/web_url_loader_impl.cc

Issue 294193002: Set response headers for data URL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months 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 | « content/child/web_url_loader_impl.h ('k') | content/child/web_url_loader_impl_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/web_url_loader_impl.cc
diff --git a/content/child/web_url_loader_impl.cc b/content/child/web_url_loader_impl.cc
index 085cd6d243018eeb63028ea48e656f264caaaf05..5a443ec784bf6a890e444e206f6229dd700de69c 100644
--- a/content/child/web_url_loader_impl.cc
+++ b/content/child/web_url_loader_impl.cc
@@ -66,6 +66,52 @@ namespace content {
// Utilities ------------------------------------------------------------------
+int GetInfoFromDataURL(const GURL& url,
+ ResourceResponseInfo* info,
+ std::string* data) {
+ std::string mime_type;
+ std::string charset;
+ if (!net::DataURL::Parse(url, &mime_type, &charset, data))
darin (slow to review) 2014/06/02 16:49:25 Keep in mind that for navigations to data: URL, we
tyoshino (SeeGerritForStatus) 2014/06/03 13:04:38 Thanks for the pointer, Darin. Once IsToken check
+ return net::ERR_INVALID_URL;
+
+ DCHECK(!mime_type.empty());
+ DCHECK(!charset.empty());
+
+ // mime_type set by net::DataURL::Parse() is guaranteed to be in
+ // token "/" token
+ // form. Now just ensure charset is token. The grammar for charset is not
+ // specially defined in RFC2045 and RFC2397. It just need to be token or
+ // quoted-string since it's an attribute value of media type. But charset in
+ // Content-Type header is specified explicitly to follow token ABNF in
+ // httpbis spec.
+ if (!net::HttpUtil::IsToken(charset))
darin (slow to review) 2014/06/02 16:49:25 perhaps this check should be performed by net::Dat
tyoshino (SeeGerritForStatus) 2014/06/03 13:04:38 It's worth doing for spec compliance. However, it
+ return net::ERR_INVALID_URL;
+
+ // Assure same time for all time fields of data: URLs.
+ Time now = Time::Now();
+ info->load_timing.request_start = TimeTicks::Now();
+ info->load_timing.request_start_time = now;
+ info->request_time = now;
+ info->response_time = now;
+
+ scoped_refptr<net::HttpResponseHeaders> headers(
+ new net::HttpResponseHeaders(std::string()));
+ headers->ReplaceStatusLine("HTTP/1.1 200 OK");
+ std::string content_type_header =
+ "Content-Type: " + mime_type + ";charset=" + charset;
+ headers->AddHeader(content_type_header);
+ headers->AddHeader("Access-Control-Allow-Origin: *");
+ info->headers = headers;
+
+ info->mime_type.swap(mime_type);
+ info->charset.swap(charset);
+ info->security_info.clear();
+ info->content_length = data->length();
+ info->encoded_data_length = 0;
+
+ return net::OK;
+}
+
namespace {
const char kThrottledErrorDescription[] =
@@ -125,35 +171,6 @@ class HeaderFlattener : public WebHTTPHeaderVisitor {
bool has_accept_header_;
};
-// Extracts the information from a data: url.
-bool GetInfoFromDataURL(const GURL& url,
- ResourceResponseInfo* info,
- std::string* data,
- int* error_code) {
- std::string mime_type;
- std::string charset;
- if (net::DataURL::Parse(url, &mime_type, &charset, data)) {
- *error_code = net::OK;
- // Assure same time for all time fields of data: URLs.
- Time now = Time::Now();
- info->load_timing.request_start = TimeTicks::Now();
- info->load_timing.request_start_time = now;
- info->request_time = now;
- info->response_time = now;
- info->headers = NULL;
- info->mime_type.swap(mime_type);
- info->charset.swap(charset);
- info->security_info.clear();
- info->content_length = data->length();
- info->encoded_data_length = 0;
-
- return true;
- }
-
- *error_code = net::ERR_INVALID_URL;
- return false;
-}
-
typedef ResourceDevToolsInfo::HeadersVector HeadersVector;
// Converts timing data from |load_timing| to the format used by WebKit.
@@ -322,9 +339,9 @@ void WebURLLoaderImpl::Context::Start(const WebURLRequest& request,
// This is a sync load. Do the work now.
sync_load_response->url = url;
std::string data;
- GetInfoFromDataURL(sync_load_response->url, sync_load_response,
- &sync_load_response->data,
- &sync_load_response->error_code);
+ sync_load_response->error_code =
+ GetInfoFromDataURL(sync_load_response->url, sync_load_response,
+ &sync_load_response->data);
} else {
AddRef(); // Balanced in OnCompletedRequest
base::MessageLoop::current()->PostTask(
@@ -680,10 +697,10 @@ bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const {
void WebURLLoaderImpl::Context::HandleDataURL() {
ResourceResponseInfo info;
- int error_code;
std::string data;
- if (GetInfoFromDataURL(request_.url(), &info, &data, &error_code)) {
+ int error_code = GetInfoFromDataURL(request_.url(), &info, &data);
+ if (error_code == net::OK) {
OnReceivedResponse(info);
if (!data.empty())
OnReceivedData(data.data(), data.size(), 0);
« no previous file with comments | « content/child/web_url_loader_impl.h ('k') | content/child/web_url_loader_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698