Chromium Code Reviews| Index: content/browser/frame_host/navigation_request.cc |
| diff --git a/content/browser/frame_host/navigation_request.cc b/content/browser/frame_host/navigation_request.cc |
| index b9d3d6eebc61858cd7bedeea53d9feabcb64dbf0..ebf7df4172ec133d35a9bb6eb4a20d988cc2b973 100644 |
| --- a/content/browser/frame_host/navigation_request.cc |
| +++ b/content/browser/frame_host/navigation_request.cc |
| @@ -34,6 +34,7 @@ |
| #include "content/public/common/resource_response.h" |
| #include "content/public/common/url_constants.h" |
| #include "net/base/load_flags.h" |
| +#include "net/base/net_errors.h" |
| #include "net/base/url_util.h" |
| #include "net/http/http_request_headers.h" |
| #include "net/url_request/redirect_info.h" |
| @@ -226,6 +227,7 @@ NavigationRequest::NavigationRequest( |
| restore_type_(RestoreType::NONE), |
| is_view_source_(false), |
| bindings_(NavigationEntryImpl::kInvalidBindings), |
| + response_should_be_rendered_(true), |
| associated_site_instance_type_(AssociatedSiteInstanceType::NONE) { |
| DCHECK(!browser_initiated || (entry != nullptr && frame_entry != nullptr)); |
| if (browser_initiated) { |
| @@ -378,19 +380,19 @@ void NavigationRequest::OnResponseStarted( |
| bool is_download, |
| bool is_stream) { |
| DCHECK(state_ == STARTED); |
| + DCHECK(response); |
| state_ = RESPONSE_STARTED; |
| - // HTTP 204 (No Content) and HTTP 205 (Reset Content) responses should not |
| - // commit; they leave the frame showing the previous page. |
| - DCHECK(response); |
| - if (response->head.headers.get() && |
| - (response->head.headers->response_code() == 204 || |
| - response->head.headers->response_code() == 205)) { |
| - frame_tree_node_->navigator()->DiscardPendingEntryIfNeeded( |
| - navigation_handle_.get()); |
| - frame_tree_node_->ResetNavigationRequest(false); |
| - return; |
| - } |
| + // Check if the response should be sent to a renderer. |
| + response_should_be_rendered_ = |
| + !is_download && (!response->head.headers.get() || |
| + (response->head.headers->response_code() != 204 && |
| + response->head.headers->response_code() != 205)); |
| + |
| + // Response that will not commit should be marked as aborted in the |
| + // NavigationHandle. |
| + if (!response_should_be_rendered_) |
| + navigation_handle_->set_net_error_code(net::ERR_ABORTED); |
| // Update the service worker params of the request params. |
| bool did_create_service_worker_host = |
| @@ -411,14 +413,18 @@ void NavigationRequest::OnResponseStarted( |
| common_params_.lofi_state = LOFI_OFF; |
| // Select an appropriate renderer to commit the navigation. |
| - RenderFrameHostImpl* render_frame_host = |
| - frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); |
| - NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL(render_frame_host, |
| - common_params_.url); |
| + 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
|
| + if (response_should_be_rendered_) { |
| + render_frame_host = |
| + frame_tree_node_->render_manager()->GetFrameHostForNavigation(*this); |
| + NavigatorImpl::CheckWebUIRendererDoesNotDisplayNormalURL( |
| + render_frame_host, common_params_.url); |
| + } |
| + DCHECK(render_frame_host || !response_should_be_rendered_); |
| // For renderer-initiated navigations that are set to commit in a different |
| // renderer, allow the embedder to cancel the transfer. |
| - if (!browser_initiated_ && |
| + if (!browser_initiated_ && render_frame_host && |
| render_frame_host != frame_tree_node_->current_frame_host() && |
| !frame_tree_node_->navigator()->GetDelegate()->ShouldTransferNavigation( |
| frame_tree_node_->IsMainFrame())) { |
| @@ -566,9 +572,11 @@ void NavigationRequest::OnWillProcessResponseChecksComplete( |
| NavigationThrottle::ThrottleCheckResult result) { |
| CHECK(result != NavigationThrottle::DEFER); |
| - // Abort the request if needed. This will destroy the NavigationRequest. |
| + // 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.
|
| + // 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.
|
| + // 204/205s). This will destroy the NavigationRequest. |
| if (result == NavigationThrottle::CANCEL_AND_IGNORE || |
| - result == NavigationThrottle::CANCEL) { |
| + result == NavigationThrottle::CANCEL || !response_should_be_rendered_) { |
| // 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.
|
| frame_tree_node_->ResetNavigationRequest(false); |
| return; |