Commit 591e68b1 authored by mdjones's avatar mdjones Committed by Commit bot

Disable Reader Mode when requesting desktop site

If requesting a desktop site on mobile, Reader Mode will no longer
trigger unless its heuristic is set to ALWAYS_TRUE.

BUG=647086

Review-Url: https://codereview.chromium.org/2342873005
Cr-Commit-Position: refs/heads/master@{#419562}
parent 3ce23fa6
...@@ -59,9 +59,20 @@ public class DomDistillerTabUtils { ...@@ -59,9 +59,20 @@ public class DomDistillerTabUtils {
return nativeIsDistillerHeuristicsEnabled(); return nativeIsDistillerHeuristicsEnabled();
} }
/**
* Check if the distiller is reporting every page as distillable.
*
* @return True if heuristic is ALWAYS_TRUE.
*/
public static boolean isHeuristicAlwaysTrue() {
return nativeIsHeuristicAlwaysTrue();
}
private static native void nativeDistillCurrentPageAndView(WebContents webContents); private static native void nativeDistillCurrentPageAndView(WebContents webContents);
private static native void nativeDistillAndView( private static native void nativeDistillAndView(
WebContents sourceWebContents, WebContents destinationWebContents); WebContents sourceWebContents, WebContents destinationWebContents);
private static native String nativeGetFormattedUrlFromOriginalDistillerUrl(String url); private static native String nativeGetFormattedUrlFromOriginalDistillerUrl(String url);
private static native boolean nativeIsDistillerHeuristicsEnabled(); private static native boolean nativeIsDistillerHeuristicsEnabled();
private static native boolean nativeIsHeuristicAlwaysTrue();
} }
...@@ -92,6 +92,9 @@ public class ReaderModeManager extends TabModelSelectorTabObserver ...@@ -92,6 +92,9 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
// InfoBar tracking. // InfoBar tracking.
private boolean mIsInfoBarContainerShown; private boolean mIsInfoBarContainerShown;
// If Reader Mode is detecting all pages as distillable.
private boolean mIsReaderHeuristicAlwaysTrue;
public ReaderModeManager(TabModelSelector selector, ChromeActivity activity) { public ReaderModeManager(TabModelSelector selector, ChromeActivity activity) {
super(selector); super(selector);
...@@ -99,6 +102,15 @@ public class ReaderModeManager extends TabModelSelectorTabObserver ...@@ -99,6 +102,15 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
mTabModelSelector = selector; mTabModelSelector = selector;
mChromeActivity = activity; mChromeActivity = activity;
mTabStatusMap = new HashMap<>(); mTabStatusMap = new HashMap<>();
mIsReaderHeuristicAlwaysTrue = isDistillerHeuristicAlwaysTrue();
}
/**
* This function wraps a method that calls native code and is overridden by tests.
* @return True if the heuristic is ALWAYS_TRUE.
*/
protected boolean isDistillerHeuristicAlwaysTrue() {
return DomDistillerTabUtils.isHeuristicAlwaysTrue();
} }
/** /**
...@@ -508,7 +520,14 @@ public class ReaderModeManager extends TabModelSelectorTabObserver ...@@ -508,7 +520,14 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
int currentTabId = mTabModelSelector.getCurrentTabId(); int currentTabId = mTabModelSelector.getCurrentTabId();
if (currentTabId == Tab.INVALID_TAB_ID) return; if (currentTabId == Tab.INVALID_TAB_ID) return;
// Test if the user is requesting the desktop site. Ignore this if distiller is set to
// ALWAYS_TRUE.
boolean usingRequestDesktopSite = getBasePageWebContents() != null
&& getBasePageWebContents().getNavigationController().getUseDesktopUserAgent()
&& !mIsReaderHeuristicAlwaysTrue;
if (mReaderModePanel == null || !mTabStatusMap.containsKey(currentTabId) if (mReaderModePanel == null || !mTabStatusMap.containsKey(currentTabId)
|| usingRequestDesktopSite
|| mTabStatusMap.get(currentTabId).getStatus() != POSSIBLE || mTabStatusMap.get(currentTabId).getStatus() != POSSIBLE
|| mTabStatusMap.get(currentTabId).isDismissed() || mTabStatusMap.get(currentTabId).isDismissed()
|| mIsInfoBarContainerShown || mIsInfoBarContainerShown
......
...@@ -79,6 +79,11 @@ public class ReaderModeManagerTest extends InstrumentationTestCase { ...@@ -79,6 +79,11 @@ public class ReaderModeManagerTest extends InstrumentationTestCase {
return null; return null;
} }
@Override
protected boolean isDistillerHeuristicAlwaysTrue() {
return true;
}
@Override @Override
protected void recordPanelVisibilityForNavigation(boolean visible) { protected void recordPanelVisibilityForNavigation(boolean visible) {
mRecordedCount++; mRecordedCount++;
......
...@@ -68,6 +68,13 @@ jboolean IsDistillerHeuristicsEnabled(JNIEnv* env, ...@@ -68,6 +68,13 @@ jboolean IsDistillerHeuristicsEnabled(JNIEnv* env,
!= dom_distiller::DistillerHeuristicsType::NONE; != dom_distiller::DistillerHeuristicsType::NONE;
} }
// Returns true if distiller is reporting every page as distillable.
jboolean IsHeuristicAlwaysTrue(JNIEnv* env,
const JavaParamRef<jclass>& clazz) {
return dom_distiller::GetDistillerHeuristicsType()
== dom_distiller::DistillerHeuristicsType::ALWAYS_TRUE;
}
} // namespace android } // namespace android
bool RegisterDomDistillerTabUtils(JNIEnv* env) { bool RegisterDomDistillerTabUtils(JNIEnv* env) {
......
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