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

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

Issue 1366883002: [Reland] Post loading tasks on the appropriate WebFrameScheduler's queue (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix UAF in BackgroundHTMLParser Created 5 years, 2 months 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
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 #include "content/child/web_url_loader_impl.h" 5 #include "content/child/web_url_loader_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h" 14 #include "base/memory/scoped_ptr.h"
15 #include "base/single_thread_task_runner.h" 15 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_util.h" 16 #include "base/strings/string_util.h"
17 #include "base/time/time.h" 17 #include "base/time/time.h"
18 #include "components/mime_util/mime_util.h" 18 #include "components/mime_util/mime_util.h"
19 #include "components/scheduler/child/web_task_runner_impl.h"
19 #include "content/child/child_thread_impl.h" 20 #include "content/child/child_thread_impl.h"
20 #include "content/child/ftp_directory_listing_response_delegate.h" 21 #include "content/child/ftp_directory_listing_response_delegate.h"
21 #include "content/child/multipart_response_delegate.h" 22 #include "content/child/multipart_response_delegate.h"
22 #include "content/child/request_extra_data.h" 23 #include "content/child/request_extra_data.h"
23 #include "content/child/request_info.h" 24 #include "content/child/request_info.h"
24 #include "content/child/resource_dispatcher.h" 25 #include "content/child/resource_dispatcher.h"
25 #include "content/child/shared_memory_data_consumer_handle.h" 26 #include "content/child/shared_memory_data_consumer_handle.h"
26 #include "content/child/sync_load_response.h" 27 #include "content/child/sync_load_response.h"
27 #include "content/child/web_url_request_util.h" 28 #include "content/child/web_url_request_util.h"
28 #include "content/child/weburlresponse_extradata_impl.h" 29 #include "content/child/weburlresponse_extradata_impl.h"
29 #include "content/common/resource_messages.h" 30 #include "content/common/resource_messages.h"
30 #include "content/common/resource_request_body.h" 31 #include "content/common/resource_request_body.h"
31 #include "content/common/service_worker/service_worker_types.h" 32 #include "content/common/service_worker/service_worker_types.h"
32 #include "content/common/ssl_status_serialization.h" 33 #include "content/common/ssl_status_serialization.h"
33 #include "content/public/child/fixed_received_data.h" 34 #include "content/public/child/fixed_received_data.h"
34 #include "content/public/child/request_peer.h" 35 #include "content/public/child/request_peer.h"
35 #include "content/public/common/content_switches.h" 36 #include "content/public/common/content_switches.h"
36 #include "net/base/data_url.h" 37 #include "net/base/data_url.h"
37 #include "net/base/filename_util.h" 38 #include "net/base/filename_util.h"
38 #include "net/base/net_errors.h" 39 #include "net/base/net_errors.h"
39 #include "net/http/http_response_headers.h" 40 #include "net/http/http_response_headers.h"
40 #include "net/http/http_util.h" 41 #include "net/http/http_util.h"
41 #include "net/ssl/ssl_cipher_suite_names.h" 42 #include "net/ssl/ssl_cipher_suite_names.h"
42 #include "net/ssl/ssl_connection_status_flags.h" 43 #include "net/ssl/ssl_connection_status_flags.h"
43 #include "net/url_request/url_request_data_job.h" 44 #include "net/url_request/url_request_data_job.h"
44 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h" 45 #include "third_party/WebKit/public/platform/WebHTTPLoadInfo.h"
46 #include "third_party/WebKit/public/platform/WebTraceLocation.h"
45 #include "third_party/WebKit/public/platform/WebURL.h" 47 #include "third_party/WebKit/public/platform/WebURL.h"
46 #include "third_party/WebKit/public/platform/WebURLError.h" 48 #include "third_party/WebKit/public/platform/WebURLError.h"
47 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h" 49 #include "third_party/WebKit/public/platform/WebURLLoadTiming.h"
48 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h" 50 #include "third_party/WebKit/public/platform/WebURLLoaderClient.h"
49 #include "third_party/WebKit/public/platform/WebURLRequest.h" 51 #include "third_party/WebKit/public/platform/WebURLRequest.h"
50 #include "third_party/WebKit/public/platform/WebURLResponse.h" 52 #include "third_party/WebKit/public/platform/WebURLResponse.h"
51 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" 53 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
52 54
53 using base::Time; 55 using base::Time;
54 using base::TimeTicks; 56 using base::TimeTicks;
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 // WebURLLoaderImpl::Context -------------------------------------------------- 249 // WebURLLoaderImpl::Context --------------------------------------------------
248 250
249 // This inner class exists since the WebURLLoader may be deleted while inside a 251 // This inner class exists since the WebURLLoader may be deleted while inside a
250 // call to WebURLLoaderClient. Refcounting is to keep the context from being 252 // call to WebURLLoaderClient. Refcounting is to keep the context from being
251 // deleted if it may have work to do after calling into the client. 253 // deleted if it may have work to do after calling into the client.
252 class WebURLLoaderImpl::Context : public base::RefCounted<Context>, 254 class WebURLLoaderImpl::Context : public base::RefCounted<Context>,
253 public RequestPeer { 255 public RequestPeer {
254 public: 256 public:
255 Context(WebURLLoaderImpl* loader, 257 Context(WebURLLoaderImpl* loader,
256 ResourceDispatcher* resource_dispatcher, 258 ResourceDispatcher* resource_dispatcher,
257 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 259 scoped_ptr<blink::WebTaskRunner> task_runner);
258 260
259 WebURLLoaderClient* client() const { return client_; } 261 WebURLLoaderClient* client() const { return client_; }
260 void set_client(WebURLLoaderClient* client) { client_ = client; } 262 void set_client(WebURLLoaderClient* client) { client_ = client; }
261 263
262 void Cancel(); 264 void Cancel();
263 void SetDefersLoading(bool value); 265 void SetDefersLoading(bool value);
264 void DidChangePriority(WebURLRequest::Priority new_priority, 266 void DidChangePriority(WebURLRequest::Priority new_priority,
265 int intra_priority_value); 267 int intra_priority_value);
266 bool AttachThreadedDataReceiver( 268 bool AttachThreadedDataReceiver(
267 blink::WebThreadedDataReceiver* threaded_data_receiver); 269 blink::WebThreadedDataReceiver* threaded_data_receiver);
268 void Start(const WebURLRequest& request, 270 void Start(const WebURLRequest& request,
269 SyncLoadResponse* sync_load_response); 271 SyncLoadResponse* sync_load_response);
272 void SetWebTaskRunner(scoped_ptr<blink::WebTaskRunner> task_runner);
270 273
271 // RequestPeer methods: 274 // RequestPeer methods:
272 void OnUploadProgress(uint64 position, uint64 size) override; 275 void OnUploadProgress(uint64 position, uint64 size) override;
273 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, 276 bool OnReceivedRedirect(const net::RedirectInfo& redirect_info,
274 const ResourceResponseInfo& info) override; 277 const ResourceResponseInfo& info) override;
275 void OnReceivedResponse(const ResourceResponseInfo& info) override; 278 void OnReceivedResponse(const ResourceResponseInfo& info) override;
276 void OnDownloadedData(int len, int encoded_data_length) override; 279 void OnDownloadedData(int len, int encoded_data_length) override;
277 void OnReceivedData(scoped_ptr<ReceivedData> data) override; 280 void OnReceivedData(scoped_ptr<ReceivedData> data) override;
278 void OnReceivedCachedMetadata(const char* data, int len) override; 281 void OnReceivedCachedMetadata(const char* data, int len) override;
279 void OnCompletedRequest(int error_code, 282 void OnCompletedRequest(int error_code,
280 bool was_ignored_by_handler, 283 bool was_ignored_by_handler,
281 bool stale_copy_in_cache, 284 bool stale_copy_in_cache,
282 const std::string& security_info, 285 const std::string& security_info,
283 const base::TimeTicks& completion_time, 286 const base::TimeTicks& completion_time,
284 int64 total_transfer_size) override; 287 int64 total_transfer_size) override;
285 void OnReceivedCompletedResponse(const ResourceResponseInfo& info, 288 void OnReceivedCompletedResponse(const ResourceResponseInfo& info,
286 scoped_ptr<ReceivedData> data, 289 scoped_ptr<ReceivedData> data,
287 int error_code, 290 int error_code,
288 bool was_ignored_by_handler, 291 bool was_ignored_by_handler,
289 bool stale_copy_in_cache, 292 bool stale_copy_in_cache,
290 const std::string& security_info, 293 const std::string& security_info,
291 const base::TimeTicks& completion_time, 294 const base::TimeTicks& completion_time,
292 int64 total_transfer_size) override; 295 int64 total_transfer_size) override;
293 296
294 private: 297 private:
295 friend class base::RefCounted<Context>; 298 friend class base::RefCounted<Context>;
296 ~Context() override; 299 ~Context() override;
297 300
301 class HandleDataURLTask : public blink::WebTaskRunner::Task {
302 public:
303 explicit HandleDataURLTask(scoped_refptr<Context> context)
304 : context_(context) {}
305
306 void run() override {
307 context_->HandleDataURL();
308 }
309
310 private:
311 scoped_refptr<Context> context_;
312 };
313
298 // Called when the body data stream is detached from the reader side. 314 // Called when the body data stream is detached from the reader side.
299 void CancelBodyStreaming(); 315 void CancelBodyStreaming();
300 // We can optimize the handling of data URLs in most cases. 316 // We can optimize the handling of data URLs in most cases.
301 bool CanHandleDataURLRequestLocally() const; 317 bool CanHandleDataURLRequestLocally() const;
302 void HandleDataURL(); 318 void HandleDataURL();
303 319
304 WebURLLoaderImpl* loader_; 320 WebURLLoaderImpl* loader_;
305 WebURLRequest request_; 321 WebURLRequest request_;
306 WebURLLoaderClient* client_; 322 WebURLLoaderClient* client_;
307 ResourceDispatcher* resource_dispatcher_; 323 ResourceDispatcher* resource_dispatcher_;
308 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 324 scoped_ptr<blink::WebTaskRunner> web_task_runner_;
309 WebReferrerPolicy referrer_policy_; 325 WebReferrerPolicy referrer_policy_;
310 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; 326 scoped_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_;
311 scoped_ptr<MultipartResponseDelegate> multipart_delegate_; 327 scoped_ptr<MultipartResponseDelegate> multipart_delegate_;
312 scoped_ptr<StreamOverrideParameters> stream_override_; 328 scoped_ptr<StreamOverrideParameters> stream_override_;
313 scoped_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; 329 scoped_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_;
314 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; 330 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA};
315 DeferState defers_loading_; 331 DeferState defers_loading_;
316 int request_id_; 332 int request_id_;
317 }; 333 };
318 334
319 WebURLLoaderImpl::Context::Context( 335 WebURLLoaderImpl::Context::Context(
320 WebURLLoaderImpl* loader, 336 WebURLLoaderImpl* loader,
321 ResourceDispatcher* resource_dispatcher, 337 ResourceDispatcher* resource_dispatcher,
322 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 338 scoped_ptr<blink::WebTaskRunner> web_task_runner)
323 : loader_(loader), 339 : loader_(loader),
324 client_(NULL), 340 client_(NULL),
325 resource_dispatcher_(resource_dispatcher), 341 resource_dispatcher_(resource_dispatcher),
326 task_runner_(task_runner), 342 web_task_runner_(web_task_runner.Pass()),
327 referrer_policy_(blink::WebReferrerPolicyDefault), 343 referrer_policy_(blink::WebReferrerPolicyDefault),
328 defers_loading_(NOT_DEFERRING), 344 defers_loading_(NOT_DEFERRING),
329 request_id_(-1) { 345 request_id_(-1) {
330 } 346 }
331 347
332 void WebURLLoaderImpl::Context::Cancel() { 348 void WebURLLoaderImpl::Context::Cancel() {
333 if (resource_dispatcher_ && // NULL in unittest. 349 if (resource_dispatcher_ && // NULL in unittest.
334 request_id_ != -1) { 350 request_id_ != -1) {
335 resource_dispatcher_->Cancel(request_id_); 351 resource_dispatcher_->Cancel(request_id_);
336 request_id_ = -1; 352 request_id_ = -1;
(...skipping 15 matching lines...) Expand all
352 loader_ = NULL; 368 loader_ = NULL;
353 } 369 }
354 370
355 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) { 371 void WebURLLoaderImpl::Context::SetDefersLoading(bool value) {
356 if (request_id_ != -1) 372 if (request_id_ != -1)
357 resource_dispatcher_->SetDefersLoading(request_id_, value); 373 resource_dispatcher_->SetDefersLoading(request_id_, value);
358 if (value && defers_loading_ == NOT_DEFERRING) { 374 if (value && defers_loading_ == NOT_DEFERRING) {
359 defers_loading_ = SHOULD_DEFER; 375 defers_loading_ = SHOULD_DEFER;
360 } else if (!value && defers_loading_ != NOT_DEFERRING) { 376 } else if (!value && defers_loading_ != NOT_DEFERRING) {
361 if (defers_loading_ == DEFERRED_DATA) { 377 if (defers_loading_ == DEFERRED_DATA) {
362 task_runner_->PostTask(FROM_HERE, 378 // TODO(alexclarke): Find a way to let blink and chromium FROM_HERE
363 base::Bind(&Context::HandleDataURL, this)); 379 // coexist.
380 web_task_runner_->postTask(
381 ::blink::WebTraceLocation(__FUNCTION__, __FILE__),
382 new HandleDataURLTask(this));
364 } 383 }
365 defers_loading_ = NOT_DEFERRING; 384 defers_loading_ = NOT_DEFERRING;
366 } 385 }
367 } 386 }
368 387
369 void WebURLLoaderImpl::Context::DidChangePriority( 388 void WebURLLoaderImpl::Context::DidChangePriority(
370 WebURLRequest::Priority new_priority, int intra_priority_value) { 389 WebURLRequest::Priority new_priority, int intra_priority_value) {
371 if (request_id_ != -1) { 390 if (request_id_ != -1) {
372 resource_dispatcher_->DidChangePriority( 391 resource_dispatcher_->DidChangePriority(
373 request_id_, 392 request_id_,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 430 }
412 431
413 if (CanHandleDataURLRequestLocally()) { 432 if (CanHandleDataURLRequestLocally()) {
414 if (sync_load_response) { 433 if (sync_load_response) {
415 // This is a sync load. Do the work now. 434 // This is a sync load. Do the work now.
416 sync_load_response->url = url; 435 sync_load_response->url = url;
417 sync_load_response->error_code = 436 sync_load_response->error_code =
418 GetInfoFromDataURL(sync_load_response->url, sync_load_response, 437 GetInfoFromDataURL(sync_load_response->url, sync_load_response,
419 &sync_load_response->data); 438 &sync_load_response->data);
420 } else { 439 } else {
421 task_runner_->PostTask(FROM_HERE, 440 // TODO(alexclarke): Find a way to let blink and chromium FROM_HERE
422 base::Bind(&Context::HandleDataURL, this)); 441 // coexist.
442 web_task_runner_->postTask(
443 ::blink::WebTraceLocation(__FUNCTION__, __FILE__),
444 new HandleDataURLTask(this));
423 } 445 }
424 return; 446 return;
425 } 447 }
426 448
427 // PlzNavigate: outside of tests, the only navigation requests going through 449 // PlzNavigate: outside of tests, the only navigation requests going through
428 // the WebURLLoader are the ones created by CommitNavigation. Several browser 450 // the WebURLLoader are the ones created by CommitNavigation. Several browser
429 // tests load HTML directly through a data url which will be handled by the 451 // tests load HTML directly through a data url which will be handled by the
430 // block above. 452 // block above.
431 DCHECK_IMPLIES(base::CommandLine::ForCurrentProcess()->HasSwitch( 453 DCHECK_IMPLIES(base::CommandLine::ForCurrentProcess()->HasSwitch(
432 switches::kEnableBrowserSideNavigation), 454 switches::kEnableBrowserSideNavigation),
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
475 request_info.fetch_credentials_mode = 497 request_info.fetch_credentials_mode =
476 GetFetchCredentialsModeForWebURLRequest(request); 498 GetFetchCredentialsModeForWebURLRequest(request);
477 request_info.fetch_redirect_mode = 499 request_info.fetch_redirect_mode =
478 GetFetchRedirectModeForWebURLRequest(request); 500 GetFetchRedirectModeForWebURLRequest(request);
479 request_info.fetch_request_context_type = 501 request_info.fetch_request_context_type =
480 GetRequestContextTypeForWebURLRequest(request); 502 GetRequestContextTypeForWebURLRequest(request);
481 request_info.fetch_frame_type = 503 request_info.fetch_frame_type =
482 GetRequestContextFrameTypeForWebURLRequest(request); 504 GetRequestContextFrameTypeForWebURLRequest(request);
483 request_info.extra_data = request.extraData(); 505 request_info.extra_data = request.extraData();
484 request_info.report_raw_headers = request.reportRawHeaders(); 506 request_info.report_raw_headers = request.reportRawHeaders();
507 request_info.loading_web_task_runner.reset(web_task_runner_->clone());
485 508
486 scoped_refptr<ResourceRequestBody> request_body = 509 scoped_refptr<ResourceRequestBody> request_body =
487 GetRequestBodyForWebURLRequest(request).get(); 510 GetRequestBodyForWebURLRequest(request).get();
488 511
489 if (sync_load_response) { 512 if (sync_load_response) {
490 resource_dispatcher_->StartSync( 513 resource_dispatcher_->StartSync(
491 request_info, request_body.get(), sync_load_response); 514 request_info, request_body.get(), sync_load_response);
492 return; 515 return;
493 } 516 }
494 517
495 request_id_ = resource_dispatcher_->StartAsync( 518 request_id_ = resource_dispatcher_->StartAsync(
496 request_info, request_body.get(), this); 519 request_info, request_body.get(), this);
497 } 520 }
498 521
522 void WebURLLoaderImpl::Context::SetWebTaskRunner(
523 scoped_ptr<blink::WebTaskRunner> web_task_runner) {
524 web_task_runner_ = web_task_runner.Pass();
525 }
526
499 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) { 527 void WebURLLoaderImpl::Context::OnUploadProgress(uint64 position, uint64 size) {
500 if (client_) 528 if (client_)
501 client_->didSendData(loader_, position, size); 529 client_->didSendData(loader_, position, size);
502 } 530 }
503 531
504 bool WebURLLoaderImpl::Context::OnReceivedRedirect( 532 bool WebURLLoaderImpl::Context::OnReceivedRedirect(
505 const net::RedirectInfo& redirect_info, 533 const net::RedirectInfo& redirect_info,
506 const ResourceResponseInfo& info) { 534 const ResourceResponseInfo& info) {
507 if (!client_) 535 if (!client_)
508 return false; 536 return false;
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 } 862 }
835 863
836 OnCompletedRequest(error_code, false, false, info.security_info, 864 OnCompletedRequest(error_code, false, false, info.security_info,
837 base::TimeTicks::Now(), 0); 865 base::TimeTicks::Now(), 0);
838 } 866 }
839 867
840 // WebURLLoaderImpl ----------------------------------------------------------- 868 // WebURLLoaderImpl -----------------------------------------------------------
841 869
842 WebURLLoaderImpl::WebURLLoaderImpl( 870 WebURLLoaderImpl::WebURLLoaderImpl(
843 ResourceDispatcher* resource_dispatcher, 871 ResourceDispatcher* resource_dispatcher,
844 scoped_refptr<base::SingleThreadTaskRunner> task_runner) 872 scoped_ptr<blink::WebTaskRunner> web_task_runner)
845 : context_(new Context(this, resource_dispatcher, task_runner)) { 873 : context_(new Context(this, resource_dispatcher, web_task_runner.Pass())) {
846 } 874 }
847 875
848 WebURLLoaderImpl::~WebURLLoaderImpl() { 876 WebURLLoaderImpl::~WebURLLoaderImpl() {
849 cancel(); 877 cancel();
850 } 878 }
851 879
852 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, 880 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url,
853 const ResourceResponseInfo& info, 881 const ResourceResponseInfo& info,
854 WebURLResponse* response, 882 WebURLResponse* response,
855 bool report_security_info) { 883 bool report_security_info) {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority, 1080 void WebURLLoaderImpl::didChangePriority(WebURLRequest::Priority new_priority,
1053 int intra_priority_value) { 1081 int intra_priority_value) {
1054 context_->DidChangePriority(new_priority, intra_priority_value); 1082 context_->DidChangePriority(new_priority, intra_priority_value);
1055 } 1083 }
1056 1084
1057 bool WebURLLoaderImpl::attachThreadedDataReceiver( 1085 bool WebURLLoaderImpl::attachThreadedDataReceiver(
1058 blink::WebThreadedDataReceiver* threaded_data_receiver) { 1086 blink::WebThreadedDataReceiver* threaded_data_receiver) {
1059 return context_->AttachThreadedDataReceiver(threaded_data_receiver); 1087 return context_->AttachThreadedDataReceiver(threaded_data_receiver);
1060 } 1088 }
1061 1089
1090 void WebURLLoaderImpl::setLoadingTaskRunner(
1091 blink::WebTaskRunner* loading_task_runner) {
1092 // There's no guarantee on the lifetime of |loading_task_runner| so we take a
1093 // copy.
1094 context_->SetWebTaskRunner(make_scoped_ptr(loading_task_runner->clone()));
1095 }
1096
1062 } // namespace content 1097 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698