OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/child/weburlloader_impl.h" | 7 #include "webkit/child/weburlloader_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" |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 public ResourceLoaderBridge::Peer { | 217 public ResourceLoaderBridge::Peer { |
218 public: | 218 public: |
219 explicit Context(WebURLLoaderImpl* loader); | 219 explicit Context(WebURLLoaderImpl* loader); |
220 | 220 |
221 WebURLLoaderClient* client() const { return client_; } | 221 WebURLLoaderClient* client() const { return client_; } |
222 void set_client(WebURLLoaderClient* client) { client_ = client; } | 222 void set_client(WebURLLoaderClient* client) { client_ = client; } |
223 | 223 |
224 void Cancel(); | 224 void Cancel(); |
225 void SetDefersLoading(bool value); | 225 void SetDefersLoading(bool value); |
226 void DidChangePriority(WebURLRequest::Priority new_priority); | 226 void DidChangePriority(WebURLRequest::Priority new_priority); |
| 227 blink::WebParserResourceBridge* ConstructParserResourceBridge(); |
227 void Start( | 228 void Start( |
228 const WebURLRequest& request, | 229 const WebURLRequest& request, |
229 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, | 230 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, |
230 WebKitPlatformSupportImpl* platform); | 231 WebKitPlatformSupportImpl* platform); |
231 | 232 |
232 // ResourceLoaderBridge::Peer methods: | 233 // ResourceLoaderBridge::Peer methods: |
233 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; | 234 virtual void OnUploadProgress(uint64 position, uint64 size) OVERRIDE; |
234 virtual bool OnReceivedRedirect( | 235 virtual bool OnReceivedRedirect( |
235 const GURL& new_url, | 236 const GURL& new_url, |
236 const ResourceResponseInfo& info, | 237 const ResourceResponseInfo& info, |
237 bool* has_new_first_party_for_cookies, | 238 bool* has_new_first_party_for_cookies, |
238 GURL* new_first_party_for_cookies) OVERRIDE; | 239 GURL* new_first_party_for_cookies) OVERRIDE; |
239 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; | 240 virtual void OnReceivedResponse(const ResourceResponseInfo& info) OVERRIDE; |
240 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; | 241 virtual void OnDownloadedData(int len, int encoded_data_length) OVERRIDE; |
241 virtual void OnReceivedData(const char* data, | 242 virtual void OnReceivedData(const char* data, |
242 int data_length, | 243 int data_length, |
243 int encoded_data_length) OVERRIDE; | 244 int encoded_data_length) OVERRIDE; |
244 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE; | 245 virtual void OnReceivedCachedMetadata(const char* data, int len) OVERRIDE; |
245 virtual void OnCompletedRequest( | 246 virtual void OnCompletedRequest( |
246 int error_code, | 247 int error_code, |
247 bool was_ignored_by_handler, | 248 bool was_ignored_by_handler, |
248 const std::string& security_info, | 249 const std::string& security_info, |
249 const base::TimeTicks& completion_time) OVERRIDE; | 250 const base::TimeTicks& completion_time) OVERRIDE; |
250 | 251 virtual void OnParserResourceMessageFilterAdded() OVERRIDE; |
251 private: | 252 private: |
252 friend class base::RefCounted<Context>; | 253 friend class base::RefCounted<Context>; |
253 virtual ~Context() {} | 254 virtual ~Context() {} |
254 | 255 |
255 // We can optimize the handling of data URLs in most cases. | 256 // We can optimize the handling of data URLs in most cases. |
256 bool CanHandleDataURL(const GURL& url) const; | 257 bool CanHandleDataURL(const GURL& url) const; |
257 void HandleDataURL(); | 258 void HandleDataURL(); |
258 | 259 |
259 WebURLLoaderImpl* loader_; | 260 WebURLLoaderImpl* loader_; |
260 WebURLRequest request_; | 261 WebURLRequest request_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 bridge_->SetDefersLoading(value); | 294 bridge_->SetDefersLoading(value); |
294 } | 295 } |
295 | 296 |
296 void WebURLLoaderImpl::Context::DidChangePriority( | 297 void WebURLLoaderImpl::Context::DidChangePriority( |
297 WebURLRequest::Priority new_priority) { | 298 WebURLRequest::Priority new_priority) { |
298 if (bridge_) | 299 if (bridge_) |
299 bridge_->DidChangePriority( | 300 bridge_->DidChangePriority( |
300 ConvertWebKitPriorityToNetPriority(new_priority)); | 301 ConvertWebKitPriorityToNetPriority(new_priority)); |
301 } | 302 } |
302 | 303 |
| 304 blink::WebParserResourceBridge* |
| 305 WebURLLoaderImpl::Context::ConstructParserResourceBridge() { |
| 306 if (bridge_) |
| 307 return bridge_->ConstructParserResourceBridge(); |
| 308 |
| 309 return NULL; |
| 310 } |
| 311 |
303 void WebURLLoaderImpl::Context::Start( | 312 void WebURLLoaderImpl::Context::Start( |
304 const WebURLRequest& request, | 313 const WebURLRequest& request, |
305 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, | 314 ResourceLoaderBridge::SyncLoadResponse* sync_load_response, |
306 WebKitPlatformSupportImpl* platform) { | 315 WebKitPlatformSupportImpl* platform) { |
307 DCHECK(!bridge_.get()); | 316 DCHECK(!bridge_.get()); |
308 | 317 |
309 request_ = request; // Save the request. | 318 request_ = request; // Save the request. |
310 | 319 |
311 GURL url = request.url(); | 320 GURL url = request.url(); |
312 if (url.SchemeIs("data") && CanHandleDataURL(url)) { | 321 if (url.SchemeIs("data") && CanHandleDataURL(url)) { |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 loader_, (completion_time - TimeTicks()).InSecondsF()); | 628 loader_, (completion_time - TimeTicks()).InSecondsF()); |
620 } | 629 } |
621 } | 630 } |
622 | 631 |
623 // We are done with the bridge now, and so we need to release the reference | 632 // We are done with the bridge now, and so we need to release the reference |
624 // to ourselves that we took on behalf of the bridge. This may cause our | 633 // to ourselves that we took on behalf of the bridge. This may cause our |
625 // destruction. | 634 // destruction. |
626 Release(); | 635 Release(); |
627 } | 636 } |
628 | 637 |
| 638 void WebURLLoaderImpl::Context::OnParserResourceMessageFilterAdded() { |
| 639 if (client_) |
| 640 client_->didAddParserResourceMessageFilter(); |
| 641 } |
| 642 |
629 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { | 643 bool WebURLLoaderImpl::Context::CanHandleDataURL(const GURL& url) const { |
630 DCHECK(url.SchemeIs("data")); | 644 DCHECK(url.SchemeIs("data")); |
631 | 645 |
632 // Optimize for the case where we can handle a data URL locally. We must | 646 // Optimize for the case where we can handle a data URL locally. We must |
633 // skip this for data URLs targetted at frames since those could trigger a | 647 // skip this for data URLs targetted at frames since those could trigger a |
634 // download. | 648 // download. |
635 // | 649 // |
636 // NOTE: We special case MIME types we can render both for performance | 650 // NOTE: We special case MIME types we can render both for performance |
637 // reasons as well as to support unit tests, which do not have an underlying | 651 // reasons as well as to support unit tests, which do not have an underlying |
638 // ResourceLoaderBridge implementation. | 652 // ResourceLoaderBridge implementation. |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 } | 861 } |
848 | 862 |
849 void WebURLLoaderImpl::setDefersLoading(bool value) { | 863 void WebURLLoaderImpl::setDefersLoading(bool value) { |
850 context_->SetDefersLoading(value); | 864 context_->SetDefersLoading(value); |
851 } | 865 } |
852 | 866 |
853 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { | 867 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority) { |
854 context_->DidChangePriority(new_priority); | 868 context_->DidChangePriority(new_priority); |
855 } | 869 } |
856 | 870 |
| 871 blink::WebParserResourceBridge* |
| 872 WebURLLoaderImpl::constructParserResourceBridge() { |
| 873 return context_->ConstructParserResourceBridge(); |
| 874 } |
| 875 |
857 } // namespace webkit_glue | 876 } // namespace webkit_glue |
OLD | NEW |