1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const nsICommandLineHandler = Ci.nsICommandLineHandler;
6 const nsIPrefBranch = Ci.nsIPrefBranch;
7 const nsIWindowWatcher = Ci.nsIWindowWatcher;
8 const nsIProperties = Ci.nsIProperties;
9 const nsIFile = Ci.nsIFile;
10 const nsISimpleEnumerator = Ci.nsISimpleEnumerator;
13 * This file provides a generic default command-line handler.
15 * It opens the chrome window specified by the pref "toolkit.defaultChromeURI"
16 * with the flags specified by the pref "toolkit.defaultChromeFeatures"
17 * or "chrome,dialog=no,all" is it is not available.
18 * The arguments passed to the window are the nsICommandLine instance.
20 * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset.
23 function getDirectoryService() {
24 return Cc["@mozilla.org/file/directory_service;1"].getService(nsIProperties);
27 export function nsDefaultCLH() {}
28 nsDefaultCLH.prototype = {
29 classID: Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}"),
33 QueryInterface: ChromeUtils.generateQI([nsICommandLineHandler]),
35 /* nsICommandLineHandler */
37 handle: function clh_handle(cmdLine) {
39 while ((printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false))) {
40 var out = 'print-xpcom-dir("' + printDir + '"): ';
42 out += getDirectoryService().get(printDir, nsIFile).path;
44 out += "<Not Provided>";
53 (printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist", false))
55 out = 'print-xpcom-dirlist("' + printDirList + '"): ';
57 for (let file of getDirectoryService().get(
61 out += file.path + ";";
64 out += "<Not Provided>";
71 if (cmdLine.handleFlag("silent", false)) {
72 cmdLine.preventDefault = true;
75 if (cmdLine.preventDefault) {
80 Cc["@mozilla.org/preferences-service;1"].getService(nsIPrefBranch);
83 var singletonWindowType = prefs.getCharPref(
84 "toolkit.singletonWindowType"
87 var win = Services.wm.getMostRecentWindow(singletonWindowType);
90 cmdLine.preventDefault = true;
95 // if the pref is missing, ignore the exception
97 var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
99 var flags = prefs.getCharPref(
100 "toolkit.defaultChromeFeatures",
101 "chrome,dialog=no,all"
105 Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(
108 wwatch.openWindow(null, chromeURI, "_blank", flags, cmdLine);