| 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 <openssl/ssl.h> | 7 #include <openssl/ssl.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "content/child/web_url_request_util.h" | 32 #include "content/child/web_url_request_util.h" |
| 33 #include "content/child/weburlresponse_extradata_impl.h" | 33 #include "content/child/weburlresponse_extradata_impl.h" |
| 34 #include "content/common/resource_messages.h" | 34 #include "content/common/resource_messages.h" |
| 35 #include "content/common/resource_request.h" | 35 #include "content/common/resource_request.h" |
| 36 #include "content/common/resource_request_body_impl.h" | 36 #include "content/common/resource_request_body_impl.h" |
| 37 #include "content/common/service_worker/service_worker_types.h" | 37 #include "content/common/service_worker/service_worker_types.h" |
| 38 #include "content/common/url_loader.mojom.h" | 38 #include "content/common/url_loader.mojom.h" |
| 39 #include "content/public/child/fixed_received_data.h" | 39 #include "content/public/child/fixed_received_data.h" |
| 40 #include "content/public/child/request_peer.h" | 40 #include "content/public/child/request_peer.h" |
| 41 #include "content/public/common/browser_side_navigation_policy.h" | 41 #include "content/public/common/browser_side_navigation_policy.h" |
| 42 #include "mojo/public/cpp/bindings/associated_group.h" |
| 42 #include "net/base/data_url.h" | 43 #include "net/base/data_url.h" |
| 43 #include "net/base/filename_util.h" | 44 #include "net/base/filename_util.h" |
| 44 #include "net/base/net_errors.h" | 45 #include "net/base/net_errors.h" |
| 45 #include "net/cert/cert_status_flags.h" | 46 #include "net/cert/cert_status_flags.h" |
| 46 #include "net/cert/ct_sct_to_string.h" | 47 #include "net/cert/ct_sct_to_string.h" |
| 47 #include "net/cert/x509_util.h" | 48 #include "net/cert/x509_util.h" |
| 48 #include "net/http/http_response_headers.h" | 49 #include "net/http/http_response_headers.h" |
| 49 #include "net/http/http_util.h" | 50 #include "net/http/http_util.h" |
| 50 #include "net/ssl/ssl_cipher_suite_names.h" | 51 #include "net/ssl/ssl_cipher_suite_names.h" |
| 51 #include "net/ssl/ssl_connection_status_flags.h" | 52 #include "net/ssl/ssl_connection_status_flags.h" |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 | 357 |
| 357 // This inner class exists since the WebURLLoader may be deleted while inside a | 358 // This inner class exists since the WebURLLoader may be deleted while inside a |
| 358 // call to WebURLLoaderClient. Refcounting is to keep the context from being | 359 // call to WebURLLoaderClient. Refcounting is to keep the context from being |
| 359 // deleted if it may have work to do after calling into the client. | 360 // deleted if it may have work to do after calling into the client. |
| 360 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { | 361 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { |
| 361 public: | 362 public: |
| 362 using ReceivedData = RequestPeer::ReceivedData; | 363 using ReceivedData = RequestPeer::ReceivedData; |
| 363 | 364 |
| 364 Context(WebURLLoaderImpl* loader, | 365 Context(WebURLLoaderImpl* loader, |
| 365 ResourceDispatcher* resource_dispatcher, | 366 ResourceDispatcher* resource_dispatcher, |
| 366 mojom::URLLoaderFactory* factory); | 367 mojom::URLLoaderFactory* factory, |
| 368 mojo::AssociatedGroup* associated_group); |
| 367 | 369 |
| 368 WebURLLoaderClient* client() const { return client_; } | 370 WebURLLoaderClient* client() const { return client_; } |
| 369 void set_client(WebURLLoaderClient* client) { client_ = client; } | 371 void set_client(WebURLLoaderClient* client) { client_ = client; } |
| 370 | 372 |
| 371 void Cancel(); | 373 void Cancel(); |
| 372 void SetDefersLoading(bool value); | 374 void SetDefersLoading(bool value); |
| 373 void DidChangePriority(WebURLRequest::Priority new_priority, | 375 void DidChangePriority(WebURLRequest::Priority new_priority, |
| 374 int intra_priority_value); | 376 int intra_priority_value); |
| 375 void Start(const WebURLRequest& request, | 377 void Start(const WebURLRequest& request, |
| 376 SyncLoadResponse* sync_load_response); | 378 SyncLoadResponse* sync_load_response); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 405 WebURLLoaderClient* client_; | 407 WebURLLoaderClient* client_; |
| 406 ResourceDispatcher* resource_dispatcher_; | 408 ResourceDispatcher* resource_dispatcher_; |
| 407 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 409 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 408 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 410 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
| 409 std::unique_ptr<StreamOverrideParameters> stream_override_; | 411 std::unique_ptr<StreamOverrideParameters> stream_override_; |
| 410 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; | 412 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; |
| 411 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; | 413 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; |
| 412 DeferState defers_loading_; | 414 DeferState defers_loading_; |
| 413 int request_id_; | 415 int request_id_; |
| 414 | 416 |
| 417 // These are owned by the Blink::Platform singleton. |
| 415 mojom::URLLoaderFactory* url_loader_factory_; | 418 mojom::URLLoaderFactory* url_loader_factory_; |
| 419 mojo::AssociatedGroup* associated_group_; |
| 416 }; | 420 }; |
| 417 | 421 |
| 418 // A thin wrapper class for Context to ensure its lifetime while it is | 422 // A thin wrapper class for Context to ensure its lifetime while it is |
| 419 // handling IPC messages coming from ResourceDispatcher. Owns one ref to | 423 // handling IPC messages coming from ResourceDispatcher. Owns one ref to |
| 420 // Context and held by ResourceDispatcher. | 424 // Context and held by ResourceDispatcher. |
| 421 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { | 425 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { |
| 422 public: | 426 public: |
| 423 explicit RequestPeerImpl(Context* context); | 427 explicit RequestPeerImpl(Context* context); |
| 424 | 428 |
| 425 // RequestPeer methods: | 429 // RequestPeer methods: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 438 | 442 |
| 439 private: | 443 private: |
| 440 scoped_refptr<Context> context_; | 444 scoped_refptr<Context> context_; |
| 441 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); | 445 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); |
| 442 }; | 446 }; |
| 443 | 447 |
| 444 // WebURLLoaderImpl::Context -------------------------------------------------- | 448 // WebURLLoaderImpl::Context -------------------------------------------------- |
| 445 | 449 |
| 446 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader, | 450 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader, |
| 447 ResourceDispatcher* resource_dispatcher, | 451 ResourceDispatcher* resource_dispatcher, |
| 448 mojom::URLLoaderFactory* url_loader_factory) | 452 mojom::URLLoaderFactory* url_loader_factory, |
| 453 mojo::AssociatedGroup* associated_group) |
| 449 : loader_(loader), | 454 : loader_(loader), |
| 450 client_(NULL), | 455 client_(NULL), |
| 451 resource_dispatcher_(resource_dispatcher), | 456 resource_dispatcher_(resource_dispatcher), |
| 452 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 457 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 453 defers_loading_(NOT_DEFERRING), | 458 defers_loading_(NOT_DEFERRING), |
| 454 request_id_(-1), | 459 request_id_(-1), |
| 455 url_loader_factory_(url_loader_factory) {} | 460 url_loader_factory_(url_loader_factory), |
| 461 associated_group_(associated_group) {} |
| 456 | 462 |
| 457 void WebURLLoaderImpl::Context::Cancel() { | 463 void WebURLLoaderImpl::Context::Cancel() { |
| 458 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, | 464 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, |
| 459 TRACE_EVENT_FLAG_FLOW_IN); | 465 TRACE_EVENT_FLAG_FLOW_IN); |
| 460 if (resource_dispatcher_ && // NULL in unittest. | 466 if (resource_dispatcher_ && // NULL in unittest. |
| 461 request_id_ != -1) { | 467 request_id_ != -1) { |
| 462 resource_dispatcher_->Cancel(request_id_); | 468 resource_dispatcher_->Cancel(request_id_); |
| 463 request_id_ = -1; | 469 request_id_ = -1; |
| 464 } | 470 } |
| 465 | 471 |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 request.getLoadingIPCType(), url_loader_factory_); | 622 request.getLoadingIPCType(), url_loader_factory_); |
| 617 return; | 623 return; |
| 618 } | 624 } |
| 619 | 625 |
| 620 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, | 626 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, |
| 621 TRACE_EVENT_FLAG_FLOW_OUT); | 627 TRACE_EVENT_FLAG_FLOW_OUT); |
| 622 request_id_ = resource_dispatcher_->StartAsync( | 628 request_id_ = resource_dispatcher_->StartAsync( |
| 623 std::move(resource_request), request.requestorID(), task_runner_, | 629 std::move(resource_request), request.requestorID(), task_runner_, |
| 624 extra_data->frame_origin(), | 630 extra_data->frame_origin(), |
| 625 base::MakeUnique<WebURLLoaderImpl::RequestPeerImpl>(this), | 631 base::MakeUnique<WebURLLoaderImpl::RequestPeerImpl>(this), |
| 626 request.getLoadingIPCType(), url_loader_factory_); | 632 request.getLoadingIPCType(), url_loader_factory_, associated_group_); |
| 627 | 633 |
| 628 if (defers_loading_ != NOT_DEFERRING) | 634 if (defers_loading_ != NOT_DEFERRING) |
| 629 resource_dispatcher_->SetDefersLoading(request_id_, true); | 635 resource_dispatcher_->SetDefersLoading(request_id_, true); |
| 630 } | 636 } |
| 631 | 637 |
| 632 void WebURLLoaderImpl::Context::SetTaskRunner( | 638 void WebURLLoaderImpl::Context::SetTaskRunner( |
| 633 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 639 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 634 task_runner_ = task_runner; | 640 task_runner_ = task_runner; |
| 635 } | 641 } |
| 636 | 642 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 const base::TimeTicks& completion_time, | 1007 const base::TimeTicks& completion_time, |
| 1002 int64_t total_transfer_size) { | 1008 int64_t total_transfer_size) { |
| 1003 context_->OnCompletedRequest(error_code, was_ignored_by_handler, | 1009 context_->OnCompletedRequest(error_code, was_ignored_by_handler, |
| 1004 stale_copy_in_cache, completion_time, | 1010 stale_copy_in_cache, completion_time, |
| 1005 total_transfer_size); | 1011 total_transfer_size); |
| 1006 } | 1012 } |
| 1007 | 1013 |
| 1008 // WebURLLoaderImpl ----------------------------------------------------------- | 1014 // WebURLLoaderImpl ----------------------------------------------------------- |
| 1009 | 1015 |
| 1010 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, | 1016 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, |
| 1011 mojom::URLLoaderFactory* url_loader_factory) | 1017 mojom::URLLoaderFactory* url_loader_factory, |
| 1012 : context_(new Context(this, resource_dispatcher, url_loader_factory)) {} | 1018 mojo::AssociatedGroup* associated_group) |
| 1019 : context_(new Context(this, |
| 1020 resource_dispatcher, |
| 1021 url_loader_factory, |
| 1022 associated_group)) {} |
| 1013 | 1023 |
| 1014 WebURLLoaderImpl::~WebURLLoaderImpl() { | 1024 WebURLLoaderImpl::~WebURLLoaderImpl() { |
| 1015 cancel(); | 1025 cancel(); |
| 1016 } | 1026 } |
| 1017 | 1027 |
| 1018 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, | 1028 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, |
| 1019 const ResourceResponseInfo& info, | 1029 const ResourceResponseInfo& info, |
| 1020 WebURLResponse* response, | 1030 WebURLResponse* response, |
| 1021 bool report_security_info) { | 1031 bool report_security_info) { |
| 1022 response->setURL(url); | 1032 response->setURL(url); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 int intra_priority_value) { | 1250 int intra_priority_value) { |
| 1241 context_->DidChangePriority(new_priority, intra_priority_value); | 1251 context_->DidChangePriority(new_priority, intra_priority_value); |
| 1242 } | 1252 } |
| 1243 | 1253 |
| 1244 void WebURLLoaderImpl::setLoadingTaskRunner( | 1254 void WebURLLoaderImpl::setLoadingTaskRunner( |
| 1245 blink::WebTaskRunner* loading_task_runner) { | 1255 blink::WebTaskRunner* loading_task_runner) { |
| 1246 context_->SetTaskRunner(loading_task_runner->toSingleThreadTaskRunner()); | 1256 context_->SetTaskRunner(loading_task_runner->toSingleThreadTaskRunner()); |
| 1247 } | 1257 } |
| 1248 | 1258 |
| 1249 } // namespace content | 1259 } // namespace content |
| OLD | NEW |