michael@0: /* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var gConnectionsDialog = { michael@0: beforeAccept: function () michael@0: { michael@0: var proxyTypePref = document.getElementById("network.proxy.type"); michael@0: if (proxyTypePref.value == 2) { michael@0: this.doAutoconfigURLFixup(); michael@0: return true; michael@0: } michael@0: michael@0: if (proxyTypePref.value != 1) michael@0: return true; michael@0: michael@0: var httpProxyURLPref = document.getElementById("network.proxy.http"); michael@0: var httpProxyPortPref = document.getElementById("network.proxy.http_port"); michael@0: var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); michael@0: michael@0: // If the port is 0 and the proxy server is specified, focus on the port and cancel submission. michael@0: for (let prefName of ["http","ssl","ftp","socks"]) { michael@0: let proxyPortPref = document.getElementById("network.proxy." + prefName + "_port"); michael@0: let proxyPref = document.getElementById("network.proxy." + prefName); michael@0: // Only worry about ports which are currently active. If the share option is on, then ignore michael@0: // all ports except the HTTP port michael@0: if (proxyPref.value != "" && proxyPortPref.value == 0 && michael@0: (prefName == "http" || !shareProxiesPref.value)) { michael@0: document.getElementById("networkProxy" + prefName.toUpperCase() + "_Port").focus(); michael@0: return false; michael@0: } michael@0: } michael@0: michael@0: // In the case of a shared proxy preference, backup the current values and update with the HTTP value michael@0: if (shareProxiesPref.value) { michael@0: var proxyPrefs = ["ssl", "ftp", "socks"]; michael@0: for (var i = 0; i < proxyPrefs.length; ++i) { michael@0: var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]); michael@0: var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port"); michael@0: var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]); michael@0: var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port"); michael@0: backupServerURLPref.value = backupServerURLPref.value || proxyServerURLPref.value; michael@0: backupPortPref.value = backupPortPref.value || proxyPortPref.value; michael@0: proxyServerURLPref.value = httpProxyURLPref.value; michael@0: proxyPortPref.value = httpProxyPortPref.value; michael@0: } michael@0: } michael@0: michael@0: this.sanitizeNoProxiesPref(); michael@0: michael@0: return true; michael@0: }, michael@0: michael@0: checkForSystemProxy: function () michael@0: { michael@0: if ("@mozilla.org/system-proxy-settings;1" in Components.classes) michael@0: document.getElementById("systemPref").removeAttribute("hidden"); michael@0: }, michael@0: michael@0: proxyTypeChanged: function () michael@0: { michael@0: var proxyTypePref = document.getElementById("network.proxy.type"); michael@0: michael@0: // Update http michael@0: var httpProxyURLPref = document.getElementById("network.proxy.http"); michael@0: httpProxyURLPref.disabled = proxyTypePref.value != 1; michael@0: var httpProxyPortPref = document.getElementById("network.proxy.http_port"); michael@0: httpProxyPortPref.disabled = proxyTypePref.value != 1; michael@0: michael@0: // Now update the other protocols michael@0: this.updateProtocolPrefs(); michael@0: michael@0: var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); michael@0: shareProxiesPref.disabled = proxyTypePref.value != 1; michael@0: var autologinProxyPref = document.getElementById("signon.autologin.proxy"); michael@0: autologinProxyPref.disabled = proxyTypePref.value == 0; michael@0: var noProxiesPref = document.getElementById("network.proxy.no_proxies_on"); michael@0: noProxiesPref.disabled = proxyTypePref.value != 1; michael@0: michael@0: var autoconfigURLPref = document.getElementById("network.proxy.autoconfig_url"); michael@0: autoconfigURLPref.disabled = proxyTypePref.value != 2; michael@0: michael@0: this.updateReloadButton(); michael@0: }, michael@0: michael@0: updateDNSPref: function () michael@0: { michael@0: var socksVersionPref = document.getElementById("network.proxy.socks_version"); michael@0: var socksDNSPref = document.getElementById("network.proxy.socks_remote_dns"); michael@0: var proxyTypePref = document.getElementById("network.proxy.type"); michael@0: var isDefinitelySocks4 = !socksVersionPref.disabled && socksVersionPref.value == 4; michael@0: socksDNSPref.disabled = (isDefinitelySocks4 || proxyTypePref.value == 0); michael@0: return undefined; michael@0: }, michael@0: michael@0: updateReloadButton: function () michael@0: { michael@0: // Disable the "Reload PAC" button if the selected proxy type is not PAC or michael@0: // if the current value of the PAC textbox does not match the value stored michael@0: // in prefs. Likewise, disable the reload button if PAC is not configured michael@0: // in prefs. michael@0: michael@0: var typedURL = document.getElementById("networkProxyAutoconfigURL").value; michael@0: var proxyTypeCur = document.getElementById("network.proxy.type").value; michael@0: michael@0: var prefs = michael@0: Components.classes["@mozilla.org/preferences-service;1"]. michael@0: getService(Components.interfaces.nsIPrefBranch); michael@0: var pacURL = prefs.getCharPref("network.proxy.autoconfig_url"); michael@0: var proxyType = prefs.getIntPref("network.proxy.type"); michael@0: michael@0: var disableReloadPref = michael@0: document.getElementById("pref.advanced.proxies.disable_button.reload"); michael@0: disableReloadPref.disabled = michael@0: (proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL); michael@0: }, michael@0: michael@0: readProxyType: function () michael@0: { michael@0: this.proxyTypeChanged(); michael@0: return undefined; michael@0: }, michael@0: michael@0: updateProtocolPrefs: function () michael@0: { michael@0: var proxyTypePref = document.getElementById("network.proxy.type"); michael@0: var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); michael@0: var proxyPrefs = ["ssl", "ftp", "socks"]; michael@0: for (var i = 0; i < proxyPrefs.length; ++i) { michael@0: var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]); michael@0: var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port"); michael@0: michael@0: // Restore previous per-proxy custom settings, if present. michael@0: if (!shareProxiesPref.value) { michael@0: var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]); michael@0: var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port"); michael@0: if (backupServerURLPref.hasUserValue) { michael@0: proxyServerURLPref.value = backupServerURLPref.value; michael@0: backupServerURLPref.reset(); michael@0: } michael@0: if (backupPortPref.hasUserValue) { michael@0: proxyPortPref.value = backupPortPref.value; michael@0: backupPortPref.reset(); michael@0: } michael@0: } michael@0: michael@0: proxyServerURLPref.updateElements(); michael@0: proxyPortPref.updateElements(); michael@0: proxyServerURLPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value; michael@0: proxyPortPref.disabled = proxyServerURLPref.disabled; michael@0: } michael@0: var socksVersionPref = document.getElementById("network.proxy.socks_version"); michael@0: socksVersionPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value; michael@0: this.updateDNSPref(); michael@0: return undefined; michael@0: }, michael@0: michael@0: readProxyProtocolPref: function (aProtocol, aIsPort) michael@0: { michael@0: var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); michael@0: if (shareProxiesPref.value) { michael@0: var pref = document.getElementById("network.proxy.http" + (aIsPort ? "_port" : "")); michael@0: return pref.value; michael@0: } michael@0: michael@0: var backupPref = document.getElementById("network.proxy.backup." + aProtocol + (aIsPort ? "_port" : "")); michael@0: return backupPref.hasUserValue ? backupPref.value : undefined; michael@0: }, michael@0: michael@0: reloadPAC: function () michael@0: { michael@0: Components.classes["@mozilla.org/network/protocol-proxy-service;1"]. michael@0: getService().reloadPAC(); michael@0: }, michael@0: michael@0: doAutoconfigURLFixup: function () michael@0: { michael@0: var autoURL = document.getElementById("networkProxyAutoconfigURL"); michael@0: var autoURLPref = document.getElementById("network.proxy.autoconfig_url"); michael@0: var URIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"] michael@0: .getService(Components.interfaces.nsIURIFixup); michael@0: try { michael@0: autoURLPref.value = autoURL.value = URIFixup.createFixupURI(autoURL.value, 0).spec; michael@0: } catch(ex) {} michael@0: }, michael@0: michael@0: sanitizeNoProxiesPref: function() michael@0: { michael@0: var noProxiesPref = document.getElementById("network.proxy.no_proxies_on"); michael@0: // replace substrings of ; and \n with commas if they're neither immediately michael@0: // preceded nor followed by a valid separator character michael@0: noProxiesPref.value = noProxiesPref.value.replace(/([^, \n;])[;\n]+(?![,\n;])/g, '$1,'); michael@0: // replace any remaining ; and \n since some may follow commas, etc. michael@0: noProxiesPref.value = noProxiesPref.value.replace(/[;\n]/g, ''); michael@0: }, michael@0: michael@0: readHTTPProxyServer: function () michael@0: { michael@0: var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); michael@0: if (shareProxiesPref.value) michael@0: this.updateProtocolPrefs(); michael@0: return undefined; michael@0: }, michael@0: michael@0: readHTTPProxyPort: function () michael@0: { michael@0: var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings"); michael@0: if (shareProxiesPref.value) michael@0: this.updateProtocolPrefs(); michael@0: return undefined; michael@0: } michael@0: };