browser/components/preferences/connection.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/preferences/connection.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,213 @@
     1.4 +/* -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +var gConnectionsDialog = {
    1.10 +  beforeAccept: function ()
    1.11 +  {
    1.12 +    var proxyTypePref = document.getElementById("network.proxy.type");
    1.13 +    if (proxyTypePref.value == 2) {
    1.14 +      this.doAutoconfigURLFixup();
    1.15 +      return true;
    1.16 +    }
    1.17 +
    1.18 +    if (proxyTypePref.value != 1)
    1.19 +      return true;
    1.20 +
    1.21 +    var httpProxyURLPref = document.getElementById("network.proxy.http");
    1.22 +    var httpProxyPortPref = document.getElementById("network.proxy.http_port");
    1.23 +    var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
    1.24 +
    1.25 +    // If the port is 0 and the proxy server is specified, focus on the port and cancel submission.
    1.26 +    for (let prefName of ["http","ssl","ftp","socks"]) {
    1.27 +      let proxyPortPref = document.getElementById("network.proxy." + prefName + "_port");
    1.28 +      let proxyPref = document.getElementById("network.proxy." + prefName);
    1.29 +      // Only worry about ports which are currently active. If the share option is on, then ignore
    1.30 +      // all ports except the HTTP port
    1.31 +      if (proxyPref.value != "" && proxyPortPref.value == 0 &&
    1.32 +            (prefName == "http" || !shareProxiesPref.value)) {
    1.33 +        document.getElementById("networkProxy" + prefName.toUpperCase() + "_Port").focus();
    1.34 +        return false;
    1.35 +      }
    1.36 +    }
    1.37 +
    1.38 +    // In the case of a shared proxy preference, backup the current values and update with the HTTP value
    1.39 +    if (shareProxiesPref.value) {
    1.40 +      var proxyPrefs = ["ssl", "ftp", "socks"];
    1.41 +      for (var i = 0; i < proxyPrefs.length; ++i) {
    1.42 +        var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]);
    1.43 +        var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port");
    1.44 +        var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]);
    1.45 +        var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port");
    1.46 +        backupServerURLPref.value = backupServerURLPref.value || proxyServerURLPref.value;
    1.47 +        backupPortPref.value = backupPortPref.value || proxyPortPref.value;
    1.48 +        proxyServerURLPref.value = httpProxyURLPref.value;
    1.49 +        proxyPortPref.value = httpProxyPortPref.value;
    1.50 +      }
    1.51 +    }
    1.52 +    
    1.53 +    this.sanitizeNoProxiesPref();
    1.54 +    
    1.55 +    return true;
    1.56 +  },
    1.57 +
    1.58 +  checkForSystemProxy: function ()
    1.59 +  {
    1.60 +    if ("@mozilla.org/system-proxy-settings;1" in Components.classes)
    1.61 +      document.getElementById("systemPref").removeAttribute("hidden");
    1.62 +  },
    1.63 +  
    1.64 +  proxyTypeChanged: function ()
    1.65 +  {
    1.66 +    var proxyTypePref = document.getElementById("network.proxy.type");
    1.67 +
    1.68 +    // Update http
    1.69 +    var httpProxyURLPref = document.getElementById("network.proxy.http");
    1.70 +    httpProxyURLPref.disabled = proxyTypePref.value != 1;
    1.71 +    var httpProxyPortPref = document.getElementById("network.proxy.http_port");
    1.72 +    httpProxyPortPref.disabled = proxyTypePref.value != 1;
    1.73 +
    1.74 +    // Now update the other protocols
    1.75 +    this.updateProtocolPrefs();
    1.76 +
    1.77 +    var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
    1.78 +    shareProxiesPref.disabled = proxyTypePref.value != 1;
    1.79 +    var autologinProxyPref = document.getElementById("signon.autologin.proxy");
    1.80 +    autologinProxyPref.disabled = proxyTypePref.value == 0;
    1.81 +    var noProxiesPref = document.getElementById("network.proxy.no_proxies_on");
    1.82 +    noProxiesPref.disabled = proxyTypePref.value != 1;
    1.83 +
    1.84 +    var autoconfigURLPref = document.getElementById("network.proxy.autoconfig_url");
    1.85 +    autoconfigURLPref.disabled = proxyTypePref.value != 2;
    1.86 +
    1.87 +    this.updateReloadButton();
    1.88 +  },
    1.89 +  
    1.90 +  updateDNSPref: function ()
    1.91 +  {
    1.92 +    var socksVersionPref = document.getElementById("network.proxy.socks_version");
    1.93 +    var socksDNSPref = document.getElementById("network.proxy.socks_remote_dns");
    1.94 +    var proxyTypePref = document.getElementById("network.proxy.type");
    1.95 +    var isDefinitelySocks4 = !socksVersionPref.disabled && socksVersionPref.value == 4;
    1.96 +    socksDNSPref.disabled = (isDefinitelySocks4 || proxyTypePref.value == 0);
    1.97 +    return undefined;
    1.98 +  },
    1.99 +  
   1.100 +  updateReloadButton: function ()
   1.101 +  {
   1.102 +    // Disable the "Reload PAC" button if the selected proxy type is not PAC or
   1.103 +    // if the current value of the PAC textbox does not match the value stored
   1.104 +    // in prefs.  Likewise, disable the reload button if PAC is not configured
   1.105 +    // in prefs.
   1.106 +
   1.107 +    var typedURL = document.getElementById("networkProxyAutoconfigURL").value;
   1.108 +    var proxyTypeCur = document.getElementById("network.proxy.type").value;
   1.109 +
   1.110 +    var prefs =
   1.111 +        Components.classes["@mozilla.org/preferences-service;1"].
   1.112 +        getService(Components.interfaces.nsIPrefBranch);
   1.113 +    var pacURL = prefs.getCharPref("network.proxy.autoconfig_url");
   1.114 +    var proxyType = prefs.getIntPref("network.proxy.type");
   1.115 +
   1.116 +    var disableReloadPref =
   1.117 +        document.getElementById("pref.advanced.proxies.disable_button.reload");
   1.118 +    disableReloadPref.disabled =
   1.119 +        (proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL);
   1.120 +  },
   1.121 +  
   1.122 +  readProxyType: function ()
   1.123 +  {
   1.124 +    this.proxyTypeChanged();
   1.125 +    return undefined;
   1.126 +  },
   1.127 +  
   1.128 +  updateProtocolPrefs: function ()
   1.129 +  {
   1.130 +    var proxyTypePref = document.getElementById("network.proxy.type");
   1.131 +    var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
   1.132 +    var proxyPrefs = ["ssl", "ftp", "socks"];
   1.133 +    for (var i = 0; i < proxyPrefs.length; ++i) {
   1.134 +      var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]);
   1.135 +      var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port");
   1.136 +      
   1.137 +      // Restore previous per-proxy custom settings, if present. 
   1.138 +      if (!shareProxiesPref.value) {
   1.139 +        var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]);
   1.140 +        var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port");
   1.141 +        if (backupServerURLPref.hasUserValue) {
   1.142 +          proxyServerURLPref.value = backupServerURLPref.value;
   1.143 +          backupServerURLPref.reset();
   1.144 +        }
   1.145 +        if (backupPortPref.hasUserValue) {
   1.146 +          proxyPortPref.value = backupPortPref.value;
   1.147 +          backupPortPref.reset();
   1.148 +        }
   1.149 +      }
   1.150 +
   1.151 +      proxyServerURLPref.updateElements();
   1.152 +      proxyPortPref.updateElements();
   1.153 +      proxyServerURLPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value;
   1.154 +      proxyPortPref.disabled = proxyServerURLPref.disabled;
   1.155 +    }
   1.156 +    var socksVersionPref = document.getElementById("network.proxy.socks_version");
   1.157 +    socksVersionPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value;
   1.158 +    this.updateDNSPref();
   1.159 +    return undefined;
   1.160 +  },
   1.161 +  
   1.162 +  readProxyProtocolPref: function (aProtocol, aIsPort)
   1.163 +  {
   1.164 +    var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
   1.165 +    if (shareProxiesPref.value) {
   1.166 +      var pref = document.getElementById("network.proxy.http" + (aIsPort ? "_port" : ""));    
   1.167 +      return pref.value;
   1.168 +    }
   1.169 +    
   1.170 +    var backupPref = document.getElementById("network.proxy.backup." + aProtocol + (aIsPort ? "_port" : ""));
   1.171 +    return backupPref.hasUserValue ? backupPref.value : undefined;
   1.172 +  },
   1.173 +
   1.174 +  reloadPAC: function ()
   1.175 +  {
   1.176 +    Components.classes["@mozilla.org/network/protocol-proxy-service;1"].
   1.177 +        getService().reloadPAC();
   1.178 +  },
   1.179 +  
   1.180 +  doAutoconfigURLFixup: function ()
   1.181 +  {
   1.182 +    var autoURL = document.getElementById("networkProxyAutoconfigURL");
   1.183 +    var autoURLPref = document.getElementById("network.proxy.autoconfig_url");
   1.184 +    var URIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
   1.185 +                             .getService(Components.interfaces.nsIURIFixup);
   1.186 +    try {
   1.187 +      autoURLPref.value = autoURL.value = URIFixup.createFixupURI(autoURL.value, 0).spec;
   1.188 +    } catch(ex) {}
   1.189 +  },
   1.190 +
   1.191 +  sanitizeNoProxiesPref: function()
   1.192 +  {
   1.193 +    var noProxiesPref = document.getElementById("network.proxy.no_proxies_on");
   1.194 +    // replace substrings of ; and \n with commas if they're neither immediately
   1.195 +    // preceded nor followed by a valid separator character
   1.196 +    noProxiesPref.value = noProxiesPref.value.replace(/([^, \n;])[;\n]+(?![,\n;])/g, '$1,');
   1.197 +    // replace any remaining ; and \n since some may follow commas, etc. 
   1.198 +    noProxiesPref.value = noProxiesPref.value.replace(/[;\n]/g, '');
   1.199 +  },
   1.200 +  
   1.201 +  readHTTPProxyServer: function ()
   1.202 +  {
   1.203 +    var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
   1.204 +    if (shareProxiesPref.value)
   1.205 +      this.updateProtocolPrefs();
   1.206 +    return undefined;
   1.207 +  },
   1.208 +  
   1.209 +  readHTTPProxyPort: function ()
   1.210 +  {
   1.211 +    var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
   1.212 +    if (shareProxiesPref.value)
   1.213 +      this.updateProtocolPrefs();
   1.214 +    return undefined;
   1.215 +  }
   1.216 +};

mercurial