OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 // This file replaces WebCore/platform/network/win/ResourceHandleWin.cpp with a | 5 // This file replaces WebCore/platform/network/win/ResourceHandleWin.cpp with a |
6 // platform-neutral implementation that simply defers almost entirely to | 6 // platform-neutral implementation that simply defers almost entirely to |
7 // ResouceLoaderBridge. | 7 // ResouceLoaderBridge. |
8 // | 8 // |
9 // This uses the same ResourceHandle.h header file that the rest of WebKit | 9 // This uses the same ResourceHandle.h header file that the rest of WebKit |
10 // uses, allowing us to avoid complicated changes. Our specific things are | 10 // uses, allowing us to avoid complicated changes. Our specific things are |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 128 |
129 pair<HTTPHeaderMap::iterator, bool> result = | 129 pair<HTTPHeaderMap::iterator, bool> result = |
130 header_map->add(name_str, value_str); | 130 header_map->add(name_str, value_str); |
131 if (!result.second) | 131 if (!result.second) |
132 result.first->second += ", " + value_str; | 132 result.first->second += ", " + value_str; |
133 } | 133 } |
134 } | 134 } |
135 | 135 |
136 static ResourceResponse MakeResourceResponse( | 136 static ResourceResponse MakeResourceResponse( |
137 const KURL& kurl, | 137 const KURL& kurl, |
138 const ResourceLoaderBridge::ResponseInfo& info) { | 138 const ResourceLoaderBridge::ResponseInfo& info, |
| 139 const std::string& disposition_fallback_charset) { |
139 int status_code = 0; | 140 int status_code = 0; |
140 long long expected_content_length = info.content_length; | 141 long long expected_content_length = info.content_length; |
141 String status_text; | 142 String status_text; |
142 HTTPHeaderMap header_map; | 143 HTTPHeaderMap header_map; |
143 | 144 |
144 // It's okay if there are no headers | 145 // It's okay if there are no headers |
145 if (info.headers) | 146 if (info.headers) |
146 ExtractInfoFromHeaders(info.headers, | 147 ExtractInfoFromHeaders(info.headers, |
147 &header_map, | 148 &header_map, |
148 &status_code, | 149 &status_code, |
149 &status_text, | 150 &status_text, |
150 &expected_content_length); | 151 &expected_content_length); |
151 | 152 |
152 // TODO(darin): We should leverage HttpResponseHeaders for this, and this | 153 // TODO(darin): We should leverage HttpResponseHeaders for this, and this |
153 // should be using the same code as ResourceDispatcherHost. | 154 // should be using the same code as ResourceDispatcherHost. |
154 // TODO(jungshik): Figure out the actual value of the referrer charset and | |
155 // pass it to GetSuggestedFilename. | |
156 std::wstring suggested_filename; | 155 std::wstring suggested_filename; |
157 if (info.headers) { | 156 if (info.headers) { |
158 std::string disp_val; | 157 std::string disp_val; |
159 if (info.headers->EnumerateHeader(NULL, "content-disposition", &disp_val)) { | 158 if (info.headers->EnumerateHeader(NULL, "content-disposition", &disp_val)) { |
160 suggested_filename = net::GetSuggestedFilename( | 159 suggested_filename = net::GetSuggestedFilename( |
161 webkit_glue::KURLToGURL(kurl), disp_val, "", std::wstring()); | 160 webkit_glue::KURLToGURL(kurl), disp_val, |
| 161 disposition_fallback_charset, std::wstring()); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 ResourceResponse response(kurl, | 165 ResourceResponse response(kurl, |
166 webkit_glue::StdStringToString(info.mime_type), | 166 webkit_glue::StdStringToString(info.mime_type), |
167 expected_content_length, | 167 expected_content_length, |
168 webkit_glue::StdStringToString(info.charset), | 168 webkit_glue::StdStringToString(info.charset), |
169 webkit_glue::StdWStringToString(suggested_filename)); | 169 webkit_glue::StdWStringToString(suggested_filename)); |
170 | 170 |
171 if (info.headers) { | 171 if (info.headers) { |
(...skipping 27 matching lines...) Expand all Loading... |
199 // WebKit doesn't provide a way for us to set expected content length after | 199 // WebKit doesn't provide a way for us to set expected content length after |
200 // calling the constructor, so we parse the headers first and then swap in | 200 // calling the constructor, so we parse the headers first and then swap in |
201 // our HTTP header map. Ideally we would like a setter for expected content | 201 // our HTTP header map. Ideally we would like a setter for expected content |
202 // length (perhaps by abstracting ResourceResponse interface into | 202 // length (perhaps by abstracting ResourceResponse interface into |
203 // ResourceResponseBase) but that would require forking. | 203 // ResourceResponseBase) but that would require forking. |
204 const_cast<HTTPHeaderMap*>(&response.httpHeaderFields())->swap(header_map); | 204 const_cast<HTTPHeaderMap*>(&response.httpHeaderFields())->swap(header_map); |
205 | 205 |
206 return response; | 206 return response; |
207 } | 207 } |
208 | 208 |
| 209 inline static std::string FallbackCharsetForFileName( |
| 210 const ResourceRequest& request) { |
| 211 return webkit_glue::StringToStdString( |
| 212 request.contentDispositionFallbackEncoding()); |
| 213 } |
| 214 |
209 class ResourceHandleInternal : public ResourceLoaderBridge::Peer { | 215 class ResourceHandleInternal : public ResourceLoaderBridge::Peer { |
210 public: | 216 public: |
211 ResourceHandleInternal(ResourceHandle* job, const ResourceRequest& r, | 217 ResourceHandleInternal(ResourceHandle* job, const ResourceRequest& r, |
212 ResourceHandleClient* c); | 218 ResourceHandleClient* c); |
213 ~ResourceHandleInternal(); | 219 ~ResourceHandleInternal(); |
214 | 220 |
215 // If the response parameter is null, then an asynchronous load is started. | 221 // If the response parameter is null, then an asynchronous load is started. |
216 bool Start(ResourceLoaderBridge::SyncLoadResponse* response); | 222 bool Start(ResourceLoaderBridge::SyncLoadResponse* response); |
217 | 223 |
218 // Used to cancel an asynchronous load. | 224 // Used to cancel an asynchronous load. |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 return true; | 415 return true; |
410 } | 416 } |
411 | 417 |
412 // TODO(abarth): These are wrong! I need to figure out how to get the right | 418 // TODO(abarth): These are wrong! I need to figure out how to get the right |
413 // strings here. See: http://crbug.com/8706 | 419 // strings here. See: http://crbug.com/8706 |
414 std::string frame_origin = | 420 std::string frame_origin = |
415 webkit_glue::StringToStdString(request_.mainDocumentURL().string()); | 421 webkit_glue::StringToStdString(request_.mainDocumentURL().string()); |
416 std::string main_frame_origin = | 422 std::string main_frame_origin = |
417 webkit_glue::StringToStdString(request_.mainDocumentURL().string()); | 423 webkit_glue::StringToStdString(request_.mainDocumentURL().string()); |
418 | 424 |
| 425 std::string fallback_charset = FallbackCharsetForFileName(request_); |
| 426 |
419 // TODO(darin): is latin1 really correct here? It is if the strings are | 427 // TODO(darin): is latin1 really correct here? It is if the strings are |
420 // already ASCII (i.e., if they are already escaped properly). | 428 // already ASCII (i.e., if they are already escaped properly). |
421 // TODO(brettw) this should take parameter encoding into account when | 429 // TODO(brettw) this should take parameter encoding into account when |
422 // creating the GURLs. | 430 // creating the GURLs. |
423 bridge_.reset(ResourceLoaderBridge::Create( | 431 bridge_.reset(ResourceLoaderBridge::Create( |
424 webkit_glue::CStringToStdString(method), | 432 webkit_glue::CStringToStdString(method), |
425 url, | 433 url, |
426 webkit_glue::KURLToGURL(request_.policyURL()), | 434 webkit_glue::KURLToGURL(request_.policyURL()), |
427 referrer, | 435 referrer, |
428 frame_origin, | 436 frame_origin, |
429 main_frame_origin, | 437 main_frame_origin, |
430 webkit_glue::CStringToStdString(headerBuf.latin1()), | 438 webkit_glue::CStringToStdString(headerBuf.latin1()), |
431 load_flags_, | 439 load_flags_, |
432 requestor_pid, | 440 requestor_pid, |
433 FromTargetType(request_.targetType()), | 441 FromTargetType(request_.targetType()), |
434 request_.appCacheContextID(), | 442 request_.appCacheContextID(), |
435 request_.requestorID())); | 443 request_.requestorID(), |
| 444 fallback_charset)); |
436 if (!bridge_.get()) | 445 if (!bridge_.get()) |
437 return false; | 446 return false; |
438 | 447 |
439 if (request_.httpBody()) { | 448 if (request_.httpBody()) { |
440 // GET and HEAD requests shouldn't have http bodies. | 449 // GET and HEAD requests shouldn't have http bodies. |
441 DCHECK(method != "GET" && method != "HEAD"); | 450 DCHECK(method != "GET" && method != "HEAD"); |
442 const Vector<FormDataElement>& elements = request_.httpBody()->elements(); | 451 const Vector<FormDataElement>& elements = request_.httpBody()->elements(); |
443 size_t n = elements.size(); | 452 size_t n = elements.size(); |
444 for (size_t i = 0; i < n; ++i) { | 453 for (size_t i = 0; i < n; ++i) { |
445 const FormDataElement& e = elements[static_cast<unsigned>(i)]; | 454 const FormDataElement& e = elements[static_cast<unsigned>(i)]; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 | 537 |
529 request_ = new_request; | 538 request_ = new_request; |
530 } | 539 } |
531 | 540 |
532 void ResourceHandleInternal::OnReceivedResponse( | 541 void ResourceHandleInternal::OnReceivedResponse( |
533 const ResourceLoaderBridge::ResponseInfo& info, | 542 const ResourceLoaderBridge::ResponseInfo& info, |
534 bool content_filtered) { | 543 bool content_filtered) { |
535 DCHECK(pending_); | 544 DCHECK(pending_); |
536 | 545 |
537 // TODO(darin): need a way to properly initialize a ResourceResponse | 546 // TODO(darin): need a way to properly initialize a ResourceResponse |
538 ResourceResponse response = MakeResourceResponse(request_.url(), info); | 547 std::string fallback_charset = FallbackCharsetForFileName(request_); |
| 548 ResourceResponse response = MakeResourceResponse(request_.url(), info, |
| 549 fallback_charset); |
539 response.setIsContentFiltered(content_filtered); | 550 response.setIsContentFiltered(content_filtered); |
540 | 551 |
541 expected_content_length_ = response.expectedContentLength(); | 552 expected_content_length_ = response.expectedContentLength(); |
542 | 553 |
543 if (client_) | 554 if (client_) |
544 client_->didReceiveResponse(job_, response); | 555 client_->didReceiveResponse(job_, response); |
545 | 556 |
546 // we may have been cancelled after didReceiveResponse, which would leave us | 557 // we may have been cancelled after didReceiveResponse, which would leave us |
547 // without a client and therefore without much need to do multipart handling. | 558 // without a client and therefore without much need to do multipart handling. |
548 | 559 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 if (status != URLRequestStatus::SUCCESS && | 741 if (status != URLRequestStatus::SUCCESS && |
731 status != URLRequestStatus::HANDLED_EXTERNALLY) { | 742 status != URLRequestStatus::HANDLED_EXTERNALLY) { |
732 response = ResourceResponse(kurl, String(), 0, String(), String()); | 743 response = ResourceResponse(kurl, String(), 0, String(), String()); |
733 error = ResourceError(net::kErrorDomain, | 744 error = ResourceError(net::kErrorDomain, |
734 sync_load_response.status.os_error(), | 745 sync_load_response.status.os_error(), |
735 kurl.string(), | 746 kurl.string(), |
736 String() /* localized description */); | 747 String() /* localized description */); |
737 return; | 748 return; |
738 } | 749 } |
739 | 750 |
740 response = MakeResourceResponse(kurl, sync_load_response); | 751 std::string fallback_charset = FallbackCharsetForFileName(request); |
| 752 response = MakeResourceResponse(kurl, sync_load_response, fallback_charset); |
741 | 753 |
742 data.clear(); | 754 data.clear(); |
743 data.append(sync_load_response.data.data(), | 755 data.append(sync_load_response.data.data(), |
744 sync_load_response.data.size()); | 756 sync_load_response.data.size()); |
745 } | 757 } |
746 | 758 |
747 // static | 759 // static |
748 bool ResourceHandle::willLoadFromCache(ResourceRequest& request) { | 760 bool ResourceHandle::willLoadFromCache(ResourceRequest& request) { |
749 // | 761 // |
750 // This method is used to determine if a POST request can be repeated from | 762 // This method is used to determine if a POST request can be repeated from |
751 // cache, but you cannot really know until you actually try to read from the | 763 // cache, but you cannot really know until you actually try to read from the |
752 // cache. Even if we checked now, something else could come along and wipe | 764 // cache. Even if we checked now, something else could come along and wipe |
753 // out the cache entry by the time we fetch it. | 765 // out the cache entry by the time we fetch it. |
754 // | 766 // |
755 // So, we always say yes here, which allows us to generate an ERR_CACHE_MISS | 767 // So, we always say yes here, which allows us to generate an ERR_CACHE_MISS |
756 // if the request cannot be serviced from cache. We force the 'DontLoad' | 768 // if the request cannot be serviced from cache. We force the 'DontLoad' |
757 // cache policy at this point to ensure that we never hit the network for | 769 // cache policy at this point to ensure that we never hit the network for |
758 // this request. | 770 // this request. |
759 // | 771 // |
760 DCHECK(request.httpMethod() == "POST"); | 772 DCHECK(request.httpMethod() == "POST"); |
761 request.setCachePolicy(ReturnCacheDataDontLoad); | 773 request.setCachePolicy(ReturnCacheDataDontLoad); |
762 return true; | 774 return true; |
763 } | 775 } |
764 | 776 |
765 } // namespace WebCore | 777 } // namespace WebCore |
OLD | NEW |