Bug 782421 - Use parsed result for reader articles. r=lucasr

This commit is contained in:
Brian Nicholson 2012-08-14 17:29:40 -04:00
parent 8973b4d41e
commit 39ea6bd8b8
3 changed files with 34 additions and 13 deletions

View File

@ -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));
}

View File

@ -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

View File

@ -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);