Commit 968c2dfa authored by Jinsuk Kim's avatar Jinsuk Kim Committed by Commit Bot

Android: Fix gesture navigation not working on a new tab

Gesture navigation on rendered pages opened via 'open in a new tab'
was not working due to a bug in the logic determining the activation
of its UI. This CL fixes the bug by having it use the same logic
used by native pages.

Bug: 989729

Change-Id: Ifdf6df5fa4ec5a7ce592167d16c5c63434c27b94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728535Reviewed-by: default avatarTheresa  <twellington@chromium.org>
Reviewed-by: default avatarMatthew Jones <mdjones@chromium.org>
Commit-Queue: Jinsuk Kim <jinsukkim@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683397}
parent cd10c5b3
......@@ -82,6 +82,8 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
// Handles overscroll history navigation.
private NavigationHandler mNavigationHandler;
private NavigationHandler.ActionDelegate mActionDelegate;
public static SwipeRefreshHandler from(Tab tab) {
SwipeRefreshHandler handler = get(tab);
if (handler == null) {
......@@ -172,6 +174,7 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
if (mNavigationHandler != null) {
mNavigationHandler.destroy();
mNavigationHandler = null;
mActionDelegate = null;
}
setEnabled(false);
}
......@@ -219,7 +222,7 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
return mSwipeRefreshLayout.start();
} else if (type == OverscrollAction.HISTORY_NAVIGATION) {
if (mNavigationHandler != null) {
boolean navigable = navigateForward ? mTab.canGoForward() : mTab.canGoBack();
boolean navigable = mActionDelegate.canNavigate(navigateForward);
boolean showGlow = navigateForward && !mTab.canGoForward();
mNavigationHandler.onDown(); // Simulates the initial onDown event.
if (navigable) {
......@@ -237,8 +240,8 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
private void updateNavigationHandler() {
if (mNavigationDelegate.isNavigationEnabled(mContainerView)) {
if (mNavigationHandler == null) {
mNavigationHandler = new NavigationHandler(mContainerView,
mNavigationDelegate.createActionDelegate(),
mActionDelegate = mNavigationDelegate.createActionDelegate();
mNavigationHandler = new NavigationHandler(mContainerView, mActionDelegate,
NavigationGlowFactory.forRenderedPage(
mContainerView, mTab.getWebContents()));
}
......
......@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.gesturenav;
import android.os.Handler;
import org.chromium.chrome.browser.tab.Tab;
/**
......@@ -13,6 +15,7 @@ import org.chromium.chrome.browser.tab.Tab;
*/
public class TabbedActionDelegate implements NavigationHandler.ActionDelegate {
private final Tab mTab;
private final Handler mHandler = new Handler();
public TabbedActionDelegate(Tab tab) {
mTab = tab;
......@@ -28,7 +31,10 @@ public class TabbedActionDelegate implements NavigationHandler.ActionDelegate {
if (forward) {
mTab.goForward();
} else {
mTab.getActivity().onBackPressed();
// Perform back action at the next UI thread execution. The back action can
// potentially close the tab we're running on, which causes use-after-destroy
// exception if the closing operation is performed synchronously.
mHandler.post(() -> mTab.getActivity().onBackPressed());
}
}
......
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