зеркало из https://github.com/mozilla/pjs.git
Bug 520547 - revert renaming of PlacesUtils methods from bug 477583. r=mano, r=gavin
This commit is contained in:
Родитель
708fc9f0dc
Коммит
a76b9bc522
|
@ -645,7 +645,7 @@ BrowserGlue.prototype = {
|
|||
var bookmarksBackupFile = PlacesUtils.backups.getMostRecent("json");
|
||||
if (bookmarksBackupFile) {
|
||||
// restore from JSON backup
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(bookmarksBackupFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(bookmarksBackupFile);
|
||||
importBookmarks = false;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -511,7 +511,7 @@ var PlacesOrganizer = {
|
|||
return;
|
||||
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(aFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(aFile);
|
||||
}
|
||||
catch(ex) {
|
||||
this._showErrorAlert(PlacesUIUtils.getString("bookmarksRestoreParseError"));
|
||||
|
|
|
@ -103,7 +103,7 @@ function run_test() {
|
|||
} catch(ex) { do_throw("couldn't export to file: " + ex); }
|
||||
LOG("exported json");
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(jsonFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
|
||||
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
||||
LOG("imported json");
|
||||
validate();
|
||||
|
|
|
@ -83,7 +83,7 @@ var tests = [
|
|||
PlacesUtils.backups.saveBookmarksToJSONFile(this.file);
|
||||
remove_all_bookmarks();
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(this.file);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(this.file);
|
||||
}
|
||||
catch (e) {
|
||||
do_throw(" Restore should not have failed");
|
||||
|
@ -100,7 +100,7 @@ var tests = [
|
|||
run: function () {
|
||||
this.file = createFile("bookmarks-test_restoreNotification.json");
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(this.file);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(this.file);
|
||||
}
|
||||
catch (e) {
|
||||
do_throw(" Restore should not have failed");
|
||||
|
@ -118,7 +118,7 @@ var tests = [
|
|||
this.file = dirSvc.get("ProfD", Ci.nsILocalFile);
|
||||
this.file.append("this file doesn't exist because nobody created it");
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(this.file);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(this.file);
|
||||
do_throw(" Restore should have failed");
|
||||
}
|
||||
catch (e) {}
|
||||
|
|
|
@ -1647,6 +1647,69 @@ var PlacesUtils = {
|
|||
return JSON.encode(aObj);
|
||||
},
|
||||
|
||||
/**
|
||||
* Restores bookmarks and tags from a JSON file.
|
||||
* WARNING: This method *removes* any bookmarks in the collection before
|
||||
* restoring from the file.
|
||||
*
|
||||
* @param aFile
|
||||
* nsIFile of bookmarks in JSON format to be restored.
|
||||
*/
|
||||
restoreBookmarksFromJSONFile:
|
||||
function PU_restoreBookmarksFromJSONFile(aFile) {
|
||||
let failed = false;
|
||||
this.observerSvc.notifyObservers(null,
|
||||
RESTORE_BEGIN_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
|
||||
try {
|
||||
// open file stream
|
||||
var stream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
stream.init(aFile, 0x01, 0, 0);
|
||||
var converted = Cc["@mozilla.org/intl/converter-input-stream;1"].
|
||||
createInstance(Ci.nsIConverterInputStream);
|
||||
converted.init(stream, "UTF-8", 8192,
|
||||
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
|
||||
|
||||
// read in contents
|
||||
var str = {};
|
||||
var jsonStr = "";
|
||||
while (converted.readString(8192, str) != 0)
|
||||
jsonStr += str.value;
|
||||
converted.close();
|
||||
|
||||
if (jsonStr.length == 0)
|
||||
return; // empty file
|
||||
|
||||
this.restoreBookmarksFromJSONString(jsonStr, true);
|
||||
}
|
||||
catch (exc) {
|
||||
failed = true;
|
||||
this.observerSvc.notifyObservers(null,
|
||||
RESTORE_FAILED_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
Cu.reportError("Bookmarks JSON restore failed: " + exc);
|
||||
throw exc;
|
||||
}
|
||||
finally {
|
||||
if (!failed) {
|
||||
this.observerSvc.notifyObservers(null,
|
||||
RESTORE_SUCCESS_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Serializes bookmarks using JSON, and writes to the supplied file.
|
||||
*
|
||||
* @see backups.saveBookmarksToJSONFile(aFile)
|
||||
*/
|
||||
backupBookmarksToFile: function PU_backupBookmarksToFile(aFile) {
|
||||
this.backups.saveBookmarksToJSONFile(aFile);
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper to create and manage backups.
|
||||
*/
|
||||
|
@ -1904,60 +1967,6 @@ var PlacesUtils = {
|
|||
return;
|
||||
|
||||
this.saveBookmarksToJSONFile(newBackupFile);
|
||||
},
|
||||
|
||||
/**
|
||||
* Restores bookmarks and tags from a JSON file.
|
||||
* WARNING: This method *removes* any bookmarks in the collection before
|
||||
* restoring from the file.
|
||||
*
|
||||
* @param aFile
|
||||
* nsIFile of bookmarks in JSON format to be restored.
|
||||
*/
|
||||
restoreBookmarksFromJSONFile:
|
||||
function PU_B_restoreBookmarksFromJSONFile(aFile) {
|
||||
let failed = false;
|
||||
PlacesUtils.observerSvc.notifyObservers(null,
|
||||
RESTORE_BEGIN_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
|
||||
try {
|
||||
// open file stream
|
||||
var stream = Cc["@mozilla.org/network/file-input-stream;1"].
|
||||
createInstance(Ci.nsIFileInputStream);
|
||||
stream.init(aFile, 0x01, 0, 0);
|
||||
var converted = Cc["@mozilla.org/intl/converter-input-stream;1"].
|
||||
createInstance(Ci.nsIConverterInputStream);
|
||||
converted.init(stream, "UTF-8", 8192,
|
||||
Ci.nsIConverterInputStream.DEFAULT_REPLACEMENT_CHARACTER);
|
||||
|
||||
// read in contents
|
||||
var str = {};
|
||||
var jsonStr = "";
|
||||
while (converted.readString(8192, str) != 0)
|
||||
jsonStr += str.value;
|
||||
converted.close();
|
||||
|
||||
if (jsonStr.length == 0)
|
||||
return; // empty file
|
||||
|
||||
PlacesUtils.restoreBookmarksFromJSONString(jsonStr, true);
|
||||
}
|
||||
catch (exc) {
|
||||
failed = true;
|
||||
PlacesUtils.observerSvc.notifyObservers(null,
|
||||
RESTORE_FAILED_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
Components.utils.reportError("Bookmarks JSON restore failed: " + exc);
|
||||
throw exc;
|
||||
}
|
||||
finally {
|
||||
if (!failed) {
|
||||
PlacesUtils.observerSvc.notifyObservers(null,
|
||||
RESTORE_SUCCESS_NSIOBSERVER_TOPIC,
|
||||
RESTORE_NSIOBSERVER_DATA);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},
|
||||
|
|
|
@ -249,7 +249,7 @@ function run_test() {
|
|||
|
||||
// restore json file
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(jsonFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
|
||||
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
||||
|
||||
// validate
|
||||
|
|
|
@ -164,7 +164,7 @@ function run_test() {
|
|||
|
||||
// restore json file
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(jsonFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
|
||||
} catch(ex) {
|
||||
do_throw("couldn't import the exported file: " + ex);
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ function run_test() {
|
|||
|
||||
// restore json file
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(jsonFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
|
||||
} catch(ex) {
|
||||
do_throw("couldn't import the exported file: " + ex);
|
||||
}
|
||||
|
|
|
@ -188,7 +188,7 @@ function run_test() {
|
|||
|
||||
// restore json file
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(jsonFile, excludedItemsFromRestore);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile, excludedItemsFromRestore);
|
||||
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
||||
|
||||
// validate
|
||||
|
|
|
@ -118,7 +118,7 @@ function run_test() {
|
|||
|
||||
// restore json file
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(jsonFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
|
||||
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
||||
|
||||
// validate
|
||||
|
|
|
@ -140,7 +140,7 @@ function run_test() {
|
|||
|
||||
// restore json file
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(jsonFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
|
||||
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
||||
|
||||
// validate
|
||||
|
|
|
@ -161,7 +161,7 @@ function run_test() {
|
|||
|
||||
// restore json file
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(jsonFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
|
||||
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
||||
|
||||
// validate
|
||||
|
|
|
@ -106,7 +106,7 @@ function run_test() {
|
|||
|
||||
// restore json file
|
||||
try {
|
||||
PlacesUtils.backups.restoreBookmarksFromJSONFile(jsonFile);
|
||||
PlacesUtils.restoreBookmarksFromJSONFile(jsonFile);
|
||||
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
||||
|
||||
// validate
|
||||
|
|
Загрузка…
Ссылка в новой задаче