]> git.donarmstrong.com Git - dactyl.git/blobdiff - common/modules/services.jsm
Import r6923 from upstream hg supporting Firefox up to 22.0a1
[dactyl.git] / common / modules / services.jsm
index 76c4b6bd7a69e9f1991da8c1700b5e21448f71bb..d3ac781fac3fdfff5fde6cf3a5ca43cfa444b45b 100644 (file)
@@ -1,16 +1,20 @@
-// Copyright (c) 2008-2011 by Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2012 Kris Maglione <maglione.k at Gmail>
 //
 // This work is licensed for reuse under an MIT license. Details are
 // given in the LICENSE.txt file included with this file.
-/* use strict */
+"use strict";
 
 try {
 
 var global = this;
-Components.utils.import("resource://dactyl/bootstrap.jsm");
 defineModule("services", {
-    exports: ["services"]
-}, this);
+    exports: ["PrivateBrowsingUtils", "services"]
+});
+
+try {
+    var { PrivateBrowsingUtils } = Cu.import("resource://gre/modules/PrivateBrowsingUtils.jsm");
+}
+catch (e) {}
 
 /**
  * A lazily-instantiated XPCOM class and service cache.
@@ -27,7 +31,6 @@ var Services = Module("Services", {
         this.add("appShell",            "@mozilla.org/appshell/appShellService;1",          "nsIAppShellService");
         this.add("appStartup",          "@mozilla.org/toolkit/app-startup;1",               "nsIAppStartup");
         this.add("bookmarks",           "@mozilla.org/browser/nav-bookmarks-service;1",     "nsINavBookmarksService");
-        this.add("bootstrap",           "@dactyl.googlecode.com/base/bootstrap");
         this.add("browserSearch",       "@mozilla.org/browser/search-service;1",            "nsIBrowserSearchService");
         this.add("cache",               "@mozilla.org/network/cache-service;1",             "nsICacheService");
         this.add("charset",             "@mozilla.org/charset-converter-manager;1",         "nsICharsetConverterManager");
@@ -109,12 +112,13 @@ var Services = Module("Services", {
         this.addClass("Xmlhttp",      "@mozilla.org/xmlextras/xmlhttprequest;1",   [], "open");
         this.addClass("XPathEvaluator", "@mozilla.org/dom/xpath-evaluator;1",      "nsIDOMXPathEvaluator");
         this.addClass("XMLDocument",  "@mozilla.org/xml/xml-document;1",           ["nsIDOMXMLDocument", "nsIDOMNodeSelector"]);
+        this.addClass("XMLSerializer","@mozilla.org/xmlextras/xmlserializer;1",    ["nsIDOMSerializer"]);
         this.addClass("ZipReader",    "@mozilla.org/libjar/zip-reader;1",          "nsIZipReader", "open", false);
         this.addClass("ZipWriter",    "@mozilla.org/zipwriter;1",                  "nsIZipWriter", "open", false);
     },
     reinit: function () {},
 
-    _create: function (name, args) {
+    _create: function _create(name, args) {
         try {
             var service = this.services[name];
 
@@ -131,7 +135,10 @@ var Services = Module("Services", {
             }
             return res;
         }
-        catch (e if service.quiet !== false) {
+        catch (e) {
+            if (service.quiet === false)
+                throw e.stack ? e : Error(e);
+
             if (typeof util !== "undefined")
                 util.reportError(e);
             else
@@ -150,7 +157,7 @@ var Services = Module("Services", {
      * @param {string} meth The name of the function used to instantiate
      *     the service.
      */
-    add: function (name, class_, ifaces, meth) {
+    add: function add(name, class_, ifaces, meth) {
         const self = this;
         this.services[name] = { method: meth, class: class_, interfaces: Array.concat(ifaces || []) };
         if (name in this && ifaces && !this.__lookupGetter__(name) && !(this[name] instanceof Ci.nsISupports))
@@ -168,14 +175,14 @@ var Services = Module("Services", {
      * @param {string} init Name of a property or method used to initialize the
      *     class.
      */
-    addClass: function (name, class_, ifaces, init, quiet) {
+    addClass: function addClass(name, class_, ifaces, init, quiet) {
         const self = this;
         this.services[name] = { class: class_, interfaces: Array.concat(ifaces || []), method: "createInstance", init: init, quiet: quiet };
         if (init)
             memoize(this.services[name], "callable",
                     function () callable(XPCOMShim(this.interfaces)[this.init]));
 
-        this[name] = function () self._create(name, arguments);
+        this[name] = function Create() self._create(name, arguments);
         update.apply(null, [this[name]].concat([Ci[i] for each (i in Array.concat(ifaces))]));
         return this[name];
     },
@@ -199,7 +206,7 @@ var Services = Module("Services", {
      *
      * @param {string} name The service's cache key.
      */
-    has: function (name) Set.has(this.services, name) && this.services[name].class in Cc &&
+    has: function has(name) Set.has(this.services, name) && this.services[name].class in Cc &&
         this.services[name].interfaces.every(function (iface) iface in Ci)
 });