2012-08-04 05:22:55 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
2010-06-22 20:59:15 +04:00
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
const nsICommandLineHandler = Ci.nsICommandLineHandler;
|
|
|
|
const nsIPrefBranch = Ci.nsIPrefBranch;
|
|
|
|
const nsIWindowWatcher = Ci.nsIWindowWatcher;
|
|
|
|
const nsIProperties = Ci.nsIProperties;
|
|
|
|
const nsIFile = Ci.nsIFile;
|
|
|
|
const nsISimpleEnumerator = Ci.nsISimpleEnumerator;
|
2005-01-17 21:50:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* This file provides a generic default command-line handler.
|
|
|
|
*
|
|
|
|
* It opens the chrome window specified by the pref "toolkit.defaultChromeURI"
|
2006-04-12 06:43:01 +04:00
|
|
|
* with the flags specified by the pref "toolkit.defaultChromeFeatures"
|
2006-04-11 19:03:27 +04:00
|
|
|
* or "chrome,dialog=no,all" is it is not available.
|
|
|
|
* The arguments passed to the window are the nsICommandLine instance.
|
2005-01-17 21:50:18 +03:00
|
|
|
*
|
2006-04-11 19:03:27 +04:00
|
|
|
* It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset.
|
2005-01-17 21:50:18 +03:00
|
|
|
*/
|
|
|
|
|
2016-12-31 05:47:25 +03:00
|
|
|
function getDirectoryService() {
|
2018-02-28 20:51:33 +03:00
|
|
|
return Cc["@mozilla.org/file/directory_service;1"].getService(nsIProperties);
|
2007-04-20 19:22:17 +04:00
|
|
|
}
|
|
|
|
|
2010-06-22 20:59:15 +04:00
|
|
|
function nsDefaultCLH() {}
|
|
|
|
nsDefaultCLH.prototype = {
|
|
|
|
classID: Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}"),
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2010-06-22 20:59:15 +04:00
|
|
|
/* nsISupports */
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2018-04-23 06:55:06 +03:00
|
|
|
QueryInterface: ChromeUtils.generateQI([nsICommandLineHandler]),
|
2005-01-17 21:50:18 +03:00
|
|
|
|
|
|
|
/* nsICommandLineHandler */
|
|
|
|
|
2017-03-21 21:29:43 +03:00
|
|
|
handle: function clh_handle(cmdLine) {
|
2007-04-20 19:22:17 +04:00
|
|
|
var printDir;
|
2012-12-19 02:27:56 +04:00
|
|
|
while ((printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false))) {
|
2007-04-20 19:22:17 +04:00
|
|
|
var out = 'print-xpcom-dir("' + printDir + '"): ';
|
|
|
|
try {
|
|
|
|
out += getDirectoryService().get(printDir, nsIFile).path;
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2007-04-20 19:22:17 +04:00
|
|
|
out += "<Not Provided>";
|
|
|
|
}
|
|
|
|
|
|
|
|
dump(out + "\n");
|
2018-02-28 20:51:33 +03:00
|
|
|
Cu.reportError(out);
|
2007-04-20 19:22:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
var printDirList;
|
2012-12-19 02:27:56 +04:00
|
|
|
while (
|
|
|
|
(printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist", false))
|
|
|
|
) {
|
2007-04-20 19:22:17 +04:00
|
|
|
out = 'print-xpcom-dirlist("' + printDirList + '"): ';
|
|
|
|
try {
|
2018-08-19 05:27:50 +03:00
|
|
|
for (let file of getDirectoryService().get(
|
|
|
|
printDirList,
|
|
|
|
nsISimpleEnumerator
|
|
|
|
)) {
|
|
|
|
out += file.path + ";";
|
2019-07-05 12:14:05 +03:00
|
|
|
}
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {
|
2007-04-20 19:22:17 +04:00
|
|
|
out += "<Not Provided>";
|
|
|
|
}
|
|
|
|
|
|
|
|
dump(out + "\n");
|
2018-02-28 20:51:33 +03:00
|
|
|
Cu.reportError(out);
|
2007-04-20 19:22:17 +04:00
|
|
|
}
|
2016-02-04 01:22:33 +03:00
|
|
|
|
2008-12-18 23:05:46 +03:00
|
|
|
if (cmdLine.handleFlag("silent", false)) {
|
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
}
|
2007-04-20 19:22:17 +04:00
|
|
|
|
2005-01-17 21:50:18 +03:00
|
|
|
if (cmdLine.preventDefault) {
|
2007-04-20 19:22:17 +04:00
|
|
|
return;
|
2019-07-05 12:14:05 +03:00
|
|
|
}
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
var prefs = Cc["@mozilla.org/preferences-service;1"].getService(
|
|
|
|
nsIPrefBranch
|
|
|
|
);
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2006-02-05 17:58:27 +03:00
|
|
|
try {
|
|
|
|
var singletonWindowType = prefs.getCharPref(
|
|
|
|
"toolkit.singletonWindowType"
|
|
|
|
);
|
|
|
|
|
2017-10-30 19:29:58 +03:00
|
|
|
var win = Services.wm.getMostRecentWindow(singletonWindowType);
|
2006-02-05 17:58:27 +03:00
|
|
|
if (win) {
|
|
|
|
win.focus();
|
2016-02-04 05:09:49 +03:00
|
|
|
cmdLine.preventDefault = true;
|
|
|
|
return;
|
2006-02-05 17:58:27 +03:00
|
|
|
}
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {}
|
2006-02-05 17:58:27 +03:00
|
|
|
|
2016-02-04 01:22:33 +03:00
|
|
|
// if the pref is missing, ignore the exception
|
2005-02-27 10:12:05 +03:00
|
|
|
try {
|
|
|
|
var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI");
|
2005-01-17 21:50:18 +03:00
|
|
|
|
2017-03-07 17:29:48 +03:00
|
|
|
var flags = prefs.getCharPref(
|
|
|
|
"toolkit.defaultChromeFeatures",
|
|
|
|
"chrome,dialog=no,all"
|
|
|
|
);
|
2006-04-11 19:03:27 +04:00
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
var wwatch = Cc["@mozilla.org/embedcomp/window-watcher;1"].getService(
|
2005-02-27 10:12:05 +03:00
|
|
|
nsIWindowWatcher
|
|
|
|
);
|
|
|
|
wwatch.openWindow(null, chromeURI, "_blank", flags, cmdLine);
|
2016-12-31 05:47:25 +03:00
|
|
|
} catch (e) {}
|
2005-01-17 21:50:18 +03:00
|
|
|
},
|
|
|
|
|
2017-03-21 21:29:43 +03:00
|
|
|
helpInfo: "",
|
2005-01-17 21:50:18 +03:00
|
|
|
};
|
|
|
|
|
2019-01-30 21:26:59 +03:00
|
|
|
var EXPORTED_SYMBOLS = ["nsDefaultCLH"];
|