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