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: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | var gConnectionsDialog = { |
michael@0 | 7 | beforeAccept: function () |
michael@0 | 8 | { |
michael@0 | 9 | var proxyTypePref = document.getElementById("network.proxy.type"); |
michael@0 | 10 | if (proxyTypePref.value == 2) { |
michael@0 | 11 | this.doAutoconfigURLFixup(); |
michael@0 | 12 | return true; |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | if (proxyTypePref.value != 1) |
michael@0 | 16 | return true; |
michael@0 | 17 | |
michael@0 | 18 | var httpProxyURLPref = document.getElementById("network.proxy.http"); |
michael@0 | 19 | var httpProxyPortPref = document.getElementById("network.proxy.http_port"); |
michael@0 | 20 | var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); |
michael@0 | 21 | |
michael@0 | 22 | // If the port is 0 and the proxy server is specified, focus on the port and cancel submission. |
michael@0 | 23 | for (let prefName of ["http","ssl","ftp","socks"]) { |
michael@0 | 24 | let proxyPortPref = document.getElementById("network.proxy." + prefName + "_port"); |
michael@0 | 25 | let proxyPref = document.getElementById("network.proxy." + prefName); |
michael@0 | 26 | // Only worry about ports which are currently active. If the share option is on, then ignore |
michael@0 | 27 | // all ports except the HTTP port |
michael@0 | 28 | if (proxyPref.value != "" && proxyPortPref.value == 0 && |
michael@0 | 29 | (prefName == "http" || !shareProxiesPref.value)) { |
michael@0 | 30 | document.getElementById("networkProxy" + prefName.toUpperCase() + "_Port").focus(); |
michael@0 | 31 | return false; |
michael@0 | 32 | } |
michael@0 | 33 | } |
michael@0 | 34 | |
michael@0 | 35 | // In the case of a shared proxy preference, backup the current values and update with the HTTP value |
michael@0 | 36 | if (shareProxiesPref.value) { |
michael@0 | 37 | var proxyPrefs = ["ssl", "ftp", "socks"]; |
michael@0 | 38 | for (var i = 0; i < proxyPrefs.length; ++i) { |
michael@0 | 39 | var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]); |
michael@0 | 40 | var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port"); |
michael@0 | 41 | var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]); |
michael@0 | 42 | var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port"); |
michael@0 | 43 | backupServerURLPref.value = backupServerURLPref.value || proxyServerURLPref.value; |
michael@0 | 44 | backupPortPref.value = backupPortPref.value || proxyPortPref.value; |
michael@0 | 45 | proxyServerURLPref.value = httpProxyURLPref.value; |
michael@0 | 46 | proxyPortPref.value = httpProxyPortPref.value; |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | this.sanitizeNoProxiesPref(); |
michael@0 | 51 | |
michael@0 | 52 | return true; |
michael@0 | 53 | }, |
michael@0 | 54 | |
michael@0 | 55 | checkForSystemProxy: function () |
michael@0 | 56 | { |
michael@0 | 57 | if ("@mozilla.org/system-proxy-settings;1" in Components.classes) |
michael@0 | 58 | document.getElementById("systemPref").removeAttribute("hidden"); |
michael@0 | 59 | }, |
michael@0 | 60 | |
michael@0 | 61 | proxyTypeChanged: function () |
michael@0 | 62 | { |
michael@0 | 63 | var proxyTypePref = document.getElementById("network.proxy.type"); |
michael@0 | 64 | |
michael@0 | 65 | // Update http |
michael@0 | 66 | var httpProxyURLPref = document.getElementById("network.proxy.http"); |
michael@0 | 67 | httpProxyURLPref.disabled = proxyTypePref.value != 1; |
michael@0 | 68 | var httpProxyPortPref = document.getElementById("network.proxy.http_port"); |
michael@0 | 69 | httpProxyPortPref.disabled = proxyTypePref.value != 1; |
michael@0 | 70 | |
michael@0 | 71 | // Now update the other protocols |
michael@0 | 72 | this.updateProtocolPrefs(); |
michael@0 | 73 | |
michael@0 | 74 | var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); |
michael@0 | 75 | shareProxiesPref.disabled = proxyTypePref.value != 1; |
michael@0 | 76 | var autologinProxyPref = document.getElementById("signon.autologin.proxy"); |
michael@0 | 77 | autologinProxyPref.disabled = proxyTypePref.value == 0; |
michael@0 | 78 | var noProxiesPref = document.getElementById("network.proxy.no_proxies_on"); |
michael@0 | 79 | noProxiesPref.disabled = proxyTypePref.value != 1; |
michael@0 | 80 | |
michael@0 | 81 | var autoconfigURLPref = document.getElementById("network.proxy.autoconfig_url"); |
michael@0 | 82 | autoconfigURLPref.disabled = proxyTypePref.value != 2; |
michael@0 | 83 | |
michael@0 | 84 | this.updateReloadButton(); |
michael@0 | 85 | }, |
michael@0 | 86 | |
michael@0 | 87 | updateDNSPref: function () |
michael@0 | 88 | { |
michael@0 | 89 | var socksVersionPref = document.getElementById("network.proxy.socks_version"); |
michael@0 | 90 | var socksDNSPref = document.getElementById("network.proxy.socks_remote_dns"); |
michael@0 | 91 | var proxyTypePref = document.getElementById("network.proxy.type"); |
michael@0 | 92 | var isDefinitelySocks4 = !socksVersionPref.disabled && socksVersionPref.value == 4; |
michael@0 | 93 | socksDNSPref.disabled = (isDefinitelySocks4 || proxyTypePref.value == 0); |
michael@0 | 94 | return undefined; |
michael@0 | 95 | }, |
michael@0 | 96 | |
michael@0 | 97 | updateReloadButton: function () |
michael@0 | 98 | { |
michael@0 | 99 | // Disable the "Reload PAC" button if the selected proxy type is not PAC or |
michael@0 | 100 | // if the current value of the PAC textbox does not match the value stored |
michael@0 | 101 | // in prefs. Likewise, disable the reload button if PAC is not configured |
michael@0 | 102 | // in prefs. |
michael@0 | 103 | |
michael@0 | 104 | var typedURL = document.getElementById("networkProxyAutoconfigURL").value; |
michael@0 | 105 | var proxyTypeCur = document.getElementById("network.proxy.type").value; |
michael@0 | 106 | |
michael@0 | 107 | var prefs = |
michael@0 | 108 | Components.classes["@mozilla.org/preferences-service;1"]. |
michael@0 | 109 | getService(Components.interfaces.nsIPrefBranch); |
michael@0 | 110 | var pacURL = prefs.getCharPref("network.proxy.autoconfig_url"); |
michael@0 | 111 | var proxyType = prefs.getIntPref("network.proxy.type"); |
michael@0 | 112 | |
michael@0 | 113 | var disableReloadPref = |
michael@0 | 114 | document.getElementById("pref.advanced.proxies.disable_button.reload"); |
michael@0 | 115 | disableReloadPref.disabled = |
michael@0 | 116 | (proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL); |
michael@0 | 117 | }, |
michael@0 | 118 | |
michael@0 | 119 | readProxyType: function () |
michael@0 | 120 | { |
michael@0 | 121 | this.proxyTypeChanged(); |
michael@0 | 122 | return undefined; |
michael@0 | 123 | }, |
michael@0 | 124 | |
michael@0 | 125 | updateProtocolPrefs: function () |
michael@0 | 126 | { |
michael@0 | 127 | var proxyTypePref = document.getElementById("network.proxy.type"); |
michael@0 | 128 | var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); |
michael@0 | 129 | var proxyPrefs = ["ssl", "ftp", "socks"]; |
michael@0 | 130 | for (var i = 0; i < proxyPrefs.length; ++i) { |
michael@0 | 131 | var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]); |
michael@0 | 132 | var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port"); |
michael@0 | 133 | |
michael@0 | 134 | // Restore previous per-proxy custom settings, if present. |
michael@0 | 135 | if (!shareProxiesPref.value) { |
michael@0 | 136 | var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]); |
michael@0 | 137 | var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port"); |
michael@0 | 138 | if (backupServerURLPref.hasUserValue) { |
michael@0 | 139 | proxyServerURLPref.value = backupServerURLPref.value; |
michael@0 | 140 | backupServerURLPref.reset(); |
michael@0 | 141 | } |
michael@0 | 142 | if (backupPortPref.hasUserValue) { |
michael@0 | 143 | proxyPortPref.value = backupPortPref.value; |
michael@0 | 144 | backupPortPref.reset(); |
michael@0 | 145 | } |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | proxyServerURLPref.updateElements(); |
michael@0 | 149 | proxyPortPref.updateElements(); |
michael@0 | 150 | proxyServerURLPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value; |
michael@0 | 151 | proxyPortPref.disabled = proxyServerURLPref.disabled; |
michael@0 | 152 | } |
michael@0 | 153 | var socksVersionPref = document.getElementById("network.proxy.socks_version"); |
michael@0 | 154 | socksVersionPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value; |
michael@0 | 155 | this.updateDNSPref(); |
michael@0 | 156 | return undefined; |
michael@0 | 157 | }, |
michael@0 | 158 | |
michael@0 | 159 | readProxyProtocolPref: function (aProtocol, aIsPort) |
michael@0 | 160 | { |
michael@0 | 161 | var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); |
michael@0 | 162 | if (shareProxiesPref.value) { |
michael@0 | 163 | var pref = document.getElementById("network.proxy.http" + (aIsPort ? "_port" : "")); |
michael@0 | 164 | return pref.value; |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | var backupPref = document.getElementById("network.proxy.backup." + aProtocol + (aIsPort ? "_port" : "")); |
michael@0 | 168 | return backupPref.hasUserValue ? backupPref.value : undefined; |
michael@0 | 169 | }, |
michael@0 | 170 | |
michael@0 | 171 | reloadPAC: function () |
michael@0 | 172 | { |
michael@0 | 173 | Components.classes["@mozilla.org/network/protocol-proxy-service;1"]. |
michael@0 | 174 | getService().reloadPAC(); |
michael@0 | 175 | }, |
michael@0 | 176 | |
michael@0 | 177 | doAutoconfigURLFixup: function () |
michael@0 | 178 | { |
michael@0 | 179 | var autoURL = document.getElementById("networkProxyAutoconfigURL"); |
michael@0 | 180 | var autoURLPref = document.getElementById("network.proxy.autoconfig_url"); |
michael@0 | 181 | var URIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"] |
michael@0 | 182 | .getService(Components.interfaces.nsIURIFixup); |
michael@0 | 183 | try { |
michael@0 | 184 | autoURLPref.value = autoURL.value = URIFixup.createFixupURI(autoURL.value, 0).spec; |
michael@0 | 185 | } catch(ex) {} |
michael@0 | 186 | }, |
michael@0 | 187 | |
michael@0 | 188 | sanitizeNoProxiesPref: function() |
michael@0 | 189 | { |
michael@0 | 190 | var noProxiesPref = document.getElementById("network.proxy.no_proxies_on"); |
michael@0 | 191 | // replace substrings of ; and \n with commas if they're neither immediately |
michael@0 | 192 | // preceded nor followed by a valid separator character |
michael@0 | 193 | noProxiesPref.value = noProxiesPref.value.replace(/([^, \n;])[;\n]+(?![,\n;])/g, '$1,'); |
michael@0 | 194 | // replace any remaining ; and \n since some may follow commas, etc. |
michael@0 | 195 | noProxiesPref.value = noProxiesPref.value.replace(/[;\n]/g, ''); |
michael@0 | 196 | }, |
michael@0 | 197 | |
michael@0 | 198 | readHTTPProxyServer: function () |
michael@0 | 199 | { |
michael@0 | 200 | var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); |
michael@0 | 201 | if (shareProxiesPref.value) |
michael@0 | 202 | this.updateProtocolPrefs(); |
michael@0 | 203 | return undefined; |
michael@0 | 204 | }, |
michael@0 | 205 | |
michael@0 | 206 | readHTTPProxyPort: function () |
michael@0 | 207 | { |
michael@0 | 208 | var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); |
michael@0 | 209 | if (shareProxiesPref.value) |
michael@0 | 210 | this.updateProtocolPrefs(); |
michael@0 | 211 | return undefined; |
michael@0 | 212 | } |
michael@0 | 213 | }; |