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