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

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

Issue 1451103004: Handle destroyed tab cases in Reader Mode (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 1 month 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 e00460f7d23dc8e50a67e8f5bb12e53d62f3a422..b0cbabcd76b3bb5ba1dd814b18ec88cfc2f056d6 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
@@ -299,9 +299,14 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
boolean isMainFrame, String validatedUrl, boolean isErrorPage,
boolean isIframeSrcdoc) {
if (!isMainFrame) return;
- mTabStatusMap.get(readerTabId).setUrl(validatedUrl);
+
+ // Make sure the tab was not destroyed.
+ ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
+ if (tabInfo == null) return;
+
+ tabInfo.setUrl(validatedUrl);
if (DomDistillerUrlUtils.isDistilledPage(validatedUrl)) {
- mTabStatusMap.get(readerTabId).setStatus(STARTED);
+ tabInfo.setStatus(STARTED);
closeReaderPanel(StateChangeReason.UNKNOWN, true);
mReaderModePageUrl = validatedUrl;
}
@@ -316,16 +321,20 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
if (isNavigationInPage) return;
if (DomDistillerUrlUtils.isDistilledPage(url)) return;
- mTabStatusMap.get(readerTabId).setStatus(POSSIBLE);
+ // Make sure the tab was not destroyed.
+ ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
+ if (tabInfo == null) return;
+
+ tabInfo.setStatus(POSSIBLE);
if (!TextUtils.equals(url,
DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(
mReaderModePageUrl))) {
- mTabStatusMap.get(readerTabId).setStatus(NOT_POSSIBLE);
+ tabInfo.setStatus(NOT_POSSIBLE);
mIsUmaRecorded = false;
}
mReaderModePageUrl = null;
- if (mTabStatusMap.containsKey(readerTabId)
- && mTabStatusMap.get(readerTabId).getStatus() != POSSIBLE) {
+
+ if (tabInfo.getStatus() != POSSIBLE) {
closeReaderPanel(StateChangeReason.UNKNOWN, false);
} else {
requestReaderPanelShow(StateChangeReason.UNKNOWN);
@@ -409,10 +418,14 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
new DistillablePageUtils.PageDistillableDelegate() {
@Override
public void onIsPageDistillableResult(boolean isDistillable, boolean isLast) {
- if (!mTabStatusMap.containsKey(readerTabId)) return;
ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
-
Tab readerTab = mTabModelSelector.getTabById(readerTabId);
+
+ // It is possible that the tab was destroyed before this callback happens.
+ // TODO(wychen/mdjones): Remove the callback when a Tab/WebContents is
+ // destroyed so that this never happens.
+ if (readerTab == null || tabInfo == null) return;
+
// Make sure the page didn't navigate while waiting for a response.
if (!readerTab.getUrl().equals(tabInfo.getUrl())) return;
« 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