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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 | 300 |
300 // This inner class exists since the WebURLLoader may be deleted while inside a | 301 // This inner class exists since the WebURLLoader may be deleted while inside a |
301 // call to WebURLLoaderClient. Refcounting is to keep the context from being | 302 // call to WebURLLoaderClient. Refcounting is to keep the context from being |
302 // deleted if it may have work to do after calling into the client. | 303 // deleted if it may have work to do after calling into the client. |
303 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { | 304 class WebURLLoaderImpl::Context : public base::RefCounted<Context> { |
304 public: | 305 public: |
305 using ReceivedData = RequestPeer::ReceivedData; | 306 using ReceivedData = RequestPeer::ReceivedData; |
306 | 307 |
307 Context(WebURLLoaderImpl* loader, | 308 Context(WebURLLoaderImpl* loader, |
308 ResourceDispatcher* resource_dispatcher, | 309 ResourceDispatcher* resource_dispatcher, |
309 std::unique_ptr<blink::WebTaskRunner> task_runner); | 310 std::unique_ptr<blink::WebTaskRunner> task_runner, |
| 311 mojom::URLLoaderFactory* factory); |
310 | 312 |
311 WebURLLoaderClient* client() const { return client_; } | 313 WebURLLoaderClient* client() const { return client_; } |
312 void set_client(WebURLLoaderClient* client) { client_ = client; } | 314 void set_client(WebURLLoaderClient* client) { client_ = client; } |
313 | 315 |
314 void Cancel(); | 316 void Cancel(); |
315 void SetDefersLoading(bool value); | 317 void SetDefersLoading(bool value); |
316 void DidChangePriority(WebURLRequest::Priority new_priority, | 318 void DidChangePriority(WebURLRequest::Priority new_priority, |
317 int intra_priority_value); | 319 int intra_priority_value); |
318 void Start(const WebURLRequest& request, | 320 void Start(const WebURLRequest& request, |
319 SyncLoadResponse* sync_load_response); | 321 SyncLoadResponse* sync_load_response); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 WebURLLoaderClient* client_; | 363 WebURLLoaderClient* client_; |
362 ResourceDispatcher* resource_dispatcher_; | 364 ResourceDispatcher* resource_dispatcher_; |
363 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; | 365 std::unique_ptr<blink::WebTaskRunner> web_task_runner_; |
364 WebReferrerPolicy referrer_policy_; | 366 WebReferrerPolicy referrer_policy_; |
365 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; | 367 std::unique_ptr<FtpDirectoryListingResponseDelegate> ftp_listing_delegate_; |
366 std::unique_ptr<StreamOverrideParameters> stream_override_; | 368 std::unique_ptr<StreamOverrideParameters> stream_override_; |
367 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; | 369 std::unique_ptr<SharedMemoryDataConsumerHandle::Writer> body_stream_writer_; |
368 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; | 370 enum DeferState {NOT_DEFERRING, SHOULD_DEFER, DEFERRED_DATA}; |
369 DeferState defers_loading_; | 371 DeferState defers_loading_; |
370 int request_id_; | 372 int request_id_; |
| 373 |
| 374 mojom::URLLoaderFactory* url_loader_factory_; |
371 }; | 375 }; |
372 | 376 |
373 // A thin wrapper class for Context to ensure its lifetime while it is | 377 // A thin wrapper class for Context to ensure its lifetime while it is |
374 // handling IPC messages coming from ResourceDispatcher. Owns one ref to | 378 // handling IPC messages coming from ResourceDispatcher. Owns one ref to |
375 // Context and held by ResourceDispatcher. | 379 // Context and held by ResourceDispatcher. |
376 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { | 380 class WebURLLoaderImpl::RequestPeerImpl : public RequestPeer { |
377 public: | 381 public: |
378 explicit RequestPeerImpl(Context* context); | 382 explicit RequestPeerImpl(Context* context); |
379 | 383 |
380 // RequestPeer methods: | 384 // RequestPeer methods: |
(...skipping 14 matching lines...) Expand all Loading... |
395 private: | 399 private: |
396 scoped_refptr<Context> context_; | 400 scoped_refptr<Context> context_; |
397 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); | 401 DISALLOW_COPY_AND_ASSIGN(RequestPeerImpl); |
398 }; | 402 }; |
399 | 403 |
400 // WebURLLoaderImpl::Context -------------------------------------------------- | 404 // WebURLLoaderImpl::Context -------------------------------------------------- |
401 | 405 |
402 WebURLLoaderImpl::Context::Context( | 406 WebURLLoaderImpl::Context::Context( |
403 WebURLLoaderImpl* loader, | 407 WebURLLoaderImpl* loader, |
404 ResourceDispatcher* resource_dispatcher, | 408 ResourceDispatcher* resource_dispatcher, |
405 std::unique_ptr<blink::WebTaskRunner> web_task_runner) | 409 std::unique_ptr<blink::WebTaskRunner> web_task_runner, |
| 410 mojom::URLLoaderFactory* url_loader_factory) |
406 : loader_(loader), | 411 : loader_(loader), |
407 client_(NULL), | 412 client_(NULL), |
408 resource_dispatcher_(resource_dispatcher), | 413 resource_dispatcher_(resource_dispatcher), |
409 web_task_runner_(std::move(web_task_runner)), | 414 web_task_runner_(std::move(web_task_runner)), |
410 referrer_policy_(blink::WebReferrerPolicyDefault), | 415 referrer_policy_(blink::WebReferrerPolicyDefault), |
411 defers_loading_(NOT_DEFERRING), | 416 defers_loading_(NOT_DEFERRING), |
412 request_id_(-1) {} | 417 request_id_(-1), |
| 418 url_loader_factory_(url_loader_factory) {} |
413 | 419 |
414 void WebURLLoaderImpl::Context::Cancel() { | 420 void WebURLLoaderImpl::Context::Cancel() { |
415 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, | 421 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Cancel", this, |
416 TRACE_EVENT_FLAG_FLOW_IN); | 422 TRACE_EVENT_FLAG_FLOW_IN); |
417 if (resource_dispatcher_ && // NULL in unittest. | 423 if (resource_dispatcher_ && // NULL in unittest. |
418 request_id_ != -1) { | 424 request_id_ != -1) { |
419 resource_dispatcher_->Cancel(request_id_); | 425 resource_dispatcher_->Cancel(request_id_); |
420 request_id_ = -1; | 426 request_id_ = -1; |
421 } | 427 } |
422 | 428 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
561 if (stream_override_.get()) { | 567 if (stream_override_.get()) { |
562 CHECK(IsBrowserSideNavigationEnabled()); | 568 CHECK(IsBrowserSideNavigationEnabled()); |
563 DCHECK(!sync_load_response); | 569 DCHECK(!sync_load_response); |
564 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); | 570 DCHECK_NE(WebURLRequest::FrameTypeNone, request.getFrameType()); |
565 request_info.resource_body_stream_url = stream_override_->stream_url; | 571 request_info.resource_body_stream_url = stream_override_->stream_url; |
566 } | 572 } |
567 | 573 |
568 if (sync_load_response) { | 574 if (sync_load_response) { |
569 DCHECK(defers_loading_ == NOT_DEFERRING); | 575 DCHECK(defers_loading_ == NOT_DEFERRING); |
570 resource_dispatcher_->StartSync( | 576 resource_dispatcher_->StartSync( |
571 request_info, request_body.get(), sync_load_response); | 577 request_info, request_body.get(), sync_load_response, |
| 578 request.getLoadingIPCType(), url_loader_factory_); |
572 return; | 579 return; |
573 } | 580 } |
574 | 581 |
575 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, | 582 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, |
576 TRACE_EVENT_FLAG_FLOW_OUT); | 583 TRACE_EVENT_FLAG_FLOW_OUT); |
577 request_id_ = resource_dispatcher_->StartAsync( | 584 request_id_ = resource_dispatcher_->StartAsync( |
578 request_info, request_body.get(), | 585 request_info, request_body.get(), |
579 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this))); | 586 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this)), |
| 587 request.getLoadingIPCType(), url_loader_factory_); |
580 | 588 |
581 if (defers_loading_ != NOT_DEFERRING) | 589 if (defers_loading_ != NOT_DEFERRING) |
582 resource_dispatcher_->SetDefersLoading(request_id_, true); | 590 resource_dispatcher_->SetDefersLoading(request_id_, true); |
583 } | 591 } |
584 | 592 |
585 void WebURLLoaderImpl::Context::SetWebTaskRunner( | 593 void WebURLLoaderImpl::Context::SetWebTaskRunner( |
586 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { | 594 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { |
587 web_task_runner_ = std::move(web_task_runner); | 595 web_task_runner_ = std::move(web_task_runner); |
588 } | 596 } |
589 | 597 |
(...skipping 349 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 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1227 response->clearHTTPHeaderField(webStringName); | 1238 response->clearHTTPHeaderField(webStringName); |
1228 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1239 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
1229 response->addHTTPHeaderField(webStringName, | 1240 response->addHTTPHeaderField(webStringName, |
1230 WebString::fromLatin1(value)); | 1241 WebString::fromLatin1(value)); |
1231 } | 1242 } |
1232 } | 1243 } |
1233 return true; | 1244 return true; |
1234 } | 1245 } |
1235 | 1246 |
1236 } // namespace content | 1247 } // namespace content |
OLD | NEW |