diff options
Diffstat (limited to 'xul-ext')
-rw-r--r-- | xul-ext/Makefile | 5 | ||||
-rw-r--r-- | xul-ext/chrome/content/icevault.js | 38 | ||||
-rw-r--r-- | xul-ext/defaults/preferences/icevault.js | 2 | ||||
-rw-r--r-- | xul-ext/protocol | 6 |
4 files changed, 33 insertions, 18 deletions
diff --git a/xul-ext/Makefile b/xul-ext/Makefile index aa2eff2..7fa5d6a 100644 --- a/xul-ext/Makefile +++ b/xul-ext/Makefile @@ -1,6 +1,7 @@ -all: ../icevault.xpi +XPI_NAME ?= ../icevault.xpi +all: $(XPI_NAME) -%.xpi: chrome.manifest install.rdf COPYING $(shell find chrome/ -type f) +%.xpi: chrome.manifest install.rdf COPYING $(shell find chrome/ defaults/ -type f) zip $@ $^ clean: diff --git a/xul-ext/chrome/content/icevault.js b/xul-ext/chrome/content/icevault.js index fe2cb50..f2c4c79 100644 --- a/xul-ext/chrome/content/icevault.js +++ b/xul-ext/chrome/content/icevault.js @@ -21,7 +21,8 @@ var icevault = (function() { const Cc = Components.classes, CC = Components.Constructor, - Ci = Components.interfaces; + Ci = Components.interfaces, + Cu = Components.utils; const UnixServerSocket = CC( "@mozilla.org/network/server-socket;1" , "nsIServerSocket" @@ -36,17 +37,24 @@ var icevault = (function() { , "nsIConverterOutputStream" , "init" ); - // XXX should be changeable from the preferences - let sockName = Cc["@mozilla.org/file/directory_service;1"] - .getService(Ci.nsIProperties) - .get("ProfD", Ci.nsIFile); - sockName.append("S.IceVault"); - const sockPerms = parseInt("0770", 8); - const convertStringToUTF8 = Cc["@mozilla.org/intl/utf8converterservice;1"] .getService(Ci.nsIUTF8ConverterService) .convertStringToUTF8; + + let prefs = Cc["@mozilla.org/preferences-service;1"] + .getService(Ci.nsIPrefService) + .getBranch("extensions.icevault."); + var sockPath = prefs.getCharPref("socketPath", Ci.nsIRelativeFilePref); + const sockPerms = parseInt(prefs.getCharPref("socketPerms"), 8); + + Cu.import("resource://gre/modules/FileUtils.jsm"); + if (sockPath.charAt(0) == '/') + sockPath = new FileUtils.File(sockPath); + else // take relative files in the profile directory + sockPath = FileUtils.getFile("ProfD", [sockPath]); + + // Write the given UTF8 string to the ConverterOutputStream, then flush var send = function(stream, msg) { //console.log("Sending: " + msg) @@ -199,11 +207,11 @@ var icevault = (function() { if (Application.storage.has("IceVault.serverSocket")) server = Application.storage.get("IceVault.serverSocket", null); else { - console.log("Initializing IceVault"); + console.log("Initializing IceVault (listening on " + sockPath.path + ")"); try { - if (sockName.exists()) - sockName.remove(false); // remove stalled socket - server = new UnixServerSocket(sockName, sockPerms, -1); + if (sockPath.exists()) + sockPath.remove(false); // remove stalled socket + server = new UnixServerSocket(sockPath, sockPerms, -1); } finally { Application.storage.set("IceVault.serverSocket", server); @@ -213,10 +221,10 @@ var icevault = (function() { }, clean: function() { - if (!Application.windows.length && sockName.exists()) { + if (!Application.windows.length && sockPath.exists()) { // remove the socket if the last window was just closed - console.log("Removing " + sockName.path); - sockName.remove(false); + console.log("Removing " + sockPath.path); + sockPath.remove(false); } } } diff --git a/xul-ext/defaults/preferences/icevault.js b/xul-ext/defaults/preferences/icevault.js new file mode 100644 index 0000000..16b6032 --- /dev/null +++ b/xul-ext/defaults/preferences/icevault.js @@ -0,0 +1,2 @@ +pref('extensions.icevault.socketPath', 'S.IceVault'); +pref('extensions.icevault.socketPerms', '0700'); diff --git a/xul-ext/protocol b/xul-ext/protocol index b29e2fd..94f7744 100644 --- a/xul-ext/protocol +++ b/xul-ext/protocol @@ -1,6 +1,10 @@ Upon startup, Firefox creates and listens on a new UNIX socket (shared between all tabs and windows) on which commands can be thrown in to fill -HTML forms. The greeting message indicates that the server is ready to +HTML forms. The socket path and permissions can respectively be +configured with the "extensions.icevault.socketPath" and +"extensions.icevault.socketPerms" preferences in "about:config". + +The greeting message indicates that the server is ready to accept commands. Each command and response are single UTF8 string lines ending with a newline character `\n'. (JSON-encoding ensures that control characters are escaped properly; decoding to a string rather |