Bug 852040 - Apply use of BookmarkJSONUtils.importFromURL r=mbrubeck

--HG--
extra : rebase_source : 0b1a99da2455b86fce5aeae991d3f3384336e596
This commit is contained in:
Raymond Lee 2013-03-22 13:08:03 +08:00
parent 734ad9acf6
commit f1d6807807
2 changed files with 4 additions and 33 deletions

View File

@ -60,40 +60,9 @@ BrowserStartup.prototype = {
return; // no need to do initial import
}
Cu.import("resource://gre/modules/PlacesUtils.jsm");
Cu.import("resource://gre/modules/BookmarkJSONUtils.jsm");
try {
let observer = {
onStreamComplete : function(aLoader, aContext, aStatus, aLength, aResult) {
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].
createInstance(Ci.nsIScriptableUnicodeConverter);
let jsonStr = "";
try {
converter.charset = "UTF-8";
jsonStr = converter.convertFromByteArray(aResult, aResult.length);
// aReplace=false since this may be called when there are existing
// bookmarks that we don't want to overwrite ("no mobile root"
// case from above)
PlacesUtils.restoreBookmarksFromJSONString(jsonStr, false);
} catch (err) {
Cu.reportError("Failed to parse default bookmarks from bookmarks.json: " + err);
}
}
};
let ioSvc = Cc["@mozilla.org/network/io-service;1"].
getService(Ci.nsIIOService);
let uri = ioSvc.newURI("chrome://browser/locale/bookmarks.json", null, null);
let channel = ioSvc.newChannelFromURI(uri);
let sl = Cc["@mozilla.org/network/stream-loader;1"].
createInstance(Ci.nsIStreamLoader);
sl.init(observer);
channel.asyncOpen(sl, channel);
} catch (err) {
// Report the error, but ignore it.
Cu.reportError("Failed to load default bookmarks from bookmarks.json: " + err);
}
BookmarkJSONUtils.importFromURL("chrome://browser/locale/bookmarks.json", false);
},
_startupActions: function() {

View File

@ -102,6 +102,7 @@ BookmarkImporter.prototype = {
deferred.resolve();
} catch (ex) {
notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_FAILED);
Cu.reportError("Failed to import from URL: " + ex);
deferred.reject(ex);
}
}.bind(this));
@ -117,6 +118,7 @@ BookmarkImporter.prototype = {
channel.asyncOpen(streamLoader, channel);
} catch (ex) {
notifyObservers(PlacesUtils.TOPIC_BOOKMARKS_RESTORE_FAILED);
Cu.reportError("Failed to import from URL: " + ex);
deferred.reject(ex);
}