| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/message_loop.h" | 10 #include "base/message_loop.h" |
| 11 #include "base/process_util.h" | 11 #include "base/process_util.h" |
| 12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
| 13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
| 14 #include "base/time.h" | 14 #include "base/time.h" |
| 15 #include "net/base/data_url.h" | 15 #include "net/base/data_url.h" |
| 16 #include "net/base/load_flags.h" | 16 #include "net/base/load_flags.h" |
| 17 #include "net/base/mime_util.h" |
| 17 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
| 18 #include "net/base/net_util.h" | 19 #include "net/base/net_util.h" |
| 19 #include "net/http/http_response_headers.h" | 20 #include "net/http/http_response_headers.h" |
| 20 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" | 21 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPHeaderVisitor.h" |
| 21 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPLoadInfo.h" | 22 #include "third_party/WebKit/WebKit/chromium/public/WebHTTPLoadInfo.h" |
| 22 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h" | 23 #include "third_party/WebKit/WebKit/chromium/public/WebSecurityPolicy.h" |
| 23 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" | 24 #include "third_party/WebKit/WebKit/chromium/public/WebURL.h" |
| 24 #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" | 25 #include "third_party/WebKit/WebKit/chromium/public/WebURLError.h" |
| 25 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoadTiming.h" | 26 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoadTiming.h" |
| 26 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" | 27 #include "third_party/WebKit/WebKit/chromium/public/WebURLLoaderClient.h" |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 virtual void OnReceivedCachedMetadata(const char* data, int len); | 296 virtual void OnReceivedCachedMetadata(const char* data, int len); |
| 296 virtual void OnCompletedRequest( | 297 virtual void OnCompletedRequest( |
| 297 const URLRequestStatus& status, | 298 const URLRequestStatus& status, |
| 298 const std::string& security_info, | 299 const std::string& security_info, |
| 299 const base::Time& completion_time); | 300 const base::Time& completion_time); |
| 300 | 301 |
| 301 private: | 302 private: |
| 302 friend class base::RefCounted<Context>; | 303 friend class base::RefCounted<Context>; |
| 303 ~Context() {} | 304 ~Context() {} |
| 304 | 305 |
| 306 // We can optimize the handling of data URLs in most cases. |
| 307 bool CanHandleDataURL(const GURL& url) const; |
| 305 void HandleDataURL(); | 308 void HandleDataURL(); |
| 306 | 309 |
| 307 WebURLLoaderImpl* loader_; | 310 WebURLLoaderImpl* loader_; |
| 308 WebURLRequest request_; | 311 WebURLRequest request_; |
| 309 WebURLLoaderClient* client_; | 312 WebURLLoaderClient* client_; |
| 310 scoped_ptr<ResourceLoaderBridge> bridge_; | 313 scoped_ptr<ResourceLoaderBridge> bridge_; |
| 311 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 314 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
| 312 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; | 315 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; |
| 313 scoped_ptr<ResourceLoaderBridge> completed_bridge_; | 316 scoped_ptr<ResourceLoaderBridge> completed_bridge_; |
| 314 | 317 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 343 } | 346 } |
| 344 | 347 |
| 345 void WebURLLoaderImpl::Context::Start( | 348 void WebURLLoaderImpl::Context::Start( |
| 346 const WebURLRequest& request, | 349 const WebURLRequest& request, |
| 347 ResourceLoaderBridge::SyncLoadResponse* sync_load_response) { | 350 ResourceLoaderBridge::SyncLoadResponse* sync_load_response) { |
| 348 DCHECK(!bridge_.get()); | 351 DCHECK(!bridge_.get()); |
| 349 | 352 |
| 350 request_ = request; // Save the request. | 353 request_ = request; // Save the request. |
| 351 | 354 |
| 352 GURL url = request.url(); | 355 GURL url = request.url(); |
| 353 if (url.SchemeIs("data")) { | 356 if (url.SchemeIs("data") && CanHandleDataURL(url)) { |
| 354 if (sync_load_response) { | 357 if (sync_load_response) { |
| 355 // This is a sync load. Do the work now. | 358 // This is a sync load. Do the work now. |
| 356 sync_load_response->url = url; | 359 sync_load_response->url = url; |
| 357 std::string data; | 360 std::string data; |
| 358 GetInfoFromDataURL(sync_load_response->url, sync_load_response, | 361 GetInfoFromDataURL(sync_load_response->url, sync_load_response, |
| 359 &sync_load_response->data, | 362 &sync_load_response->data, |
| 360 &sync_load_response->status); | 363 &sync_load_response->status); |
| 361 } else { | 364 } else { |
| 362 AddRef(); // Balanced in OnCompletedRequest | 365 AddRef(); // Balanced in OnCompletedRequest |
| 363 MessageLoop::current()->PostTask(FROM_HERE, | 366 MessageLoop::current()->PostTask(FROM_HERE, |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 | 658 |
| 656 // Temporary logging, see site_isolation_metrics.h/cc | 659 // Temporary logging, see site_isolation_metrics.h/cc |
| 657 SiteIsolationMetrics::RemoveCompletedResponse(response_url_); | 660 SiteIsolationMetrics::RemoveCompletedResponse(response_url_); |
| 658 | 661 |
| 659 // We are done with the bridge now, and so we need to release the reference | 662 // We are done with the bridge now, and so we need to release the reference |
| 660 // to ourselves that we took on behalf of the bridge. This may cause our | 663 // to ourselves that we took on behalf of the bridge. This may cause our |
| 661 // destruction. | 664 // destruction. |
| 662 Release(); | 665 Release(); |
| 663 } | 666 } |
| 664 | 667 |
| 668 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { |
| 669 DCHECK(url.SchemeIs("data")); |
| 670 |
| 671 // Optimize for the case where we can handle a data URL locally. We must |
| 672 // skip this for data URLs targetted at frames since those could trigger a |
| 673 // download. |
| 674 // |
| 675 // NOTE: We special case MIME types we can render both for performance |
| 676 // reasons as well as to support unit tests, which do not have an underlying |
| 677 // ResourceLoaderBridge implementation. |
| 678 |
| 679 if (request_.targetType() != WebURLRequest::TargetIsMainFrame && |
| 680 request_.targetType() != WebURLRequest::TargetIsSubframe) |
| 681 return true; |
| 682 |
| 683 std::string mime_type, unused_charset; |
| 684 if (net::DataURL::Parse(url, &mime_type, &unused_charset, NULL) && |
| 685 net::IsSupportedMimeType(mime_type)) |
| 686 return true; |
| 687 |
| 688 return false; |
| 689 } |
| 690 |
| 665 void WebURLLoaderImpl::Context::HandleDataURL() { | 691 void WebURLLoaderImpl::Context::HandleDataURL() { |
| 666 ResourceResponseInfo info; | 692 ResourceResponseInfo info; |
| 667 URLRequestStatus status; | 693 URLRequestStatus status; |
| 668 std::string data; | 694 std::string data; |
| 669 | 695 |
| 670 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { | 696 if (GetInfoFromDataURL(request_.url(), &info, &data, &status)) { |
| 671 OnReceivedResponse(info, false); | 697 OnReceivedResponse(info, false); |
| 672 if (!data.empty()) | 698 if (!data.empty()) |
| 673 OnReceivedData(data.data(), data.size()); | 699 OnReceivedData(data.data(), data.size()); |
| 674 } | 700 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 | 749 |
| 724 void WebURLLoaderImpl::cancel() { | 750 void WebURLLoaderImpl::cancel() { |
| 725 context_->Cancel(); | 751 context_->Cancel(); |
| 726 } | 752 } |
| 727 | 753 |
| 728 void WebURLLoaderImpl::setDefersLoading(bool value) { | 754 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 729 context_->SetDefersLoading(value); | 755 context_->SetDefersLoading(value); |
| 730 } | 756 } |
| 731 | 757 |
| 732 } // namespace webkit_glue | 758 } // namespace webkit_glue |
| OLD | NEW |