tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

file_bug1198095.js (1034B)


      1 /* eslint-env mozilla/chrome-script */
      2 
      3 // eslint-disable-next-line mozilla/reject-importGlobalProperties
      4 Cu.importGlobalProperties(["File"]);
      5 
      6 function createFileWithData(message) {
      7  var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(
      8    Ci.nsIProperties
      9  );
     10  var testFile = dirSvc.get("ProfD", Ci.nsIFile);
     11  testFile.append("fileAPItestfileBug1198095");
     12 
     13  var outStream = Cc[
     14    "@mozilla.org/network/file-output-stream;1"
     15  ].createInstance(Ci.nsIFileOutputStream);
     16  outStream.init(
     17    testFile,
     18    0x02 | 0x08 | 0x20, // write, create, truncate
     19    0o666,
     20    0
     21  );
     22 
     23  outStream.write(message, message.length);
     24  outStream.close();
     25 
     26  return File.createFromNsIFile(testFile);
     27 }
     28 
     29 addMessageListener("file.open", function (message) {
     30  createFileWithData(message).then(function (file) {
     31    sendAsyncMessage("file.opened", file);
     32  });
     33 });
     34 
     35 addMessageListener("file.modify", function (message) {
     36  createFileWithData(message).then(function (file) {
     37    sendAsyncMessage("file.modified", file);
     38  });
     39 });