| 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 <algorithm> | 9 #include <algorithm> |
| 10 #include <deque> | 10 #include <deque> |
| 11 #include <string> | |
| 12 | 11 |
| 13 #include "base/bind.h" | 12 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 15 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
| 16 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
| 18 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 19 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 20 #include "content/child/ftp_directory_listing_response_delegate.h" | 19 #include "content/child/ftp_directory_listing_response_delegate.h" |
| 21 #include "content/child/multipart_response_delegate.h" | 20 #include "content/child/multipart_response_delegate.h" |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 347 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
| 349 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; | 348 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; |
| 350 scoped_ptr<ResourceLoaderBridge> completed_bridge_; | 349 scoped_ptr<ResourceLoaderBridge> completed_bridge_; |
| 351 scoped_ptr<StreamOverrideParameters> stream_override_; | 350 scoped_ptr<StreamOverrideParameters> stream_override_; |
| 352 mojo::ScopedDataPipeProducerHandle body_stream_writer_; | 351 mojo::ScopedDataPipeProducerHandle body_stream_writer_; |
| 353 mojo::common::HandleWatcher body_stream_writer_watcher_; | 352 mojo::common::HandleWatcher body_stream_writer_watcher_; |
| 354 // TODO(yhirano): Delete this buffer after implementing the back-pressure | 353 // TODO(yhirano): Delete this buffer after implementing the back-pressure |
| 355 // mechanism. | 354 // mechanism. |
| 356 std::deque<char> body_stream_buffer_; | 355 std::deque<char> body_stream_buffer_; |
| 357 bool got_all_stream_body_data_; | 356 bool got_all_stream_body_data_; |
| 358 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; | |
| 359 DeferState defers_loading_; | |
| 360 }; | 357 }; |
| 361 | 358 |
| 362 WebURLLoaderImpl::Context::Context( | 359 WebURLLoaderImpl::Context::Context( |
| 363 WebURLLoaderImpl* loader, | 360 WebURLLoaderImpl* loader, |
| 364 ResourceDispatcher* resource_dispatcher, | 361 ResourceDispatcher* resource_dispatcher, |
| 365 scoped_refptr<base::SingleThreadTaskRunner> task_runner) | 362 scoped_refptr<base::SingleThreadTaskRunner> task_runner) |
| 366 : loader_(loader), | 363 : loader_(loader), |
| 367 client_(NULL), | 364 client_(NULL), |
| 368 resource_dispatcher_(resource_dispatcher), | 365 resource_dispatcher_(resource_dispatcher), |
| 369 task_runner_(task_runner), | 366 task_runner_(task_runner), |
| 370 referrer_policy_(blink::WebReferrerPolicyDefault), | 367 referrer_policy_(blink::WebReferrerPolicyDefault), |
| 371 got_all_stream_body_data_(false), | 368 got_all_stream_body_data_(false) { |
| 372 defers_loading_(NOT_DEFERRING) { | |
| 373 } | 369 } |
| 374 | 370 |
| 375 void WebURLLoaderImpl::Context::Cancel() { | 371 void WebURLLoaderImpl::Context::Cancel() { |
| 376 if (bridge_) { | 372 if (bridge_) { |
| 377 bridge_->Cancel(); | 373 bridge_->Cancel(); |
| 378 bridge_.reset(); | 374 bridge_.reset(); |
| 379 } | 375 } |
| 380 | 376 |
| 381 // Ensure that we do not notify the multipart delegate anymore as it has | 377 // Ensure that we do not notify the multipart delegate anymore as it has |
| 382 // its own pointer to the client. | 378 // its own pointer to the client. |
| 383 if (multipart_delegate_) | 379 if (multipart_delegate_) |
| 384 multipart_delegate_->Cancel(); | 380 multipart_delegate_->Cancel(); |
| 385 // Ditto for the ftp delegate. | 381 // Ditto for the ftp delegate. |
| 386 if (ftp_listing_delegate_) | 382 if (ftp_listing_delegate_) |
| 387 ftp_listing_delegate_->Cancel(); | 383 ftp_listing_delegate_->Cancel(); |
| 388 | 384 |
| 389 // Do not make any further calls to the client. | 385 // Do not make any further calls to the client. |
| 390 client_ = NULL; | 386 client_ = NULL; |
| 391 loader_ = NULL; | 387 loader_ = NULL; |
| 392 } | 388 } |
| 393 | 389 |
| 394 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { | 390 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { |
| 395 if (bridge_) | 391 if (bridge_) |
| 396 bridge_->SetDefersLoading(value); | 392 bridge_->SetDefersLoading(value); |
| 397 if (value) { | |
| 398 DCHECK_EQ(NOT_DEFERRING, defers_loading_); | |
| 399 defers_loading_ = SHOULD_DEFER; | |
| 400 } else { | |
| 401 DCHECK_NE(NOT_DEFERRING, defers_loading_); | |
| 402 if (defers_loading_ == DEFERRED_DATA) { | |
| 403 task_runner_->PostTask(FROM_HERE, | |
| 404 base::Bind(&Context::HandleDataURL, this)); | |
| 405 } | |
| 406 defers_loading_ = NOT_DEFERRING; | |
| 407 } | |
| 408 } | 393 } |
| 409 | 394 |
| 410 void WebURLLoaderImpl::Context::DidChangePriority( | 395 void WebURLLoaderImpl::Context::DidChangePriority( |
| 411 WebURLRequest::Priority new_priority, int intra_priority_value) { | 396 WebURLRequest::Priority new_priority, int intra_priority_value) { |
| 412 if (bridge_) | 397 if (bridge_) |
| 413 bridge_->DidChangePriority( | 398 bridge_->DidChangePriority( |
| 414 ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value); | 399 ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value); |
| 415 } | 400 } |
| 416 | 401 |
| 417 bool WebURLLoaderImpl::Context::AttachThreadedDataReceiver( | 402 bool WebURLLoaderImpl::Context::AttachThreadedDataReceiver( |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 | 829 |
| 845 std::string mime_type, unused_charset; | 830 std::string mime_type, unused_charset; |
| 846 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) && | 831 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) && |
| 847 net::IsSupportedMimeType(mime_type)) | 832 net::IsSupportedMimeType(mime_type)) |
| 848 return true; | 833 return true; |
| 849 | 834 |
| 850 return false; | 835 return false; |
| 851 } | 836 } |
| 852 | 837 |
| 853 void WebURLLoaderImpl::Context::HandleDataURL() { | 838 void WebURLLoaderImpl::Context::HandleDataURL() { |
| 854 DCHECK_NE(defers_loading_, DEFERRED_DATA); | |
| 855 if (defers_loading_ == SHOULD_DEFER) { | |
| 856 defers_loading_ = DEFERRED_DATA; | |
| 857 return; | |
| 858 } | |
| 859 | |
| 860 ResourceResponseInfo info; | 839 ResourceResponseInfo info; |
| 861 std::string data; | 840 std::string data; |
| 862 | 841 |
| 863 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); | 842 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); |
| 864 | 843 |
| 865 if (error_code == net::OK) { | 844 if (error_code == net::OK) { |
| 866 OnReceivedResponse(info); | 845 OnReceivedResponse(info); |
| 867 if (!data.empty()) | 846 if (!data.empty()) |
| 868 OnReceivedData(data.data(), data.size(), 0); | 847 OnReceivedData(data.data(), data.size(), 0); |
| 869 } | 848 } |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1175 int intra_priority_value) { | 1154 int intra_priority_value) { |
| 1176 context_->DidChangePriority(new_priority, intra_priority_value); | 1155 context_->DidChangePriority(new_priority, intra_priority_value); |
| 1177 } | 1156 } |
| 1178 | 1157 |
| 1179 bool WebURLLoaderImpl::attachThreadedDataReceiver( | 1158 bool WebURLLoaderImpl::attachThreadedDataReceiver( |
| 1180 blink::WebThreadedDataReceiver* threaded_data_receiver) { | 1159 blink::WebThreadedDataReceiver* threaded_data_receiver) { |
| 1181 return context_->AttachThreadedDataReceiver(threaded_data_receiver); | 1160 return context_->AttachThreadedDataReceiver(threaded_data_receiver); |
| 1182 } | 1161 } |
| 1183 | 1162 |
| 1184 } // namespace content | 1163 } // namespace content |
| OLD | NEW |