Bug 386531 - XPCOMUtilify console command line handler. r+a=mconnor

This commit is contained in:
rflint@ryanflint.com 2007-11-22 21:24:20 -08:00
Родитель c32b61d5f9
Коммит 8a48dae7e3
1 изменённых файлов: 32 добавлений и 125 удалений

Просмотреть файл

@ -38,133 +38,40 @@
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****
const Cc = Components.classes;
const Ci = Components.interfaces;
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
/*
* -jsconsole commandline handler; starts up the Error console.
*/
function jsConsoleHandler() {}
jsConsoleHandler.prototype = {
handle: function clh_handle(cmdLine) {
if (!cmdLine.handleFlag("jsconsole", false))
return;
const nsISupports = Components.interfaces.nsISupports;
const nsICategoryManager = Components.interfaces.nsICategoryManager;
const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
const nsICommandLine = Components.interfaces.nsICommandLine;
const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
const nsIFactory = Components.interfaces.nsIFactory;
const nsIModule = Components.interfaces.nsIModule;
const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
const nsIWindowMediator = Components.interfaces.nsIWindowMediator;
/*
* Classes
*/
const jsConsoleHandler = {
/* nsISupports */
QueryInterface : function clh_QI(iid) {
if (iid.equals(nsICommandLineHandler) ||
iid.equals(nsIFactory) ||
iid.equals(nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
/* nsICommandLineHandler */
handle : function clh_handle(cmdLine) {
if (!cmdLine.handleFlag("jsconsole", false))
return;
var windowMediator = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(nsIWindowMediator);
var console = windowMediator.getMostRecentWindow("global:console");
if (!console) {
var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(nsIWindowWatcher);
wwatch.openWindow(null, "chrome://global/content/console.xul", "_blank",
"chrome,dialog=no,all", cmdLine);
} else {
// the Error console was already open
console.focus();
}
if (cmdLine.state == nsICommandLine.STATE_REMOTE_AUTO) {
cmdLine.preventDefault = true;
}
},
helpInfo : " -jsconsole Open the Error console.\n",
/* nsIFactory */
createInstance : function clh_CI(outer, iid) {
if (outer != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return this.QueryInterface(iid);
},
lockFactory : function clh_lock(lock) {
/* no-op */
var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
getService(Ci.nsIWindowMediator);
var console = wm.getMostRecentWindow("global:console");
if (!console) {
var wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
wwatch.openWindow(null, "chrome://global/content/console.xul", "_blank",
"chrome,dialog=no,all", cmdLine);
} else {
console.focus(); // the Error console was already open
}
if (cmdLine.state == Ci.nsICommandLine.STATE_REMOTE_AUTO)
cmdLine.preventDefault = true;
},
helpInfo : " -jsconsole Open the Error console.\n",
classDescription: "jsConsoleHandler",
classID: Components.ID("{2cd0c310-e127-44d0-88fc-4435c9ab4d4b}"),
contractID: "@mozilla.org/toolkit/console-clh;1",
QueryInterface: XPCOMUtils.generateQI([Ci.nsICommandLineHandler]),
_xpcom_categories: [{category: "command-line-handler", entry: "b-jsconsole"}]
};
const clh_contractID = "@mozilla.org/toolkit/console-clh;1";
const clh_CID = Components.ID("{2cd0c310-e127-44d0-88fc-4435c9ab4d4b}");
const clh_category = "c-jsconsole";
const jsConsoleHandlerModule = {
/* nsISupports */
QueryInterface : function mod_QI(iid) {
if (iid.equals(nsIModule) ||
iid.equals(nsISupports))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
},
/* nsIModule */
getClassObject : function mod_gch(compMgr, cid, iid) {
if (cid.equals(clh_CID))
return jsConsoleHandler.QueryInterface(iid);
throw Components.results.NS_ERROR_NOT_REGISTERED;
},
registerSelf : function mod_regself(compMgr, fileSpec, location, type) {
compMgr.QueryInterface(nsIComponentRegistrar);
compMgr.registerFactoryLocation(clh_CID,
"jsConsoleHandler",
clh_contractID,
fileSpec,
location,
type);
var catMan = Components.classes["@mozilla.org/categorymanager;1"]
.getService(nsICategoryManager);
catMan.addCategoryEntry("command-line-handler",
clh_category,
clh_contractID, true, true);
},
unregisterSelf : function mod_unreg(compMgr, location, type) {
compMgr.QueryInterface(nsIComponentRegistrar);
compMgr.unregisterFactoryLocation(clh_CID, location);
var catMan = Components.classes["@mozilla.org/categorymanager;1"]
.getService(nsICategoryManager);
catMan.deleteCategoryEntry("command-line-handler", clh_category);
},
canUnload : function (compMgr) {
return true;
}
};
/* module initialisation */
function NSGetModule(comMgr, fileSpec) {
return jsConsoleHandlerModule;
}
function NSGetModule(compMgr, fileSpec)
XPCOMUtils.generateModule([jsConsoleHandler]);