Bug 1735252 [wpt PR 31197] - Regenerate WPT certificates, a=testonly
[gecko.git] / toolkit / components / DefaultCLH.jsm
blob553a2f06885c750edc6adde733e7ee2810b42321
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;
14 /**
15  * This file provides a generic default command-line handler.
16  *
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.
21  *
22  * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset.
23  */
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}"),
33   /* nsISupports */
35   QueryInterface: ChromeUtils.generateQI([nsICommandLineHandler]),
37   /* nsICommandLineHandler */
39   handle: function clh_handle(cmdLine) {
40     var printDir;
41     while ((printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false))) {
42       var out = 'print-xpcom-dir("' + printDir + '"): ';
43       try {
44         out += getDirectoryService().get(printDir, nsIFile).path;
45       } catch (e) {
46         out += "<Not Provided>";
47       }
49       dump(out + "\n");
50       Cu.reportError(out);
51     }
53     var printDirList;
54     while (
55       (printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist", false))
56     ) {
57       out = 'print-xpcom-dirlist("' + printDirList + '"): ';
58       try {
59         for (let file of getDirectoryService().get(
60           printDirList,
61           nsISimpleEnumerator
62         )) {
63           out += file.path + ";";
64         }
65       } catch (e) {
66         out += "<Not Provided>";
67       }
69       dump(out + "\n");
70       Cu.reportError(out);
71     }
73     if (cmdLine.handleFlag("silent", false)) {
74       cmdLine.preventDefault = true;
75     }
77     if (cmdLine.preventDefault) {
78       return;
79     }
81     var prefs = Cc["@mozilla.org/preferences-service;1"].getService(
82       nsIPrefBranch
83     );
85     try {
86       var singletonWindowType = prefs.getCharPref(
87         "toolkit.singletonWindowType"
88       );
90       var win = Services.wm.getMostRecentWindow(singletonWindowType);
91       if (win) {
92         win.focus();
93         cmdLine.preventDefault = true;
94         return;
95       }
96     } catch (e) {}
98     // if the pref is missing, ignore the exception
99     try {
100       var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
102       var flags = prefs.getCharPref(
103         "toolkit.defaultChromeFeatures",
104         "chrome,dialog=no,all"
105       );
107       var wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(
108         nsIWindowWatcher
109       );
110       wwatch.openWindow(null, chromeURI, "_blank", flags, cmdLine);
111     } catch (e) {}
112   },
114   helpInfo: "",
117 var EXPORTED_SYMBOLS = ["nsDefaultCLH"];