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 #include "content/child/web_url_loader_impl.h" | 5 #include "content/child/web_url_loader_impl.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "content/child/web_url_request_util.h" | 33 #include "content/child/web_url_request_util.h" |
34 #include "content/child/weburlresponse_extradata_impl.h" | 34 #include "content/child/weburlresponse_extradata_impl.h" |
35 #include "content/common/resource_messages.h" | 35 #include "content/common/resource_messages.h" |
36 #include "content/common/resource_request.h" | 36 #include "content/common/resource_request.h" |
37 #include "content/common/resource_request_body_impl.h" | 37 #include "content/common/resource_request_body_impl.h" |
38 #include "content/common/service_worker/service_worker_types.h" | 38 #include "content/common/service_worker/service_worker_types.h" |
39 #include "content/common/url_loader.mojom.h" | 39 #include "content/common/url_loader.mojom.h" |
40 #include "content/public/child/fixed_received_data.h" | 40 #include "content/public/child/fixed_received_data.h" |
41 #include "content/public/child/request_peer.h" | 41 #include "content/public/child/request_peer.h" |
42 #include "content/public/common/browser_side_navigation_policy.h" | 42 #include "content/public/common/browser_side_navigation_policy.h" |
43 #include "mojo/public/cpp/bindings/associated_group.h" | |
44 #include "net/base/data_url.h" | 43 #include "net/base/data_url.h" |
45 #include "net/base/filename_util.h" | 44 #include "net/base/filename_util.h" |
46 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
47 #include "net/cert/cert_status_flags.h" | 46 #include "net/cert/cert_status_flags.h" |
48 #include "net/cert/ct_sct_to_string.h" | 47 #include "net/cert/ct_sct_to_string.h" |
49 #include "net/cert/x509_util.h" | 48 #include "net/cert/x509_util.h" |
50 #include "net/http/http_response_headers.h" | 49 #include "net/http/http_response_headers.h" |
51 #include "net/http/http_util.h" | 50 #include "net/http/http_util.h" |
52 #include "net/ssl/ssl_cipher_suite_names.h" | 51 #include "net/ssl/ssl_cipher_suite_names.h" |
53 #include "net/ssl/ssl_connection_status_flags.h" | 52 #include "net/ssl/ssl_connection_status_flags.h" |
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 354 |
356 // This inner class exists since the WebURLLoader may be deleted while inside a | 355 // This inner class exists since the WebURLLoader may be deleted while inside a |
357 // call to WebURLLoaderClient. Refcounting is to keep the context from being | 356 // call to WebURLLoaderClient. Refcounting is to keep the context from being |
358 // deleted if it may have work to do after calling into the client. | 357 // deleted if it may have work to do after calling into the client. |
359 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { | 358 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { |
360 public: | 359 public: |
361 using ReceivedData = RequestPeer::ReceivedData; | 360 using ReceivedData = RequestPeer::ReceivedData; |
362 | 361 |
363 Context(WebURLLoaderImpl* loader, | 362 Context(WebURLLoaderImpl* loader, |
364 ResourceDispatcher* resource_dispatcher, | 363 ResourceDispatcher* resource_dispatcher, |
365 mojom::URLLoaderFactory* factory, | 364 mojom::URLLoaderFactory* factory); |
366 mojo::AssociatedGroup* associated_group); | |
367 | 365 |
368 WebURLLoaderClient* client() const { return client_; } | 366 WebURLLoaderClient* client() const { return client_; } |
369 void set_client(WebURLLoaderClient* client) { client_ = client; } | 367 void set_client(WebURLLoaderClient* client) { client_ = client; } |
370 | 368 |
371 void Cancel(); | 369 void Cancel(); |
372 void SetDefersLoading(bool value); | 370 void SetDefersLoading(bool value); |
373 void DidChangePriority(WebURLRequest::Priority new_priority, | 371 void DidChangePriority(WebURLRequest::Priority new_priority, |
374 int intra_priority_value); | 372 int intra_priority_value); |
375 void Start(const WebURLRequest& request, | 373 void Start(const WebURLRequest& request, |
376 SyncLoadResponse* sync_load_response); | 374 SyncLoadResponse* sync_load_response); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 407 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
410 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 408 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
411 std::unique_ptr<StreamOverrideParameters> stream_override_; | 409 std::unique_ptr<StreamOverrideParameters> stream_override_; |
412 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; | 410 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; |
413 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; | 411 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; |
414 DeferState defers_loading_; | 412 DeferState defers_loading_; |
415 int request_id_; | 413 int request_id_; |
416 | 414 |
417 // These are owned by the Blink::Platform singleton. | 415 // These are owned by the Blink::Platform singleton. |
418 mojom::URLLoaderFactory* url_loader_factory_; | 416 mojom::URLLoaderFactory* url_loader_factory_; |
419 mojo::AssociatedGroup* associated_group_; | |
420 }; | 417 }; |
421 | 418 |
422 // A thin wrapper class for Context to ensure its lifetime while it is | 419 // A thin wrapper class for Context to ensure its lifetime while it is |
423 // handling IPC messages coming from ResourceDispatcher. Owns one ref to | 420 // handling IPC messages coming from ResourceDispatcher. Owns one ref to |
424 // Context and held by ResourceDispatcher. | 421 // Context and held by ResourceDispatcher. |
425 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { | 422 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { |
426 public: | 423 public: |
427 explicit RequestPeerImpl(Context* context); | 424 explicit RequestPeerImpl(Context* context); |
428 | 425 |
429 // RequestPeer methods: | 426 // RequestPeer methods: |
(...skipping 14 matching lines...) Expand all Loading... |
444 | 441 |
445 private: | 442 private: |
446 scoped_refptr<Context> context_; | 443 scoped_refptr<Context> context_; |
447 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); | 444 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); |
448 }; | 445 }; |
449 | 446 |
450 // WebURLLoaderImpl::Context -------------------------------------------------- | 447 // WebURLLoaderImpl::Context -------------------------------------------------- |
451 | 448 |
452 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader, | 449 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader, |
453 ResourceDispatcher* resource_dispatcher, | 450 ResourceDispatcher* resource_dispatcher, |
454 mojom::URLLoaderFactory* url_loader_factory, | 451 mojom::URLLoaderFactory* url_loader_factory) |
455 mojo::AssociatedGroup* associated_group) | |
456 : loader_(loader), | 452 : loader_(loader), |
457 client_(NULL), | 453 client_(NULL), |
458 resource_dispatcher_(resource_dispatcher), | 454 resource_dispatcher_(resource_dispatcher), |
459 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 455 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
460 defers_loading_(NOT_DEFERRING), | 456 defers_loading_(NOT_DEFERRING), |
461 request_id_(-1), | 457 request_id_(-1), |
462 url_loader_factory_(url_loader_factory), | 458 url_loader_factory_(url_loader_factory) {} |
463 associated_group_(associated_group) {} | |
464 | 459 |
465 void WebURLLoaderImpl::Context::Cancel() { | 460 void WebURLLoaderImpl::Context::Cancel() { |
466 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, | 461 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, |
467 TRACE_EVENT_FLAG_FLOW_IN); | 462 TRACE_EVENT_FLAG_FLOW_IN); |
468 if (resource_dispatcher_ && // NULL in unittest. | 463 if (resource_dispatcher_ && // NULL in unittest. |
469 request_id_ != -1) { | 464 request_id_ != -1) { |
470 resource_dispatcher_->Cancel(request_id_); | 465 resource_dispatcher_->Cancel(request_id_); |
471 request_id_ = -1; | 466 request_id_ = -1; |
472 } | 467 } |
473 | 468 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 request.getLoadingIPCType(), url_loader_factory_); | 626 request.getLoadingIPCType(), url_loader_factory_); |
632 return; | 627 return; |
633 } | 628 } |
634 | 629 |
635 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, | 630 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, |
636 TRACE_EVENT_FLAG_FLOW_OUT); | 631 TRACE_EVENT_FLAG_FLOW_OUT); |
637 request_id_ = resource_dispatcher_->StartAsync( | 632 request_id_ = resource_dispatcher_->StartAsync( |
638 std::move(resource_request), request.requestorID(), task_runner_, | 633 std::move(resource_request), request.requestorID(), task_runner_, |
639 extra_data->frame_origin(), | 634 extra_data->frame_origin(), |
640 base::MakeUnique<WebURLLoaderImpl::RequestPeerImpl>(this), | 635 base::MakeUnique<WebURLLoaderImpl::RequestPeerImpl>(this), |
641 request.getLoadingIPCType(), url_loader_factory_, associated_group_); | 636 request.getLoadingIPCType(), url_loader_factory_); |
642 | 637 |
643 if (defers_loading_ != NOT_DEFERRING) | 638 if (defers_loading_ != NOT_DEFERRING) |
644 resource_dispatcher_->SetDefersLoading(request_id_, true); | 639 resource_dispatcher_->SetDefersLoading(request_id_, true); |
645 } | 640 } |
646 | 641 |
647 void WebURLLoaderImpl::Context::SetTaskRunner( | 642 void WebURLLoaderImpl::Context::SetTaskRunner( |
648 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 643 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
649 task_runner_ = task_runner; | 644 task_runner_ = task_runner; |
650 } | 645 } |
651 | 646 |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1029 int64_t total_transfer_size, | 1024 int64_t total_transfer_size, |
1030 int64_t encoded_body_size) { | 1025 int64_t encoded_body_size) { |
1031 context_->OnCompletedRequest(error_code, was_ignored_by_handler, | 1026 context_->OnCompletedRequest(error_code, was_ignored_by_handler, |
1032 stale_copy_in_cache, completion_time, | 1027 stale_copy_in_cache, completion_time, |
1033 total_transfer_size, encoded_body_size); | 1028 total_transfer_size, encoded_body_size); |
1034 } | 1029 } |
1035 | 1030 |
1036 // WebURLLoaderImpl ----------------------------------------------------------- | 1031 // WebURLLoaderImpl ----------------------------------------------------------- |
1037 | 1032 |
1038 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, | 1033 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, |
1039 mojom::URLLoaderFactory* url_loader_factory, | 1034 mojom::URLLoaderFactory* url_loader_factory) |
1040 mojo::AssociatedGroup* associated_group) | 1035 : context_(new Context(this, resource_dispatcher, url_loader_factory)) {} |
1041 : context_(new Context(this, | |
1042 resource_dispatcher, | |
1043 url_loader_factory, | |
1044 associated_group)) {} | |
1045 | 1036 |
1046 WebURLLoaderImpl::~WebURLLoaderImpl() { | 1037 WebURLLoaderImpl::~WebURLLoaderImpl() { |
1047 cancel(); | 1038 cancel(); |
1048 } | 1039 } |
1049 | 1040 |
1050 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, | 1041 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, |
1051 const ResourceResponseInfo& info, | 1042 const ResourceResponseInfo& info, |
1052 WebURLResponse* response, | 1043 WebURLResponse* response, |
1053 bool report_security_info) { | 1044 bool report_security_info) { |
1054 response->setURL(url); | 1045 response->setURL(url); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1261 int intra_priority_value) { | 1252 int intra_priority_value) { |
1262 context_->DidChangePriority(new_priority, intra_priority_value); | 1253 context_->DidChangePriority(new_priority, intra_priority_value); |
1263 } | 1254 } |
1264 | 1255 |
1265 void WebURLLoaderImpl::setLoadingTaskRunner( | 1256 void WebURLLoaderImpl::setLoadingTaskRunner( |
1266 base::SingleThreadTaskRunner* loading_task_runner) { | 1257 base::SingleThreadTaskRunner* loading_task_runner) { |
1267 context_->SetTaskRunner(loading_task_runner); | 1258 context_->SetTaskRunner(loading_task_runner); |
1268 } | 1259 } |
1269 | 1260 |
1270 } // namespace content | 1261 } // namespace content |
OLD | NEW |