Chromium Code Reviews| 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 b18f268f155cacbda0c34739091b45ed2b1bcf27..55297a17ee3a580e03bee55b2ac6b509f060050b 100644 |
| --- a/content/child/web_url_loader_impl.cc |
| +++ b/content/child/web_url_loader_impl.cc |
| @@ -65,6 +65,48 @@ 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)) |
| + return net::ERR_INVALID_URL; |
| + |
| + // mime_type set by net::DataURL::Parse() is guaranteed to be in |
| + // token "/" token |
| + // form. charset is also guaranteed to be a token. |
| + |
| + DCHECK(!mime_type.empty()); |
| + DCHECK(!charset.empty()); |
| + |
| + // 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"); |
| + // charset in Content-Type header is specified explicitly to follow token |
| + // ABNF in httpbis spec. |
| + std::string content_type_header = |
| + "Content-Type: " + mime_type + ";charset=" + charset; |
| + headers->AddHeader(content_type_header); |
| + headers->AddHeader("Access-Control-Allow-Origin: *"); |
|
robwu
2014/07/29 10:44:44
Could you also add the following line:
header
|
| + 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[] = |
| @@ -124,35 +166,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. |
| @@ -321,9 +334,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( |
| @@ -681,10 +694,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); |