| 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 17 matching lines...) Expand all Loading... |
| 28 #include "content/child/request_info.h" | 28 #include "content/child/request_info.h" |
| 29 #include "content/child/resource_dispatcher.h" | 29 #include "content/child/resource_dispatcher.h" |
| 30 #include "content/child/shared_memory_data_consumer_handle.h" | 30 #include "content/child/shared_memory_data_consumer_handle.h" |
| 31 #include "content/child/sync_load_response.h" | 31 #include "content/child/sync_load_response.h" |
| 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_body_impl.h" | 35 #include "content/common/resource_request_body_impl.h" |
| 36 #include "content/common/service_worker/service_worker_types.h" | 36 #include "content/common/service_worker/service_worker_types.h" |
| 37 #include "content/common/ssl_status_serialization.h" | 37 #include "content/common/ssl_status_serialization.h" |
| 38 #include "content/common/url_loader.mojom.h" |
| 38 #include "content/public/child/fixed_received_data.h" | 39 #include "content/public/child/fixed_received_data.h" |
| 39 #include "content/public/child/request_peer.h" | 40 #include "content/public/child/request_peer.h" |
| 40 #include "content/public/common/browser_side_navigation_policy.h" | 41 #include "content/public/common/browser_side_navigation_policy.h" |
| 41 #include "content/public/common/ssl_status.h" | 42 #include "content/public/common/ssl_status.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/http/http_response_headers.h" | 48 #include "net/http/http_response_headers.h" |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 294 |
| 294 } // namespace | 295 } // namespace |
| 295 | 296 |
| 296 // This inner class exists since the WebURLLoader may be deleted while inside a | 297 // This inner class exists since the WebURLLoader may be deleted while inside a |
| 297 // call to WebURLLoaderClient. Refcounting is to keep the context from being | 298 // call to WebURLLoaderClient. Refcounting is to keep the context from being |
| 298 // deleted if it may have work to do after calling into the client. | 299 // deleted if it may have work to do after calling into the client. |
| 299 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { | 300 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { |
| 300 public: | 301 public: |
| 301 using ReceivedData = RequestPeer::ReceivedData; | 302 using ReceivedData = RequestPeer::ReceivedData; |
| 302 | 303 |
| 303 Context(WebURLLoaderImpl* loader, ResourceDispatcher* resource_dispatcher); | 304 Context(WebURLLoaderImpl* loader, |
| 305 ResourceDispatcher* resource_dispatcher, |
| 306 mojom::URLLoaderFactory* factory); |
| 304 | 307 |
| 305 WebURLLoaderClient* client() const { return client_; } | 308 WebURLLoaderClient* client() const { return client_; } |
| 306 void set_client(WebURLLoaderClient* client) { client_ = client; } | 309 void set_client(WebURLLoaderClient* client) { client_ = client; } |
| 307 | 310 |
| 308 void Cancel(); | 311 void Cancel(); |
| 309 void SetDefersLoading(bool value); | 312 void SetDefersLoading(bool value); |
| 310 void DidChangePriority(WebURLRequest::Priority new_priority, | 313 void DidChangePriority(WebURLRequest::Priority new_priority, |
| 311 int intra_priority_value); | 314 int intra_priority_value); |
| 312 void Start(const WebURLRequest& request, | 315 void Start(const WebURLRequest& request, |
| 313 SyncLoadResponse* sync_load_response); | 316 SyncLoadResponse* sync_load_response); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 343 WebURLLoaderClient* client_; | 346 WebURLLoaderClient* client_; |
| 344 ResourceDispatcher* resource_dispatcher_; | 347 ResourceDispatcher* resource_dispatcher_; |
| 345 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 348 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 346 WebReferrerPolicy referrer_policy_; | 349 WebReferrerPolicy referrer_policy_; |
| 347 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 350 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
| 348 std::unique_ptr<StreamOverrideParameters> stream_override_; | 351 std::unique_ptr<StreamOverrideParameters> stream_override_; |
| 349 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; | 352 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; |
| 350 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; | 353 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; |
| 351 DeferState defers_loading_; | 354 DeferState defers_loading_; |
| 352 int request_id_; | 355 int request_id_; |
| 356 |
| 357 mojom::URLLoaderFactory* url_loader_factory_; |
| 353 }; | 358 }; |
| 354 | 359 |
| 355 // A thin wrapper class for Context to ensure its lifetime while it is | 360 // A thin wrapper class for Context to ensure its lifetime while it is |
| 356 // handling IPC messages coming from ResourceDispatcher. Owns one ref to | 361 // handling IPC messages coming from ResourceDispatcher. Owns one ref to |
| 357 // Context and held by ResourceDispatcher. | 362 // Context and held by ResourceDispatcher. |
| 358 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { | 363 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { |
| 359 public: | 364 public: |
| 360 explicit RequestPeerImpl(Context* context); | 365 explicit RequestPeerImpl(Context* context); |
| 361 | 366 |
| 362 // RequestPeer methods: | 367 // RequestPeer methods: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 375 int64_t total_transfer_size) override; | 380 int64_t total_transfer_size) override; |
| 376 | 381 |
| 377 private: | 382 private: |
| 378 scoped_refptr<Context> context_; | 383 scoped_refptr<Context> context_; |
| 379 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); | 384 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); |
| 380 }; | 385 }; |
| 381 | 386 |
| 382 // WebURLLoaderImpl::Context -------------------------------------------------- | 387 // WebURLLoaderImpl::Context -------------------------------------------------- |
| 383 | 388 |
| 384 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader, | 389 WebURLLoaderImpl::Context::Context(WebURLLoaderImpl* loader, |
| 385 ResourceDispatcher* resource_dispatcher) | 390 ResourceDispatcher* resource_dispatcher, |
| 391 mojom::URLLoaderFactory* url_loader_factory) |
| 386 : loader_(loader), | 392 : loader_(loader), |
| 387 client_(NULL), | 393 client_(NULL), |
| 388 resource_dispatcher_(resource_dispatcher), | 394 resource_dispatcher_(resource_dispatcher), |
| 389 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 395 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 390 referrer_policy_(blink::WebReferrerPolicyDefault), | 396 referrer_policy_(blink::WebReferrerPolicyDefault), |
| 391 defers_loading_(NOT_DEFERRING), | 397 defers_loading_(NOT_DEFERRING), |
| 392 request_id_(-1) {} | 398 request_id_(-1), |
| 399 url_loader_factory_(url_loader_factory) {} |
| 393 | 400 |
| 394 void WebURLLoaderImpl::Context::Cancel() { | 401 void WebURLLoaderImpl::Context::Cancel() { |
| 395 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, | 402 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, |
| 396 TRACE_EVENT_FLAG_FLOW_IN); | 403 TRACE_EVENT_FLAG_FLOW_IN); |
| 397 if (resource_dispatcher_ && // NULL in unittest. | 404 if (resource_dispatcher_ && // NULL in unittest. |
| 398 request_id_ != -1) { | 405 request_id_ != -1) { |
| 399 resource_dispatcher_->Cancel(request_id_); | 406 resource_dispatcher_->Cancel(request_id_); |
| 400 request_id_ = -1; | 407 request_id_ = -1; |
| 401 } | 408 } |
| 402 | 409 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 if (stream_override_.get()) { | 542 if (stream_override_.get()) { |
| 536 CHECK(IsBrowserSideNavigationEnabled()); | 543 CHECK(IsBrowserSideNavigationEnabled()); |
| 537 DCHECK(!sync_load_response); | 544 DCHECK(!sync_load_response); |
| 538 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); | 545 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); |
| 539 request_info.resource_body_stream_url = stream_override_->stream_url; | 546 request_info.resource_body_stream_url = stream_override_->stream_url; |
| 540 } | 547 } |
| 541 | 548 |
| 542 if (sync_load_response) { | 549 if (sync_load_response) { |
| 543 DCHECK(defers_loading_ == NOT_DEFERRING); | 550 DCHECK(defers_loading_ == NOT_DEFERRING); |
| 544 resource_dispatcher_->StartSync( | 551 resource_dispatcher_->StartSync( |
| 545 request_info, request_body.get(), sync_load_response); | 552 request_info, request_body.get(), sync_load_response, |
| 553 request.getLoadingIPCType(), url_loader_factory_); |
| 546 return; | 554 return; |
| 547 } | 555 } |
| 548 | 556 |
| 549 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, | 557 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, |
| 550 TRACE_EVENT_FLAG_FLOW_OUT); | 558 TRACE_EVENT_FLAG_FLOW_OUT); |
| 551 request_id_ = resource_dispatcher_->StartAsync( | 559 request_id_ = resource_dispatcher_->StartAsync( |
| 552 request_info, request_body.get(), | 560 request_info, request_body.get(), |
| 553 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this))); | 561 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this)), |
| 562 request.getLoadingIPCType(), url_loader_factory_); |
| 554 | 563 |
| 555 if (defers_loading_ != NOT_DEFERRING) | 564 if (defers_loading_ != NOT_DEFERRING) |
| 556 resource_dispatcher_->SetDefersLoading(request_id_, true); | 565 resource_dispatcher_->SetDefersLoading(request_id_, true); |
| 557 } | 566 } |
| 558 | 567 |
| 559 void WebURLLoaderImpl::Context::SetTaskRunner( | 568 void WebURLLoaderImpl::Context::SetTaskRunner( |
| 560 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { | 569 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner) { |
| 561 task_runner_ = task_runner; | 570 task_runner_ = task_runner; |
| 562 } | 571 } |
| 563 | 572 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 const std::string& security_info, | 923 const std::string& security_info, |
| 915 const base::TimeTicks& completion_time, | 924 const base::TimeTicks& completion_time, |
| 916 int64_t total_transfer_size) { | 925 int64_t total_transfer_size) { |
| 917 context_->OnCompletedRequest(error_code, was_ignored_by_handler, | 926 context_->OnCompletedRequest(error_code, was_ignored_by_handler, |
| 918 stale_copy_in_cache, security_info, | 927 stale_copy_in_cache, security_info, |
| 919 completion_time, total_transfer_size); | 928 completion_time, total_transfer_size); |
| 920 } | 929 } |
| 921 | 930 |
| 922 // WebURLLoaderImpl ----------------------------------------------------------- | 931 // WebURLLoaderImpl ----------------------------------------------------------- |
| 923 | 932 |
| 924 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher) | 933 WebURLLoaderImpl::WebURLLoaderImpl(ResourceDispatcher* resource_dispatcher, |
| 925 : context_(new Context(this, resource_dispatcher)) {} | 934 mojom::URLLoaderFactory* url_loader_factory) |
| 935 : context_(new Context(this, resource_dispatcher, url_loader_factory)) {} |
| 926 | 936 |
| 927 WebURLLoaderImpl::~WebURLLoaderImpl() { | 937 WebURLLoaderImpl::~WebURLLoaderImpl() { |
| 928 cancel(); | 938 cancel(); |
| 929 } | 939 } |
| 930 | 940 |
| 931 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, | 941 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, |
| 932 const ResourceResponseInfo& info, | 942 const ResourceResponseInfo& info, |
| 933 WebURLResponse* response, | 943 WebURLResponse* response, |
| 934 bool report_security_info) { | 944 bool report_security_info) { |
| 935 response->setURL(url); | 945 response->setURL(url); |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1202 response->clearHTTPHeaderField(webStringName); | 1212 response->clearHTTPHeaderField(webStringName); |
| 1203 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1213 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
| 1204 response->addHTTPHeaderField(webStringName, | 1214 response->addHTTPHeaderField(webStringName, |
| 1205 WebString::fromLatin1(value)); | 1215 WebString::fromLatin1(value)); |
| 1206 } | 1216 } |
| 1207 } | 1217 } |
| 1208 return true; | 1218 return true; |
| 1209 } | 1219 } |
| 1210 | 1220 |
| 1211 } // namespace content | 1221 } // namespace content |
| OLD | NEW |