summaryrefslogtreecommitdiffstats
path: root/dom/html/test/simpleFileOpener.js
blob: 9cec9cbf1887aa92acebdda95eb044e58365d225 (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
33
34
35
36
37
/* eslint-env mozilla/chrome-script */

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);
    }

    File.createFromNsIFile(file).then(function (domFile) {
      sendAsyncMessage("file.opened", {
        fullPath: file.path,
        leafName: file.leafName,
        domFile,
      });
    });
  } 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());
  }
});