code: function _saveCanvas(canvas) {
    // Use the path given on the command line and saved under
    // persisted.screenshotPath, if available. If not, use the path to the
    // temporary folder as a fallback.
    var file = null;
    if ("screenshotPath" in persisted) {
      file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
      file.initWithPath(persisted.screenshotPath);
    }
    else {
      file = Cc["@mozilla.org/file/directory_service;1"].
             getService(Ci.nsIProperties).
             get("TmpD", Ci.nsIFile);
    }
  
    var fileName = utils.appInfo.name + "-" +
                   utils.appInfo.locale + "." +
                   utils.appInfo.version + "." +
                   utils.appInfo.buildID + "." +
                   utils.appInfo.os + ".png";
    file.append(fileName);
  
    // if a file already exists, don't overwrite it and create a new name
    file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, parseInt("0666", 8));
  
    // create a data url from the canvas and then create URIs of the source
    // and targets
    var io = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
    var source = io.newURI(canvas.toDataURL("image/png", ""), "UTF8", null);
    var target = io.newFileURI(file)
  
    // prepare to save the canvas data
    var wbPersist = Cc["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"].
                    createInstance(Ci.nsIWebBrowserPersist);
  
    wbPersist.persistFlags = Ci.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
    wbPersist.persistFlags |= Ci.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
  
    // save the canvas data to the file
    wbPersist.saveURI(source, null, null, null, null, file);
  }
docs: Saves a given Canvas object to a file.
  The path to save the file under should be given on the command line. If not,
  it will be saved in the temporary folder of the system.
  
  @param {canvas} canvas