1 # ***** BEGIN LICENSE BLOCK *****
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
14 # The Original Code is the Mozilla Firefox browser.
16 # The Initial Developer of the Original Code is
17 # Benjamin Smedberg <benjamin@smedbergs.us>
19 # Portions created by the Initial Developer are Copyright (C) 2004
20 # the Initial Developer. All Rights Reserved.
23 # Daniel Glazman <daniel.glazman@disruptive-innovations.com>
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
39 const nsISupports = Components.interfaces.nsISupports;
41 const nsICategoryManager = Components.interfaces.nsICategoryManager;
42 const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
43 const nsICommandLine = Components.interfaces.nsICommandLine;
44 const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
45 const nsIFactory = Components.interfaces.nsIFactory;
46 const nsIModule = Components.interfaces.nsIModule;
47 const nsIPrefBranch = Components.interfaces.nsIPrefBranch;
48 const nsISupportsString = Components.interfaces.nsISupportsString;
49 const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
50 const nsIProperties = Components.interfaces.nsIProperties;
51 const nsIFile = Components.interfaces.nsIFile;
52 const nsISimpleEnumerator = Components.interfaces.nsISimpleEnumerator;
55 * This file provides a generic default command-line handler.
57 * It opens the chrome window specified by the pref "toolkit.defaultChromeURI"
58 * with the flags specified by the pref "toolkit.defaultChromeFeatures"
59 * or "chrome,dialog=no,all" is it is not available.
60 * The arguments passed to the window are the nsICommandLine instance.
62 * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset.
65 function getDirectoryService()
67 return Components.classes["@mozilla.org/file/directory_service;1"]
68 .getService(nsIProperties);
74 QueryInterface : function clh_QI(iid) {
75 if (iid.equals(nsICommandLineHandler) ||
76 iid.equals(nsIFactory) ||
77 iid.equals(nsISupports))
80 throw Components.results.NS_ERROR_NO_INTERFACE;
83 /* nsICommandLineHandler */
85 handle : function clh_handle(cmdLine) {
87 while (printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false)) {
88 var out = "print-xpcom-dir(\"" + printDir + "\"): ";
90 out += getDirectoryService().get(printDir, nsIFile).path;
93 out += "<Not Provided>";
97 Components.utils.reportError(out);
101 while (printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist",
103 out = "print-xpcom-dirlist(\"" + printDirList + "\"): ";
105 var list = getDirectoryService().get(printDirList,
106 nsISimpleEnumerator);
107 while (list.hasMoreElements())
108 out += list.getNext().QueryInterface(nsIFile).path + ";";
111 out += "<Not Provided>";
115 Components.utils.reportError(out);
118 if (cmdLine.preventDefault)
121 var prefs = Components.classes["@mozilla.org/preferences-service;1"]
122 .getService(nsIPrefBranch);
125 var singletonWindowType =
126 prefs.getCharPref("toolkit.singletonWindowType");
128 Components.classes["@mozilla.org/appshell/window-mediator;1"]
129 .getService(Components.interfaces.nsIWindowMediator);
131 var win = windowMediator.getMostRecentWindow(singletonWindowType);
134 cmdLine.preventDefault = true;
140 // if the pref is missing, ignore the exception
142 var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
144 var flags = "chrome,dialog=no,all";
146 flags = prefs.getCharPref("toolkit.defaultChromeFeatures");
150 var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
151 .getService(nsIWindowWatcher);
152 wwatch.openWindow(null, chromeURI, "_blank",
162 createInstance : function mdh_CI(outer, iid) {
164 throw Components.results.NS_ERROR_NO_AGGREGATION;
166 return this.QueryInterface(iid);
169 lockFactory : function mdh_lock(lock) {
174 const clh_contractID = "@mozilla.org/toolkit/default-clh;1";
175 const clh_CID = Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}");
180 QueryInterface : function mod_QI(iid) {
181 if (iid.equals(nsIModule) ||
182 iid.equals(nsISupports))
185 throw Components.results.NS_ERROR_NO_INTERFACE;
190 getClassObject : function mod_gch(compMgr, cid, iid) {
191 if (cid.equals(clh_CID))
192 return nsDefaultCLH.QueryInterface(iid);
194 throw components.results.NS_ERROR_FAILURE;
197 registerSelf : function mod_regself(compMgr, fileSpec, location, type) {
198 var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
200 compReg.registerFactoryLocation(clh_CID,
207 var catMan = Components.classes["@mozilla.org/categorymanager;1"]
208 .getService(nsICategoryManager);
210 catMan.addCategoryEntry("command-line-handler",
212 clh_contractID, true, true);
215 unregisterSelf : function mod_unreg(compMgr, location, type) {
216 var compReg = compMgr.QueryInterface(nsIComponentRegistrar);
217 compReg.unregisterFactoryLocation(clh_CID, location);
219 var catMan = Components.classes["@mozilla.org/categorymanager;1"]
220 .getService(nsICategoryManager);
222 catMan.deleteCategoryEntry("command-line-handler",
226 canUnload : function (compMgr) {
231 function NSGetModule(compMgr, fileSpec) {