Bug 1142217 - Make the '+-' button in reader view work. r=markh

This commit is contained in:
Florian Quèze 2015-03-12 23:47:26 +01:00
Родитель 8c6f31c21a
Коммит 60df7c858c
3 изменённых файлов: 59 добавлений и 5 удалений

Просмотреть файл

@ -194,6 +194,8 @@ ReadingListImpl.prototype = {
this._invalidateIterators();
let item = this._itemFromObject(obj);
this._callListeners("onItemAdded", item);
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
mm.broadcastAsyncMessage("Reader:Added", item);
return item;
}),
@ -234,9 +236,23 @@ ReadingListImpl.prototype = {
item.list = null;
this._itemsByURL.delete(item.url);
this._invalidateIterators();
let mm = Cc["@mozilla.org/globalmessagemanager;1"].getService(Ci.nsIMessageListenerManager);
mm.broadcastAsyncMessage("Reader:Removed", item);
this._callListeners("onItemDeleted", item);
}),
/**
* Find any item that matches a given URL - either the item's URL, or its
* resolved URL.
*
* @param {String/nsIURI} uri - URI to match against. This will be normalized.
*/
getItemForURL: Task.async(function* (uri) {
let url = this._normalizeURI(uri).spec;
let [item] = yield this.iterator({url: url}, {resolvedURL: url}).items(1);
return item;
}),
/**
* Adds a listener that will be notified when the list changes. Listeners
* are objects with the following optional methods:
@ -288,6 +304,22 @@ ReadingListImpl.prototype = {
// A Set containing listener objects.
_listeners: null,
/**
* Normalize a URI, stripping away extraneous parts we don't want to store
* or compare against.
*
* @param {nsIURI/String} uri - URI to normalize.
* @returns {nsIURI} Cloned and normalized version of the input URI.
*/
_normalizeURI(uri) {
if (typeof uri == "string") {
uri = Services.io.newURI(uri, "", null);
}
uri = uri.cloneIgnoringRef();
uri.userPass = "";
return uri;
},
/**
* Returns the ReadingListItem represented by the given simple object. If
* the item doesn't exist yet, it's created first.
@ -349,6 +381,8 @@ ReadingListImpl.prototype = {
},
};
let _unserializable = () => {}; // See comments in the ReadingListItem ctor.
/**
* An item in a reading list.
*
@ -359,6 +393,18 @@ ReadingListImpl.prototype = {
*/
function ReadingListItem(props={}) {
this._properties = {};
// |this._unserializable| works around a problem when sending one of these
// items via a message manager. If |this.list| is set, the item can't be
// transferred directly, so .toJSON is implicitly called and the object
// returned via that is sent. However, once the item is deleted and |this.list|
// is null, the item *can* be directly serialized - so the message handler
// sees the "raw" object - ie, it sees "_properties" etc.
// We work around this problem by *always* having an unserializable property
// on the object - this way the implicit .toJSON call is always made, even
// when |this.list| is null.
this._unserializable = _unserializable;
this.setProperties(props, false);
}
@ -830,7 +876,7 @@ function hash(str) {
hasher.updateFromStream(stream, -1);
let binaryStr = hasher.finish(false);
let hexStr =
[("0" + binaryStr.charCodeAt(i).toString(16)).slice(-2) for (i in hash)].
[("0" + binaryStr.charCodeAt(i).toString(16)).slice(-2) for (i in binaryStr)].
join("");
return hexStr;
}

Просмотреть файл

@ -697,7 +697,7 @@ function hash(str) {
hasher.updateFromStream(stream, -1);
let binaryStr = hasher.finish(false);
let hexStr =
[("0" + binaryStr.charCodeAt(i).toString(16)).slice(-2) for (i in hash)].
[("0" + binaryStr.charCodeAt(i).toString(16)).slice(-2) for (i in binaryStr)].
join("");
return hexStr;
}

Просмотреть файл

@ -14,6 +14,7 @@ Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/Task.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ReaderMode", "resource://gre/modules/ReaderMode.jsm");
XPCOMUtils.defineLazyModuleGetter(this, "ReadingList", "resource:///modules/readinglist/ReadingList.jsm");
const gStringBundle = Services.strings.createBundle("chrome://global/locale/aboutReader.properties");
@ -42,7 +43,7 @@ let ReaderParent = {
receiveMessage: function(message) {
switch (message.name) {
case "Reader:AddToList":
// XXX: To implement.
ReadingList.addItem(message.data.article);
break;
case "Reader:ArticleGet":
@ -59,11 +60,18 @@ let ReaderParent = {
break;
}
case "Reader:ListStatusRequest":
// XXX: To implement.
ReadingList.count(message.data).then(count => {
let mm = message.target.messageManager
mm.sendAsyncMessage("Reader:ListStatusData",
{ inReadingList: !!count, url: message.data.url });
});
break;
case "Reader:RemoveFromList":
// XXX: To implement.
// We need to get the "real" item to delete it.
ReadingList.getItemForURL(message.data.url).then(item => {
ReadingList.deleteItem(item)
});
break;
case "Reader:Share":