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 { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
7 const nsICommandLineHandler = Ci.nsICommandLineHandler;
8 const nsIPrefBranch = Ci.nsIPrefBranch;
9 const nsIWindowWatcher = Ci.nsIWindowWatcher;
10 const nsIProperties = Ci.nsIProperties;
11 const nsIFile = Ci.nsIFile;
12 const nsISimpleEnumerator = Ci.nsISimpleEnumerator;
15 * This file provides a generic default command-line handler.
17 * It opens the chrome window specified by the pref "toolkit.defaultChromeURI"
18 * with the flags specified by the pref "toolkit.defaultChromeFeatures"
19 * or "chrome,dialog=no,all" is it is not available.
20 * The arguments passed to the window are the nsICommandLine instance.
22 * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset.
25 function getDirectoryService() {
26 return Cc["@mozilla.org/file/directory_service;1"].getService(nsIProperties);
29 function nsDefaultCLH() {}
30 nsDefaultCLH.prototype = {
31 classID: Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}"),
35 QueryInterface: ChromeUtils.generateQI([nsICommandLineHandler]),
37 /* nsICommandLineHandler */
39 handle: function clh_handle(cmdLine) {
41 while ((printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false))) {
42 var out = 'print-xpcom-dir("' + printDir + '"): ';
44 out += getDirectoryService().get(printDir, nsIFile).path;
46 out += "<Not Provided>";
55 (printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist", false))
57 out = 'print-xpcom-dirlist("' + printDirList + '"): ';
59 for (let file of getDirectoryService().get(
63 out += file.path + ";";
66 out += "<Not Provided>";
73 if (cmdLine.handleFlag("silent", false)) {
74 cmdLine.preventDefault = true;
77 if (cmdLine.preventDefault) {
81 var prefs = Cc["@mozilla.org/preferences-service;1"].getService(
86 var singletonWindowType = prefs.getCharPref(
87 "toolkit.singletonWindowType"
90 var win = Services.wm.getMostRecentWindow(singletonWindowType);
93 cmdLine.preventDefault = true;
98 // if the pref is missing, ignore the exception
100 var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
102 var flags = prefs.getCharPref(
103 "toolkit.defaultChromeFeatures",
104 "chrome,dialog=no,all"
107 var wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(
110 wwatch.openWindow(null, chromeURI, "_blank", flags, cmdLine);
117 var EXPORTED_SYMBOLS = ["nsDefaultCLH"];