1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/nsDefaultCLH.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,125 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +Components.utils.import("resource://gre/modules/XPCOMUtils.jsm"); 1.9 + 1.10 +const nsISupports = Components.interfaces.nsISupports; 1.11 + 1.12 +const nsICommandLine = Components.interfaces.nsICommandLine; 1.13 +const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler; 1.14 +const nsIPrefBranch = Components.interfaces.nsIPrefBranch; 1.15 +const nsISupportsString = Components.interfaces.nsISupportsString; 1.16 +const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher; 1.17 +const nsIProperties = Components.interfaces.nsIProperties; 1.18 +const nsIFile = Components.interfaces.nsIFile; 1.19 +const nsISimpleEnumerator = Components.interfaces.nsISimpleEnumerator; 1.20 + 1.21 +/** 1.22 + * This file provides a generic default command-line handler. 1.23 + * 1.24 + * It opens the chrome window specified by the pref "toolkit.defaultChromeURI" 1.25 + * with the flags specified by the pref "toolkit.defaultChromeFeatures" 1.26 + * or "chrome,dialog=no,all" is it is not available. 1.27 + * The arguments passed to the window are the nsICommandLine instance. 1.28 + * 1.29 + * It doesn't do anything if the pref "toolkit.defaultChromeURI" is unset. 1.30 + */ 1.31 + 1.32 +function getDirectoryService() 1.33 +{ 1.34 + return Components.classes["@mozilla.org/file/directory_service;1"] 1.35 + .getService(nsIProperties); 1.36 +} 1.37 + 1.38 +function nsDefaultCLH() { } 1.39 +nsDefaultCLH.prototype = { 1.40 + classID: Components.ID("{6ebc941a-f2ff-4d56-b3b6-f7d0b9d73344}"), 1.41 + 1.42 + /* nsISupports */ 1.43 + 1.44 + QueryInterface : XPCOMUtils.generateQI([nsICommandLineHandler]), 1.45 + 1.46 + /* nsICommandLineHandler */ 1.47 + 1.48 + handle : function clh_handle(cmdLine) { 1.49 + var printDir; 1.50 + while ((printDir = cmdLine.handleFlagWithParam("print-xpcom-dir", false))) { 1.51 + var out = "print-xpcom-dir(\"" + printDir + "\"): "; 1.52 + try { 1.53 + out += getDirectoryService().get(printDir, nsIFile).path; 1.54 + } 1.55 + catch (e) { 1.56 + out += "<Not Provided>"; 1.57 + } 1.58 + 1.59 + dump(out + "\n"); 1.60 + Components.utils.reportError(out); 1.61 + } 1.62 + 1.63 + var printDirList; 1.64 + while ((printDirList = cmdLine.handleFlagWithParam("print-xpcom-dirlist", 1.65 + false))) { 1.66 + out = "print-xpcom-dirlist(\"" + printDirList + "\"): "; 1.67 + try { 1.68 + var list = getDirectoryService().get(printDirList, 1.69 + nsISimpleEnumerator); 1.70 + while (list.hasMoreElements()) 1.71 + out += list.getNext().QueryInterface(nsIFile).path + ";"; 1.72 + } 1.73 + catch (e) { 1.74 + out += "<Not Provided>"; 1.75 + } 1.76 + 1.77 + dump(out + "\n"); 1.78 + Components.utils.reportError(out); 1.79 + } 1.80 + 1.81 + if (cmdLine.handleFlag("silent", false)) { 1.82 + cmdLine.preventDefault = true; 1.83 + } 1.84 + 1.85 + if (cmdLine.preventDefault) 1.86 + return; 1.87 + 1.88 + var prefs = Components.classes["@mozilla.org/preferences-service;1"] 1.89 + .getService(nsIPrefBranch); 1.90 + 1.91 + try { 1.92 + var singletonWindowType = 1.93 + prefs.getCharPref("toolkit.singletonWindowType"); 1.94 + var windowMediator = 1.95 + Components.classes["@mozilla.org/appshell/window-mediator;1"] 1.96 + .getService(Components.interfaces.nsIWindowMediator); 1.97 + 1.98 + var win = windowMediator.getMostRecentWindow(singletonWindowType); 1.99 + if (win) { 1.100 + win.focus(); 1.101 + cmdLine.preventDefault = true; 1.102 + return; 1.103 + } 1.104 + } 1.105 + catch (e) { } 1.106 + 1.107 + // if the pref is missing, ignore the exception 1.108 + try { 1.109 + var chromeURI = prefs.getCharPref("toolkit.defaultChromeURI"); 1.110 + 1.111 + var flags = "chrome,dialog=no,all"; 1.112 + try { 1.113 + flags = prefs.getCharPref("toolkit.defaultChromeFeatures"); 1.114 + } 1.115 + catch (e) { } 1.116 + 1.117 + var wwatch = Components.classes["@mozilla.org/embedcomp/window-watcher;1"] 1.118 + .getService(nsIWindowWatcher); 1.119 + wwatch.openWindow(null, chromeURI, "_blank", 1.120 + flags, cmdLine); 1.121 + } 1.122 + catch (e) { } 1.123 + }, 1.124 + 1.125 + helpInfo : "", 1.126 +}; 1.127 + 1.128 +this.NSGetFactory = XPCOMUtils.generateNSGetFactory([nsDefaultCLH]);