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 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1153 return context_->AttachThreadedDataReceiver(threaded_data_receiver); | 1164 return context_->AttachThreadedDataReceiver(threaded_data_receiver); |
1154 } | 1165 } |
1155 | 1166 |
1156 void WebURLLoaderImpl::setLoadingTaskRunner( | 1167 void WebURLLoaderImpl::setLoadingTaskRunner( |
1157 blink::WebTaskRunner* loading_task_runner) { | 1168 blink::WebTaskRunner* loading_task_runner) { |
1158 // There's no guarantee on the lifetime of |loading_task_runner| so we take a | 1169 // There's no guarantee on the lifetime of |loading_task_runner| so we take a |
1159 // copy. | 1170 // copy. |
1160 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone())); | 1171 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone())); |
1161 } | 1172 } |
1162 | 1173 |
1174 bool WebURLLoaderImpl::ParseAdditionalHeaders( | |
hiroshige
2016/02/25 18:10:24
What is the reason to place ParseAdditionalHeaders
yhirano
2016/02/25 18:35:13
Because I want to use net:: functions.
hiroshige
2016/02/25 21:46:31
Hmm.
The code around this has some issues: |kRepla
| |
1175 const char* bytes, | |
1176 size_t size, | |
1177 blink::WebURLResponse* response, | |
1178 size_t* end) { | |
1179 int headers_end_pos = | |
1180 net::HttpUtil::LocateEndOfAdditionalHeaders(bytes, size, 0); | |
1181 | |
1182 if (headers_end_pos < 0) | |
1183 return false; | |
1184 | |
1185 *end = headers_end_pos; | |
1186 // Eat headers and prepend a status line as is required by | |
1187 // HttpResponseHeaders. | |
1188 std::string headers("HTTP/1.1 200 OK\r\n"); | |
1189 headers.append(bytes, headers_end_pos); | |
1190 | |
1191 scoped_refptr<net::HttpResponseHeaders> response_headers = | |
1192 new net::HttpResponseHeaders( | |
1193 net::HttpUtil::AssembleRawHeaders(headers.c_str(), headers.size())); | |
1194 | |
1195 std::string mime_type; | |
1196 response_headers->GetMimeType(&mime_type); | |
1197 response->setMIMEType(WebString::fromUTF8(mime_type)); | |
1198 | |
1199 std::string charset; | |
1200 response_headers->GetCharset(&charset); | |
1201 response->setTextEncodingName(WebString::fromUTF8(charset)); | |
1202 | |
1203 // Copy headers listed in kReplaceHeaders to the response. | |
1204 for (size_t i = 0; i < arraysize(kReplaceHeaders); ++i) { | |
1205 std::string name(kReplaceHeaders[i]); | |
1206 std::string value; | |
1207 size_t iterator = 0; | |
1208 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | |
1209 response->addHTTPHeaderField(WebString::fromLatin1(name), | |
1210 WebString::fromLatin1(value)); | |
1211 } | |
1212 } | |
1213 return true; | |
1214 } | |
1215 | |
1163 } // namespace content | 1216 } // namespace content |
OLD | NEW |