[Pkg-mozext-commits] [sage-extension] 01/20: switch to using promises with mozIAsyncLivemarks for FF 40 compatibility, fixes #132
David Prévot
taffit at moszumanska.debian.org
Sat Feb 13 01:36:52 UTC 2016
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository sage-extension.
commit 7e5f561c2903116a2a065a3eb26c05074e4482ee
Author: Peter Andrews <petea at jhu.edu>
Date: Fri Jul 31 06:35:11 2015 -0700
switch to using promises with mozIAsyncLivemarks for FF 40 compatibility, fixes #132
---
src/chrome/content/opml.js | 102 +++++++++++++++++++-------------------
src/chrome/content/sidebar.js | 61 ++++++++++-------------
src/modules/SageUpdateChecker.jsm | 53 ++++++++++----------
3 files changed, 101 insertions(+), 115 deletions(-)
diff --git a/src/chrome/content/opml.js b/src/chrome/content/opml.js
index 49679ce..65ddf93 100644
--- a/src/chrome/content/opml.js
+++ b/src/chrome/content/opml.js
@@ -282,63 +282,61 @@ function createOpmlOutline(aOpmlDoc, aResultNode) {
var outlineNode = aOpmlDoc.createElement("outline");
- PlacesUtils.livemarks.getLivemark(
- { id: aResultNode.itemId },
- (function(aStatus, aLivemark) {
- var isLivemark = false,
- feedURI;
- if (Components.isSuccessCode(aStatus)) {
- isLivemark = true;
- feedURI = aLivemark.feedURI;
- }
-
- var childNode, childNodeType;
- if (type == bmsvc.TYPE_FOLDER && !isLivemark) {
- outlineNode.setAttribute("text", title);
- aResultNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
- aResultNode.containerOpen = true;
- var promise;
- if (aResultNode.childCount > 0) {
- var i = 0;
- function step() {
- childNode = aResultNode.getChild(i);
- i++;
- childNodeType = bmsvc.getItemType(childNode.itemId);
- if (childNodeType == bmsvc.TYPE_FOLDER || childNodeType == bmsvc.TYPE_BOOKMARK) {
- promise = createOpmlOutline(aOpmlDoc, childNode);
- promise.then(function(opmlOutline) {
- outlineNode.appendChild(opmlOutline);
- if (i < aResultNode.childCount) {
- step();
- } else {
- aResultNode.containerOpen = false;
- deferred.resolve(outlineNode);
- }
- });
- }
+ var onLivemarkResolved = function(aLivemark) {
+ var childNode, childNodeType;
+ if (type == bmsvc.TYPE_FOLDER && !aLivemark) {
+ outlineNode.setAttribute("text", title);
+ aResultNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
+ aResultNode.containerOpen = true;
+ var promise;
+ if (aResultNode.childCount > 0) {
+ var i = 0;
+ function step() {
+ childNode = aResultNode.getChild(i);
+ i++;
+ childNodeType = bmsvc.getItemType(childNode.itemId);
+ if (childNodeType == bmsvc.TYPE_FOLDER || childNodeType == bmsvc.TYPE_BOOKMARK) {
+ promise = createOpmlOutline(aOpmlDoc, childNode);
+ promise.then(function(opmlOutline) {
+ outlineNode.appendChild(opmlOutline);
+ if (i < aResultNode.childCount) {
+ step();
+ } else {
+ aResultNode.containerOpen = false;
+ deferred.resolve(outlineNode);
+ }
+ });
}
- step();
- } else {
- aResultNode.containerOpen = false;
- deferred.resolve(outlineNode);
}
- } else if (type == bmsvc.TYPE_BOOKMARK) {
- var url = bmsvc.getBookmarkURI(aResultNode.itemId).spec;
- outlineNode.setAttribute("type", "rss");
- outlineNode.setAttribute("text", title);
- outlineNode.setAttribute("title", title);
- outlineNode.setAttribute("xmlUrl", url);
- deferred.resolve(outlineNode);
- } else if (isLivemark) {
- outlineNode.setAttribute("type", "rss");
- outlineNode.setAttribute("text", title);
- outlineNode.setAttribute("title", title);
- outlineNode.setAttribute("xmlUrl", feedURI.spec);
- deferred.resolve(outlineNode);
+ step();
} else {
+ aResultNode.containerOpen = false;
deferred.resolve(outlineNode);
}
- }).bind(this));
+ } else if (type == bmsvc.TYPE_BOOKMARK) {
+ var url = bmsvc.getBookmarkURI(aResultNode.itemId).spec;
+ outlineNode.setAttribute("type", "rss");
+ outlineNode.setAttribute("text", title);
+ outlineNode.setAttribute("title", title);
+ outlineNode.setAttribute("xmlUrl", url);
+ deferred.resolve(outlineNode);
+ } else if (aLivemark) {
+ outlineNode.setAttribute("type", "rss");
+ outlineNode.setAttribute("text", title);
+ outlineNode.setAttribute("title", title);
+ outlineNode.setAttribute("xmlUrl", aLivemark.feedURI.spec);
+ deferred.resolve(outlineNode);
+ } else {
+ deferred.resolve(outlineNode);
+ }
+ }.bind(this);
+
+ PlacesUtils.livemarks.getLivemark({ id: aResultNode.itemId }).then(aLivemark => {
+ onLivemarkResolved(aLivemark);
+ }).catch(function() {
+ onLivemarkResolved(null);
+ });
+
return deferred.promise;
}
diff --git a/src/chrome/content/sidebar.js b/src/chrome/content/sidebar.js
index d4efa0b..5bdd1d4 100644
--- a/src/chrome/content/sidebar.js
+++ b/src/chrome/content/sidebar.js
@@ -212,17 +212,12 @@ var sidebarController = {
properties.push("sage_state_" + state);
} catch (e) { }
} else {
- PlacesUtils.livemarks.getLivemark(
- { id: itemId },
- function (aStatus, aLivemark) {
- if (Components.isSuccessCode(aStatus)) {
- this._controller.cacheLivemarkInfo(node, aLivemark);
- properties.push("livemark");
- // The livemark attribute is set as a cell property on the title cell.
- this._invalidateCellValue(node, this.COLUMN_TYPE_TITLE);
- }
- }.bind(this)
- );
+ PlacesUtils.livemarks.getLivemark({ id: itemId }).then(aLivemark => {
+ this._controller.cacheLivemarkInfo(node, aLivemark);
+ properties.push("livemark");
+ // The livemark attribute is set as a cell property on the title cell.
+ this._invalidateCellValue(node, this.COLUMN_TYPE_TITLE);
+ }).catch(function() {});
}
}
properties.forEach(function(property) {
@@ -272,32 +267,26 @@ var sidebarController = {
},
loadFeedFromNode : function(aNode, aEvent) {
+ logger.debug("loadFeedFromNode");
var nodeType = aNode.type,
- itemId = aNode.itemId,
- uri;
- PlacesUtils.livemarks.getLivemark(
- { id: itemId },
- (function(aStatus, aLivemark) {
- var isLivemark = false,
- feedURI;
- if (Components.isSuccessCode(aStatus)) {
- isLivemark = true;
- feedURI = aLivemark.feedURI;
- }
- if ((nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER ||
- nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT) && isLivemark) {
- uri = feedURI.spec;
- } else {
- uri = PlacesUtils.bookmarks.getBookmarkURI(itemId).spec;
- }
-
- lastItemId = itemId;
- this.setStatus("loading", strRes.getFormattedString("RESULT_LOADING", [PlacesUtils.bookmarks.getItemTitle(itemId)]));
- feedLoader.loadURI(uri);
- if (SageUtils.getSagePrefValue(SageUtils.PREF_RENDER_FEEDS)) {
- openURI(SageUtils.FEED_SUMMARY_URI + "#feed/" + encodeURIComponent(uri), aEvent);
- }
- }).bind(this));
+ itemId = aNode.itemId;
+
+ var onURIResolved = function(uri) {
+ lastItemId = itemId;
+ this.setStatus("loading", strRes.getFormattedString("RESULT_LOADING", [PlacesUtils.bookmarks.getItemTitle(itemId)]));
+ feedLoader.loadURI(uri);
+ if (SageUtils.getSagePrefValue(SageUtils.PREF_RENDER_FEEDS)) {
+ openURI(SageUtils.FEED_SUMMARY_URI + "#feed/" + encodeURIComponent(uri), aEvent);
+ }
+ }.bind(this);
+
+ PlacesUtils.livemarks.getLivemark({ id: itemId }).then(aLivemark => {
+ onURIResolved(aLivemark.feedURI.spec);
+ }).catch(function() {
+ if (nodeType == Ci.nsINavHistoryResultNode.RESULT_TYPE_URI) {
+ onURIResolved(PlacesUtils.bookmarks.getBookmarkURI(itemId).spec);
+ }
+ });
},
checkFeeds : function(aFolderId) {
diff --git a/src/modules/SageUpdateChecker.jsm b/src/modules/SageUpdateChecker.jsm
index 8a3ad85..9381805 100644
--- a/src/modules/SageUpdateChecker.jsm
+++ b/src/modules/SageUpdateChecker.jsm
@@ -154,35 +154,34 @@ var SageUpdateChecker = {
queueItems: function uc_queueItems(aResultNode) {
var itemId = aResultNode.itemId;
- PlacesUtils.livemarks.getLivemark(
- { id: itemId },
- (function(aStatus, aLivemark) {
- var isLivemark = false,
- feedURI;
- if (Components.isSuccessCode(aStatus)) {
- isLivemark = true;
- feedURI = aLivemark.feedURI;
+
+ var onLivemarkResolved = function(aLivemark) {
+ var itemType = this.bmsvc.getItemType(itemId);
+ if (itemType == this.bmsvc.TYPE_BOOKMARK || aLivemark) {
+ var url = (aLivemark ? aLivemark.feedURI : this.bmsvc.getBookmarkURI(itemId)).spec;
+ var status = this.getItemAnnotation(itemId, SageUtils.ANNO_STATUS);
+ if (url && status != SageUtils.STATUS_UPDATE) {
+ var feed = {
+ id: itemId,
+ url: url
+ };
+ this.checkList.push(feed);
}
- var itemType = this.bmsvc.getItemType(itemId);
- if (itemType == this.bmsvc.TYPE_BOOKMARK || isLivemark) {
- var url = (isLivemark ? feedURI : this.bmsvc.getBookmarkURI(itemId)).spec;
- var status = this.getItemAnnotation(itemId, SageUtils.ANNO_STATUS);
- if (url && status != SageUtils.STATUS_UPDATE) {
- var feed = {
- id: itemId,
- url: url
- };
- this.checkList.push(feed);
- }
- } else if (itemType == this.bmsvc.TYPE_FOLDER) {
- aResultNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
- aResultNode.containerOpen = true;
- for (var i = 0; i < aResultNode.childCount; i ++) {
- this.queueItems(aResultNode.getChild(i));
- }
- aResultNode.containerOpen = false;
+ } else if (itemType == this.bmsvc.TYPE_FOLDER) {
+ aResultNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
+ aResultNode.containerOpen = true;
+ for (var i = 0; i < aResultNode.childCount; i ++) {
+ this.queueItems(aResultNode.getChild(i));
}
- }).bind(this));
+ aResultNode.containerOpen = false;
+ }
+ }.bind(this);
+
+ PlacesUtils.livemarks.getLivemark({ id: itemId }).then(aLivemark => {
+ onLivemarkResolved(aLivemark);
+ }).catch(function() {
+ onLivemarkResolved(null);
+ });
},
setHasNew: function(aValue) {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-mozext/sage-extension.git
More information about the Pkg-mozext-commits
mailing list