| Index: chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java
|
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java
|
| index 1cf61ad2cda32070f1e9b05faf3ec49c0272dd38..7d4f59cfdb9d2bc2ce450192f8535ab4bd6a85c7 100644
|
| --- a/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java
|
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java
|
| @@ -4,7 +4,11 @@
|
|
|
| package org.chromium.chrome.browser.dom_distiller;
|
|
|
| +import android.app.Activity;
|
| import android.content.Context;
|
| +import android.content.Intent;
|
| +import android.net.Uri;
|
| +import android.support.customtabs.CustomTabsIntent;
|
| import android.text.TextUtils;
|
|
|
| import org.chromium.base.ApiCompatibilityUtils;
|
| @@ -17,7 +21,9 @@ import org.chromium.chrome.browser.ChromeSwitches;
|
| import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.PanelState;
|
| import org.chromium.chrome.browser.compositor.bottombar.OverlayPanel.StateChangeReason;
|
| import org.chromium.chrome.browser.compositor.bottombar.readermode.ReaderModePanel;
|
| +import org.chromium.chrome.browser.customtabs.CustomTabActivity;
|
| import org.chromium.chrome.browser.device.DeviceClassManager;
|
| +import org.chromium.chrome.browser.document.ChromeLauncherActivity;
|
| import org.chromium.chrome.browser.infobar.InfoBar;
|
| import org.chromium.chrome.browser.infobar.InfoBarContainer;
|
| import org.chromium.chrome.browser.infobar.InfoBarContainer.InfoBarContainerObserver;
|
| @@ -26,9 +32,13 @@ import org.chromium.chrome.browser.tabmodel.TabCreatorManager;
|
| import org.chromium.chrome.browser.tabmodel.TabModel;
|
| import org.chromium.chrome.browser.tabmodel.TabModelSelector;
|
| import org.chromium.chrome.browser.tabmodel.TabModelSelectorTabObserver;
|
| +import org.chromium.chrome.browser.util.IntentUtils;
|
| import org.chromium.chrome.browser.widget.findinpage.FindToolbarObserver;
|
| import org.chromium.components.dom_distiller.content.DistillablePageUtils;
|
| import org.chromium.components.dom_distiller.core.DomDistillerUrlUtils;
|
| +import org.chromium.components.navigation_interception.InterceptNavigationDelegate;
|
| +import org.chromium.components.navigation_interception.NavigationParams;
|
| +import org.chromium.content.browser.ContentViewCore;
|
| import org.chromium.content_public.browser.LoadUrlParams;
|
| import org.chromium.content_public.browser.WebContents;
|
| import org.chromium.content_public.browser.WebContentsObserver;
|
| @@ -48,21 +58,22 @@ import java.util.concurrent.TimeUnit;
|
| public class ReaderModeManager extends TabModelSelectorTabObserver
|
| implements InfoBarContainerObserver, ReaderModeManagerDelegate {
|
|
|
| - /**
|
| - * POSSIBLE means reader mode can be entered.
|
| - */
|
| + /** POSSIBLE means reader mode can be entered. */
|
| public static final int POSSIBLE = 0;
|
|
|
| - /**
|
| - * NOT_POSSIBLE means reader mode cannot be entered.
|
| - */
|
| + /** NOT_POSSIBLE means reader mode cannot be entered. */
|
| public static final int NOT_POSSIBLE = 1;
|
|
|
| - /**
|
| - * STARTED means reader mode is currently in reader mode.
|
| - */
|
| + /** STARTED means reader mode is currently in reader mode. */
|
| public static final int STARTED = 2;
|
|
|
| + /** The scheme used to access DOM-Distiller. */
|
| + public static final String DOM_DISTILLER_SCHEME = "chrome-distiller";
|
| +
|
| + /** The intent extra that indicates origin from Reader Mode */
|
| + public static final String EXTRA_READER_MODE_PARENT =
|
| + "org.chromium.chrome.browser.dom_distiller.EXTRA_READER_MODE_PARENT";
|
| +
|
| // The url of the last page visited if the last page was reader mode page. Otherwise null.
|
| private String mReaderModePageUrl;
|
|
|
| @@ -84,6 +95,12 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
|
| // The primary means of getting the currently active tab.
|
| private TabModelSelector mTabModelSelector;
|
|
|
| + // If the activity this manager is associated with is a custom tab.
|
| + private boolean mIsCustomTab;
|
| +
|
| + // Hold on to the InterceptNavigationDelegate that the custom tab uses.
|
| + InterceptNavigationDelegate mCustomTabNavigationDelegate;
|
| +
|
| private final int mHeaderBackgroundColor;
|
| private boolean mIsFullscreenModeEntered;
|
| private boolean mIsFindToolbarShowing;
|
| @@ -145,9 +162,53 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
|
| };
|
| }
|
|
|
| + /**
|
| + * Notify the manager that the current activity is a custom tab.
|
| + */
|
| + public void setIsCustomTab() {
|
| + mIsCustomTab = true;
|
| + }
|
| +
|
| // TabModelSelectorTabObserver:
|
|
|
| @Override
|
| + public void onLoadUrl(Tab tab, LoadUrlParams params, int loadType) {
|
| + // If a distiller URL was loaded and this is a custom tab, add a navigation
|
| + // handler to bring any navigations back to the main chrome activity.
|
| + if (tab == null || !mIsCustomTab
|
| + || !DomDistillerUrlUtils.isDistilledPage(params.getUrl())) {
|
| + return;
|
| + }
|
| +
|
| + ContentViewCore cvc = tab.getContentViewCore();
|
| + if (cvc == null) return;
|
| +
|
| + mCustomTabNavigationDelegate = new InterceptNavigationDelegate() {
|
| + @Override
|
| + public boolean shouldIgnoreNavigation(NavigationParams params) {
|
| + if (DomDistillerUrlUtils.isDistilledPage(params.url) || params.isExternalProtocol) {
|
| + return false;
|
| + }
|
| +
|
| + Intent returnIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(params.url));
|
| + returnIntent.setClassName(mChromeActivity, ChromeLauncherActivity.class.getName());
|
| +
|
| + // Set the parent ID of the tab to be created.
|
| + returnIntent.putExtra(EXTRA_READER_MODE_PARENT,
|
| + IntentUtils.safeGetInt(mChromeActivity.getIntent().getExtras(),
|
| + EXTRA_READER_MODE_PARENT, Tab.INVALID_TAB_ID));
|
| +
|
| + mChromeActivity.startActivity(returnIntent);
|
| + mChromeActivity.finish();
|
| + return true;
|
| + }
|
| + };
|
| +
|
| + DomDistillerTabUtils.setInterceptNavigationDelegate(mCustomTabNavigationDelegate,
|
| + cvc.getWebContents());
|
| + }
|
| +
|
| + @Override
|
| public void onShown(Tab shownTab) {
|
| int shownTabId = shownTab.getId();
|
|
|
| @@ -383,6 +444,11 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
|
| }
|
| }
|
|
|
| + @Override
|
| + public boolean supportsOverlayPanelUI() {
|
| + return !SysUtils.isLowEndDevice();
|
| + }
|
| +
|
| /**
|
| * @return True if the keyboard might be showing. This is not 100% accurate; see
|
| * UiUtils.isKeyboardShowing(...).
|
| @@ -497,6 +563,7 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
|
| * Open a link from the panel in a new tab.
|
| * @param url The URL to load.
|
| */
|
| + @Override
|
| public void createNewTab(String url) {
|
| if (mChromeActivity == null) return;
|
|
|
| @@ -511,6 +578,29 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
|
| TabModel.TabLaunchType.FROM_LINK, mChromeActivity.getActivityTab());
|
| }
|
|
|
| + @Override
|
| + public void distillInCustomTab() {
|
| + WebContents baseWebContents = getBasePageWebContents();
|
| + if (baseWebContents == null || mChromeActivity == null || mTabModelSelector == null) return;
|
| +
|
| + String url = baseWebContents.getUrl();
|
| + if (url == null) return;
|
| +
|
| + String distillerUrl =
|
| + DomDistillerUrlUtils.getDistillerViewUrlFromUrl(DOM_DISTILLER_SCHEME, url);
|
| +
|
| + Intent customTabIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(distillerUrl));
|
| + customTabIntent.setClassName(mChromeActivity, CustomTabActivity.class.getName());
|
| +
|
| + customTabIntent.putExtra(CustomTabsIntent.EXTRA_TITLE_VISIBILITY_STATE,
|
| + CustomTabsIntent.SHOW_PAGE_TITLE);
|
| +
|
| + // Add the parent ID as an intent extra for back button functionality.
|
| + customTabIntent.putExtra(EXTRA_READER_MODE_PARENT, mTabModelSelector.getCurrentTabId());
|
| +
|
| + mChromeActivity.startActivity(customTabIntent);
|
| + }
|
| +
|
| /**
|
| * @return Whether the Reader Mode panel is opened (state is EXPANDED or MAXIMIZED).
|
| */
|
| @@ -586,8 +676,18 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
|
| && !CommandLine.getInstance().hasSwitch(
|
| ChromeSwitches.DISABLE_READER_MODE_BOTTOM_BAR)
|
| && !DeviceFormFactor.isTablet(context)
|
| - && DomDistillerTabUtils.isDistillerHeuristicsEnabled()
|
| - && !SysUtils.isLowEndDevice();
|
| + && DomDistillerTabUtils.isDistillerHeuristicsEnabled();
|
| return enabled;
|
| }
|
| +
|
| + /**
|
| + * Determine if Reader Mode created the intent for a tab being created.
|
| + * @param activity The current Activity handling the intent.
|
| + * @param intent The Intent creating a new tab.
|
| + * @return True if the intent was created by Reader Mode.
|
| + */
|
| + public static boolean isReaderModeCreatedIntent(Activity activity, Intent intent) {
|
| + return activity != null && intent != null && isEnabled(activity)
|
| + && intent.getExtras().containsKey(EXTRA_READER_MODE_PARENT);
|
| + }
|
| }
|
|
|