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 ...@@ -82,6 +82,8 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
// Handles overscroll history navigation. // Handles overscroll history navigation.
private NavigationHandler mNavigationHandler; private NavigationHandler mNavigationHandler;
private NavigationHandler.ActionDelegate mActionDelegate;
public static SwipeRefreshHandler from(Tab tab) { public static SwipeRefreshHandler from(Tab tab) {
SwipeRefreshHandler handler = get(tab); SwipeRefreshHandler handler = get(tab);
if (handler == null) { if (handler == null) {
...@@ -172,6 +174,7 @@ public class SwipeRefreshHandler extends TabWebContentsUserData ...@@ -172,6 +174,7 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
if (mNavigationHandler != null) { if (mNavigationHandler != null) {
mNavigationHandler.destroy(); mNavigationHandler.destroy();
mNavigationHandler = null; mNavigationHandler = null;
mActionDelegate = null;
} }
setEnabled(false); setEnabled(false);
} }
...@@ -219,7 +222,7 @@ public class SwipeRefreshHandler extends TabWebContentsUserData ...@@ -219,7 +222,7 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
return mSwipeRefreshLayout.start(); return mSwipeRefreshLayout.start();
} else if (type == OverscrollAction.HISTORY_NAVIGATION) { } else if (type == OverscrollAction.HISTORY_NAVIGATION) {
if (mNavigationHandler != null) { if (mNavigationHandler != null) {
boolean navigable = navigateForward ? mTab.canGoForward() : mTab.canGoBack(); boolean navigable = mActionDelegate.canNavigate(navigateForward);
boolean showGlow = navigateForward && !mTab.canGoForward(); boolean showGlow = navigateForward && !mTab.canGoForward();
mNavigationHandler.onDown(); // Simulates the initial onDown event. mNavigationHandler.onDown(); // Simulates the initial onDown event.
if (navigable) { if (navigable) {
...@@ -237,8 +240,8 @@ public class SwipeRefreshHandler extends TabWebContentsUserData ...@@ -237,8 +240,8 @@ public class SwipeRefreshHandler extends TabWebContentsUserData
private void updateNavigationHandler() { private void updateNavigationHandler() {
if (mNavigationDelegate.isNavigationEnabled(mContainerView)) { if (mNavigationDelegate.isNavigationEnabled(mContainerView)) {
if (mNavigationHandler == null) { if (mNavigationHandler == null) {
mNavigationHandler = new NavigationHandler(mContainerView, mActionDelegate = mNavigationDelegate.createActionDelegate();
mNavigationDelegate.createActionDelegate(), mNavigationHandler = new NavigationHandler(mContainerView, mActionDelegate,
NavigationGlowFactory.forRenderedPage( NavigationGlowFactory.forRenderedPage(
mContainerView, mTab.getWebContents())); mContainerView, mTab.getWebContents()));
} }
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
package org.chromium.chrome.browser.gesturenav; package org.chromium.chrome.browser.gesturenav;
import android.os.Handler;
import org.chromium.chrome.browser.tab.Tab; import org.chromium.chrome.browser.tab.Tab;
/** /**
...@@ -13,6 +15,7 @@ import org.chromium.chrome.browser.tab.Tab; ...@@ -13,6 +15,7 @@ import org.chromium.chrome.browser.tab.Tab;
*/ */
public class TabbedActionDelegate implements NavigationHandler.ActionDelegate { public class TabbedActionDelegate implements NavigationHandler.ActionDelegate {
private final Tab mTab; private final Tab mTab;
private final Handler mHandler = new Handler();
public TabbedActionDelegate(Tab tab) { public TabbedActionDelegate(Tab tab) {
mTab = tab; mTab = tab;
...@@ -28,7 +31,10 @@ public class TabbedActionDelegate implements NavigationHandler.ActionDelegate { ...@@ -28,7 +31,10 @@ public class TabbedActionDelegate implements NavigationHandler.ActionDelegate {
if (forward) { if (forward) {
mTab.goForward(); mTab.goForward();
} else { } 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