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 | // Progress heartbeat timer duration (ms) |
michael@0 | 6 | const kHeartbeatDuration = 1000; |
michael@0 | 7 | // Start and end progress screen css margins as percentages |
michael@0 | 8 | const kProgressMarginStart = 30; |
michael@0 | 9 | const kProgressMarginEnd = 70; |
michael@0 | 10 | |
michael@0 | 11 | const WebProgress = { |
michael@0 | 12 | get _identityBox() { return document.getElementById("identity-box"); }, |
michael@0 | 13 | |
michael@0 | 14 | init: function init() { |
michael@0 | 15 | messageManager.addMessageListener("Content:StateChange", this); |
michael@0 | 16 | messageManager.addMessageListener("Content:LocationChange", this); |
michael@0 | 17 | messageManager.addMessageListener("Content:SecurityChange", this); |
michael@0 | 18 | |
michael@0 | 19 | Elements.progress.addEventListener("transitionend", this, true); |
michael@0 | 20 | Elements.tabList.addEventListener("TabSelect", this, true); |
michael@0 | 21 | |
michael@0 | 22 | let urlBar = document.getElementById("urlbar-edit"); |
michael@0 | 23 | urlBar.addEventListener("input", this, false); |
michael@0 | 24 | |
michael@0 | 25 | return this; |
michael@0 | 26 | }, |
michael@0 | 27 | |
michael@0 | 28 | receiveMessage: function receiveMessage(aMessage) { |
michael@0 | 29 | let json = aMessage.json; |
michael@0 | 30 | let tab = Browser.getTabForBrowser(aMessage.target); |
michael@0 | 31 | |
michael@0 | 32 | switch (aMessage.name) { |
michael@0 | 33 | case "Content:StateChange": { |
michael@0 | 34 | if (json.stateFlags & Ci.nsIWebProgressListener.STATE_IS_WINDOW) { |
michael@0 | 35 | if (json.stateFlags & Ci.nsIWebProgressListener.STATE_START) |
michael@0 | 36 | this._windowStart(json, tab); |
michael@0 | 37 | else if (json.stateFlags & Ci.nsIWebProgressListener.STATE_STOP) |
michael@0 | 38 | this._windowStop(json, tab); |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | if (json.stateFlags & Ci.nsIWebProgressListener.STATE_IS_NETWORK) { |
michael@0 | 42 | if (json.stateFlags & Ci.nsIWebProgressListener.STATE_START) |
michael@0 | 43 | this._networkStart(json, tab); |
michael@0 | 44 | else if (json.stateFlags & Ci.nsIWebProgressListener.STATE_STOP) |
michael@0 | 45 | this._networkStop(json, tab); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | this._progressStep(tab); |
michael@0 | 49 | break; |
michael@0 | 50 | } |
michael@0 | 51 | |
michael@0 | 52 | case "Content:LocationChange": { |
michael@0 | 53 | this._locationChange(json, tab); |
michael@0 | 54 | this._progressStep(tab); |
michael@0 | 55 | break; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | case "Content:SecurityChange": { |
michael@0 | 59 | this._securityChange(json, tab); |
michael@0 | 60 | this._progressStep(tab); |
michael@0 | 61 | break; |
michael@0 | 62 | } |
michael@0 | 63 | } |
michael@0 | 64 | }, |
michael@0 | 65 | |
michael@0 | 66 | handleEvent: function handleEvent(aEvent) { |
michael@0 | 67 | switch (aEvent.type) { |
michael@0 | 68 | case "transitionend": |
michael@0 | 69 | this._progressTransEnd(aEvent); |
michael@0 | 70 | break; |
michael@0 | 71 | case "TabSelect": |
michael@0 | 72 | this._onTabSelect(aEvent); |
michael@0 | 73 | break; |
michael@0 | 74 | case "input": |
michael@0 | 75 | this._onUrlBarInput(aEvent); |
michael@0 | 76 | break; |
michael@0 | 77 | } |
michael@0 | 78 | }, |
michael@0 | 79 | |
michael@0 | 80 | _securityChange: function _securityChange(aJson, aTab) { |
michael@0 | 81 | let state = aJson.state; |
michael@0 | 82 | let nsIWebProgressListener = Ci.nsIWebProgressListener; |
michael@0 | 83 | |
michael@0 | 84 | if (state & nsIWebProgressListener.STATE_IDENTITY_EV_TOPLEVEL) { |
michael@0 | 85 | aTab._identityState = "verifiedIdentity"; |
michael@0 | 86 | } else if (state & nsIWebProgressListener.STATE_IS_SECURE) { |
michael@0 | 87 | aTab._identityState = "verifiedDomain"; |
michael@0 | 88 | } else { |
michael@0 | 89 | aTab._identityState = ""; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | if (aTab == Browser.selectedTab) { |
michael@0 | 93 | this._identityBox.className = aTab._identityState; |
michael@0 | 94 | } |
michael@0 | 95 | }, |
michael@0 | 96 | |
michael@0 | 97 | _locationChange: function _locationChange(aJson, aTab) { |
michael@0 | 98 | let spec = aJson.location; |
michael@0 | 99 | let location = spec.split("#")[0]; // Ignore fragment identifier changes. |
michael@0 | 100 | |
michael@0 | 101 | if (aTab == Browser.selectedTab) { |
michael@0 | 102 | BrowserUI.updateURI(); |
michael@0 | 103 | BrowserUI.update(); |
michael@0 | 104 | BrowserUI.updateStartURIAttributes(aJson.location); |
michael@0 | 105 | } |
michael@0 | 106 | |
michael@0 | 107 | let locationHasChanged = (location != aTab.browser.lastLocation); |
michael@0 | 108 | if (locationHasChanged) { |
michael@0 | 109 | Browser.getNotificationBox(aTab.browser).removeTransientNotifications(); |
michael@0 | 110 | aTab.browser.lastLocation = location; |
michael@0 | 111 | aTab.browser.userTypedValue = ""; |
michael@0 | 112 | aTab.browser.appIcon = { href: null, size:-1 }; |
michael@0 | 113 | |
michael@0 | 114 | #ifdef MOZ_CRASHREPORTER |
michael@0 | 115 | if (CrashReporter.enabled) |
michael@0 | 116 | CrashReporter.annotateCrashReport("URL", spec); |
michael@0 | 117 | #endif |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | let event = document.createEvent("UIEvents"); |
michael@0 | 121 | event.initUIEvent("URLChanged", true, false, window, locationHasChanged); |
michael@0 | 122 | aTab.browser.dispatchEvent(event); |
michael@0 | 123 | }, |
michael@0 | 124 | |
michael@0 | 125 | _networkStart: function _networkStart(aJson, aTab) { |
michael@0 | 126 | aTab.startLoading(); |
michael@0 | 127 | |
michael@0 | 128 | if (aTab == Browser.selectedTab) { |
michael@0 | 129 | // NO_STARTUI_VISIBILITY since the current uri for the tab has not |
michael@0 | 130 | // been updated yet. If we're coming off of the start page, this |
michael@0 | 131 | // would briefly show StartUI until _locationChange is called. |
michael@0 | 132 | BrowserUI.update(BrowserUI.NO_STARTUI_VISIBILITY); |
michael@0 | 133 | } |
michael@0 | 134 | }, |
michael@0 | 135 | |
michael@0 | 136 | _networkStop: function _networkStop(aJson, aTab) { |
michael@0 | 137 | aTab.endLoading(); |
michael@0 | 138 | |
michael@0 | 139 | if (aTab == Browser.selectedTab) { |
michael@0 | 140 | BrowserUI.update(); |
michael@0 | 141 | } |
michael@0 | 142 | }, |
michael@0 | 143 | |
michael@0 | 144 | _windowStart: function _windowStart(aJson, aTab) { |
michael@0 | 145 | this._progressStart(aJson, aTab); |
michael@0 | 146 | }, |
michael@0 | 147 | |
michael@0 | 148 | _windowStop: function _windowStop(aJson, aTab) { |
michael@0 | 149 | this._progressStop(aJson, aTab); |
michael@0 | 150 | }, |
michael@0 | 151 | |
michael@0 | 152 | _progressStart: function _progressStart(aJson, aTab) { |
michael@0 | 153 | // We will get multiple calls from _windowStart, so |
michael@0 | 154 | // only process once. |
michael@0 | 155 | if (aTab._progressActive) |
michael@0 | 156 | return; |
michael@0 | 157 | |
michael@0 | 158 | aTab._progressActive = true; |
michael@0 | 159 | |
michael@0 | 160 | // 'Whoosh' in |
michael@0 | 161 | aTab._progressCount = kProgressMarginStart; |
michael@0 | 162 | this._showProgressBar(aTab); |
michael@0 | 163 | }, |
michael@0 | 164 | |
michael@0 | 165 | _showProgressBar: function (aTab) { |
michael@0 | 166 | // display the track |
michael@0 | 167 | if (aTab == Browser.selectedTab) { |
michael@0 | 168 | Elements.progressContainer.removeAttribute("collapsed"); |
michael@0 | 169 | Elements.progress.style.width = aTab._progressCount + "%"; |
michael@0 | 170 | Elements.progress.removeAttribute("fade"); |
michael@0 | 171 | } |
michael@0 | 172 | |
michael@0 | 173 | // Create a pulse timer to keep things moving even if we don't |
michael@0 | 174 | // collect any state changes. |
michael@0 | 175 | setTimeout(function() { |
michael@0 | 176 | WebProgress._progressStepTimer(aTab); |
michael@0 | 177 | }, kHeartbeatDuration, this); |
michael@0 | 178 | }, |
michael@0 | 179 | |
michael@0 | 180 | _stepProgressCount: function _stepProgressCount(aTab) { |
michael@0 | 181 | // Step toward the end margin in smaller slices as we get closer |
michael@0 | 182 | let left = kProgressMarginEnd - aTab._progressCount; |
michael@0 | 183 | let step = left * .05; |
michael@0 | 184 | aTab._progressCount += Math.ceil(step); |
michael@0 | 185 | |
michael@0 | 186 | // Don't go past the 'whoosh out' margin. |
michael@0 | 187 | if (aTab._progressCount > kProgressMarginEnd) { |
michael@0 | 188 | aTab._progressCount = kProgressMarginEnd; |
michael@0 | 189 | } |
michael@0 | 190 | }, |
michael@0 | 191 | |
michael@0 | 192 | _progressStep: function _progressStep(aTab) { |
michael@0 | 193 | if (!aTab._progressActive) |
michael@0 | 194 | return; |
michael@0 | 195 | this._stepProgressCount(aTab); |
michael@0 | 196 | if (aTab == Browser.selectedTab) { |
michael@0 | 197 | Elements.progress.style.width = aTab._progressCount + "%"; |
michael@0 | 198 | } |
michael@0 | 199 | }, |
michael@0 | 200 | |
michael@0 | 201 | _progressStepTimer: function _progressStepTimer(aTab) { |
michael@0 | 202 | if (!aTab._progressActive) |
michael@0 | 203 | return; |
michael@0 | 204 | this._progressStep(aTab); |
michael@0 | 205 | |
michael@0 | 206 | setTimeout(function() { |
michael@0 | 207 | WebProgress._progressStepTimer(aTab); |
michael@0 | 208 | }, kHeartbeatDuration, this); |
michael@0 | 209 | }, |
michael@0 | 210 | |
michael@0 | 211 | _progressStop: function _progressStop(aJson, aTab) { |
michael@0 | 212 | aTab._progressActive = false; |
michael@0 | 213 | // 'Whoosh out' and fade |
michael@0 | 214 | if (aTab == Browser.selectedTab) { |
michael@0 | 215 | Elements.progress.style.width = "100%"; |
michael@0 | 216 | Elements.progress.setAttribute("fade", true); |
michael@0 | 217 | } |
michael@0 | 218 | }, |
michael@0 | 219 | |
michael@0 | 220 | _progressTransEnd: function _progressTransEnd(aEvent) { |
michael@0 | 221 | if (!Elements.progress.hasAttribute("fade")) |
michael@0 | 222 | return; |
michael@0 | 223 | // Close out fade finished, reset |
michael@0 | 224 | if (aEvent.propertyName == "opacity") { |
michael@0 | 225 | Elements.progress.style.width = "0px"; |
michael@0 | 226 | Elements.progressContainer.setAttribute("collapsed", true); |
michael@0 | 227 | } |
michael@0 | 228 | }, |
michael@0 | 229 | |
michael@0 | 230 | _onTabSelect: function(aEvent) { |
michael@0 | 231 | let tab = Browser.getTabFromChrome(aEvent.originalTarget); |
michael@0 | 232 | this._identityBox.className = tab._identityState || ""; |
michael@0 | 233 | if (tab._progressActive) { |
michael@0 | 234 | this._showProgressBar(tab); |
michael@0 | 235 | } else { |
michael@0 | 236 | Elements.progress.setAttribute("fade", true); |
michael@0 | 237 | Elements.progressContainer.setAttribute("collapsed", true); |
michael@0 | 238 | } |
michael@0 | 239 | }, |
michael@0 | 240 | |
michael@0 | 241 | _onUrlBarInput: function(aEvent) { |
michael@0 | 242 | Browser.selectedTab._identityState = this._identityBox.className = ""; |
michael@0 | 243 | }, |
michael@0 | 244 | }; |