Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
7 const nsISupports = Components.interfaces.nsISupports;
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;
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 */
29 function getDirectoryService()
30 {
31 return Components.classes["@mozilla.org/file/directory_service;1"]
32 .getService(nsIProperties);
33 }
35 function nsDefaultCLH() { }
36 nsDefaultCLH.prototype = {
37 classID: Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}"),
39 /* nsISupports */
41 QueryInterface : XPCOMUtils.generateQI([nsICommandLineHandler]),
43 /* nsICommandLineHandler */
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 }
56 dump(out + "\n");
57 Components.utils.reportError(out);
58 }
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 }
74 dump(out + "\n");
75 Components.utils.reportError(out);
76 }
78 if (cmdLine.handleFlag("silent", false)) {
79 cmdLine.preventDefault = true;
80 }
82 if (cmdLine.preventDefault)
83 return;
85 var prefs = Components.classes["@mozilla.org/preferences-service;1"]
86 .getService(nsIPrefBranch);
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);
95 var win = windowMediator.getMostRecentWindow(singletonWindowType);
96 if (win) {
97 win.focus();
98 cmdLine.preventDefault = true;
99 return;
100 }
101 }
102 catch (e) { }
104 // if the pref is missing, ignore the exception
105 try {
106 var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
108 var flags = "chrome,dialog=no,all";
109 try {
110 flags = prefs.getCharPref("toolkit.defaultChromeFeatures");
111 }
112 catch (e) { }
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 },
122 helpInfo : "",
123 };
125 this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsDefaultCLH]);