|
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/. */ |
|
4 |
|
5 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); |
|
6 |
|
7 const nsISupports = Components.interfaces.nsISupports; |
|
8 |
|
9 const nsICommandLine = Components.interfaces.nsICommandLine; |
|
10 const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler; |
|
11 const nsIPrefBranch = Components.interfaces.nsIPrefBranch; |
|
12 const nsISupportsString = Components.interfaces.nsISupportsString; |
|
13 const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; |
|
14 const nsIProperties = Components.interfaces.nsIProperties; |
|
15 const nsIFile = Components.interfaces.nsIFile; |
|
16 const nsISimpleEnumerator = Components.interfaces.nsISimpleEnumerator; |
|
17 |
|
18 /** |
|
19 * This file provides a generic default command-line handler. |
|
20 * |
|
21 * It opens the chrome window specified by the pref "toolkit.defaultChromeURI" |
|
22 * with the flags specified by the pref "toolkit.defaultChromeFeatures" |
|
23 * or "chrome,dialog=no,all" is it is not available. |
|
24 * The arguments passed to the window are the nsICommandLine instance. |
|
25 * |
|
26 * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset. |
|
27 */ |
|
28 |
|
29 function getDirectoryService() |
|
30 { |
|
31 return Components.classes["@mozilla.org/file/directory_service;1"] |
|
32 .getService(nsIProperties); |
|
33 } |
|
34 |
|
35 function nsDefaultCLH() { } |
|
36 nsDefaultCLH.prototype = { |
|
37 classID: Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}"), |
|
38 |
|
39 /* nsISupports */ |
|
40 |
|
41 QueryInterface : XPCOMUtils.generateQI([nsICommandLineHandler]), |
|
42 |
|
43 /* nsICommandLineHandler */ |
|
44 |
|
45 handle : function clh_handle(cmdLine) { |
|
46 var printDir; |
|
47 while ((printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false))) { |
|
48 var out = "print-xpcom-dir(\"" + printDir + "\"): "; |
|
49 try { |
|
50 out += getDirectoryService().get(printDir, nsIFile).path; |
|
51 } |
|
52 catch (e) { |
|
53 out += "<Not Provided>"; |
|
54 } |
|
55 |
|
56 dump(out + "\n"); |
|
57 Components.utils.reportError(out); |
|
58 } |
|
59 |
|
60 var printDirList; |
|
61 while ((printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist", |
|
62 false))) { |
|
63 out = "print-xpcom-dirlist(\"" + printDirList + "\"): "; |
|
64 try { |
|
65 var list = getDirectoryService().get(printDirList, |
|
66 nsISimpleEnumerator); |
|
67 while (list.hasMoreElements()) |
|
68 out += list.getNext().QueryInterface(nsIFile).path + ";"; |
|
69 } |
|
70 catch (e) { |
|
71 out += "<Not Provided>"; |
|
72 } |
|
73 |
|
74 dump(out + "\n"); |
|
75 Components.utils.reportError(out); |
|
76 } |
|
77 |
|
78 if (cmdLine.handleFlag("silent", false)) { |
|
79 cmdLine.preventDefault = true; |
|
80 } |
|
81 |
|
82 if (cmdLine.preventDefault) |
|
83 return; |
|
84 |
|
85 var prefs = Components.classes["@mozilla.org/preferences-service;1"] |
|
86 .getService(nsIPrefBranch); |
|
87 |
|
88 try { |
|
89 var singletonWindowType = |
|
90 prefs.getCharPref("toolkit.singletonWindowType"); |
|
91 var windowMediator = |
|
92 Components.classes["@mozilla.org/appshell/window-mediator;1"] |
|
93 .getService(Components.interfaces.nsIWindowMediator); |
|
94 |
|
95 var win = windowMediator.getMostRecentWindow(singletonWindowType); |
|
96 if (win) { |
|
97 win.focus(); |
|
98 cmdLine.preventDefault = true; |
|
99 return; |
|
100 } |
|
101 } |
|
102 catch (e) { } |
|
103 |
|
104 // if the pref is missing, ignore the exception |
|
105 try { |
|
106 var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI"); |
|
107 |
|
108 var flags = "chrome,dialog=no,all"; |
|
109 try { |
|
110 flags = prefs.getCharPref("toolkit.defaultChromeFeatures"); |
|
111 } |
|
112 catch (e) { } |
|
113 |
|
114 var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] |
|
115 .getService(nsIWindowWatcher); |
|
116 wwatch.openWindow(null, chromeURI, "_blank", |
|
117 flags, cmdLine); |
|
118 } |
|
119 catch (e) { } |
|
120 }, |
|
121 |
|
122 helpInfo : "", |
|
123 }; |
|
124 |
|
125 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsDefaultCLH]); |