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* const 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 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 context_->DidChangePriority(new_priority, intra_priority_value); | 1147 context_->DidChangePriority(new_priority, intra_priority_value); |
1137 } | 1148 } |
1138 | 1149 |
1139 void WebURLLoaderImpl::setLoadingTaskRunner( | 1150 void WebURLLoaderImpl::setLoadingTaskRunner( |
1140 blink::WebTaskRunner* loading_task_runner) { | 1151 blink::WebTaskRunner* loading_task_runner) { |
1141 // There's no guarantee on the lifetime of |loading_task_runner| so we take a | 1152 // There's no guarantee on the lifetime of |loading_task_runner| so we take a |
1142 // copy. | 1153 // copy. |
1143 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone())); | 1154 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone())); |
1144 } | 1155 } |
1145 | 1156 |
| 1157 // This function is implemented here because it uses net functions. it is |
| 1158 // tested in |
| 1159 // third_party/WebKit/Source/core/fetch/MultipartImageResourceParserTest.cpp. |
| 1160 bool WebURLLoaderImpl::ParseMultipartHeadersFromBody( |
| 1161 const char* bytes, |
| 1162 size_t size, |
| 1163 blink::WebURLResponse* response, |
| 1164 size_t* end) { |
| 1165 int headers_end_pos = |
| 1166 net::HttpUtil::LocateEndOfAdditionalHeaders(bytes, size, 0); |
| 1167 |
| 1168 if (headers_end_pos < 0) |
| 1169 return false; |
| 1170 |
| 1171 *end = headers_end_pos; |
| 1172 // Eat headers and prepend a status line as is required by |
| 1173 // HttpResponseHeaders. |
| 1174 std::string headers("HTTP/1.1 200 OK\r\n"); |
| 1175 headers.append(bytes, headers_end_pos); |
| 1176 |
| 1177 scoped_refptr<net::HttpResponseHeaders> response_headers = |
| 1178 new net::HttpResponseHeaders( |
| 1179 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size())); |
| 1180 |
| 1181 std::string mime_type; |
| 1182 response_headers->GetMimeType(&mime_type); |
| 1183 response->setMIMEType(WebString::fromUTF8(mime_type)); |
| 1184 |
| 1185 std::string charset; |
| 1186 response_headers->GetCharset(&charset); |
| 1187 response->setTextEncodingName(WebString::fromUTF8(charset)); |
| 1188 |
| 1189 // Copy headers listed in kReplaceHeaders to the response. |
| 1190 for (size_t i = 0; i < arraysize(kReplaceHeaders); ++i) { |
| 1191 std::string name(kReplaceHeaders[i]); |
| 1192 std::string value; |
| 1193 WebString webStringName(WebString::fromLatin1(name)); |
| 1194 size_t iterator = 0; |
| 1195 |
| 1196 response->clearHTTPHeaderField(webStringName); |
| 1197 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
| 1198 response->addHTTPHeaderField(webStringName, |
| 1199 WebString::fromLatin1(value)); |
| 1200 } |
| 1201 } |
| 1202 return true; |
| 1203 } |
| 1204 |
1146 } // namespace content | 1205 } // namespace content |
OLD | NEW |