mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1146773 - Unify the code paths for adding an item to the reading list (location bar + reader mode). r=margaret
This commit is contained in:
parent
ab96b15185
commit
39382eb1e1
@ -421,7 +421,7 @@ ReadingListImpl.prototype = {
|
||||
* @return {Promise} Promise that is fullfilled with the added item.
|
||||
*/
|
||||
addItemFromBrowser: Task.async(function* (browser, url) {
|
||||
let metadata = yield getMetadataFromBrowser(browser);
|
||||
let metadata = yield this.getMetadataFromBrowser(browser);
|
||||
let record = {
|
||||
url: url,
|
||||
title: metadata.title,
|
||||
@ -436,6 +436,25 @@ ReadingListImpl.prototype = {
|
||||
return (yield this.addItem(record));
|
||||
}),
|
||||
|
||||
/**
|
||||
* Get page metadata from the content document in a given <xul:browser>.
|
||||
* @see PageMetadata.jsm
|
||||
*
|
||||
* @param {<xul:browser>} browser - Browser element for the document.
|
||||
* @returns {Promise} Promise that is fulfilled with an object describing the metadata.
|
||||
*/
|
||||
getMetadataFromBrowser(browser) {
|
||||
let mm = browser.messageManager;
|
||||
return new Promise(resolve => {
|
||||
function handleResult(msg) {
|
||||
mm.removeMessageListener("PageMetadata:PageDataResult", handleResult);
|
||||
resolve(msg.json);
|
||||
}
|
||||
mm.addMessageListener("PageMetadata:PageDataResult", handleResult);
|
||||
mm.sendAsyncMessage("PageMetadata:GetPageData");
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Adds a listener that will be notified when the list changes. Listeners
|
||||
* are objects with the following optional methods:
|
||||
@ -1043,25 +1062,6 @@ function clone(obj) {
|
||||
return Cu.cloneInto(obj, {}, { cloneFunctions: false });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get page metadata from the content document in a given <xul:browser>.
|
||||
* @see PageMetadata.jsm
|
||||
*
|
||||
* @param {<xul:browser>} browser - Browser element for the document.
|
||||
* @returns {Promise} Promise that is fulfilled with an object describing the metadata.
|
||||
*/
|
||||
function getMetadataFromBrowser(browser) {
|
||||
let mm = browser.messageManager;
|
||||
return new Promise(resolve => {
|
||||
function handleResult(msg) {
|
||||
mm.removeMessageListener("PageMetadata:PageDataResult", handleResult);
|
||||
resolve(msg.json);
|
||||
}
|
||||
mm.addMessageListener("PageMetadata:PageDataResult", handleResult);
|
||||
mm.sendAsyncMessage("PageMetadata:GetPageData");
|
||||
});
|
||||
}
|
||||
|
||||
Object.defineProperty(this, "ReadingList", {
|
||||
get() {
|
||||
if (!this._singleton) {
|
||||
|
@ -45,11 +45,17 @@ let ReaderParent = {
|
||||
switch (message.name) {
|
||||
case "Reader:AddToList":
|
||||
let article = message.data.article;
|
||||
ReadingList.addItem({
|
||||
url: article.url,
|
||||
title: article.title,
|
||||
excerpt: article.excerpt,
|
||||
status: article.status
|
||||
ReadingList.getMetadataFromBrowser(message.target).then(function(metadata) {
|
||||
if (metadata.previews.length > 0) {
|
||||
article.preview = metadata.previews[0];
|
||||
}
|
||||
|
||||
ReadingList.addItem({
|
||||
url: article.url,
|
||||
title: article.title,
|
||||
excerpt: article.excerpt,
|
||||
preview: article.preview
|
||||
});
|
||||
});
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user