Commit 727acaba authored by mdjones's avatar mdjones Committed by Commit bot

Handle destroyed tab cases in Reader Mode

There are instances where callbacks and events can be triggered
and then the host tab for Reader Mode is destroyed. This change
adds checks for these cases.

BUG=556930, 556456, 556354

Review URL: https://codereview.chromium.org/1451103004

Cr-Commit-Position: refs/heads/master@{#361168}
parent 4cec7676
...@@ -299,9 +299,14 @@ public class ReaderModeManager extends TabModelSelectorTabObserver ...@@ -299,9 +299,14 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
boolean isMainFrame, String validatedUrl, boolean isErrorPage, boolean isMainFrame, String validatedUrl, boolean isErrorPage,
boolean isIframeSrcdoc) { boolean isIframeSrcdoc) {
if (!isMainFrame) return; 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)) { if (DomDistillerUrlUtils.isDistilledPage(validatedUrl)) {
mTabStatusMap.get(readerTabId).setStatus(STARTED); tabInfo.setStatus(STARTED);
closeReaderPanel(StateChangeReason.UNKNOWN, true); closeReaderPanel(StateChangeReason.UNKNOWN, true);
mReaderModePageUrl = validatedUrl; mReaderModePageUrl = validatedUrl;
} }
...@@ -316,16 +321,20 @@ public class ReaderModeManager extends TabModelSelectorTabObserver ...@@ -316,16 +321,20 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
if (isNavigationInPage) return; if (isNavigationInPage) return;
if (DomDistillerUrlUtils.isDistilledPage(url)) 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, if (!TextUtils.equals(url,
DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl( DomDistillerUrlUtils.getOriginalUrlFromDistillerUrl(
mReaderModePageUrl))) { mReaderModePageUrl))) {
mTabStatusMap.get(readerTabId).setStatus(NOT_POSSIBLE); tabInfo.setStatus(NOT_POSSIBLE);
mIsUmaRecorded = false; mIsUmaRecorded = false;
} }
mReaderModePageUrl = null; mReaderModePageUrl = null;
if (mTabStatusMap.containsKey(readerTabId)
&& mTabStatusMap.get(readerTabId).getStatus() != POSSIBLE) { if (tabInfo.getStatus() != POSSIBLE) {
closeReaderPanel(StateChangeReason.UNKNOWN, false); closeReaderPanel(StateChangeReason.UNKNOWN, false);
} else { } else {
requestReaderPanelShow(StateChangeReason.UNKNOWN); requestReaderPanelShow(StateChangeReason.UNKNOWN);
...@@ -409,10 +418,14 @@ public class ReaderModeManager extends TabModelSelectorTabObserver ...@@ -409,10 +418,14 @@ public class ReaderModeManager extends TabModelSelectorTabObserver
new DistillablePageUtils.PageDistillableDelegate() { new DistillablePageUtils.PageDistillableDelegate() {
@Override @Override
public void onIsPageDistillableResult(boolean isDistillable, boolean isLast) { public void onIsPageDistillableResult(boolean isDistillable, boolean isLast) {
if (!mTabStatusMap.containsKey(readerTabId)) return;
ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId); ReaderModeTabInfo tabInfo = mTabStatusMap.get(readerTabId);
Tab readerTab = mTabModelSelector.getTabById(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. // Make sure the page didn't navigate while waiting for a response.
if (!readerTab.getUrl().equals(tabInfo.getUrl())) return; if (!readerTab.getUrl().equals(tabInfo.getUrl())) return;
......
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