From 92ed83c72e2e1006bd2c94cbe02870f7d2404cae Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Mon, 23 Mar 2015 23:19:24 +0100 Subject: Use about:config to determine the socket path and perms. --- cli/icevault.1 | 8 +++++++ xul-ext/Makefile | 5 +++-- xul-ext/chrome/content/icevault.js | 38 +++++++++++++++++++------------- xul-ext/defaults/preferences/icevault.js | 2 ++ xul-ext/protocol | 6 ++++- 5 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 xul-ext/defaults/preferences/icevault.js diff --git a/cli/icevault.1 b/cli/icevault.1 index c9dba3d..0eac11f 100644 --- a/cli/icevault.1 +++ b/cli/icevault.1 @@ -120,6 +120,10 @@ Specify the path of the UNIX socket used to communicate with the browser. If the path does not start with a slash "/", it is assumed to be relative to the default Firefox profile (or first profile found if there is no default profile) in the "~/.mozilla/firefox" directory. +The socket path and permissions can be configured on the +Iceweasel/Firefox side with the "extensions.icevault.socketPath" and +"extensions.icevault.socketPerms" preferences in "about:config", +respectively. .TP .B \-\-version @@ -166,6 +170,10 @@ The path of the UNIX socket used to communicate with the browser. If the path does not start with a slash "/", it is assumed to be relative to the default Firefox profile (or first profile found if there is no default profile) in the "~/.mozilla/firefox" directory. +The socket path and permissions can be configured on the +Iceweasel/Firefox side with the "extensions.icevault.socketPath" and +"extensions.icevault.socketPerms" preferences in "about:config", +respectively. (Default: "S.IceVault".) .TP 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 -- cgit v1.2.3