michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); michael@0: michael@0: const nsISupports = Components.interfaces.nsISupports; michael@0: michael@0: const nsICommandLine = Components.interfaces.nsICommandLine; michael@0: const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler; michael@0: const nsIPrefBranch = Components.interfaces.nsIPrefBranch; michael@0: const nsISupportsString = Components.interfaces.nsISupportsString; michael@0: const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; michael@0: const nsIProperties = Components.interfaces.nsIProperties; michael@0: const nsIFile = Components.interfaces.nsIFile; michael@0: const nsISimpleEnumerator = Components.interfaces.nsISimpleEnumerator; michael@0: michael@0: /** michael@0: * This file provides a generic default command-line handler. michael@0: * michael@0: * It opens the chrome window specified by the pref "toolkit.defaultChromeURI" michael@0: * with the flags specified by the pref "toolkit.defaultChromeFeatures" michael@0: * or "chrome,dialog=no,all" is it is not available. michael@0: * The arguments passed to the window are the nsICommandLine instance. michael@0: * michael@0: * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset. michael@0: */ michael@0: michael@0: function getDirectoryService() michael@0: { michael@0: return Components.classes["@mozilla.org/file/directory_service;1"] michael@0: .getService(nsIProperties); michael@0: } michael@0: michael@0: function nsDefaultCLH() { } michael@0: nsDefaultCLH.prototype = { michael@0: classID: Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}"), michael@0: michael@0: /* nsISupports */ michael@0: michael@0: QueryInterface : XPCOMUtils.generateQI([nsICommandLineHandler]), michael@0: michael@0: /* nsICommandLineHandler */ michael@0: michael@0: handle : function clh_handle(cmdLine) { michael@0: var printDir; michael@0: while ((printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false))) { michael@0: var out = "print-xpcom-dir(\"" + printDir + "\"): "; michael@0: try { michael@0: out += getDirectoryService().get(printDir, nsIFile).path; michael@0: } michael@0: catch (e) { michael@0: out += ""; michael@0: } michael@0: michael@0: dump(out + "\n"); michael@0: Components.utils.reportError(out); michael@0: } michael@0: michael@0: var printDirList; michael@0: while ((printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist", michael@0: false))) { michael@0: out = "print-xpcom-dirlist(\"" + printDirList + "\"): "; michael@0: try { michael@0: var list = getDirectoryService().get(printDirList, michael@0: nsISimpleEnumerator); michael@0: while (list.hasMoreElements()) michael@0: out += list.getNext().QueryInterface(nsIFile).path + ";"; michael@0: } michael@0: catch (e) { michael@0: out += ""; michael@0: } michael@0: michael@0: dump(out + "\n"); michael@0: Components.utils.reportError(out); michael@0: } michael@0: michael@0: if (cmdLine.handleFlag("silent", false)) { michael@0: cmdLine.preventDefault = true; michael@0: } michael@0: michael@0: if (cmdLine.preventDefault) michael@0: return; michael@0: michael@0: var prefs = Components.classes["@mozilla.org/preferences-service;1"] michael@0: .getService(nsIPrefBranch); michael@0: michael@0: try { michael@0: var singletonWindowType = michael@0: prefs.getCharPref("toolkit.singletonWindowType"); michael@0: var windowMediator = michael@0: Components.classes["@mozilla.org/appshell/window-mediator;1"] michael@0: .getService(Components.interfaces.nsIWindowMediator); michael@0: michael@0: var win = windowMediator.getMostRecentWindow(singletonWindowType); michael@0: if (win) { michael@0: win.focus(); michael@0: cmdLine.preventDefault = true; michael@0: return; michael@0: } michael@0: } michael@0: catch (e) { } michael@0: michael@0: // if the pref is missing, ignore the exception michael@0: try { michael@0: var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI"); michael@0: michael@0: var flags = "chrome,dialog=no,all"; michael@0: try { michael@0: flags = prefs.getCharPref("toolkit.defaultChromeFeatures"); michael@0: } michael@0: catch (e) { } michael@0: michael@0: var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] michael@0: .getService(nsIWindowWatcher); michael@0: wwatch.openWindow(null, chromeURI, "_blank", michael@0: flags, cmdLine); michael@0: } michael@0: catch (e) { } michael@0: }, michael@0: michael@0: helpInfo : "", michael@0: }; michael@0: michael@0: this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsDefaultCLH]);