Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(829)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/dom_distiller/ReaderModeManager.java

Issue 1784093002: Ensure tab is valid when distiller callback is set (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get tab by id Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 8cc347dffb5341dbf0309f2e5dbdaa2bc90f187b..b1563e7faa3d4d8c6555ec813fa80d5a6b554e65 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
@@ -183,7 +183,7 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
}
// Make sure there is a distillability delegate set on the WebContents.
- setDistillabilityCallback();
+ setDistillabilityCallback(shownTabId);
requestReaderPanelShow(StateChangeReason.UNKNOWN);
}
@@ -239,7 +239,7 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
closeReaderPanel(StateChangeReason.CONTENT_CHANGED, true);
}
// Make sure there is a distillability delegate set on the WebContents.
- setDistillabilityCallback();
+ setDistillabilityCallback(tab.getId());
}
if (tab.getInfoBarContainer() != null) tab.getInfoBarContainer().addObserver(this);
@@ -502,17 +502,21 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
return mReaderModePanel.isPanelOpened();
}
- // Set the callback for updating reader mode status based on whether or not the page should
- // be viewed in reader mode.
- private void setDistillabilityCallback() {
- Tab currentTab = mTabModelSelector.getCurrentTab();
- if (currentTab == null || currentTab.getWebContents() == null
- || currentTab.getContentViewCore() == null) {
+ /**
+ * Set the callback for updating reader mode status based on whether or not the page should
+ * be viewed in reader mode.
+ * @param tabId The ID of the tab having its callback set.
+ */
+ private void setDistillabilityCallback(final int tabId) {
+ if (tabId == Tab.INVALID_TAB_ID || mTabStatusMap.get(tabId).isCallbackSet()) {
return;
}
- final int readerTabId = currentTab.getId();
- if (mTabStatusMap.get(readerTabId).isCallbackSet()) {
+ if (mTabModelSelector == null) return;
+
+ Tab currentTab = mTabModelSelector.getTabById(tabId);
+ if (currentTab == null || currentTab.getWebContents() == null
+ || currentTab.getContentViewCore() == null) {
return;
}
@@ -522,8 +526,8 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
public void onIsPageDistillableResult(boolean isDistillable, boolean isLast) {
if (mTabModelSelector == null) return;
- ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
- Tab readerTab = mTabModelSelector.getTabById(readerTabId);
+ ReaderModeTabInfo tabInfo = mTabStatusMap.get(tabId);
+ Tab readerTab = mTabModelSelector.getTabById(tabId);
// It is possible that the tab was destroyed before this callback happens.
// TODO(wychen/mdjones): Remove the callback when a Tab/WebContents is
@@ -536,7 +540,7 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
if (isDistillable) {
tabInfo.setStatus(POSSIBLE);
// The user may have changed tabs.
- if (readerTabId == mTabModelSelector.getCurrentTabId()) {
+ if (tabId == mTabModelSelector.getCurrentTabId()) {
// TODO(mdjones): Add reason DISTILLER_STATE_CHANGE.
requestReaderPanelShow(StateChangeReason.UNKNOWN);
}
@@ -551,7 +555,7 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
}
}
});
- mTabStatusMap.get(readerTabId).setIsCallbackSet(true);
+ mTabStatusMap.get(tabId).setIsCallbackSet(true);
}
/**
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698