Chromium Code Reviews| 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.loadingIPC() == blink::WebURLRequest::LoadingIPC::Mojo) { | |
| 545 url_loader_factory_->CreateURLLoader(GetProxy(&loader)); | |
| 546 } | |
|
kinuko
2016/05/20 09:38:51
nit: no {} for one-line body for consistency in th
yhirano
2016/05/20 11:32:54
Done.
| |
| 547 | |
| 537 if (sync_load_response) { | 548 if (sync_load_response) { |
| 538 DCHECK(defers_loading_ == NOT_DEFERRING); | 549 DCHECK(defers_loading_ == NOT_DEFERRING); |
| 539 resource_dispatcher_->StartSync( | 550 resource_dispatcher_->StartSync(request_info, request_body.get(), |
| 540 request_info, request_body.get(), sync_load_response); | 551 sync_load_response, std::move(loader)); |
| 541 return; | 552 return; |
| 542 } | 553 } |
| 543 | 554 |
| 544 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, | 555 TRACE_EVENT_WITH_FLOW0("loading", "WebURLLoaderImpl::Context::Start", this, |
| 545 TRACE_EVENT_FLAG_FLOW_OUT); | 556 TRACE_EVENT_FLAG_FLOW_OUT); |
| 546 request_id_ = resource_dispatcher_->StartAsync( | 557 request_id_ = resource_dispatcher_->StartAsync( |
| 547 request_info, request_body.get(), | 558 request_info, request_body.get(), |
| 548 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this))); | 559 base::WrapUnique(new WebURLLoaderImpl::RequestPeerImpl(this)), |
| 560 std::move(loader)); | |
| 549 | 561 |
| 550 if (defers_loading_ != NOT_DEFERRING) | 562 if (defers_loading_ != NOT_DEFERRING) |
| 551 resource_dispatcher_->SetDefersLoading(request_id_, true); | 563 resource_dispatcher_->SetDefersLoading(request_id_, true); |
| 552 } | 564 } |
| 553 | 565 |
| 554 void WebURLLoaderImpl::Context::SetWebTaskRunner( | 566 void WebURLLoaderImpl::Context::SetWebTaskRunner( |
| 555 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { | 567 std::unique_ptr<blink::WebTaskRunner> web_task_runner) { |
| 556 web_task_runner_ = std::move(web_task_runner); | 568 web_task_runner_ = std::move(web_task_runner); |
| 557 } | 569 } |
| 558 | 570 |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 908 int64_t total_transfer_size) { | 920 int64_t total_transfer_size) { |
| 909 context_->OnCompletedRequest(error_code, was_ignored_by_handler, | 921 context_->OnCompletedRequest(error_code, was_ignored_by_handler, |
| 910 stale_copy_in_cache, security_info, | 922 stale_copy_in_cache, security_info, |
| 911 completion_time, total_transfer_size); | 923 completion_time, total_transfer_size); |
| 912 } | 924 } |
| 913 | 925 |
| 914 // WebURLLoaderImpl ----------------------------------------------------------- | 926 // WebURLLoaderImpl ----------------------------------------------------------- |
| 915 | 927 |
| 916 WebURLLoaderImpl::WebURLLoaderImpl( | 928 WebURLLoaderImpl::WebURLLoaderImpl( |
| 917 ResourceDispatcher* resource_dispatcher, | 929 ResourceDispatcher* resource_dispatcher, |
| 918 std::unique_ptr<blink::WebTaskRunner> web_task_runner) | 930 std::unique_ptr<blink::WebTaskRunner> web_task_runner, |
| 919 : context_( | 931 mojom::URLLoaderFactory* url_loader_factory) |
| 920 new Context(this, resource_dispatcher, std::move(web_task_runner))) {} | 932 : context_(new Context(this, |
| 933 resource_dispatcher, | |
| 934 std::move(web_task_runner), | |
| 935 url_loader_factory)) {} | |
| 921 | 936 |
| 922 WebURLLoaderImpl::~WebURLLoaderImpl() { | 937 WebURLLoaderImpl::~WebURLLoaderImpl() { |
| 923 cancel(); | 938 cancel(); |
| 924 } | 939 } |
| 925 | 940 |
| 926 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, | 941 void WebURLLoaderImpl::PopulateURLResponse(const GURL& url, |
| 927 const ResourceResponseInfo& info, | 942 const ResourceResponseInfo& info, |
| 928 WebURLResponse* response, | 943 WebURLResponse* response, |
| 929 bool report_security_info) { | 944 bool report_security_info) { |
| 930 response->setURL(url); | 945 response->setURL(url); |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1189 response->clearHTTPHeaderField(webStringName); | 1204 response->clearHTTPHeaderField(webStringName); |
| 1190 while (response_headers->EnumerateHeader(&iterator, name, &value)) { | 1205 while (response_headers->EnumerateHeader(&iterator, name, &value)) { |
| 1191 response->addHTTPHeaderField(webStringName, | 1206 response->addHTTPHeaderField(webStringName, |
| 1192 WebString::fromLatin1(value)); | 1207 WebString::fromLatin1(value)); |
| 1193 } | 1208 } |
| 1194 } | 1209 } |
| 1195 return true; | 1210 return true; |
| 1196 } | 1211 } |
| 1197 | 1212 |
| 1198 } // namespace content | 1213 } // namespace content |
| OLD | NEW |