browser/components/preferences/connection.js

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

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

mercurial