Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: content/child/web_url_loader_impl.cc

Issue 771593006: Properly handle defers loading in WebURLLoaderImpl for data uris (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | content/child/web_url_loader_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
11 12
12 #include "base/bind.h" 13 #include "base/bind.h"
13 #include "base/command_line.h" 14 #include "base/command_line.h"
14 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/single_thread_task_runner.h" 17 #include "base/single_thread_task_runner.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/time/time.h" 19 #include "base/time/time.h"
19 #include "content/child/ftp_directory_listing_response_delegate.h" 20 #include "content/child/ftp_directory_listing_response_delegate.h"
20 #include "content/child/multipart_response_delegate.h" 21 #include "content/child/multipart_response_delegate.h"
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; 348 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
348 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; 349 scoped_ptr<MultipartResponseDelegate> multipart_delegate_;
349 scoped_ptr<ResourceLoaderBridge> completed_bridge_; 350 scoped_ptr<ResourceLoaderBridge> completed_bridge_;
350 scoped_ptr<StreamOverrideParameters> stream_override_; 351 scoped_ptr<StreamOverrideParameters> stream_override_;
351 mojo::ScopedDataPipeProducerHandle body_stream_writer_; 352 mojo::ScopedDataPipeProducerHandle body_stream_writer_;
352 mojo::common::HandleWatcher body_stream_writer_watcher_; 353 mojo::common::HandleWatcher body_stream_writer_watcher_;
353 // TODO(yhirano): Delete this buffer after implementing the back-pressure 354 // TODO(yhirano): Delete this buffer after implementing the back-pressure
354 // mechanism. 355 // mechanism.
355 std::deque<char> body_stream_buffer_; 356 std::deque<char> body_stream_buffer_;
356 bool got_all_stream_body_data_; 357 bool got_all_stream_body_data_;
358 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA};
359 DeferState defers_loading_;
357 }; 360 };
358 361
359 WebURLLoaderImpl::Context::Context( 362 WebURLLoaderImpl::Context::Context(
360 WebURLLoaderImpl* loader, 363 WebURLLoaderImpl* loader,
361 ResourceDispatcher* resource_dispatcher, 364 ResourceDispatcher* resource_dispatcher,
362 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 365 scoped_refptr<base::SingleThreadTaskRunner> task_runner)
363 : loader_(loader), 366 : loader_(loader),
364 client_(NULL), 367 client_(NULL),
365 resource_dispatcher_(resource_dispatcher), 368 resource_dispatcher_(resource_dispatcher),
366 task_runner_(task_runner), 369 task_runner_(task_runner),
367 referrer_policy_(blink::WebReferrerPolicyDefault), 370 referrer_policy_(blink::WebReferrerPolicyDefault),
368 got_all_stream_body_data_(false) { 371 got_all_stream_body_data_(false),
372 defers_loading_(NOT_DEFERRING) {
369 } 373 }
370 374
371 void WebURLLoaderImpl::Context::Cancel() { 375 void WebURLLoaderImpl::Context::Cancel() {
372 if (bridge_) { 376 if (bridge_) {
373 bridge_->Cancel(); 377 bridge_->Cancel();
374 bridge_.reset(); 378 bridge_.reset();
375 } 379 }
376 380
377 // Ensure that we do not notify the multipart delegate anymore as it has 381 // Ensure that we do not notify the multipart delegate anymore as it has
378 // its own pointer to the client. 382 // its own pointer to the client.
379 if (multipart_delegate_) 383 if (multipart_delegate_)
380 multipart_delegate_->Cancel(); 384 multipart_delegate_->Cancel();
381 // Ditto for the ftp delegate. 385 // Ditto for the ftp delegate.
382 if (ftp_listing_delegate_) 386 if (ftp_listing_delegate_)
383 ftp_listing_delegate_->Cancel(); 387 ftp_listing_delegate_->Cancel();
384 388
385 // Do not make any further calls to the client. 389 // Do not make any further calls to the client.
386 client_ = NULL; 390 client_ = NULL;
387 loader_ = NULL; 391 loader_ = NULL;
388 } 392 }
389 393
390 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { 394 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) {
391 if (bridge_) 395 if (bridge_)
392 bridge_->SetDefersLoading(value); 396 bridge_->SetDefersLoading(value);
397 if (value && defers_loading_ == NOT_DEFERRING) {
398 defers_loading_ = SHOULD_DEFER;
399 } else if (!value && defers_loading_ != NOT_DEFERRING) {
400 if (defers_loading_ == DEFERRED_DATA) {
401 task_runner_->PostTask(FROM_HERE,
402 base::Bind(&Context::HandleDataURL, this));
403 }
404 defers_loading_ = NOT_DEFERRING;
405 }
393 } 406 }
394 407
395 void WebURLLoaderImpl::Context::DidChangePriority( 408 void WebURLLoaderImpl::Context::DidChangePriority(
396 WebURLRequest::Priority new_priority, int intra_priority_value) { 409 WebURLRequest::Priority new_priority, int intra_priority_value) {
397 if (bridge_) 410 if (bridge_)
398 bridge_->DidChangePriority( 411 bridge_->DidChangePriority(
399 ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value); 412 ConvertWebKitPriorityToNetPriority(new_priority), intra_priority_value);
400 } 413 }
401 414
402 bool WebURLLoaderImpl::Context::AttachThreadedDataReceiver( 415 bool WebURLLoaderImpl::Context::AttachThreadedDataReceiver(
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 844
832 std::string mime_type, unused_charset; 845 std::string mime_type, unused_charset;
833 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) && 846 if (net::DataURL::Parse(request_.url(), &mime_type, &unused_charset, NULL) &&
834 net::IsSupportedMimeType(mime_type)) 847 net::IsSupportedMimeType(mime_type))
835 return true; 848 return true;
836 849
837 return false; 850 return false;
838 } 851 }
839 852
840 void WebURLLoaderImpl::Context::HandleDataURL() { 853 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
841 ResourceResponseInfo info; 860 ResourceResponseInfo info;
842 std::string data; 861 std::string data;
843 862
844 int error_code = GetInfoFromDataURL(request_.url(), &info, &data); 863 int error_code = GetInfoFromDataURL(request_.url(), &info, &data);
845 864
846 if (error_code == net::OK) { 865 if (error_code == net::OK) {
847 OnReceivedResponse(info); 866 OnReceivedResponse(info);
848 if (!data.empty()) 867 if (!data.empty())
849 OnReceivedData(data.data(), data.size(), 0); 868 OnReceivedData(data.data(), data.size(), 0);
850 } 869 }
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 int intra_priority_value) { 1178 int intra_priority_value) {
1160 context_->DidChangePriority(new_priority, intra_priority_value); 1179 context_->DidChangePriority(new_priority, intra_priority_value);
1161 } 1180 }
1162 1181
1163 bool WebURLLoaderImpl::attachThreadedDataReceiver( 1182 bool WebURLLoaderImpl::attachThreadedDataReceiver(
1164 blink::WebThreadedDataReceiver* threaded_data_receiver) { 1183 blink::WebThreadedDataReceiver* threaded_data_receiver) {
1165 return context_->AttachThreadedDataReceiver(threaded_data_receiver); 1184 return context_->AttachThreadedDataReceiver(threaded_data_receiver);
1166 } 1185 }
1167 1186
1168 } // namespace content 1187 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/web_url_loader_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698