| 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 18 matching lines...) Expand all Loading... |
| 29 #include "content/child/request_info.h" | 29 #include "content/child/request_info.h" |
| 30 #include "content/child/resource_dispatcher.h" | 30 #include "content/child/resource_dispatcher.h" |
| 31 #include "content/child/shared_memory_data_consumer_handle.h" | 31 #include "content/child/shared_memory_data_consumer_handle.h" |
| 32 #include "content/child/sync_load_response.h" | 32 #include "content/child/sync_load_response.h" |
| 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_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/ssl_status_serialization.h" | 38 #include "content/common/ssl_status_serialization.h" |
| 39 #include "content/common/url_loader.mojom.h" |
| 39 #include "content/public/child/fixed_received_data.h" | 40 #include "content/public/child/fixed_received_data.h" |
| 40 #include "content/public/child/request_peer.h" | 41 #include "content/public/child/request_peer.h" |
| 41 #include "content/public/common/browser_side_navigation_policy.h" | 42 #include "content/public/common/browser_side_navigation_policy.h" |
| 42 #include "content/public/common/ssl_status.h" | 43 #include "content/public/common/ssl_status.h" |
| 43 #include "net/base/data_url.h" | 44 #include "net/base/data_url.h" |
| 44 #include "net/base/filename_util.h" | 45 #include "net/base/filename_util.h" |
| 45 #include "net/base/net_errors.h" | 46 #include "net/base/net_errors.h" |
| 46 #include "net/cert/cert_status_flags.h" | 47 #include "net/cert/cert_status_flags.h" |
| 47 #include "net/cert/ct_sct_to_string.h" | 48 #include "net/cert/ct_sct_to_string.h" |
| 48 #include "net/http/http_response_headers.h" | 49 #include "net/http/http_response_headers.h" |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 | 297 |
| 297 // This inner class exists since the WebURLLoader may be deleted while inside a | 298 // This inner class exists since the WebURLLoader may be deleted while inside a |
| 298 // call to WebURLLoaderClient. Refcounting is to keep the context from being | 299 // call to WebURLLoaderClient. Refcounting is to keep the context from being |
| 299 // deleted if it may have work to do after calling into the client. | 300 // deleted if it may have work to do after calling into the client. |
| 300 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { | 301 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { |
| 301 public: | 302 public: |
| 302 using ReceivedData = RequestPeer::ReceivedData; | 303 using ReceivedData = RequestPeer::ReceivedData; |
| 303 | 304 |
| 304 Context(WebURLLoaderImpl* loader, | 305 Context(WebURLLoaderImpl* loader, |
| 305 ResourceDispatcher* resource_dispatcher, | 306 ResourceDispatcher* resource_dispatcher, |
| 306 std::unique_ptr<blink::WebTaskRunner> task_runner); | 307 std::unique_ptr<blink::WebTaskRunner> task_runner, |
| 308 mojom::URLLoaderFactory* factory); |
| 307 | 309 |
| 308 WebURLLoaderClient* client() const { return client_; } | 310 WebURLLoaderClient* client() const { return client_; } |
| 309 void set_client(WebURLLoaderClient* client) { client_ = client; } | 311 void set_client(WebURLLoaderClient* client) { client_ = client; } |
| 310 | 312 |
| 311 void Cancel(); | 313 void Cancel(); |
| 312 void SetDefersLoading(bool value); | 314 void SetDefersLoading(bool value); |
| 313 void DidChangePriority(WebURLRequest::Priority new_priority, | 315 void DidChangePriority(WebURLRequest::Priority new_priority, |
| 314 int intra_priority_value); | 316 int intra_priority_value); |
| 315 void Start(const WebURLRequest& request, | 317 void Start(const WebURLRequest& request, |
| 316 SyncLoadResponse* sync_load_response); | 318 SyncLoadResponse* sync_load_response); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 WebURLLoaderClient* client_; | 360 WebURLLoaderClient* client_; |
| 359 ResourceDispatcher* resource_dispatcher_; | 361 ResourceDispatcher* resource_dispatcher_; |
| 360 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; | 362 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; |
| 361 WebReferrerPolicy referrer_policy_; | 363 WebReferrerPolicy referrer_policy_; |
| 362 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 364 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
| 363 std::unique_ptr<StreamOverrideParameters> stream_override_; | 365 std::unique_ptr<StreamOverrideParameters> stream_override_; |
| 364 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; | 366 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; |
| 365 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; | 367 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; |
| 366 DeferState defers_loading_; | 368 DeferState defers_loading_; |
| 367 int request_id_; | 369 int request_id_; |
| 370 |
| 371 mojom::URLLoaderFactory* url_loader_factory_; |
| 368 }; | 372 }; |
| 369 | 373 |
| 370 // A thin wrapper class for Context to ensure its lifetime while it is | 374 // A thin wrapper class for Context to ensure its lifetime while it is |
| 371 // handling IPC messages coming from ResourceDispatcher. Owns one ref to | 375 // handling IPC messages coming from ResourceDispatcher. Owns one ref to |
| 372 // Context and held by ResourceDispatcher. | 376 // Context and held by ResourceDispatcher. |
| 373 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { | 377 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { |
| 374 public: | 378 public: |
| 375 explicit RequestPeerImpl(Context* context); | 379 explicit RequestPeerImpl(Context* context); |
| 376 | 380 |
| 377 // RequestPeer methods: | 381 // RequestPeer methods: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 392 private: | 396 private: |
| 393 scoped_refptr<Context> context_; | 397 scoped_refptr<Context> context_; |
| 394 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); | 398 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); |
| 395 }; | 399 }; |
| 396 | 400 |
| 397 // WebURLLoaderImpl::Context -------------------------------------------------- | 401 // WebURLLoaderImpl::Context -------------------------------------------------- |
| 398 | 402 |
| 399 WebURLLoaderImpl::Context::Context( | 403 WebURLLoaderImpl::Context::Context( |
| 400 WebURLLoaderImpl* loader, | 404 WebURLLoaderImpl* loader, |
| 401 ResourceDispatcher* resource_dispatcher, | 405 ResourceDispatcher* resource_dispatcher, |
| 402 std::unique_ptr<blink::WebTaskRunner> web_task_runner) | 406 std::unique_ptr<blink::WebTaskRunner> web_task_runner, |
| 407 mojom::URLLoaderFactory* url_loader_factory) |
| 403 : loader_(loader), | 408 : loader_(loader), |
| 404 client_(NULL), | 409 client_(NULL), |
| 405 resource_dispatcher_(resource_dispatcher), | 410 resource_dispatcher_(resource_dispatcher), |
| 406 web_task_runner_(std::move(web_task_runner)), | 411 web_task_runner_(std::move(web_task_runner)), |
| 407 referrer_policy_(blink::WebReferrerPolicyDefault), | 412 referrer_policy_(blink::WebReferrerPolicyDefault), |
| 408 defers_loading_(NOT_DEFERRING), | 413 defers_loading_(NOT_DEFERRING), |
| 409 request_id_(-1) {} | 414 request_id_(-1), |
| 415 url_loader_factory_(url_loader_factory) {} |
| 410 | 416 |
| 411 void WebURLLoaderImpl::Context::Cancel() { | 417 void WebURLLoaderImpl::Context::Cancel() { |
| 412 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, | 418 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, |
| 413 TRACE_EVENT_FLAG_FLOW_IN); | 419 TRACE_EVENT_FLAG_FLOW_IN); |
| 414 if (resource_dispatcher_ && // NULL in unittest. | 420 if (resource_dispatcher_ && // NULL in unittest. |
| 415 request_id_ != -1) { | 421 request_id_ != -1) { |
| 416 resource_dispatcher_->Cancel(request_id_); | 422 resource_dispatcher_->Cancel(request_id_); |
| 417 request_id_ = -1; | 423 request_id_ = -1; |
| 418 } | 424 } |
| 419 | 425 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 if (stream_override_.get()) { | 564 if (stream_override_.get()) { |
| 559 CHECK(IsBrowserSideNavigationEnabled()); | 565 CHECK(IsBrowserSideNavigationEnabled()); |
| 560 DCHECK(!sync_load_response); | 566 DCHECK(!sync_load_response); |
| 561 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); | 567 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); |
| 562 request_info.resource_body_stream_url = stream_override_->stream_url; | 568 request_info.resource_body_stream_url = stream_override_->stream_url; |
| 563 } | 569 } |
| 564 | 570 |
| 565 if (sync_load_response) { | 571 if (sync_load_response) { |
| 566 DCHECK(defers_loading_ == NOT_DEFERRING); | 572 DCHECK(defers_loading_ == NOT_DEFERRING); |
| 567 resource_dispatcher_->StartSync( | 573 resource_dispatcher_->StartSync( |
| 568 request_info, request_body.get(), sync_load_response); | 574 request_info, request_body.get(), sync_load_response, |
| 575 request.getLoadingIPCType(), url_loader_factory_); |
| 569 return; | 576 return; |
| 570 } | 577 } |
| 571 | 578 |
| 572 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, | 579 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, |
| 573 TRACE_EVENT_FLAG_FLOW_OUT); | 580 TRACE_EVENT_FLAG_FLOW_OUT); |
| 574 request_id_ = resource_dispatcher_->StartAsync( | 581 request_id_ = resource_dispatcher_->StartAsync( |
| 575 request_info, request_body.get(), | 582 request_info, request_body.get(), |
| 576 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this))); | 583 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this)), |
| 584 request.getLoadingIPCType(), url_loader_factory_); |
| 577 | 585 |
| 578 if (defers_loading_ != NOT_DEFERRING) | 586 if (defers_loading_ != NOT_DEFERRING) |
| 579 resource_dispatcher_->SetDefersLoading(request_id_, true); | 587 resource_dispatcher_->SetDefersLoading(request_id_, true); |
| 580 } | 588 } |
| 581 | 589 |
| 582 void WebURLLoaderImpl::Context::SetWebTaskRunner( | 590 void WebURLLoaderImpl::Context::SetWebTaskRunner( |
| 583 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { | 591 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { |
| 584 web_task_runner_ = std::move(web_task_runner); | 592 web_task_runner_ = std::move(web_task_runner); |
| 585 } | 593 } |
| 586 | 594 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 939 int64_t total_transfer_size) { | 947 int64_t total_transfer_size) { |
| 940 context_->OnCompletedRequest(error_code, was_ignored_by_handler, | 948 context_->OnCompletedRequest(error_code, was_ignored_by_handler, |
| 941 stale_copy_in_cache, security_info, | 949 stale_copy_in_cache, security_info, |
| 942 completion_time, total_transfer_size); | 950 completion_time, total_transfer_size); |
| 943 } | 951 } |
| 944 | 952 |
| 945 // WebURLLoaderImpl ----------------------------------------------------------- | 953 // WebURLLoaderImpl ----------------------------------------------------------- |
| 946 | 954 |
| 947 WebURLLoaderImpl::WebURLLoaderImpl( | 955 WebURLLoaderImpl::WebURLLoaderImpl( |
| 948 ResourceDispatcher* resource_dispatcher, | 956 ResourceDispatcher* resource_dispatcher, |
| 949 std::unique_ptr<blink::WebTaskRunner> web_task_runner) | 957 std::unique_ptr<blink::WebTaskRunner> web_task_runner, |
| 950 : context_( | 958 mojom::URLLoaderFactory* url_loader_factory) |
| 951 new Context(this, resource_dispatcher, std::move(web_task_runner))) {} | 959 : context_(new Context(this, |
| 960 resource_dispatcher, |
| 961 std::move(web_task_runner), |
| 962 url_loader_factory)) {} |
| 952 | 963 |
| 953 WebURLLoaderImpl::~WebURLLoaderImpl() { | 964 WebURLLoaderImpl::~WebURLLoaderImpl() { |
| 954 cancel(); | 965 cancel(); |
| 955 } | 966 } |
| 956 | 967 |
| 957 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, | 968 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, |
| 958 const ResourceResponseInfo& info, | 969 const ResourceResponseInfo& info, |
| 959 WebURLResponse* response, | 970 WebURLResponse* response, |
| 960 bool report_security_info) { | 971 bool report_security_info) { |
| 961 response->setURL(url); | 972 response->setURL(url); |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1230 response->clearHTTPHeaderField(webStringName); | 1241 response->clearHTTPHeaderField(webStringName); |
| 1231 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1242 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
| 1232 response->addHTTPHeaderField(webStringName, | 1243 response->addHTTPHeaderField(webStringName, |
| 1233 WebString::fromLatin1(value)); | 1244 WebString::fromLatin1(value)); |
| 1234 } | 1245 } |
| 1235 } | 1246 } |
| 1236 return true; | 1247 return true; |
| 1237 } | 1248 } |
| 1238 | 1249 |
| 1239 } // namespace content | 1250 } // namespace content |
| OLD | NEW |