Bug 860625 - Use asynchronous getCharsetForURI in BookmarkJSONUtils.jsm. r=mak

This commit is contained in:
Marcos Aruj 2013-05-14 22:01:23 -06:00
parent c024c79160
commit 96772b5506

View File

@ -528,7 +528,7 @@ BookmarkExporter.prototype = {
false).root;
// Serialize to JSON and write to stream.
BookmarkNode.serializeAsJSONToOutputStream(root, streamProxy, false, false,
yield BookmarkNode.serializeAsJSONToOutputStream(root, streamProxy, false, false,
excludeItems);
root.containerOpen = false;
}
@ -552,23 +552,27 @@ let BookmarkNode = {
* Converts folder shortcuts into actual folders.
* @param aExcludeItems
* An array of item ids that should not be written to the backup.
* @returns Task promise
*/
serializeAsJSONToOutputStream: function BN_serializeAsJSONToOutputStream(
aNode, aStream, aIsUICommand, aResolveShortcuts, aExcludeItems) {
return Task.spawn(function() {
// Serialize to stream
let array = [];
if (this._appendConvertedNode(aNode, null, array, aIsUICommand,
if (yield this._appendConvertedNode(aNode, null, array, aIsUICommand,
aResolveShortcuts, aExcludeItems)) {
let json = JSON.stringify(array[0]);
aStream.write(json, json.length);
} else {
throw Cr.NS_ERROR_UNEXPECTED;
}
}.bind(this));
},
_appendConvertedNode: function BN__appendConvertedNode(
bNode, aIndex, aArray, aIsUICommand, aResolveShortcuts, aExcludeItems) {
return Task.spawn(function() {
let node = {};
// Set index in order received
@ -585,7 +589,7 @@ let BookmarkNode = {
if (PlacesUtils.nodeIsURI(bNode)) {
// Tag root accept only folder nodes
if (parent && parent.itemId == PlacesUtils.tagsFolderId)
return false;
throw new Task.Result(false);
// Check for url validity, since we can't halt while writing a backup.
// This will throw if we try to serialize an invalid url and it does
@ -593,14 +597,14 @@ let BookmarkNode = {
try {
NetUtil.newURI(bNode.uri);
} catch (ex) {
return false;
throw new Task.Result(false);
}
this._addURIProperties(bNode, node, aIsUICommand);
yield this._addURIProperties(bNode, node, aIsUICommand);
} else if (PlacesUtils.nodeIsContainer(bNode)) {
// Tag containers accept only uri nodes
if (grandParent && grandParent.itemId == PlacesUtils.tagsFolderId)
return false;
throw new Task.Result(false);
this._addContainerProperties(bNode, node, aIsUICommand,
aResolveShortcuts);
@ -609,18 +613,19 @@ let BookmarkNode = {
// Tag containers accept only uri nodes
if ((parent && parent.itemId == PlacesUtils.tagsFolderId) ||
(grandParent && grandParent.itemId == PlacesUtils.tagsFolderId))
return false;
throw new Task.Result(false);
this._addSeparatorProperties(bNode, node);
}
if (!node.feedURI && node.type == PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER) {
return this._appendConvertedComplexNode(node, bNode, aArray, aIsUICommand,
aResolveShortcuts, aExcludeItems);
throw new Task.Result(yield this._appendConvertedComplexNode(node, bNode, aArray, aIsUICommand,
aResolveShortcuts, aExcludeItems));
}
aArray.push(node);
return true;
throw new Task.Result(true);
}.bind(this));
},
_addGenericProperties: function BN__addGenericProperties(
@ -664,6 +669,7 @@ let BookmarkNode = {
_addURIProperties: function BN__addURIProperties(
aPlacesNode, aJSNode, aIsUICommand) {
return Task.spawn(function() {
aJSNode.type = PlacesUtils.TYPE_X_MOZ_PLACE;
aJSNode.uri = aPlacesNode.uri;
if (aJSNode.id && aJSNode.id != -1) {
@ -679,9 +685,10 @@ let BookmarkNode = {
// Last character-set
let uri = NetUtil.newURI(aPlacesNode.uri);
let lastCharset = PlacesUtils.history.getCharsetForURI(uri);
let lastCharset = yield PlacesUtils.getCharsetForURI(uri)
if (lastCharset)
aJSNode.charset = lastCharset;
});
},
_addSeparatorProperties: function BN__addSeparatorProperties(
@ -727,6 +734,7 @@ let BookmarkNode = {
_appendConvertedComplexNode: function BN__appendConvertedComplexNode(
aNode, aSourceNode, aArray, aIsUICommand, aResolveShortcuts,
aExcludeItems) {
return Task.spawn(function() {
let repr = {};
for (let [name, value] in Iterator(aNode))
@ -744,7 +752,7 @@ let BookmarkNode = {
let childNode = aSourceNode.getChild(i);
if (aExcludeItems && aExcludeItems.indexOf(childNode.itemId) != -1)
continue;
this._appendConvertedNode(aSourceNode.getChild(i), i, children,
yield this._appendConvertedNode(aSourceNode.getChild(i), i, children,
aIsUICommand, aResolveShortcuts,
aExcludeItems);
}
@ -753,6 +761,7 @@ let BookmarkNode = {
}
aArray.push(repr);
return true;
throw new Task.Result(true);
}.bind(this));
}
}