зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1265004 - Try to save in-memory reader view article instead of downloading r=margaret
This should guarantee that any reader view page will also be successfully saved offline. MozReview-Commit-ID: 4J8cY6hYeyU --HG-- extra : rebase_source : 689a2db7a7d81dbe89e5e58c170afe473563b2f6
This commit is contained in:
Родитель
e6d9dc2dd7
Коммит
d4c9f99c6b
|
@ -553,7 +553,7 @@ public class Tab {
|
|||
});
|
||||
|
||||
if (AboutPages.isAboutReader(url)) {
|
||||
ReadingListHelper.cacheReaderItem(pageUrl, mAppContext);
|
||||
ReadingListHelper.cacheReaderItem(pageUrl, mId, mAppContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ public final class ReadingListHelper implements NativeEventListener {
|
|||
rch.put(url, path, size);
|
||||
}
|
||||
|
||||
public static void cacheReaderItem(final String url, Context context) {
|
||||
public static void cacheReaderItem(final String url, final int tabID, Context context) {
|
||||
if (AboutPages.isAboutReader(url)) {
|
||||
throw new IllegalArgumentException("Page url must be original (not about:reader) url");
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ public final class ReadingListHelper implements NativeEventListener {
|
|||
SavedReaderViewHelper rch = SavedReaderViewHelper.getSavedReaderViewHelper(context);
|
||||
|
||||
if (!rch.isURLCached(url)) {
|
||||
GeckoAppShell.notifyObservers("Reader:AddToCache", url);
|
||||
GeckoAppShell.notifyObservers("Reader:AddToCache", Integer.toString(tabID));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -82,8 +82,13 @@ var Reader = {
|
|||
}
|
||||
|
||||
case "Reader:AddToCache": {
|
||||
let tab = BrowserApp.getTabForId(aData);
|
||||
if (!tab) {
|
||||
throw new Error("No tab for tabID = " + aData + " when trying to save reader view article");
|
||||
}
|
||||
|
||||
// If the article is coming from reader mode, we must have fetched it already.
|
||||
this._getArticle(aData).then((article) => {
|
||||
this._getArticleData(tab.browser).then((article) => {
|
||||
ReaderMode.storeArticleInCache(article);
|
||||
}).catch(e => Cu.reportError("Error storing article in cache: " + e));
|
||||
break;
|
||||
|
@ -281,6 +286,23 @@ var Reader = {
|
|||
});
|
||||
}),
|
||||
|
||||
_getArticleData: function(browser) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (browser == null) {
|
||||
reject("_getArticleData needs valid browser");
|
||||
}
|
||||
|
||||
let mm = browser.messageManager;
|
||||
let listener = (message) => {
|
||||
mm.removeMessageListener("Reader:StoredArticleData", listener);
|
||||
resolve(message.data.article);
|
||||
};
|
||||
mm.addMessageListener("Reader:StoredArticleData", listener);
|
||||
mm.sendAsyncMessage("Reader:GetStoredArticleData");
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Migrates old indexedDB reader mode cache to new JSON cache.
|
||||
*/
|
||||
|
|
|
@ -37,6 +37,7 @@ var AboutReader = function(mm, win, articlePromise) {
|
|||
this._mm.addMessageListener("Reader:CloseDropdown", this);
|
||||
this._mm.addMessageListener("Reader:AddButton", this);
|
||||
this._mm.addMessageListener("Reader:RemoveButton", this);
|
||||
this._mm.addMessageListener("Reader:GetStoredArticleData", this);
|
||||
|
||||
this._docRef = Cu.getWeakReference(doc);
|
||||
this._winRef = Cu.getWeakReference(win);
|
||||
|
@ -205,6 +206,9 @@ AboutReader.prototype = {
|
|||
}
|
||||
break;
|
||||
}
|
||||
case "Reader:GetStoredArticleData": {
|
||||
this._mm.sendAsyncMessage("Reader:StoredArticleData", { article: this._article });
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -253,6 +257,7 @@ AboutReader.prototype = {
|
|||
this._mm.removeMessageListener("Reader:CloseDropdown", this);
|
||||
this._mm.removeMessageListener("Reader:AddButton", this);
|
||||
this._mm.removeMessageListener("Reader:RemoveButton", this);
|
||||
this._mm.removeMessageListener("Reader:GetStoredArticleData", this);
|
||||
this._windowUnloaded = true;
|
||||
break;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче