third_party/js/mozmill/shared-modules/places.js
function restoreDefaultBookmarks() {
  // Set up the observer -- we're only checking for success here, so we'll simply
  // time out and throw on failure. It makes the code much clearer than handling
  // finished state and success state separately.
  var importSuccessful = false;
  var importObserver = {
    observe: function (aSubject, aTopic, aData) {
      if (aTopic == TOPIC_BOOKMARKS_RESTORE_SUCCESS) {
        importSuccessful = true;
      }
    }
  }
  observerService.addObserver(importObserver, TOPIC_BOOKMARKS_RESTORE_SUCCESS, false);

  try {
    // Fire off the import
    var bookmarksURI = utils.createURI(BOOKMARKS_RESOURCE);
    var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
                   getService(Ci.nsIPlacesImportExportService);
    importer.importHTMLFromURI(bookmarksURI, true);

    // Wait for it to be finished--the observer above will flip this flag
    mozmill.utils.waitFor(function () {
      return importSuccessful;
    }, "Default bookmarks have finished importing", BOOKMARKS_TIMEOUT);
  }
  finally {
    // Whatever happens, remove the observer afterwards
    observerService.removeObserver(importObserver, TOPIC_BOOKMARKS_RESTORE_SUCCESS);
  }
}
function restoreDefaultBookmarks() {
  // Set up the observer -- we're only checking for success here, so we'll simply
  // time out and throw on failure. It makes the code much clearer than handling
  // finished state and success state separately.
  var importSuccessful = false;
  var importObserver = {
    observe: function (aSubject, aTopic, aData) {
      if (aTopic == TOPIC_BOOKMARKS_RESTORE_SUCCESS) {
        importSuccessful = true;
      }
    }
  }
  observerService.addObserver(importObserver, TOPIC_BOOKMARKS_RESTORE_SUCCESS, false);

  try {
    // Fire off the import
    var bookmarksURI = utils.createURI(BOOKMARKS_RESOURCE);
    var importer = Cc["@mozilla.org/browser/places/import-export-service;1"].
                   getService(Ci.nsIPlacesImportExportService);
    importer.importHTMLFromURI(bookmarksURI, true);

    // Wait for it to be finished--the observer above will flip this flag
    mozmill.utils.waitFor(function () {
      return importSuccessful;
    }, "Default bookmarks have finished importing", BOOKMARKS_TIMEOUT);
  }
  finally {
    // Whatever happens, remove the observer afterwards
    observerService.removeObserver(importObserver, TOPIC_BOOKMARKS_RESTORE_SUCCESS);
  }
}
function restoreDefaultBookmarks ( ) { // Set up the observer -- we're only checking for success here, so we'll simply // time out and throw on failure. It makes the code much clearer than handling // finished state and success state separately. var importSuccessful = false ; var importObserver = { observe : function ( aSubject , aTopic , aData ) { if ( aTopic == TOPIC_BOOKMARKS_RESTORE_SUCCESS ) { importSuccessful = true ; } } } observerService . addObserver ( importObserver , TOPIC_BOOKMARKS_RESTORE_SUCCESS , false ) ; try { // Fire off the import var bookmarksURI = utils . createURI ( BOOKMARKS_RESOURCE ) ; var importer = Cc [ "@mozilla.org/browser/places/import-export-service;1" ] . getService ( Ci . nsIPlacesImportExportService ) ; importer . importHTMLFromURI ( bookmarksURI , true ) ; // Wait for it to be finished--the observer above will flip this flag mozmill . utils . waitFor ( function ( ) { return importSuccessful ; } , "Default bookmarks have finished importing" , BOOKMARKS_TIMEOUT ) ; } finally { // Whatever happens, remove the observer afterwards observerService . removeObserver ( importObserver , TOPIC_BOOKMARKS_RESTORE_SUCCESS ) ; } }
Restore the default bookmarks for the current profile
Restore the default bookmarks for the current profile