OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. | 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. |
6 | 6 |
7 #include "webkit/glue/weburlloader_impl.h" | 7 #include "webkit/glue/weburlloader_impl.h" |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/file_path.h" | 10 #include "base/file_path.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" | 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURL.h" |
26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" | 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLError.h" |
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoadTiming.h" | 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoadTiming.h" |
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" | 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLLoaderClient.h" |
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" | 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLRequest.h" |
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" | 30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebURLResponse.h" |
31 #include "webkit/glue/ftp_directory_listing_response_delegate.h" | 31 #include "webkit/glue/ftp_directory_listing_response_delegate.h" |
32 #include "webkit/glue/multipart_response_delegate.h" | 32 #include "webkit/glue/multipart_response_delegate.h" |
33 #include "webkit/glue/resource_loader_bridge.h" | 33 #include "webkit/glue/resource_loader_bridge.h" |
34 #include "webkit/glue/webkit_glue.h" | 34 #include "webkit/glue/webkit_glue.h" |
| 35 #include "webkit/glue/webkitplatformsupport_impl.h" |
35 | 36 |
36 using base::Time; | 37 using base::Time; |
37 using base::TimeDelta; | 38 using base::TimeDelta; |
38 using WebKit::WebData; | 39 using WebKit::WebData; |
39 using WebKit::WebHTTPBody; | 40 using WebKit::WebHTTPBody; |
40 using WebKit::WebHTTPHeaderVisitor; | 41 using WebKit::WebHTTPHeaderVisitor; |
41 using WebKit::WebHTTPLoadInfo; | 42 using WebKit::WebHTTPLoadInfo; |
42 using WebKit::WebSecurityPolicy; | 43 using WebKit::WebSecurityPolicy; |
43 using WebKit::WebString; | 44 using WebKit::WebString; |
44 using WebKit::WebURL; | 45 using WebKit::WebURL; |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 public: | 256 public: |
256 explicit Context(WebURLLoaderImpl* loader); | 257 explicit Context(WebURLLoaderImpl* loader); |
257 | 258 |
258 WebURLLoaderClient* client() const { return client_; } | 259 WebURLLoaderClient* client() const { return client_; } |
259 void set_client(WebURLLoaderClient* client) { client_ = client; } | 260 void set_client(WebURLLoaderClient* client) { client_ = client; } |
260 | 261 |
261 void Cancel(); | 262 void Cancel(); |
262 void SetDefersLoading(bool value); | 263 void SetDefersLoading(bool value); |
263 void Start( | 264 void Start( |
264 const WebURLRequest& request, | 265 const WebURLRequest& request, |
265 ResourceLoaderBridge::SyncLoadResponse* sync_load_response); | 266 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, |
| 267 WebKitPlatformSupportImpl* platform); |
266 void UpdateRoutingId(int new_routing_id); | 268 void UpdateRoutingId(int new_routing_id); |
267 | 269 |
268 // ResourceLoaderBridge::Peer methods: | 270 // ResourceLoaderBridge::Peer methods: |
269 virtual void OnUploadProgress(uint64 position, uint64 size); | 271 virtual void OnUploadProgress(uint64 position, uint64 size); |
270 virtual bool OnReceivedRedirect( | 272 virtual bool OnReceivedRedirect( |
271 const GURL& new_url, | 273 const GURL& new_url, |
272 const ResourceResponseInfo& info, | 274 const ResourceResponseInfo& info, |
273 bool* has_new_first_party_for_cookies, | 275 bool* has_new_first_party_for_cookies, |
274 GURL* new_first_party_for_cookies); | 276 GURL* new_first_party_for_cookies); |
275 virtual void OnReceivedResponse(const ResourceResponseInfo& info); | 277 virtual void OnReceivedResponse(const ResourceResponseInfo& info); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 bridge_->SetDefersLoading(value); | 327 bridge_->SetDefersLoading(value); |
326 } | 328 } |
327 | 329 |
328 void WebURLLoaderImpl::Context::UpdateRoutingId(int new_routing_id) { | 330 void WebURLLoaderImpl::Context::UpdateRoutingId(int new_routing_id) { |
329 if (bridge_.get()) | 331 if (bridge_.get()) |
330 bridge_->UpdateRoutingId(new_routing_id); | 332 bridge_->UpdateRoutingId(new_routing_id); |
331 } | 333 } |
332 | 334 |
333 void WebURLLoaderImpl::Context::Start( | 335 void WebURLLoaderImpl::Context::Start( |
334 const WebURLRequest& request, | 336 const WebURLRequest& request, |
335 ResourceLoaderBridge::SyncLoadResponse* sync_load_response) { | 337 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, |
| 338 WebKitPlatformSupportImpl* platform) { |
336 DCHECK(!bridge_.get()); | 339 DCHECK(!bridge_.get()); |
337 | 340 |
338 request_ = request; // Save the request. | 341 request_ = request; // Save the request. |
339 | 342 |
340 GURL url = request.url(); | 343 GURL url = request.url(); |
341 if (url.SchemeIs("data") && CanHandleDataURL(url)) { | 344 if (url.SchemeIs("data") && CanHandleDataURL(url)) { |
342 if (sync_load_response) { | 345 if (sync_load_response) { |
343 // This is a sync load. Do the work now. | 346 // This is a sync load. Do the work now. |
344 sync_load_response->url = url; | 347 sync_load_response->url = url; |
345 std::string data; | 348 std::string data; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 // the render process, so we can use requestorProcessID even for requests | 409 // the render process, so we can use requestorProcessID even for requests |
407 // from in-process plugins. | 410 // from in-process plugins. |
408 request_info.requestor_pid = request.requestorProcessID(); | 411 request_info.requestor_pid = request.requestorProcessID(); |
409 request_info.request_type = | 412 request_info.request_type = |
410 ResourceType::FromTargetType(request.targetType()); | 413 ResourceType::FromTargetType(request.targetType()); |
411 request_info.appcache_host_id = request.appCacheHostID(); | 414 request_info.appcache_host_id = request.appCacheHostID(); |
412 request_info.routing_id = request.requestorID(); | 415 request_info.routing_id = request.requestorID(); |
413 request_info.download_to_file = request.downloadToFile(); | 416 request_info.download_to_file = request.downloadToFile(); |
414 request_info.has_user_gesture = request.hasUserGesture(); | 417 request_info.has_user_gesture = request.hasUserGesture(); |
415 request_info.extra_data = request.extraData(); | 418 request_info.extra_data = request.extraData(); |
416 bridge_.reset(ResourceLoaderBridge::Create(request_info)); | 419 bridge_.reset(platform->CreateResourceLoader(request_info)); |
417 | 420 |
418 if (!request.httpBody().isNull()) { | 421 if (!request.httpBody().isNull()) { |
419 // GET and HEAD requests shouldn't have http bodies. | 422 // GET and HEAD requests shouldn't have http bodies. |
420 DCHECK(method != "GET" && method != "HEAD"); | 423 DCHECK(method != "GET" && method != "HEAD"); |
421 const WebHTTPBody& httpBody = request.httpBody(); | 424 const WebHTTPBody& httpBody = request.httpBody(); |
422 size_t i = 0; | 425 size_t i = 0; |
423 WebHTTPBody::Element element; | 426 WebHTTPBody::Element element; |
424 while (httpBody.elementAt(i++, element)) { | 427 while (httpBody.elementAt(i++, element)) { |
425 switch (element.type) { | 428 switch (element.type) { |
426 case WebHTTPBody::Element::TypeData: | 429 case WebHTTPBody::Element::TypeData: |
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 OnReceivedResponse(info); | 682 OnReceivedResponse(info); |
680 if (!data.empty()) | 683 if (!data.empty()) |
681 OnReceivedData(data.data(), data.size(), 0); | 684 OnReceivedData(data.data(), data.size(), 0); |
682 } | 685 } |
683 | 686 |
684 OnCompletedRequest(status, info.security_info, base::Time::Now()); | 687 OnCompletedRequest(status, info.security_info, base::Time::Now()); |
685 } | 688 } |
686 | 689 |
687 // WebURLLoaderImpl ----------------------------------------------------------- | 690 // WebURLLoaderImpl ----------------------------------------------------------- |
688 | 691 |
689 WebURLLoaderImpl::WebURLLoaderImpl() | 692 WebURLLoaderImpl::WebURLLoaderImpl(WebKitPlatformSupportImpl* platform) |
690 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))) { | 693 : ALLOW_THIS_IN_INITIALIZER_LIST(context_(new Context(this))), |
| 694 platform_(platform) { |
691 } | 695 } |
692 | 696 |
693 WebURLLoaderImpl::~WebURLLoaderImpl() { | 697 WebURLLoaderImpl::~WebURLLoaderImpl() { |
694 cancel(); | 698 cancel(); |
695 } | 699 } |
696 | 700 |
697 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request, | 701 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request, |
698 WebURLResponse& response, | 702 WebURLResponse& response, |
699 WebURLError& error, | 703 WebURLError& error, |
700 WebData& data) { | 704 WebData& data) { |
701 ResourceLoaderBridge::SyncLoadResponse sync_load_response; | 705 ResourceLoaderBridge::SyncLoadResponse sync_load_response; |
702 context_->Start(request, &sync_load_response); | 706 context_->Start(request, &sync_load_response, platform_); |
703 | 707 |
704 const GURL& final_url = sync_load_response.url; | 708 const GURL& final_url = sync_load_response.url; |
705 | 709 |
706 // TODO(tc): For file loads, we may want to include a more descriptive | 710 // TODO(tc): For file loads, we may want to include a more descriptive |
707 // status code or status text. | 711 // status code or status text. |
708 const net::URLRequestStatus::Status& status = | 712 const net::URLRequestStatus::Status& status = |
709 sync_load_response.status.status(); | 713 sync_load_response.status.status(); |
710 if (status != net::URLRequestStatus::SUCCESS && | 714 if (status != net::URLRequestStatus::SUCCESS && |
711 status != net::URLRequestStatus::HANDLED_EXTERNALLY) { | 715 status != net::URLRequestStatus::HANDLED_EXTERNALLY) { |
712 response.setURL(final_url); | 716 response.setURL(final_url); |
713 error.domain = WebString::fromUTF8(net::kErrorDomain); | 717 error.domain = WebString::fromUTF8(net::kErrorDomain); |
714 error.reason = sync_load_response.status.error(); | 718 error.reason = sync_load_response.status.error(); |
715 error.unreachableURL = final_url; | 719 error.unreachableURL = final_url; |
716 return; | 720 return; |
717 } | 721 } |
718 | 722 |
719 PopulateURLResponse(final_url, sync_load_response, &response); | 723 PopulateURLResponse(final_url, sync_load_response, &response); |
720 | 724 |
721 data.assign(sync_load_response.data.data(), | 725 data.assign(sync_load_response.data.data(), |
722 sync_load_response.data.size()); | 726 sync_load_response.data.size()); |
723 } | 727 } |
724 | 728 |
725 void WebURLLoaderImpl::loadAsynchronously(const WebURLRequest& request, | 729 void WebURLLoaderImpl::loadAsynchronously(const WebURLRequest& request, |
726 WebURLLoaderClient* client) { | 730 WebURLLoaderClient* client) { |
727 DCHECK(!context_->client()); | 731 DCHECK(!context_->client()); |
728 | 732 |
729 context_->set_client(client); | 733 context_->set_client(client); |
730 context_->Start(request, NULL); | 734 context_->Start(request, NULL, platform_); |
731 } | 735 } |
732 | 736 |
733 void WebURLLoaderImpl::cancel() { | 737 void WebURLLoaderImpl::cancel() { |
734 context_->Cancel(); | 738 context_->Cancel(); |
735 } | 739 } |
736 | 740 |
737 void WebURLLoaderImpl::setDefersLoading(bool value) { | 741 void WebURLLoaderImpl::setDefersLoading(bool value) { |
738 context_->SetDefersLoading(value); | 742 context_->SetDefersLoading(value); |
739 } | 743 } |
740 | 744 |
741 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { | 745 void WebURLLoaderImpl::UpdateRoutingId(int new_routing_id) { |
742 context_->UpdateRoutingId(new_routing_id); | 746 context_->UpdateRoutingId(new_routing_id); |
743 } | 747 } |
744 | 748 |
745 } // namespace webkit_glue | 749 } // namespace webkit_glue |
OLD | NEW |