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 | // -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | // dialog is just an array we'll use to store various properties from the dialog document... |
michael@0 | 8 | var dialog; |
michael@0 | 9 | |
michael@0 | 10 | // the printProgress is a nsIPrintProgress object |
michael@0 | 11 | var printProgress = null; |
michael@0 | 12 | |
michael@0 | 13 | // random global variables... |
michael@0 | 14 | var targetFile; |
michael@0 | 15 | |
michael@0 | 16 | var docTitle = ""; |
michael@0 | 17 | var docURL = ""; |
michael@0 | 18 | var progressParams = null; |
michael@0 | 19 | |
michael@0 | 20 | function ellipseString(aStr, doFront) |
michael@0 | 21 | { |
michael@0 | 22 | if (aStr.length > 3 && (aStr.substr(0, 3) == "..." || aStr.substr(aStr.length-4, 3) == "...")) |
michael@0 | 23 | return aStr; |
michael@0 | 24 | |
michael@0 | 25 | var fixedLen = 64; |
michael@0 | 26 | if (aStr.length <= fixedLen) |
michael@0 | 27 | return aStr; |
michael@0 | 28 | |
michael@0 | 29 | if (doFront) |
michael@0 | 30 | return "..." + aStr.substr(aStr.length-fixedLen, fixedLen); |
michael@0 | 31 | |
michael@0 | 32 | return aStr.substr(0, fixedLen) + "..."; |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | // all progress notifications are done through the nsIWebProgressListener implementation... |
michael@0 | 36 | var progressListener = { |
michael@0 | 37 | |
michael@0 | 38 | onStateChange: function (aWebProgress, aRequest, aStateFlags, aStatus) |
michael@0 | 39 | { |
michael@0 | 40 | if (aStateFlags & Components.interfaces.nsIWebProgressListener.STATE_STOP) |
michael@0 | 41 | window.close(); |
michael@0 | 42 | }, |
michael@0 | 43 | |
michael@0 | 44 | onProgressChange: function (aWebProgress, aRequest, aCurSelfProgress, aMaxSelfProgress, aCurTotalProgress, aMaxTotalProgress) |
michael@0 | 45 | { |
michael@0 | 46 | if (!progressParams) |
michael@0 | 47 | return; |
michael@0 | 48 | var docTitleStr = ellipseString(progressParams.docTitle, false); |
michael@0 | 49 | if (docTitleStr != docTitle) { |
michael@0 | 50 | docTitle = docTitleStr; |
michael@0 | 51 | dialog.title.value = docTitle; |
michael@0 | 52 | } |
michael@0 | 53 | var docURLStr = ellipseString(progressParams.docURL, true); |
michael@0 | 54 | if (docURLStr != docURL && dialog.title != null) { |
michael@0 | 55 | docURL = docURLStr; |
michael@0 | 56 | if (docTitle == "") |
michael@0 | 57 | dialog.title.value = docURLStr; |
michael@0 | 58 | } |
michael@0 | 59 | }, |
michael@0 | 60 | |
michael@0 | 61 | onLocationChange: function (aWebProgress, aRequest, aLocation, aFlags) {}, |
michael@0 | 62 | onSecurityChange: function (aWebProgress, aRequest, state) {}, |
michael@0 | 63 | |
michael@0 | 64 | onStatusChange: function (aWebProgress, aRequest, aStatus, aMessage) |
michael@0 | 65 | { |
michael@0 | 66 | if (aMessage) |
michael@0 | 67 | dialog.title.setAttribute("value", aMessage); |
michael@0 | 68 | }, |
michael@0 | 69 | |
michael@0 | 70 | QueryInterface: function (iid) |
michael@0 | 71 | { |
michael@0 | 72 | if (iid.equals(Components.interfaces.nsIWebProgressListener) || iid.equals(Components.interfaces.nsISupportsWeakReference)) |
michael@0 | 73 | return this; |
michael@0 | 74 | throw Components.results.NS_NOINTERFACE; |
michael@0 | 75 | } |
michael@0 | 76 | } |
michael@0 | 77 | |
michael@0 | 78 | function onLoad() { |
michael@0 | 79 | // Set global variables. |
michael@0 | 80 | printProgress = window.arguments[0]; |
michael@0 | 81 | if (window.arguments[1]) { |
michael@0 | 82 | progressParams = window.arguments[1].QueryInterface(Components.interfaces.nsIPrintProgressParams) |
michael@0 | 83 | if (progressParams) { |
michael@0 | 84 | docTitle = ellipseString(progressParams.docTitle, false); |
michael@0 | 85 | docURL = ellipseString(progressParams.docURL, true); |
michael@0 | 86 | } |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | if (!printProgress) { |
michael@0 | 90 | dump( "Invalid argument to printPreviewProgress.xul\n" ); |
michael@0 | 91 | window.close() |
michael@0 | 92 | return; |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | dialog = new Object; |
michael@0 | 96 | dialog.strings = new Array; |
michael@0 | 97 | dialog.title = document.getElementById("dialog.title"); |
michael@0 | 98 | dialog.titleLabel = document.getElementById("dialog.titleLabel"); |
michael@0 | 99 | |
michael@0 | 100 | dialog.title.value = docTitle; |
michael@0 | 101 | |
michael@0 | 102 | // set our web progress listener on the helper app launcher |
michael@0 | 103 | printProgress.registerListener(progressListener); |
michael@0 | 104 | moveToAlertPosition(); |
michael@0 | 105 | |
michael@0 | 106 | //We need to delay the set title else dom will overwrite it |
michael@0 | 107 | window.setTimeout(doneIniting, 100); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | function onUnload() |
michael@0 | 111 | { |
michael@0 | 112 | if (!printProgress) |
michael@0 | 113 | return; |
michael@0 | 114 | try { |
michael@0 | 115 | printProgress.unregisterListener(progressListener); |
michael@0 | 116 | printProgress = null; |
michael@0 | 117 | } |
michael@0 | 118 | catch(e) {} |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | function getString (stringId) { |
michael@0 | 122 | // Check if we've fetched this string already. |
michael@0 | 123 | if (!(stringId in dialog.strings)) { |
michael@0 | 124 | // Try to get it. |
michael@0 | 125 | var elem = document.getElementById( "dialog.strings."+stringId); |
michael@0 | 126 | try { |
michael@0 | 127 | if (elem && elem.childNodes && elem.childNodes[0] && |
michael@0 | 128 | elem.childNodes[0].nodeValue) |
michael@0 | 129 | dialog.strings[stringId] = elem.childNodes[0].nodeValue; |
michael@0 | 130 | // If unable to fetch string, use an empty string. |
michael@0 | 131 | else |
michael@0 | 132 | dialog.strings[stringId] = ""; |
michael@0 | 133 | } catch (e) { dialog.strings[stringId] = ""; } |
michael@0 | 134 | } |
michael@0 | 135 | return dialog.strings[stringId]; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | // If the user presses cancel, tell the app launcher and close the dialog... |
michael@0 | 139 | function onCancel () |
michael@0 | 140 | { |
michael@0 | 141 | // Cancel app launcher. |
michael@0 | 142 | try { |
michael@0 | 143 | printProgress.processCanceledByUser = true; |
michael@0 | 144 | } |
michael@0 | 145 | catch(e) {return true;} |
michael@0 | 146 | |
michael@0 | 147 | // don't Close up dialog by returning false, the backend will close the dialog when everything will be aborted. |
michael@0 | 148 | return false; |
michael@0 | 149 | } |
michael@0 | 150 | |
michael@0 | 151 | function doneIniting() |
michael@0 | 152 | { |
michael@0 | 153 | // called by function timeout in onLoad |
michael@0 | 154 | printProgress.doneIniting(); |
michael@0 | 155 | } |