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

Side by Side Diff: components/navigation_interception/intercept_navigation_throttle.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, 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/navigation_interception/intercept_navigation_throttle.h" 5 #include "components/navigation_interception/intercept_navigation_throttle.h"
6 6
7 #include "components/navigation_interception/navigation_params.h" 7 #include "components/navigation_interception/navigation_params.h"
8 #include "content/public/browser/browser_thread.h" 8 #include "content/public/browser/browser_thread.h"
9 #include "content/public/browser/navigation_handle.h" 9 #include "content/public/browser/navigation_handle.h"
10 10
11 namespace navigation_interception { 11 namespace navigation_interception {
12 12
13 namespace {
14
15 // Runs the |should_ignore_callback|. This may result in the destruction of
16 // |throttle|, hence why it is not done inside the NavigationThrottle itself.
17 content::NavigationThrottle::ThrottleCheckResult CheckCallbackAndMaybeDestroy(
18 const InterceptNavigationThrottle::CheckCallback& should_ignore_callback,
19 content::WebContents* web_contents,
20 const NavigationParams& navigation_params,
21 base::WeakPtr<InterceptNavigationThrottle> throttle) {
22 bool should_ignore_navigation =
23 should_ignore_callback.Run(web_contents, navigation_params);
24 if (!throttle)
25 return content::NavigationThrottle::DESTROYED;
26 return should_ignore_navigation
27 ? content::NavigationThrottle::CANCEL_AND_IGNORE
28 : content::NavigationThrottle::PROCEED;
29 }
30
31 } // namespace
32
13 InterceptNavigationThrottle::InterceptNavigationThrottle( 33 InterceptNavigationThrottle::InterceptNavigationThrottle(
14 content::NavigationHandle* navigation_handle, 34 content::NavigationHandle* navigation_handle,
15 CheckCallback should_ignore_callback) 35 CheckCallback should_ignore_callback)
16 : content::NavigationThrottle(navigation_handle), 36 : content::NavigationThrottle(navigation_handle),
17 should_ignore_callback_(should_ignore_callback) {} 37 should_ignore_callback_(should_ignore_callback),
38 weak_factory_(this) {}
18 39
19 InterceptNavigationThrottle::~InterceptNavigationThrottle() {} 40 InterceptNavigationThrottle::~InterceptNavigationThrottle() {}
20 41
21 content::NavigationThrottle::ThrottleCheckResult 42 content::NavigationThrottle::ThrottleCheckResult
22 InterceptNavigationThrottle::WillStartRequest() { 43 InterceptNavigationThrottle::WillStartRequest() {
23 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 44 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
24 return CheckIfShouldIgnoreNavigation(false); 45 return CheckIfShouldIgnoreNavigation(false);
25 } 46 }
26 47
27 content::NavigationThrottle::ThrottleCheckResult 48 content::NavigationThrottle::ThrottleCheckResult
28 InterceptNavigationThrottle::WillRedirectRequest() { 49 InterceptNavigationThrottle::WillRedirectRequest() {
29 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 50 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
30 return CheckIfShouldIgnoreNavigation(true); 51 return CheckIfShouldIgnoreNavigation(true);
31 } 52 }
32 53
33 content::NavigationThrottle::ThrottleCheckResult 54 content::NavigationThrottle::ThrottleCheckResult
34 InterceptNavigationThrottle::CheckIfShouldIgnoreNavigation(bool is_redirect) { 55 InterceptNavigationThrottle::CheckIfShouldIgnoreNavigation(bool is_redirect) {
35 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 56 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
36 NavigationParams navigation_params( 57 NavigationParams navigation_params(
37 navigation_handle()->GetURL(), navigation_handle()->GetReferrer(), 58 navigation_handle()->GetURL(), navigation_handle()->GetReferrer(),
38 navigation_handle()->HasUserGesture(), navigation_handle()->IsPost(), 59 navigation_handle()->HasUserGesture(), navigation_handle()->IsPost(),
39 navigation_handle()->GetPageTransition(), is_redirect, 60 navigation_handle()->GetPageTransition(), is_redirect,
40 navigation_handle()->IsExternalProtocol(), true); 61 navigation_handle()->IsExternalProtocol(), true);
41 62 return CheckCallbackAndMaybeDestroy(
42 bool should_ignore_navigation = should_ignore_callback_.Run( 63 should_ignore_callback_, navigation_handle()->GetWebContents(),
43 navigation_handle()->GetWebContents(), navigation_params); 64 navigation_params, weak_factory_.GetWeakPtr());
44 return should_ignore_navigation
45 ? content::NavigationThrottle::CANCEL_AND_IGNORE
46 : content::NavigationThrottle::PROCEED;
47 } 65 }
48 66
49 } // namespace navigation_interception 67 } // namespace navigation_interception
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698