Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1405)

Unified Diff: content/browser/frame_host/navigation_handle_impl.cc

Issue 1414723008: Add a way to cancel deferred navigations in NavigationHandle (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/navigation_handle_impl.cc
diff --git a/content/browser/frame_host/navigation_handle_impl.cc b/content/browser/frame_host/navigation_handle_impl.cc
index b1aace3597c5ecd773339efa3b2472beac3db8a7..ff96cba7b1330207420df98728a7691c52698633 100644
--- a/content/browser/frame_host/navigation_handle_impl.cc
+++ b/content/browser/frame_host/navigation_handle_impl.cc
@@ -80,6 +80,14 @@ NavigationHandleImpl::NavigationHandleImpl(const GURL& url,
NavigationHandleImpl::~NavigationHandleImpl() {
GetDelegate()->DidFinishNavigation(this);
+
+ // Cancel the navigation on the IO thread if the NavigationHandle is being
+ // destroyed in the middle of the NavigationThrottles checks.
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation) &&
+ !complete_callback_.is_null()) {
+ RunCompleteCallback(NavigationThrottle::CANCEL_AND_IGNORE);
+ }
}
NavigatorDelegate* NavigationHandleImpl::GetDelegate() const {
@@ -160,7 +168,16 @@ void NavigationHandleImpl::Resume() {
}
if (result != NavigationThrottle::DEFER)
- complete_callback_.Run(result);
+ RunCompleteCallback(result);
+}
+
+void NavigationHandleImpl::CancelDeferredNavigation(
+ NavigationThrottle::ThrottleCheckResult result) {
+ DCHECK(state_ == DEFERRING_START || state_ == DEFERRING_REDIRECT);
+ DCHECK(result == NavigationThrottle::CANCEL_AND_IGNORE ||
+ result == NavigationThrottle::CANCEL);
+ state_ = CANCELING;
+ RunCompleteCallback(result);
}
void NavigationHandleImpl::RegisterThrottleForTesting(
@@ -235,7 +252,7 @@ void NavigationHandleImpl::WillStartRequest(
// If the navigation is not deferred, run the callback.
if (result != NavigationThrottle::DEFER)
- callback.Run(result);
+ RunCompleteCallback(result);
}
void NavigationHandleImpl::WillRedirectRequest(
@@ -259,7 +276,7 @@ void NavigationHandleImpl::WillRedirectRequest(
// If the navigation is not deferred, run the callback.
if (result != NavigationThrottle::DEFER)
- callback.Run(result);
+ RunCompleteCallback(result);
}
void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) {
@@ -296,7 +313,9 @@ NavigationHandleImpl::CheckWillStartRequest() {
case NavigationThrottle::PROCEED:
continue;
+ case NavigationThrottle::CANCEL:
case NavigationThrottle::CANCEL_AND_IGNORE:
+ state_ = CANCELING;
return result;
case NavigationThrottle::DEFER:
@@ -325,7 +344,9 @@ NavigationHandleImpl::CheckWillRedirectRequest() {
case NavigationThrottle::PROCEED:
continue;
+ case NavigationThrottle::CANCEL:
case NavigationThrottle::CANCEL_AND_IGNORE:
+ state_ = CANCELING;
return result;
case NavigationThrottle::DEFER:
@@ -342,4 +363,13 @@ NavigationHandleImpl::CheckWillRedirectRequest() {
return NavigationThrottle::PROCEED;
}
+void NavigationHandleImpl::RunCompleteCallback(
+ NavigationThrottle::ThrottleCheckResult result) {
+ DCHECK(result != NavigationThrottle::DEFER);
+ if (!complete_callback_.is_null())
+ complete_callback_.Run(result);
+
+ complete_callback_.Reset();
+}
+
} // namespace content
« no previous file with comments | « content/browser/frame_host/navigation_handle_impl.h ('k') | content/browser/frame_host/navigation_handle_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698