| 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 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. | 5 // An implementation of WebURLLoader in terms of ResourceLoaderBridge. |
| 6 | 6 |
| 7 #include "content/child/web_url_loader_impl.h" | 7 #include "content/child/web_url_loader_impl.h" |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "content/child/child_thread.h" | 15 #include "content/child/child_thread.h" |
| 16 #include "content/child/ftp_directory_listing_response_delegate.h" | 16 #include "content/child/ftp_directory_listing_response_delegate.h" |
| 17 #include "content/child/request_extra_data.h" | 17 #include "content/child/request_extra_data.h" |
| 18 #include "content/child/request_info.h" | 18 #include "content/child/request_info.h" |
| 19 #include "content/child/sync_load_response.h" |
| 19 #include "content/common/resource_request_body.h" | 20 #include "content/common/resource_request_body.h" |
| 20 #include "net/base/data_url.h" | 21 #include "net/base/data_url.h" |
| 21 #include "net/base/load_flags.h" | 22 #include "net/base/load_flags.h" |
| 22 #include "net/base/mime_util.h" | 23 #include "net/base/mime_util.h" |
| 23 #include "net/base/net_errors.h" | 24 #include "net/base/net_errors.h" |
| 24 #include "net/base/net_util.h" | 25 #include "net/base/net_util.h" |
| 25 #include "net/http/http_response_headers.h" | 26 #include "net/http/http_response_headers.h" |
| 26 #include "net/http/http_util.h" | 27 #include "net/http/http_util.h" |
| 27 #include "net/url_request/url_request.h" | 28 #include "net/url_request/url_request.h" |
| 28 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" | 29 #include "third_party/WebKit/public/platform/WebHTTPHeaderVisitor.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 public: | 225 public: |
| 225 explicit Context(WebURLLoaderImpl* loader); | 226 explicit Context(WebURLLoaderImpl* loader); |
| 226 | 227 |
| 227 WebURLLoaderClient* client() const { return client_; } | 228 WebURLLoaderClient* client() const { return client_; } |
| 228 void set_client(WebURLLoaderClient* client) { client_ = client; } | 229 void set_client(WebURLLoaderClient* client) { client_ = client; } |
| 229 | 230 |
| 230 void Cancel(); | 231 void Cancel(); |
| 231 void SetDefersLoading(bool value); | 232 void SetDefersLoading(bool value); |
| 232 void DidChangePriority(WebURLRequest::Priority new_priority); | 233 void DidChangePriority(WebURLRequest::Priority new_priority); |
| 233 void Start(const WebURLRequest& request, | 234 void Start(const WebURLRequest& request, |
| 234 ResourceLoaderBridge::SyncLoadResponse* sync_load_response); | 235 SyncLoadResponse* sync_load_response); |
| 235 | 236 |
| 236 // ResourceLoaderBridge::Peer methods: | 237 // ResourceLoaderBridge::Peer methods: |
| 237 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; | 238 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; |
| 238 virtual bool OnReceivedRedirect( | 239 virtual bool OnReceivedRedirect( |
| 239 const GURL& new_url, | 240 const GURL& new_url, |
| 240 const ResourceResponseInfo& info, | 241 const ResourceResponseInfo& info, |
| 241 bool* has_new_first_party_for_cookies, | 242 bool* has_new_first_party_for_cookies, |
| 242 GURL* new_first_party_for_cookies) OVERRIDE; | 243 GURL* new_first_party_for_cookies) OVERRIDE; |
| 243 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; | 244 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; |
| 244 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; | 245 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 bridge_->SetDefersLoading(value); | 300 bridge_->SetDefersLoading(value); |
| 300 } | 301 } |
| 301 | 302 |
| 302 void WebURLLoaderImpl::Context::DidChangePriority( | 303 void WebURLLoaderImpl::Context::DidChangePriority( |
| 303 WebURLRequest::Priority new_priority) { | 304 WebURLRequest::Priority new_priority) { |
| 304 if (bridge_) | 305 if (bridge_) |
| 305 bridge_->DidChangePriority( | 306 bridge_->DidChangePriority( |
| 306 ConvertWebKitPriorityToNetPriority(new_priority)); | 307 ConvertWebKitPriorityToNetPriority(new_priority)); |
| 307 } | 308 } |
| 308 | 309 |
| 309 void WebURLLoaderImpl::Context::Start( | 310 void WebURLLoaderImpl::Context::Start(const WebURLRequest& request, |
| 310 const WebURLRequest& request, | 311 SyncLoadResponse* sync_load_response) { |
| 311 ResourceLoaderBridge::SyncLoadResponse* sync_load_response) { | |
| 312 DCHECK(!bridge_.get()); | 312 DCHECK(!bridge_.get()); |
| 313 | 313 |
| 314 request_ = request; // Save the request. | 314 request_ = request; // Save the request. |
| 315 | 315 |
| 316 GURL url = request.url(); | 316 GURL url = request.url(); |
| 317 if (url.SchemeIs("data") && CanHandleDataURL(url)) { | 317 if (url.SchemeIs("data") && CanHandleDataURL(url)) { |
| 318 if (sync_load_response) { | 318 if (sync_load_response) { |
| 319 // This is a sync load. Do the work now. | 319 // This is a sync load. Do the work now. |
| 320 sync_load_response->url = url; | 320 sync_load_response->url = url; |
| 321 std::string data; | 321 std::string data; |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { | 821 while (headers->EnumerateHeaderLines(&iter, &name, &value)) { |
| 822 response->addHTTPHeaderField(WebString::fromLatin1(name), | 822 response->addHTTPHeaderField(WebString::fromLatin1(name), |
| 823 WebString::fromLatin1(value)); | 823 WebString::fromLatin1(value)); |
| 824 } | 824 } |
| 825 } | 825 } |
| 826 | 826 |
| 827 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request, | 827 void WebURLLoaderImpl::loadSynchronously(const WebURLRequest& request, |
| 828 WebURLResponse& response, | 828 WebURLResponse& response, |
| 829 WebURLError& error, | 829 WebURLError& error, |
| 830 WebData& data) { | 830 WebData& data) { |
| 831 ResourceLoaderBridge::SyncLoadResponse sync_load_response; | 831 SyncLoadResponse sync_load_response; |
| 832 context_->Start(request, &sync_load_response); | 832 context_->Start(request, &sync_load_response); |
| 833 | 833 |
| 834 const GURL& final_url = sync_load_response.url; | 834 const GURL& final_url = sync_load_response.url; |
| 835 | 835 |
| 836 // TODO(tc): For file loads, we may want to include a more descriptive | 836 // TODO(tc): For file loads, we may want to include a more descriptive |
| 837 // status code or status text. | 837 // status code or status text. |
| 838 int error_code = sync_load_response.error_code; | 838 int error_code = sync_load_response.error_code; |
| 839 if (error_code != net::OK) { | 839 if (error_code != net::OK) { |
| 840 response.setURL(final_url); | 840 response.setURL(final_url); |
| 841 error.domain = WebString::fromUTF8(net::kErrorDomain); | 841 error.domain = WebString::fromUTF8(net::kErrorDomain); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 864 | 864 |
| 865 void WebURLLoaderImpl::setDefersLoading(bool value) { | 865 void WebURLLoaderImpl::setDefersLoading(bool value) { |
| 866 context_->SetDefersLoading(value); | 866 context_->SetDefersLoading(value); |
| 867 } | 867 } |
| 868 | 868 |
| 869 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { | 869 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { |
| 870 context_->DidChangePriority(new_priority); | 870 context_->DidChangePriority(new_priority); |
| 871 } | 871 } |
| 872 | 872 |
| 873 } // namespace content | 873 } // namespace content |
| OLD | NEW |