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/browser/frame_host/navigation_request.h" | 5 #include "content/browser/frame_host/navigation_request.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "content/browser/child_process_security_policy_impl.h" | 9 #include "content/browser/child_process_security_policy_impl.h" |
| 10 #include "content/browser/devtools/render_frame_devtools_agent_host.h" | 10 #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 #include "content/public/browser/navigation_controller.h" | 27 #include "content/public/browser/navigation_controller.h" |
| 28 #include "content/public/browser/navigation_data.h" | 28 #include "content/public/browser/navigation_data.h" |
| 29 #include "content/public/browser/navigation_ui_data.h" | 29 #include "content/public/browser/navigation_ui_data.h" |
| 30 #include "content/public/browser/storage_partition.h" | 30 #include "content/public/browser/storage_partition.h" |
| 31 #include "content/public/browser/stream_handle.h" | 31 #include "content/public/browser/stream_handle.h" |
| 32 #include "content/public/common/content_client.h" | 32 #include "content/public/common/content_client.h" |
| 33 #include "content/public/common/request_context_type.h" | 33 #include "content/public/common/request_context_type.h" |
| 34 #include "content/public/common/resource_response.h" | 34 #include "content/public/common/resource_response.h" |
| 35 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
| 36 #include "net/base/load_flags.h" | 36 #include "net/base/load_flags.h" |
| 37 #include "net/base/net_errors.h" | |
| 37 #include "net/base/url_util.h" | 38 #include "net/base/url_util.h" |
| 38 #include "net/http/http_request_headers.h" | 39 #include "net/http/http_request_headers.h" |
| 39 #include "net/url_request/redirect_info.h" | 40 #include "net/url_request/redirect_info.h" |
| 40 #include "third_party/WebKit/public/web/WebSandboxFlags.h" | 41 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
| 41 | 42 |
| 42 namespace content { | 43 namespace content { |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 46 // Returns the net load flags to use based on the navigation type. | 47 // Returns the net load flags to use based on the navigation type. |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 const NavigationEntryImpl* entry) | 220 const NavigationEntryImpl* entry) |
| 220 : frame_tree_node_(frame_tree_node), | 221 : frame_tree_node_(frame_tree_node), |
| 221 common_params_(common_params), | 222 common_params_(common_params), |
| 222 begin_params_(begin_params), | 223 begin_params_(begin_params), |
| 223 request_params_(request_params), | 224 request_params_(request_params), |
| 224 browser_initiated_(browser_initiated), | 225 browser_initiated_(browser_initiated), |
| 225 state_(NOT_STARTED), | 226 state_(NOT_STARTED), |
| 226 restore_type_(RestoreType::NONE), | 227 restore_type_(RestoreType::NONE), |
| 227 is_view_source_(false), | 228 is_view_source_(false), |
| 228 bindings_(NavigationEntryImpl::kInvalidBindings), | 229 bindings_(NavigationEntryImpl::kInvalidBindings), |
| 230 response_should_be_rendered_(true), | |
| 229 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) { | 231 associated_site_instance_type_(AssociatedSiteInstanceType::NONE) { |
| 230 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); | 232 DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); |
| 231 if (browser_initiated) { | 233 if (browser_initiated) { |
| 232 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); | 234 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); |
| 233 if (frame_entry) { | 235 if (frame_entry) { |
| 234 source_site_instance_ = frame_entry->source_site_instance(); | 236 source_site_instance_ = frame_entry->source_site_instance(); |
| 235 dest_site_instance_ = frame_entry->site_instance(); | 237 dest_site_instance_ = frame_entry->site_instance(); |
| 236 } | 238 } |
| 237 | 239 |
| 238 restore_type_ = entry->restore_type(); | 240 restore_type_ = entry->restore_type(); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 | 373 |
| 372 void NavigationRequest::OnResponseStarted( | 374 void NavigationRequest::OnResponseStarted( |
| 373 const scoped_refptr<ResourceResponse>& response, | 375 const scoped_refptr<ResourceResponse>& response, |
| 374 std::unique_ptr<StreamHandle> body, | 376 std::unique_ptr<StreamHandle> body, |
| 375 const SSLStatus& ssl_status, | 377 const SSLStatus& ssl_status, |
| 376 std::unique_ptr<NavigationData> navigation_data, | 378 std::unique_ptr<NavigationData> navigation_data, |
| 377 const GlobalRequestID& request_id, | 379 const GlobalRequestID& request_id, |
| 378 bool is_download, | 380 bool is_download, |
| 379 bool is_stream) { | 381 bool is_stream) { |
| 380 DCHECK(state_ == STARTED); | 382 DCHECK(state_ == STARTED); |
| 383 DCHECK(response); | |
| 381 state_ = RESPONSE_STARTED; | 384 state_ = RESPONSE_STARTED; |
| 382 | 385 |
| 383 // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not | 386 // Check if the response should be sent to a renderer. |
| 384 // commit; they leave the frame showing the previous page. | 387 response_should_be_rendered_ = |
| 385 DCHECK(response); | 388 !is_download && (!response->head.headers.get() || |
| 386 if (response->head.headers.get() && | 389 (response->head.headers->response_code() != 204 && |
| 387 (response->head.headers->response_code() == 204 || | 390 response->head.headers->response_code() != 205)); |
| 388 response->head.headers->response_code() == 205)) { | 391 |
| 389 frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( | 392 // Response that will not commit should be marked as aborted in the |
| 390 navigation_handle_.get()); | 393 // NavigationHandle. |
| 391 frame_tree_node_->ResetNavigationRequest(false); | 394 if (!response_should_be_rendered_) |
| 392 return; | 395 navigation_handle_->set_net_error_code(net::ERR_ABORTED); |
| 393 } | |
| 394 | 396 |
| 395 // Update the service worker params of the request params. | 397 // Update the service worker params of the request params. |
| 396 bool did_create_service_worker_host = | 398 bool did_create_service_worker_host = |
| 397 navigation_handle_->service_worker_handle() && | 399 navigation_handle_->service_worker_handle() && |
| 398 navigation_handle_->service_worker_handle() | 400 navigation_handle_->service_worker_handle() |
| 399 ->service_worker_provider_host_id() != | 401 ->service_worker_provider_host_id() != |
| 400 kInvalidServiceWorkerProviderId; | 402 kInvalidServiceWorkerProviderId; |
| 401 request_params_.service_worker_provider_id = | 403 request_params_.service_worker_provider_id = |
| 402 did_create_service_worker_host | 404 did_create_service_worker_host |
| 403 ? navigation_handle_->service_worker_handle() | 405 ? navigation_handle_->service_worker_handle() |
| 404 ->service_worker_provider_host_id() | 406 ->service_worker_provider_host_id() |
| 405 : kInvalidServiceWorkerProviderId; | 407 : kInvalidServiceWorkerProviderId; |
| 406 | 408 |
| 407 // Update the lofi state of the request. | 409 // Update the lofi state of the request. |
| 408 if (response->head.is_using_lofi) | 410 if (response->head.is_using_lofi) |
| 409 common_params_.lofi_state = LOFI_ON; | 411 common_params_.lofi_state = LOFI_ON; |
| 410 else | 412 else |
| 411 common_params_.lofi_state = LOFI_OFF; | 413 common_params_.lofi_state = LOFI_OFF; |
| 412 | 414 |
| 413 // Select an appropriate renderer to commit the navigation. | 415 // Select an appropriate renderer to commit the navigation. |
| 414 RenderFrameHostImpl* render_frame_host = | 416 RenderFrameHostImpl* render_frame_host = nullptr; |
|
clamy
2016/12/06 17:01:58
Note that this will mean having a null RFH if Navi
nasko
2016/12/08 18:25:24
Will that be the case only during WillProcessRespo
clamy
2016/12/16 17:07:14
No, we won't set the RFH to current since there wi
| |
| 415 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); | 417 if (response_should_be_rendered_) { |
| 416 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, | 418 render_frame_host = |
| 417 common_params_.url); | 419 frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); |
| 420 NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( | |
| 421 render_frame_host, common_params_.url); | |
| 422 } | |
| 423 DCHECK(render_frame_host || !response_should_be_rendered_); | |
| 418 | 424 |
| 419 // For renderer-initiated navigations that are set to commit in a different | 425 // For renderer-initiated navigations that are set to commit in a different |
| 420 // renderer, allow the embedder to cancel the transfer. | 426 // renderer, allow the embedder to cancel the transfer. |
| 421 if (!browser_initiated_ && | 427 if (!browser_initiated_ && render_frame_host && |
| 422 render_frame_host != frame_tree_node_->current_frame_host() && | 428 render_frame_host != frame_tree_node_->current_frame_host() && |
| 423 !frame_tree_node_->navigator()->GetDelegate()->ShouldTransferNavigation( | 429 !frame_tree_node_->navigator()->GetDelegate()->ShouldTransferNavigation( |
| 424 frame_tree_node_->IsMainFrame())) { | 430 frame_tree_node_->IsMainFrame())) { |
| 425 frame_tree_node_->ResetNavigationRequest(false); | 431 frame_tree_node_->ResetNavigationRequest(false); |
| 426 return; | 432 return; |
| 427 } | 433 } |
| 428 | 434 |
| 429 if (navigation_data) | 435 if (navigation_data) |
| 430 navigation_handle_->set_navigation_data(std::move(navigation_data)); | 436 navigation_handle_->set_navigation_data(std::move(navigation_data)); |
| 431 | 437 |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 return; | 565 return; |
| 560 } | 566 } |
| 561 | 567 |
| 562 loader_->FollowRedirect(); | 568 loader_->FollowRedirect(); |
| 563 } | 569 } |
| 564 | 570 |
| 565 void NavigationRequest::OnWillProcessResponseChecksComplete( | 571 void NavigationRequest::OnWillProcessResponseChecksComplete( |
| 566 NavigationThrottle::ThrottleCheckResult result) { | 572 NavigationThrottle::ThrottleCheckResult result) { |
| 567 CHECK(result != NavigationThrottle::DEFER); | 573 CHECK(result != NavigationThrottle::DEFER); |
| 568 | 574 |
| 569 // Abort the request if needed. This will destroy the NavigationRequest. | 575 // Abort the request if needed. This include requests that were blocked by |
|
nasko
2016/12/08 18:25:24
nit: includes
clamy
2016/12/16 17:07:14
Done.
| |
| 576 // NavigationThrottles and requests that should not commit (eg downloads, | |
|
nasko
2016/12/08 18:25:24
nit.: e.g.
clamy
2016/12/16 17:07:14
Done.
| |
| 577 // 204/205s). This will destroy the NavigationRequest. | |
| 570 if (result == NavigationThrottle::CANCEL_AND_IGNORE || | 578 if (result == NavigationThrottle::CANCEL_AND_IGNORE || |
| 571 result == NavigationThrottle::CANCEL) { | 579 result == NavigationThrottle::CANCEL || !response_should_be_rendered_) { |
| 572 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. | 580 // TODO(clamy): distinguish between CANCEL and CANCEL_AND_IGNORE. |
|
yzshen1
2016/12/06 17:57:37
Do we need to call frame_tree_node_->navigator()->
clamy
2016/12/16 17:07:14
Done.
| |
| 573 frame_tree_node_->ResetNavigationRequest(false); | 581 frame_tree_node_->ResetNavigationRequest(false); |
| 574 return; | 582 return; |
| 575 } | 583 } |
| 576 | 584 |
| 577 // Have the processing of the response resume in the network stack. | 585 // Have the processing of the response resume in the network stack. |
| 578 loader_->ProceedWithResponse(); | 586 loader_->ProceedWithResponse(); |
| 579 | 587 |
| 580 CommitNavigation(); | 588 CommitNavigation(); |
| 581 | 589 |
| 582 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused | 590 // DO NOT ADD CODE after this. The previous call to CommitNavigation caused |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 598 TransferNavigationHandleOwnership(render_frame_host); | 606 TransferNavigationHandleOwnership(render_frame_host); |
| 599 | 607 |
| 600 render_frame_host->CommitNavigation(response_.get(), std::move(body_), | 608 render_frame_host->CommitNavigation(response_.get(), std::move(body_), |
| 601 common_params_, request_params_, | 609 common_params_, request_params_, |
| 602 is_view_source_); | 610 is_view_source_); |
| 603 | 611 |
| 604 frame_tree_node_->ResetNavigationRequest(true); | 612 frame_tree_node_->ResetNavigationRequest(true); |
| 605 } | 613 } |
| 606 | 614 |
| 607 } // namespace content | 615 } // namespace content |
| OLD | NEW |