summaryrefslogtreecommitdiffstats
path: root/dom/html/test/simpleFileOpener.js
blob: eeffdb6a15e9b884f5cc7dc09637f1966885afd1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
Cu.importGlobalProperties(["File"]);

var file;

addMessageListener("file.open", function (stem) {
  try {
    if (!file) {
      file = Cc["@mozilla.org/file/directory_service;1"]
               .getService(Ci.nsIProperties).get("TmpD", Ci.nsIFile);
      file.append(stem);
      file.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
    }
    sendAsyncMessage("file.opened", {
      fullPath: file.path,
      leafName: file.leafName,
      domFile: File.createFromNsIFile(file),
    });
  } catch(e) {
    sendAsyncMessage("fail", e.toString());
  }
});

addMessageListener("file.remove", function () {
  try {
    file.remove(/* recursive: */ false);
    file = undefined;
    sendAsyncMessage("file.removed", null);
  } catch(e) {
    sendAsyncMessage("fail", e.toString());
  }
});