-// Copyright (c) 2008-2011 by Kris Maglione <maglione.k at Gmail>
+// Copyright (c) 2008-2013 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.
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");
this.add("downloadManager", "@mozilla.org/download-manager;1", "nsIDownloadManager");
this.add("environment", "@mozilla.org/process/environment;1", "nsIEnvironment");
this.add("extensionManager", "@mozilla.org/extensions/manager;1", "nsIExtensionManager");
- this.add("externalApp", "@mozilla.org/uriloader/external-helper-app-service;1", "nsPIExternalAppLauncher")
+ this.add("externalApp", "@mozilla.org/uriloader/external-helper-app-service;1", "nsPIExternalAppLauncher");
this.add("externalProtocol", "@mozilla.org/uriloader/external-protocol-service;1", "nsIExternalProtocolService");
this.add("favicon", "@mozilla.org/browser/favicon-service;1", "nsIFaviconService");
this.add("file:", this.PROTOCOL + "file", "nsIFileProtocolHandler");
this.add("focus", "@mozilla.org/focus-manager;1", "nsIFocusManager");
- this.add("history", "@mozilla.org/browser/global-history;2",
- ["nsIBrowserHistory", "nsIGlobalHistory2", "nsINavHistoryService", "nsPIPlacesDatabase"]);
+ this.add("history", "@mozilla.org/browser/nav-history-service;1",
+ ["nsIBrowserHistory", "nsINavHistoryService", "nsPIPlacesDatabase"]);
this.add("io", "@mozilla.org/network/io-service;1", "nsIIOService");
this.add("json", "@mozilla.org/dom/json;1", "nsIJSON", "createInstance");
this.add("listeners", "@mozilla.org/eventlistenerservice;1", "nsIEventListenerService");
this.addClass("HtmlEncoder", "@mozilla.org/layout/htmlCopyEncoder;1", "nsIDocumentEncoder");
this.addClass("InterfacePointer", "@mozilla.org/supports-interface-pointer;1", "nsISupportsInterfacePointer", "data");
this.addClass("InputStream", "@mozilla.org/scriptableinputstream;1", "nsIScriptableInputStream", "init");
+ this.addClass("MIMEStream", "@mozilla.org/network/mime-input-stream;1", "nsIMIMEInputStream", "setData");
this.addClass("Persist", "@mozilla.org/embedding/browser/nsWebBrowserPersist;1", "nsIWebBrowserPersist");
this.addClass("Pipe", "@mozilla.org/pipe;1", "nsIPipe", "init");
this.addClass("Process", "@mozilla.org/process/util;1", "nsIProcess", "init");
- this.addClass("Pump", "@mozilla.org/network/input-stream-pump;1", "nsIInputStreamPump", "init")
+ this.addClass("Pump", "@mozilla.org/network/input-stream-pump;1", "nsIInputStreamPump", "init");
this.addClass("StreamChannel","@mozilla.org/network/input-stream-channel;1",
["nsIInputStreamChannel", "nsIChannel"], "setURI");
this.addClass("StreamCopier", "@mozilla.org/network/async-stream-copier;1","nsIAsyncStreamCopier", "init");
this.addClass("Transferable", "@mozilla.org/widget/transferable;1", "nsITransferable");
this.addClass("Timer", "@mozilla.org/timer;1", "nsITimer", "initWithCallback");
this.addClass("URL", "@mozilla.org/network/standard-url;1", ["nsIStandardURL", "nsIURL"], "init");
- this.addClass("Xmlhttp", "@mozilla.org/xmlextras/xmlhttprequest;1", "nsIXMLHttpRequest", "open");
+ 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];
if (!service.interfaces.length)
return res.wrappedJSObject || res;
- service.interfaces.forEach(function (iface) res.QueryInterface(Ci[iface]));
+ service.interfaces.forEach(function (iface) res instanceof Ci[iface]);
if (service.init && args.length) {
if (service.callable)
res[service.init].apply(res, args);
}
return res;
}
- catch (e if service.quiet !== false) {
- if (typeof util !== "undefined")
+ catch (e) {
+ if (service.quiet === false)
+ throw e.stack ? e : Error(e);
+
+ if (typeof util !== "undefined" && util != null)
util.reportError(e);
else
dump("dactyl: Service creation failed for '" + service.class + "': " + e + "\n" + (e.stack || Error(e).stack));
* @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))
* @param {string} init Name of a property or method used to initialize the
* class.
*/
- addClass: function (name, class_, ifaces, init, quiet) {
- const self = this;
+ addClass: function addClass(name, class_, ifaces, init, quiet) {
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() this._create(name, arguments)).bind(this);
update.apply(null, [this[name]].concat([Ci[i] for each (i in Array.concat(ifaces))]));
return this[name];
},
*
* @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)
});
} catch(e){dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack);}
-// vim: set fdm=marker sw=4 sts=4 et ft=javascript:
+// vim: set fdm=marker sw=4 sts=4 ts=8 et ft=javascript: