diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-09-18 14:34:04 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2017-10-04 11:15:27 +0000 |
commit | e6430e577f105ad8813c92e75c54660c4985026e (patch) | |
tree | 88115e5d1fb471fea807111924dcccbeadbf9e4f /chromium/components/navigation_interception/intercept_navigation_throttle.cc | |
parent | 53d399fe6415a96ea6986ec0d402a9c07da72453 (diff) | |
download | qtwebengine-chromium-e6430e577f105ad8813c92e75c54660c4985026e.tar.gz |
BASELINE: Update Chromium to 61.0.3163.99
Change-Id: I8452f34574d88ca2b27af9bd56fc9ff3f16b1367
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Diffstat (limited to 'chromium/components/navigation_interception/intercept_navigation_throttle.cc')
-rw-r--r-- | chromium/components/navigation_interception/intercept_navigation_throttle.cc | 95 |
1 files changed, 7 insertions, 88 deletions
diff --git a/chromium/components/navigation_interception/intercept_navigation_throttle.cc b/chromium/components/navigation_interception/intercept_navigation_throttle.cc index 25875f0ae70..db7a1dd14ae 100644 --- a/chromium/components/navigation_interception/intercept_navigation_throttle.cc +++ b/chromium/components/navigation_interception/intercept_navigation_throttle.cc @@ -12,41 +12,11 @@ using content::BrowserThread; namespace navigation_interception { -namespace { - -using ChecksPerformedCallback = base::Callback<void(bool, bool)>; - -// This is used to run |should_ignore_callback| if it can destroy the -// WebContents (and the InterceptNavigationThrottle along). In that case, -// |on_checks_performed_callback| will be a no-op. -void RunCallback( - content::WebContents* web_contents, - const NavigationParams& navigation_params, - InterceptNavigationThrottle::CheckCallback should_ignore_callback, - ChecksPerformedCallback on_checks_performed_callback, - base::WeakPtr<InterceptNavigationThrottle> throttle) { - bool should_ignore_navigation = - should_ignore_callback.Run(web_contents, navigation_params); - - // If the InterceptNavigationThrottle that called RunCallback is still alive - // after |should_ignore_callback| has run, this will run - // InterceptNavigationThrottle::OnAsynchronousChecksPerformed. - // TODO(clamy): remove this boolean after crbug.com/570200 is fixed. - bool throttle_was_destroyed = !throttle.get(); - on_checks_performed_callback.Run(should_ignore_navigation, - throttle_was_destroyed); -} - -} // namespace - InterceptNavigationThrottle::InterceptNavigationThrottle( content::NavigationHandle* navigation_handle, - CheckCallback should_ignore_callback, - bool run_callback_synchronously) + CheckCallback should_ignore_callback) : content::NavigationThrottle(navigation_handle), - should_ignore_callback_(should_ignore_callback), - run_callback_synchronously_(run_callback_synchronously), - weak_factory_(this) {} + should_ignore_callback_(should_ignore_callback) {} InterceptNavigationThrottle::~InterceptNavigationThrottle() {} @@ -75,62 +45,11 @@ InterceptNavigationThrottle::CheckIfShouldIgnoreNavigation(bool is_redirect) { navigation_handle()->GetPageTransition(), is_redirect, navigation_handle()->IsExternalProtocol(), true, navigation_handle()->GetBaseURLForDataURL()); - - if (run_callback_synchronously_) { - bool should_ignore_navigation = should_ignore_callback_.Run( - navigation_handle()->GetWebContents(), navigation_params); - return should_ignore_navigation - ? content::NavigationThrottle::CANCEL_AND_IGNORE - : content::NavigationThrottle::PROCEED; - } - - // When the callback can potentially destroy the WebContents, along with the - // NavigationHandle and this InterceptNavigationThrottle, it should be run - // asynchronously. This will ensure that no objects on the stack can be - // deleted, and that the stack does not unwind through them in a deleted - // state. - BrowserThread::PostTask( - BrowserThread::UI, FROM_HERE, - base::Bind(&InterceptNavigationThrottle::RunCallbackAsynchronously, - weak_factory_.GetWeakPtr(), navigation_params)); - return DEFER; -} - -void InterceptNavigationThrottle::RunCallbackAsynchronously( - const NavigationParams& navigation_params) { - DCHECK_CURRENTLY_ON(content::BrowserThread::UI); - - // Run the callback in a helper function as it may lead ot the destruction of - // this InterceptNavigationThrottle. - RunCallback( - navigation_handle()->GetWebContents(), navigation_params, - should_ignore_callback_, - base::Bind(&InterceptNavigationThrottle::OnAsynchronousChecksPerformed, - weak_factory_.GetWeakPtr()), - weak_factory_.GetWeakPtr()); - - // DO NOT ADD CODE AFTER HERE: at this point the InterceptNavigationThrottle - // may have been destroyed by the |should_ignore_callback_|. Adding code here - // will cause use-after-free bugs. - // - // Code that needs to act on the result of the |should_ignore_callback_| - // should be put inside OnAsynchronousChecksPerformed. This function will be - // called after |should_ignore_callback_| has run, if this - // InterceptNavigationThrottle is still alive. -} - -void InterceptNavigationThrottle::OnAsynchronousChecksPerformed( - bool should_ignore_navigation, - bool throttle_was_destroyed) { - CHECK(!throttle_was_destroyed); - content::NavigationHandle* handle = navigation_handle(); - CHECK(handle); - if (should_ignore_navigation) { - navigation_handle()->CancelDeferredNavigation( - content::NavigationThrottle::CANCEL_AND_IGNORE); - } else { - handle->Resume(); - } + bool should_ignore_navigation = should_ignore_callback_.Run( + navigation_handle()->GetWebContents(), navigation_params); + return should_ignore_navigation + ? content::NavigationThrottle::CANCEL_AND_IGNORE + : content::NavigationThrottle::PROCEED; } } // namespace navigation_interception |