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" |
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/sct_status_flags.h" | 47 #include "net/cert/sct_status_flags.h" |
47 #include "net/http/http_response_headers.h" | 48 #include "net/http/http_response_headers.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 | 272 |
272 // This inner class exists since the WebURLLoader may be deleted while inside a | 273 // This inner class exists since the WebURLLoader may be deleted while inside a |
273 // call to WebURLLoaderClient. Refcounting is to keep the context from being | 274 // call to WebURLLoaderClient. Refcounting is to keep the context from being |
274 // deleted if it may have work to do after calling into the client. | 275 // deleted if it may have work to do after calling into the client. |
275 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { | 276 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { |
276 public: | 277 public: |
277 using ReceivedData = RequestPeer::ReceivedData; | 278 using ReceivedData = RequestPeer::ReceivedData; |
278 | 279 |
279 Context(WebURLLoaderImpl* loader, | 280 Context(WebURLLoaderImpl* loader, |
280 ResourceDispatcher* resource_dispatcher, | 281 ResourceDispatcher* resource_dispatcher, |
281 std::unique_ptr<blink::WebTaskRunner> task_runner); | 282 std::unique_ptr<blink::WebTaskRunner> task_runner, |
| 283 mojom::URLLoaderFactory* factory); |
282 | 284 |
283 WebURLLoaderClient* client() const { return client_; } | 285 WebURLLoaderClient* client() const { return client_; } |
284 void set_client(WebURLLoaderClient* client) { client_ = client; } | 286 void set_client(WebURLLoaderClient* client) { client_ = client; } |
285 | 287 |
286 void Cancel(); | 288 void Cancel(); |
287 void SetDefersLoading(bool value); | 289 void SetDefersLoading(bool value); |
288 void DidChangePriority(WebURLRequest::Priority new_priority, | 290 void DidChangePriority(WebURLRequest::Priority new_priority, |
289 int intra_priority_value); | 291 int intra_priority_value); |
290 void Start(const WebURLRequest& request, | 292 void Start(const WebURLRequest& request, |
291 SyncLoadResponse* sync_load_response); | 293 SyncLoadResponse* sync_load_response); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 WebURLLoaderClient* client_; | 335 WebURLLoaderClient* client_; |
334 ResourceDispatcher* resource_dispatcher_; | 336 ResourceDispatcher* resource_dispatcher_; |
335 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; | 337 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; |
336 WebReferrerPolicy referrer_policy_; | 338 WebReferrerPolicy referrer_policy_; |
337 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 339 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
338 std::unique_ptr<StreamOverrideParameters> stream_override_; | 340 std::unique_ptr<StreamOverrideParameters> stream_override_; |
339 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; | 341 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; |
340 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; | 342 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; |
341 DeferState defers_loading_; | 343 DeferState defers_loading_; |
342 int request_id_; | 344 int request_id_; |
| 345 |
| 346 mojom::URLLoaderFactory* url_loader_factory_; |
343 }; | 347 }; |
344 | 348 |
345 // A thin wrapper class for Context to ensure its lifetime while it is | 349 // A thin wrapper class for Context to ensure its lifetime while it is |
346 // handling IPC messages coming from ResourceDispatcher. Owns one ref to | 350 // handling IPC messages coming from ResourceDispatcher. Owns one ref to |
347 // Context and held by ResourceDispatcher. | 351 // Context and held by ResourceDispatcher. |
348 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { | 352 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { |
349 public: | 353 public: |
350 explicit RequestPeerImpl(Context* context); | 354 explicit RequestPeerImpl(Context* context); |
351 | 355 |
352 // RequestPeer methods: | 356 // RequestPeer methods: |
(...skipping 14 matching lines...) Expand all Loading... |
367 private: | 371 private: |
368 scoped_refptr<Context> context_; | 372 scoped_refptr<Context> context_; |
369 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); | 373 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); |
370 }; | 374 }; |
371 | 375 |
372 // WebURLLoaderImpl::Context -------------------------------------------------- | 376 // WebURLLoaderImpl::Context -------------------------------------------------- |
373 | 377 |
374 WebURLLoaderImpl::Context::Context( | 378 WebURLLoaderImpl::Context::Context( |
375 WebURLLoaderImpl* loader, | 379 WebURLLoaderImpl* loader, |
376 ResourceDispatcher* resource_dispatcher, | 380 ResourceDispatcher* resource_dispatcher, |
377 std::unique_ptr<blink::WebTaskRunner> web_task_runner) | 381 std::unique_ptr<blink::WebTaskRunner> web_task_runner, |
| 382 mojom::URLLoaderFactory* url_loader_factory) |
378 : loader_(loader), | 383 : loader_(loader), |
379 client_(NULL), | 384 client_(NULL), |
380 resource_dispatcher_(resource_dispatcher), | 385 resource_dispatcher_(resource_dispatcher), |
381 web_task_runner_(std::move(web_task_runner)), | 386 web_task_runner_(std::move(web_task_runner)), |
382 referrer_policy_(blink::WebReferrerPolicyDefault), | 387 referrer_policy_(blink::WebReferrerPolicyDefault), |
383 defers_loading_(NOT_DEFERRING), | 388 defers_loading_(NOT_DEFERRING), |
384 request_id_(-1) {} | 389 request_id_(-1), |
| 390 url_loader_factory_(url_loader_factory) {} |
385 | 391 |
386 void WebURLLoaderImpl::Context::Cancel() { | 392 void WebURLLoaderImpl::Context::Cancel() { |
387 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, | 393 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, |
388 TRACE_EVENT_FLAG_FLOW_IN); | 394 TRACE_EVENT_FLAG_FLOW_IN); |
389 if (resource_dispatcher_ && // NULL in unittest. | 395 if (resource_dispatcher_ && // NULL in unittest. |
390 request_id_ != -1) { | 396 request_id_ != -1) { |
391 resource_dispatcher_->Cancel(request_id_); | 397 resource_dispatcher_->Cancel(request_id_); |
392 request_id_ = -1; | 398 request_id_ = -1; |
393 } | 399 } |
394 | 400 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
527 // PlzNavigate: during navigation, the renderer should request a stream which | 533 // PlzNavigate: during navigation, the renderer should request a stream which |
528 // contains the body of the response. The network request has already been | 534 // contains the body of the response. The network request has already been |
529 // made by the browser. | 535 // made by the browser. |
530 if (stream_override_.get()) { | 536 if (stream_override_.get()) { |
531 CHECK(IsBrowserSideNavigationEnabled()); | 537 CHECK(IsBrowserSideNavigationEnabled()); |
532 DCHECK(!sync_load_response); | 538 DCHECK(!sync_load_response); |
533 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); | 539 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); |
534 request_info.resource_body_stream_url = stream_override_->stream_url; | 540 request_info.resource_body_stream_url = stream_override_->stream_url; |
535 } | 541 } |
536 | 542 |
| 543 mojom::URLLoaderPtr loader = nullptr; |
| 544 if (request.getLoadingIPCType() == blink::WebURLRequest::LoadingIPCType::Mojo) |
| 545 url_loader_factory_->CreateURLLoader(GetProxy(&loader)); |
| 546 |
537 if (sync_load_response) { | 547 if (sync_load_response) { |
538 DCHECK(defers_loading_ == NOT_DEFERRING); | 548 DCHECK(defers_loading_ == NOT_DEFERRING); |
539 resource_dispatcher_->StartSync( | 549 resource_dispatcher_->StartSync(request_info, request_body.get(), |
540 request_info, request_body.get(), sync_load_response); | 550 sync_load_response, std::move(loader)); |
541 return; | 551 return; |
542 } | 552 } |
543 | 553 |
544 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, | 554 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, |
545 TRACE_EVENT_FLAG_FLOW_OUT); | 555 TRACE_EVENT_FLAG_FLOW_OUT); |
546 request_id_ = resource_dispatcher_->StartAsync( | 556 request_id_ = resource_dispatcher_->StartAsync( |
547 request_info, request_body.get(), | 557 request_info, request_body.get(), |
548 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this))); | 558 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this)), |
| 559 std::move(loader)); |
549 | 560 |
550 if (defers_loading_ != NOT_DEFERRING) | 561 if (defers_loading_ != NOT_DEFERRING) |
551 resource_dispatcher_->SetDefersLoading(request_id_, true); | 562 resource_dispatcher_->SetDefersLoading(request_id_, true); |
552 } | 563 } |
553 | 564 |
554 void WebURLLoaderImpl::Context::SetWebTaskRunner( | 565 void WebURLLoaderImpl::Context::SetWebTaskRunner( |
555 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { | 566 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { |
556 web_task_runner_ = std::move(web_task_runner); | 567 web_task_runner_ = std::move(web_task_runner); |
557 } | 568 } |
558 | 569 |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
908 int64_t total_transfer_size) { | 919 int64_t total_transfer_size) { |
909 context_->OnCompletedRequest(error_code, was_ignored_by_handler, | 920 context_->OnCompletedRequest(error_code, was_ignored_by_handler, |
910 stale_copy_in_cache, security_info, | 921 stale_copy_in_cache, security_info, |
911 completion_time, total_transfer_size); | 922 completion_time, total_transfer_size); |
912 } | 923 } |
913 | 924 |
914 // WebURLLoaderImpl ----------------------------------------------------------- | 925 // WebURLLoaderImpl ----------------------------------------------------------- |
915 | 926 |
916 WebURLLoaderImpl::WebURLLoaderImpl( | 927 WebURLLoaderImpl::WebURLLoaderImpl( |
917 ResourceDispatcher* resource_dispatcher, | 928 ResourceDispatcher* resource_dispatcher, |
918 std::unique_ptr<blink::WebTaskRunner> web_task_runner) | 929 std::unique_ptr<blink::WebTaskRunner> web_task_runner, |
919 : context_( | 930 mojom::URLLoaderFactory* url_loader_factory) |
920 new Context(this, resource_dispatcher, std::move(web_task_runner))) {} | 931 : context_(new Context(this, |
| 932 resource_dispatcher, |
| 933 std::move(web_task_runner), |
| 934 url_loader_factory)) {} |
921 | 935 |
922 WebURLLoaderImpl::~WebURLLoaderImpl() { | 936 WebURLLoaderImpl::~WebURLLoaderImpl() { |
923 cancel(); | 937 cancel(); |
924 } | 938 } |
925 | 939 |
926 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, | 940 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, |
927 const ResourceResponseInfo& info, | 941 const ResourceResponseInfo& info, |
928 WebURLResponse* response, | 942 WebURLResponse* response, |
929 bool report_security_info) { | 943 bool report_security_info) { |
930 response->setURL(url); | 944 response->setURL(url); |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 response->clearHTTPHeaderField(webStringName); | 1210 response->clearHTTPHeaderField(webStringName); |
1197 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1211 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
1198 response->addHTTPHeaderField(webStringName, | 1212 response->addHTTPHeaderField(webStringName, |
1199 WebString::fromLatin1(value)); | 1213 WebString::fromLatin1(value)); |
1200 } | 1214 } |
1201 } | 1215 } |
1202 return true; | 1216 return true; |
1203 } | 1217 } |
1204 | 1218 |
1205 } // namespace content | 1219 } // namespace content |
OLD | NEW |