Commit f470789e authored by carlosk's avatar carlosk Committed by Commit bot

PlzNavigate: Updated navigation cancel policy for renderer-initiated requests.

Now the navigation cancellation logic should conform to what has been described
in the "PlzNavigate: Navigation cancellation" design document [1]. Added some
new tests to exercise the cancellation cases described in the document.

Note: This is being developed on top of http://crrev.com/912833002.

[1] https://docs.google.com/a/chromium.org/document/d/1lO7_fgppFTDd8PSQfIb888z7vODcw2Sc8r7h5Rbiwcg/edit#

BUG=376014

Review URL: https://codereview.chromium.org/914223002

Cr-Commit-Position: refs/heads/master@{#317083}
parent ca77486b
...@@ -78,6 +78,8 @@ class CONTENT_EXPORT NavigationRequest : public NavigationURLLoaderDelegate { ...@@ -78,6 +78,8 @@ class CONTENT_EXPORT NavigationRequest : public NavigationURLLoaderDelegate {
const CommonNavigationParams& common_params() const { return common_params_; } const CommonNavigationParams& common_params() const { return common_params_; }
const BeginNavigationParams& begin_params() const { return begin_params_; }
const CommitNavigationParams& commit_params() const { return commit_params_; } const CommitNavigationParams& commit_params() const { return commit_params_; }
NavigationURLLoader* loader_for_testing() const { return loader_.get(); } NavigationURLLoader* loader_for_testing() const { return loader_.get(); }
......
...@@ -703,14 +703,27 @@ void NavigatorImpl::OnBeginNavigation( ...@@ -703,14 +703,27 @@ void NavigatorImpl::OnBeginNavigation(
const CommonNavigationParams& common_params, const CommonNavigationParams& common_params,
const BeginNavigationParams& begin_params, const BeginNavigationParams& begin_params,
scoped_refptr<ResourceRequestBody> body) { scoped_refptr<ResourceRequestBody> body) {
// This is a renderer-initiated navigation.
CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch( CHECK(base::CommandLine::ForCurrentProcess()->HasSwitch(
switches::kEnableBrowserSideNavigation)); switches::kEnableBrowserSideNavigation));
DCHECK(frame_tree_node); DCHECK(frame_tree_node);
// This is a renderer-initiated navigation, so generate a new NavigationRequest* ongoing_navigation_request =
// NavigationRequest and store it in the map. navigation_request_map_.get(frame_tree_node->frame_tree_node_id());
// TODO(clamy): Renderer-initiated navigations should not always cancel the
// current one. // The renderer-initiated navigation request is ignored iff a) there is an
// ongoing request b) which is browser or user-initiated and c) the renderer
// request is not user-initiated.
if (ongoing_navigation_request &&
(ongoing_navigation_request->browser_initiated() ||
ongoing_navigation_request->begin_params().has_user_gesture) &&
!begin_params.has_user_gesture) {
return;
}
// In all other cases the current navigation, if any, is canceled and a new
// NavigationRequest is created and stored in the map. Actual cancellation
// happens when the existing request map entry is replaced and destroyed.
scoped_ptr<NavigationRequest> navigation_request = scoped_ptr<NavigationRequest> navigation_request =
NavigationRequest::CreateRendererInitiated( NavigationRequest::CreateRendererInitiated(
frame_tree_node, common_params, begin_params, body); frame_tree_node, common_params, begin_params, body);
......
...@@ -187,9 +187,10 @@ void TestRenderFrameHost::SendNavigateWithParameters( ...@@ -187,9 +187,10 @@ void TestRenderFrameHost::SendNavigateWithParameters(
OnDidCommitProvisionalLoad(msg); OnDidCommitProvisionalLoad(msg);
} }
void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url) { void TestRenderFrameHost::SendBeginNavigationWithURL(const GURL& url,
BeginNavigationParams begin_params( bool has_user_gesture) {
"GET", std::string(), net::LOAD_NORMAL, false); BeginNavigationParams begin_params("GET", std::string(), net::LOAD_NORMAL,
has_user_gesture);
CommonNavigationParams common_params; CommonNavigationParams common_params;
common_params.url = url; common_params.url = url;
common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault); common_params.referrer = Referrer(GURL(), blink::WebReferrerPolicyDefault);
...@@ -215,9 +216,9 @@ void TestRenderFrameHost::PrepareForCommit(const GURL& url) { ...@@ -215,9 +216,9 @@ void TestRenderFrameHost::PrepareForCommit(const GURL& url) {
static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
->GetNavigationRequestForNodeForTesting(frame_tree_node_); ->GetNavigationRequestForNodeForTesting(frame_tree_node_);
// We are simulating a renderer-initiated navigation. // We are simulating a renderer-initiated user-initiated navigation.
if (!request) { if (!request) {
SendBeginNavigationWithURL(url); SendBeginNavigationWithURL(url, true);
request = static_cast<NavigatorImpl*>(frame_tree_node_->navigator()) request = static_cast<NavigatorImpl*>(frame_tree_node_->navigator())
->GetNavigationRequestForNodeForTesting(frame_tree_node_); ->GetNavigationRequestForNodeForTesting(frame_tree_node_);
} }
......
...@@ -85,7 +85,7 @@ class TestRenderFrameHost : public RenderFrameHostImpl, ...@@ -85,7 +85,7 @@ class TestRenderFrameHost : public RenderFrameHostImpl,
int response_code, int response_code,
const base::FilePath* file_path_for_history_item, const base::FilePath* file_path_for_history_item,
const std::vector<GURL>& redirects); const std::vector<GURL>& redirects);
void SendBeginNavigationWithURL(const GURL& url); void SendBeginNavigationWithURL(const GURL& url, bool has_user_gesture);
void DidDisownOpener(); void DidDisownOpener();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment