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

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

Issue 1412113006: Prevent the destruction of WebContents in NavigationThrottle methods (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 months 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..46d7c784873fa5570fa5070537b48f376844410c 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 was
+ // destroyed in the middle of the NavigationThrottles checks.
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableBrowserSideNavigation) &&
+ !complete_callback_.is_null()) {
+ complete_callback_.Run(NavigationThrottle::CANCEL_AND_IGNORE);
+ }
}
NavigatorDelegate* NavigationHandleImpl::GetDelegate() const {
@@ -159,8 +167,14 @@ void NavigationHandleImpl::Resume() {
result = CheckWillRedirectRequest();
}
- if (result != NavigationThrottle::DEFER)
- complete_callback_.Run(result);
+ // If the navigation is not deferred and the NavigationHandle wasn't
+ // destroyed, run the callback.
+ if (result == NavigationThrottle::DEFER ||
+ result == NavigationThrottle::DESTROYED)
+ return;
+
+ complete_callback_.Run(result);
+ complete_callback_.Reset();
}
void NavigationHandleImpl::RegisterThrottleForTesting(
@@ -233,9 +247,14 @@ void NavigationHandleImpl::WillStartRequest(
// Notify each throttle of the request.
NavigationThrottle::ThrottleCheckResult result = CheckWillStartRequest();
- // If the navigation is not deferred, run the callback.
- if (result != NavigationThrottle::DEFER)
- callback.Run(result);
+ // If the navigation is not deferred and the NavigationHandle wasn't
+ // destroyed, run the callback.
+ if (result == NavigationThrottle::DEFER ||
+ result == NavigationThrottle::DESTROYED)
+ return;
+
+ complete_callback_.Run(result);
+ complete_callback_.Reset();
}
void NavigationHandleImpl::WillRedirectRequest(
@@ -257,9 +276,14 @@ void NavigationHandleImpl::WillRedirectRequest(
// Notify each throttle of the request.
NavigationThrottle::ThrottleCheckResult result = CheckWillRedirectRequest();
- // If the navigation is not deferred, run the callback.
- if (result != NavigationThrottle::DEFER)
- callback.Run(result);
+ // If the navigation is not deferred and the NavigationHandle wasn't
+ // destroyed, run the callback.
+ if (result == NavigationThrottle::DEFER ||
+ result == NavigationThrottle::DESTROYED)
+ return;
+
+ complete_callback_.Run(result);
+ complete_callback_.Reset();
}
void NavigationHandleImpl::DidRedirectNavigation(const GURL& new_url) {
@@ -297,6 +321,7 @@ NavigationHandleImpl::CheckWillStartRequest() {
continue;
case NavigationThrottle::CANCEL_AND_IGNORE:
+ case NavigationThrottle::DESTROYED:
return result;
case NavigationThrottle::DEFER:
@@ -326,6 +351,7 @@ NavigationHandleImpl::CheckWillRedirectRequest() {
continue;
case NavigationThrottle::CANCEL_AND_IGNORE:
+ case NavigationThrottle::DESTROYED:
return result;
case NavigationThrottle::DEFER:

Powered by Google App Engine
This is Rietveld 408576698