| 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 43d17175731ece906cb2c591d73696a62ede99d7..9355a6934f1b94afcb6a2f566650db75d1d2bde8 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
|
| @@ -81,6 +81,8 @@ public class ReaderModeManager extends EmptyTabObserver
|
| */
|
| private boolean mIsUmaRecorded;
|
|
|
| + private boolean mIsCallbackSet;
|
| +
|
| private WebContentsObserver mWebContentsObserver;
|
|
|
| private final Tab mTab;
|
| @@ -100,6 +102,7 @@ public class ReaderModeManager extends EmptyTabObserver
|
| ? ApiCompatibilityUtils.getColor(
|
| context.getResources(), R.color.reader_mode_header_bg)
|
| : 0;
|
| + mIsCallbackSet = false;
|
| }
|
|
|
| /**
|
| @@ -247,21 +250,6 @@ public class ReaderModeManager extends EmptyTabObserver
|
| private WebContentsObserver createWebContentsObserver(WebContents webContents) {
|
| return new WebContentsObserver(webContents) {
|
| @Override
|
| - public void didFinishLoad(long frameId, String validatedUrl, boolean isMainFrame) {
|
| - if (!isMainFrame) return;
|
| - if (DomDistillerUrlUtils.isDistilledPage(mTab.getUrl())) return;
|
| - updateStatusBasedOnReaderModeCriteria(true);
|
| - }
|
| -
|
| - @Override
|
| - public void didFailLoad(boolean isProvisionalLoad, boolean isMainFrame, int errorCode,
|
| - String description, String failingUrl, boolean wasIgnoredByHandler) {
|
| - if (!isMainFrame) return;
|
| - if (DomDistillerUrlUtils.isDistilledPage(mTab.getUrl())) return;
|
| - updateStatusBasedOnReaderModeCriteria(true);
|
| - }
|
| -
|
| - @Override
|
| public void didStartProvisionalLoadForFrame(long frameId, long parentFrameId,
|
| boolean isMainFrame, String validatedUrl, boolean isErrorPage,
|
| boolean isIframeSrcdoc) {
|
| @@ -288,8 +276,7 @@ public class ReaderModeManager extends EmptyTabObserver
|
| mReaderModePageUrl))) {
|
| mReaderModeStatus = NOT_POSSIBLE;
|
| mIsUmaRecorded = false;
|
| - // Do not call updateStatusBasedOnReaderModeCriteria here.
|
| - // For ADABOOST_MODEL, it is unlikely to get valid info at this event.
|
| + if (!mIsCallbackSet) setDistillabilityCallback();
|
| }
|
| mReaderModePageUrl = null;
|
| sendReaderModeStatusChangedNotification();
|
| @@ -297,22 +284,22 @@ public class ReaderModeManager extends EmptyTabObserver
|
| };
|
| }
|
|
|
| - // Updates reader mode status based on whether or not the page should be viewed in reader mode.
|
| - private void updateStatusBasedOnReaderModeCriteria(final boolean forceRecord) {
|
| + // Set the callback for updating reader mode status based on whether or not the page should
|
| + // be viewed in reader mode.
|
| + private void setDistillabilityCallback() {
|
| if (mTab.getWebContents() == null) return;
|
| if (mTab.getContentViewCore() == null) return;
|
|
|
| - DistillablePageUtils.isPageDistillable(mTab.getWebContents(),
|
| - mTab.getContentViewCore().getIsMobileOptimizedHint(),
|
| + DistillablePageUtils.setCallback(mTab.getWebContents(),
|
| new DistillablePageUtils.PageDistillableCallback() {
|
| @Override
|
| - public void onIsPageDistillableResult(boolean isDistillable) {
|
| + public void onIsPageDistillableResult(boolean isDistillable, boolean isLast) {
|
| if (isDistillable) {
|
| mReaderModeStatus = POSSIBLE;
|
| } else {
|
| mReaderModeStatus = NOT_POSSIBLE;
|
| }
|
| - if (!mIsUmaRecorded && (mReaderModeStatus == POSSIBLE || forceRecord)) {
|
| + if (!mIsUmaRecorded && (mReaderModeStatus == POSSIBLE || isLast)) {
|
| mIsUmaRecorded = true;
|
| RecordHistogram.recordBooleanHistogram(
|
| "DomDistiller.PageDistillable", mReaderModeStatus == POSSIBLE);
|
| @@ -320,6 +307,7 @@ public class ReaderModeManager extends EmptyTabObserver
|
| sendReaderModeStatusChangedNotification();
|
| }
|
| });
|
| + mIsCallbackSet = true;
|
| }
|
|
|
| private void sendReaderModeStatusChangedNotification() {
|
|
|