OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/web_url_loader_impl.h" | 5 #include "content/child/web_url_loader_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 using blink::WebURLLoaderClient; | 76 using blink::WebURLLoaderClient; |
77 using blink::WebURLRequest; | 77 using blink::WebURLRequest; |
78 using blink::WebURLResponse; | 78 using blink::WebURLResponse; |
79 | 79 |
80 namespace content { | 80 namespace content { |
81 | 81 |
82 // Utilities ------------------------------------------------------------------ | 82 // Utilities ------------------------------------------------------------------ |
83 | 83 |
84 namespace { | 84 namespace { |
85 | 85 |
| 86 // The list of response headers that we do not copy from the original |
| 87 // response when generating a WebURLResponse for a MIME payload. |
| 88 const char* kReplaceHeaders[] = { |
| 89 "content-type", |
| 90 "content-length", |
| 91 "content-disposition", |
| 92 "content-range", |
| 93 "range", |
| 94 "set-cookie" |
| 95 }; |
| 96 |
86 using HeadersVector = ResourceDevToolsInfo::HeadersVector; | 97 using HeadersVector = ResourceDevToolsInfo::HeadersVector; |
87 | 98 |
88 // Converts timing data from |load_timing| to the format used by WebKit. | 99 // Converts timing data from |load_timing| to the format used by WebKit. |
89 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing, | 100 void PopulateURLLoadTiming(const net::LoadTimingInfo& load_timing, |
90 WebURLLoadTiming* url_timing) { | 101 WebURLLoadTiming* url_timing) { |
91 DCHECK(!load_timing.request_start.is_null()); | 102 DCHECK(!load_timing.request_start.is_null()); |
92 | 103 |
93 const TimeTicks kNullTicks; | 104 const TimeTicks kNullTicks; |
94 url_timing->initialize(); | 105 url_timing->initialize(); |
95 url_timing->setRequestTime( | 106 url_timing->setRequestTime( |
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 return context_->AttachThreadedDataReceiver(threaded_data_receiver); | 1163 return context_->AttachThreadedDataReceiver(threaded_data_receiver); |
1153 } | 1164 } |
1154 | 1165 |
1155 void WebURLLoaderImpl::setLoadingTaskRunner( | 1166 void WebURLLoaderImpl::setLoadingTaskRunner( |
1156 blink::WebTaskRunner* loading_task_runner) { | 1167 blink::WebTaskRunner* loading_task_runner) { |
1157 // There's no guarantee on the lifetime of |loading_task_runner| so we take a | 1168 // There's no guarantee on the lifetime of |loading_task_runner| so we take a |
1158 // copy. | 1169 // copy. |
1159 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone())); | 1170 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone())); |
1160 } | 1171 } |
1161 | 1172 |
| 1173 // This function is implemented here because it uses net functions. it is |
| 1174 // tested in |
| 1175 // third_party/WebKit/Source/core/fetch/MultipartImageResourceParserTest.cpp. |
| 1176 bool WebURLLoaderImpl::ParseMultipartHeadersFromBody( |
| 1177 const char* bytes, |
| 1178 size_t size, |
| 1179 blink::WebURLResponse* response, |
| 1180 size_t* end) { |
| 1181 int headers_end_pos = |
| 1182 net::HttpUtil::LocateEndOfAdditionalHeaders(bytes, size, 0); |
| 1183 |
| 1184 if (headers_end_pos < 0) |
| 1185 return false; |
| 1186 |
| 1187 *end = headers_end_pos; |
| 1188 // Eat headers and prepend a status line as is required by |
| 1189 // HttpResponseHeaders. |
| 1190 std::string headers("HTTP/1.1 200 OK\r\n"); |
| 1191 headers.append(bytes, headers_end_pos); |
| 1192 |
| 1193 scoped_refptr<net::HttpResponseHeaders> response_headers = |
| 1194 new net::HttpResponseHeaders( |
| 1195 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size())); |
| 1196 |
| 1197 std::string mime_type; |
| 1198 response_headers->GetMimeType(&mime_type); |
| 1199 response->setMIMEType(WebString::fromUTF8(mime_type)); |
| 1200 |
| 1201 std::string charset; |
| 1202 response_headers->GetCharset(&charset); |
| 1203 response->setTextEncodingName(WebString::fromUTF8(charset)); |
| 1204 |
| 1205 // Copy headers listed in kReplaceHeaders to the response. |
| 1206 for (size_t i = 0; i < arraysize(kReplaceHeaders); ++i) { |
| 1207 std::string name(kReplaceHeaders[i]); |
| 1208 std::string value; |
| 1209 WebString webStringName(WebString::fromLatin1(name)); |
| 1210 size_t iterator = 0; |
| 1211 |
| 1212 response->clearHTTPHeaderField(webStringName); |
| 1213 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
| 1214 response->addHTTPHeaderField(webStringName, |
| 1215 WebString::fromLatin1(value)); |
| 1216 } |
| 1217 } |
| 1218 return true; |
| 1219 } |
| 1220 |
1162 } // namespace content | 1221 } // namespace content |
OLD | NEW |