diff --git a/mobile/android/base/Tab.java b/mobile/android/base/Tab.java index 70c751d3da6..8ecf88b73c8 100644 --- a/mobile/android/base/Tab.java +++ b/mobile/android/base/Tab.java @@ -439,7 +439,8 @@ public final class Tab { if (!mReaderEnabled) return; - GeckoApp.mAppContext.loadUrl("about:reader?url=" + Uri.encode(getURL()) + + GeckoApp.mAppContext.loadUrl("about:reader?tabId=" + mId + + "&url=" + Uri.encode(getURL()) + "&readingList=" + (mReadingListItem ? 1 : 0)); } diff --git a/mobile/android/chrome/content/aboutReader.js b/mobile/android/chrome/content/aboutReader.js index 8127319785a..6b7091fc68d 100644 --- a/mobile/android/chrome/content/aboutReader.js +++ b/mobile/android/chrome/content/aboutReader.js @@ -90,15 +90,13 @@ let AboutReader = { this._updateToggleButton(); let url = queryArgs.url; - if (url) { + let tabId = queryArgs.tabId; + if (tabId) { + dump("Loading from tab with ID: " + tabId + ", URL: " + url); + this._loadFromTab(tabId, url); + } else { dump("Fetching page with URL: " + url); this._loadFromURL(url); - } else { - var tabId = queryArgs.tabId; - if (tabId) { - dump("Loading from tab with ID: " + tabId); - this._loadFromTab(tabId); - } } }, @@ -319,10 +317,10 @@ let AboutReader = { }.bind(this)); }, - _loadFromTab: function Reader_loadFromTab(tabId) { + _loadFromTab: function Reader_loadFromTab(tabId, url) { this._showProgress(); - gChromeWin.Reader.parseDocumentFromTab(tabId, function(article) { + gChromeWin.Reader.getArticleForTab(tabId, url, function(article) { if (article) this._showContent(article); else diff --git a/mobile/android/chrome/content/browser.js b/mobile/android/chrome/content/browser.js index 9877b187522..9376c383ef7 100644 --- a/mobile/android/chrome/content/browser.js +++ b/mobile/android/chrome/content/browser.js @@ -2101,6 +2101,7 @@ function Tab(aURL, aParams) { this.clickToPlayPluginsActivated = false; this.desktopMode = false; this.originalURI = null; + this.savedArticle = null; this.create(aURL, aParams); } @@ -2840,8 +2841,16 @@ Tab.prototype = { // Do nothing if there's no article or the page in this tab has // changed let tabURL = this.browser.currentURI.specIgnoringRef; - if (article == null || (article.url != tabURL)) + if (article == null || (article.url != tabURL)) { + // Don't clear the article for about:reader pages since we want to + // use the article from the previous page + if (!/^about:reader/i.test(tabURL)) + this.savedArticle = null; + return; + } + + this.savedArticle = article; sendMessageToJava({ gecko: { @@ -6348,7 +6357,8 @@ let Reader = { switch(aTopic) { case "Reader:Add": { let tab = BrowserApp.getTabForId(aData); - let url = tab.browser.contentWindow.location.href; + let currentURI = tab.browser.currentURI; + let url = currentURI.spec; let sendResult = function(success, title) { this.log("Reader:Add success=" + success + ", url=" + url + ", title=" + title); @@ -6363,7 +6373,7 @@ let Reader = { }); }.bind(this); - this.parseDocumentFromTab(aData, function(article) { + this.getArticleForTab(aData, currentURI.specIgnoringRef, function (article) { if (!article) { sendResult(false, ""); return; @@ -6423,6 +6433,18 @@ let Reader = { } }, + getArticleForTab: function Reader_getArticleForTab(tabId, url, callback) { + let tab = BrowserApp.getTabForId(tabId); + let article = tab.savedArticle; + + if (article && article.url == url) { + this.log("Saved article found in tab"); + callback(article); + } else { + this.parseDocumentFromURL(url, callback); + } + }, + parseDocumentFromTab: function(tabId, callback) { try { this.log("parseDocumentFromTab: " + tabId);