]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/util.jsm
Import 1.0 supporting Firefox up to 14.*
[dactyl.git] / common / modules / util.jsm
index 9cc4a49e99779bb3f33bb891c3b54ae1ec2d0a96..c5cd610fbcf8ecf6fabc31dea584a43331857e59 100644 (file)
@@ -627,10 +627,10 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
      */
     formatSeconds: function formatSeconds(seconds) {
         function pad(n, val) ("0000000" + val).substr(-Math.max(n, String(val).length));
-        function div(num, denom) [Math.round(num / denom), Math.round(num % denom)];
+        function div(num, denom) [Math.floor(num / denom), Math.round(num % denom)];
         let days, hours, minutes;
 
-        [minutes, seconds] = div(seconds, 60);
+        [minutes, seconds] = div(Math.round(seconds), 60);
         [hours, minutes]   = div(minutes, 60);
         [days, hours]      = div(hours,   24);
         if (days)
@@ -710,6 +710,8 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
      *    responseType: {string} Override the type of the "response"
      *                  property.
      *
+     *    headers: {objects} Extra request headers.
+     *
      *    user: {string} The user name to send via HTTP Authentication.
      *    pass: {string} The password to send via HTTP Authentication.
      *
@@ -749,12 +751,18 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
                 params.data = data;
             }
 
-
             if (params.mimeType)
                 xmlhttp.overrideMimeType(params.mimeType);
 
-            xmlhttp.open(params.method || "GET", url, async,
-                         params.user, params.pass);
+            let args = [params.method || "GET", url, async];
+            if (params.user != null || params.pass != null)
+                args.push(params.user);
+            if (params.pass != null)
+                args.push(prams.pass);
+            xmlhttp.open.apply(xmlhttp, args);
+
+            for (let [header, val] in Iterator(params.headers || {}))
+                xmlhttp.setRequestHeader(header, val);
 
             if (params.responseType)
                 xmlhttp.responseType = params.responseType;
@@ -1308,7 +1316,7 @@ var Util = Module("Util", XPCOM([Ci.nsIObserver, Ci.nsISupportsWeakReference]),
      * Escapes a string against shell meta-characters and argument
      * separators.
      */
-    shellEscape: function shellEscape(str) '"' + String.replace(str, /[\\"$]/g, "\\$&") + '"',
+    shellEscape: function shellEscape(str) '"' + String.replace(str, /[\\"$`]/g, "\\$&") + '"',
 
     /**
      * Suspend execution for at least *delay* milliseconds. Functions by