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.h" | 35 #include "content/common/resource_request_body.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" |
| 39 #include "content/common/url_loader_type_converters.h" |
38 #include "content/public/child/fixed_received_data.h" | 40 #include "content/public/child/fixed_received_data.h" |
39 #include "content/public/child/request_peer.h" | 41 #include "content/public/child/request_peer.h" |
40 #include "content/public/common/browser_side_navigation_policy.h" | 42 #include "content/public/common/browser_side_navigation_policy.h" |
41 #include "content/public/common/signed_certificate_timestamp_id_and_status.h" | 43 #include "content/public/common/signed_certificate_timestamp_id_and_status.h" |
42 #include "content/public/common/ssl_status.h" | 44 #include "content/public/common/ssl_status.h" |
43 #include "net/base/data_url.h" | 45 #include "net/base/data_url.h" |
44 #include "net/base/filename_util.h" | 46 #include "net/base/filename_util.h" |
45 #include "net/base/net_errors.h" | 47 #include "net/base/net_errors.h" |
46 #include "net/cert/cert_status_flags.h" | 48 #include "net/cert/cert_status_flags.h" |
47 #include "net/cert/sct_status_flags.h" | 49 #include "net/cert/sct_status_flags.h" |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 297 |
296 // 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 |
297 // call to WebURLLoaderClient. Refcounting is to keep the context from being | 299 // 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. | 300 // deleted if it may have work to do after calling into the client. |
299 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { | 301 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { |
300 public: | 302 public: |
301 using ReceivedData = RequestPeer::ReceivedData; | 303 using ReceivedData = RequestPeer::ReceivedData; |
302 | 304 |
303 Context(WebURLLoaderImpl* loader, | 305 Context(WebURLLoaderImpl* loader, |
304 ResourceDispatcher* resource_dispatcher, | 306 ResourceDispatcher* resource_dispatcher, |
305 std::unique_ptr<blink::WebTaskRunner> task_runner); | 307 std::unique_ptr<blink::WebTaskRunner> task_runner, |
| 308 mojom::URLLoaderFactory* factory); |
306 | 309 |
307 WebURLLoaderClient* client() const { return client_; } | 310 WebURLLoaderClient* client() const { return client_; } |
308 void set_client(WebURLLoaderClient* client) { client_ = client; } | 311 void set_client(WebURLLoaderClient* client) { client_ = client; } |
309 | 312 |
310 void Cancel(); | 313 void Cancel(); |
311 void SetDefersLoading(bool value); | 314 void SetDefersLoading(bool value); |
312 void DidChangePriority(WebURLRequest::Priority new_priority, | 315 void DidChangePriority(WebURLRequest::Priority new_priority, |
313 int intra_priority_value); | 316 int intra_priority_value); |
314 void Start(const WebURLRequest& request, | 317 void Start(const WebURLRequest& request, |
315 SyncLoadResponse* sync_load_response); | 318 SyncLoadResponse* sync_load_response); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 WebURLLoaderClient* client_; | 360 WebURLLoaderClient* client_; |
358 ResourceDispatcher* resource_dispatcher_; | 361 ResourceDispatcher* resource_dispatcher_; |
359 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; | 362 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; |
360 WebReferrerPolicy referrer_policy_; | 363 WebReferrerPolicy referrer_policy_; |
361 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 364 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
362 std::unique_ptr<StreamOverrideParameters> stream_override_; | 365 std::unique_ptr<StreamOverrideParameters> stream_override_; |
363 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; | 366 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; |
364 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; | 367 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; |
365 DeferState defers_loading_; | 368 DeferState defers_loading_; |
366 int request_id_; | 369 int request_id_; |
| 370 |
| 371 mojom::URLLoaderFactory* url_loader_factory_; |
367 }; | 372 }; |
368 | 373 |
369 // 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 |
370 // handling IPC messages coming from ResourceDispatcher. Owns one ref to | 375 // handling IPC messages coming from ResourceDispatcher. Owns one ref to |
371 // Context and held by ResourceDispatcher. | 376 // Context and held by ResourceDispatcher. |
372 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { | 377 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { |
373 public: | 378 public: |
374 explicit RequestPeerImpl(Context* context); | 379 explicit RequestPeerImpl(Context* context); |
375 | 380 |
376 // RequestPeer methods: | 381 // RequestPeer methods: |
(...skipping 14 matching lines...) Expand all Loading... |
391 private: | 396 private: |
392 scoped_refptr<Context> context_; | 397 scoped_refptr<Context> context_; |
393 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); | 398 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); |
394 }; | 399 }; |
395 | 400 |
396 // WebURLLoaderImpl::Context -------------------------------------------------- | 401 // WebURLLoaderImpl::Context -------------------------------------------------- |
397 | 402 |
398 WebURLLoaderImpl::Context::Context( | 403 WebURLLoaderImpl::Context::Context( |
399 WebURLLoaderImpl* loader, | 404 WebURLLoaderImpl* loader, |
400 ResourceDispatcher* resource_dispatcher, | 405 ResourceDispatcher* resource_dispatcher, |
401 std::unique_ptr<blink::WebTaskRunner> web_task_runner) | 406 std::unique_ptr<blink::WebTaskRunner> web_task_runner, |
| 407 mojom::URLLoaderFactory* url_loader_factory) |
402 : loader_(loader), | 408 : loader_(loader), |
403 client_(NULL), | 409 client_(NULL), |
404 resource_dispatcher_(resource_dispatcher), | 410 resource_dispatcher_(resource_dispatcher), |
405 web_task_runner_(std::move(web_task_runner)), | 411 web_task_runner_(std::move(web_task_runner)), |
406 referrer_policy_(blink::WebReferrerPolicyDefault), | 412 referrer_policy_(blink::WebReferrerPolicyDefault), |
407 defers_loading_(NOT_DEFERRING), | 413 defers_loading_(NOT_DEFERRING), |
408 request_id_(-1) {} | 414 request_id_(-1), |
| 415 url_loader_factory_(url_loader_factory) {} |
409 | 416 |
410 void WebURLLoaderImpl::Context::Cancel() { | 417 void WebURLLoaderImpl::Context::Cancel() { |
411 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, | 418 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, |
412 TRACE_EVENT_FLAG_FLOW_IN); | 419 TRACE_EVENT_FLAG_FLOW_IN); |
413 if (resource_dispatcher_ && // NULL in unittest. | 420 if (resource_dispatcher_ && // NULL in unittest. |
414 request_id_ != -1) { | 421 request_id_ != -1) { |
415 resource_dispatcher_->Cancel(request_id_); | 422 resource_dispatcher_->Cancel(request_id_); |
416 request_id_ = -1; | 423 request_id_ = -1; |
417 } | 424 } |
418 | 425 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 // PlzNavigate: during navigation, the renderer should request a stream which | 558 // PlzNavigate: during navigation, the renderer should request a stream which |
552 // contains the body of the response. The network request has already been | 559 // contains the body of the response. The network request has already been |
553 // made by the browser. | 560 // made by the browser. |
554 if (stream_override_.get()) { | 561 if (stream_override_.get()) { |
555 CHECK(IsBrowserSideNavigationEnabled()); | 562 CHECK(IsBrowserSideNavigationEnabled()); |
556 DCHECK(!sync_load_response); | 563 DCHECK(!sync_load_response); |
557 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); | 564 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); |
558 request_info.resource_body_stream_url = stream_override_->stream_url; | 565 request_info.resource_body_stream_url = stream_override_->stream_url; |
559 } | 566 } |
560 | 567 |
| 568 mojom::URLLoaderPtr loader = nullptr; |
| 569 if (request.loadingIPC() == blink::WebURLRequest::LoadingIPC::Mojo) { |
| 570 url_loader_factory_->CreateURLLoader(GetProxy(&loader)); |
| 571 } |
| 572 |
561 if (sync_load_response) { | 573 if (sync_load_response) { |
562 DCHECK(defers_loading_ == NOT_DEFERRING); | 574 DCHECK(defers_loading_ == NOT_DEFERRING); |
563 resource_dispatcher_->StartSync( | 575 resource_dispatcher_->StartSync(request_info, request_body.get(), |
564 request_info, request_body.get(), sync_load_response); | 576 sync_load_response, std::move(loader)); |
565 return; | 577 return; |
566 } | 578 } |
567 | 579 |
568 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, | 580 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, |
569 TRACE_EVENT_FLAG_FLOW_OUT); | 581 TRACE_EVENT_FLAG_FLOW_OUT); |
570 request_id_ = resource_dispatcher_->StartAsync( | 582 request_id_ = resource_dispatcher_->StartAsync( |
571 request_info, request_body.get(), | 583 request_info, request_body.get(), |
572 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this))); | 584 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this)), |
| 585 std::move(loader)); |
573 | 586 |
574 if (defers_loading_ != NOT_DEFERRING) | 587 if (defers_loading_ != NOT_DEFERRING) |
575 resource_dispatcher_->SetDefersLoading(request_id_, true); | 588 resource_dispatcher_->SetDefersLoading(request_id_, true); |
576 } | 589 } |
577 | 590 |
578 void WebURLLoaderImpl::Context::SetWebTaskRunner( | 591 void WebURLLoaderImpl::Context::SetWebTaskRunner( |
579 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { | 592 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { |
580 web_task_runner_ = std::move(web_task_runner); | 593 web_task_runner_ = std::move(web_task_runner); |
581 } | 594 } |
582 | 595 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 int64_t total_transfer_size) { | 945 int64_t total_transfer_size) { |
933 context_->OnCompletedRequest(error_code, was_ignored_by_handler, | 946 context_->OnCompletedRequest(error_code, was_ignored_by_handler, |
934 stale_copy_in_cache, security_info, | 947 stale_copy_in_cache, security_info, |
935 completion_time, total_transfer_size); | 948 completion_time, total_transfer_size); |
936 } | 949 } |
937 | 950 |
938 // WebURLLoaderImpl ----------------------------------------------------------- | 951 // WebURLLoaderImpl ----------------------------------------------------------- |
939 | 952 |
940 WebURLLoaderImpl::WebURLLoaderImpl( | 953 WebURLLoaderImpl::WebURLLoaderImpl( |
941 ResourceDispatcher* resource_dispatcher, | 954 ResourceDispatcher* resource_dispatcher, |
942 std::unique_ptr<blink::WebTaskRunner> web_task_runner) | 955 std::unique_ptr<blink::WebTaskRunner> web_task_runner, |
943 : context_( | 956 mojom::URLLoaderFactory* url_loader_factory) |
944 new Context(this, resource_dispatcher, std::move(web_task_runner))) {} | 957 : context_(new Context(this, |
| 958 resource_dispatcher, |
| 959 std::move(web_task_runner), |
| 960 url_loader_factory)) {} |
945 | 961 |
946 WebURLLoaderImpl::~WebURLLoaderImpl() { | 962 WebURLLoaderImpl::~WebURLLoaderImpl() { |
947 cancel(); | 963 cancel(); |
948 } | 964 } |
949 | 965 |
950 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, | 966 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, |
951 const ResourceResponseInfo& info, | 967 const ResourceResponseInfo& info, |
952 WebURLResponse* response, | 968 WebURLResponse* response, |
953 bool report_security_info) { | 969 bool report_security_info) { |
954 response->setURL(url); | 970 response->setURL(url); |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1213 response->clearHTTPHeaderField(webStringName); | 1229 response->clearHTTPHeaderField(webStringName); |
1214 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1230 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
1215 response->addHTTPHeaderField(webStringName, | 1231 response->addHTTPHeaderField(webStringName, |
1216 WebString::fromLatin1(value)); | 1232 WebString::fromLatin1(value)); |
1217 } | 1233 } |
1218 } | 1234 } |
1219 return true; | 1235 return true; |
1220 } | 1236 } |
1221 | 1237 |
1222 } // namespace content | 1238 } // namespace content |
OLD | NEW |