home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / firefox-3.0.14 / chrome / browser.jar / content / browser / preferences / connection.js < prev    next >
Encoding:
JavaScript  |  2008-02-21  |  6.7 KB  |  176 lines

  1. //@line 38 "/build/buildd/firefox-3.0-3.0.14+build2+nobinonly/build-tree/mozilla/browser/components/preferences/connection.js"
  2.  
  3. var gConnectionsDialog = {
  4.   beforeAccept: function ()
  5.   {
  6.     var proxyTypePref = document.getElementById("network.proxy.type");
  7.     if (proxyTypePref.value == 2) {
  8.       this.doAutoconfigURLFixup();
  9.       return true;
  10.     }
  11.  
  12.     if (proxyTypePref.value != 1)
  13.       return true;
  14.  
  15.     var httpProxyURLPref = document.getElementById("network.proxy.http");
  16.     var httpProxyPortPref = document.getElementById("network.proxy.http_port");
  17.     var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
  18.     if (shareProxiesPref.value) {
  19.       var proxyPrefs = ["ssl", "ftp", "socks", "gopher"];
  20.       for (var i = 0; i < proxyPrefs.length; ++i) {
  21.         var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]);
  22.         var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port");
  23.         var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]);
  24.         var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port");
  25.         backupServerURLPref.value = proxyServerURLPref.value;
  26.         backupPortPref.value = proxyPortPref.value;
  27.         proxyServerURLPref.value = httpProxyURLPref.value;
  28.         proxyPortPref.value = httpProxyPortPref.value;
  29.       }
  30.     }
  31.     
  32.     var noProxiesPref = document.getElementById("network.proxy.no_proxies_on");
  33.     noProxiesPref.value = noProxiesPref.value.replace(/[;]/g,',');
  34.     
  35.     return true;
  36.   },
  37.  
  38.   checkForSystemProxy: function ()
  39.   {
  40.     if ("@mozilla.org/system-proxy-settings;1" in Components.classes)
  41.       document.getElementById("systemPref").removeAttribute("hidden");
  42.   },
  43.   
  44.   proxyTypeChanged: function ()
  45.   {
  46.     var proxyTypePref = document.getElementById("network.proxy.type");
  47.     
  48.     // Update http
  49.     var httpProxyURLPref = document.getElementById("network.proxy.http");
  50.     httpProxyURLPref.disabled = proxyTypePref.value != 1;
  51.     var httpProxyPortPref = document.getElementById("network.proxy.http_port");
  52.     httpProxyPortPref.disabled = proxyTypePref.value != 1;
  53.  
  54.     // Now update the other protocols
  55.     this.updateProtocolPrefs();
  56.  
  57.     var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
  58.     shareProxiesPref.disabled = proxyTypePref.value != 1;
  59.     
  60.     var noProxiesPref = document.getElementById("network.proxy.no_proxies_on");
  61.     noProxiesPref.disabled = proxyTypePref.value != 1;
  62.     
  63.     var autoconfigURLPref = document.getElementById("network.proxy.autoconfig_url");
  64.     autoconfigURLPref.disabled = proxyTypePref.value != 2;
  65.  
  66.     this.updateReloadButton();
  67.   },
  68.  
  69.   updateReloadButton: function ()
  70.   {
  71.     // Disable the "Reload PAC" button if the selected proxy type is not PAC or
  72.     // if the current value of the PAC textbox does not match the value stored
  73.     // in prefs.  Likewise, disable the reload button if PAC is not configured
  74.     // in prefs.
  75.  
  76.     var typedURL = document.getElementById("networkProxyAutoconfigURL").value;
  77.     var proxyTypeCur = document.getElementById("network.proxy.type").value;
  78.  
  79.     var prefs =
  80.         Components.classes["@mozilla.org/preferences-service;1"].
  81.         getService(Components.interfaces.nsIPrefBranch);
  82.     var pacURL = prefs.getCharPref("network.proxy.autoconfig_url");
  83.     var proxyType = prefs.getIntPref("network.proxy.type");
  84.  
  85.     var disableReloadPref =
  86.         document.getElementById("pref.advanced.proxies.disable_button.reload");
  87.     disableReloadPref.disabled =
  88.         (proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL);
  89.   },
  90.   
  91.   readProxyType: function ()
  92.   {
  93.     this.proxyTypeChanged();
  94.     return undefined;
  95.   },
  96.   
  97.   updateProtocolPrefs: function ()
  98.   {
  99.     var proxyTypePref = document.getElementById("network.proxy.type");
  100.     var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
  101.     var proxyPrefs = ["ssl", "ftp", "socks", "gopher"];
  102.     for (var i = 0; i < proxyPrefs.length; ++i) {
  103.       var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]);
  104.       var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port");
  105.       
  106.       // Restore previous per-proxy custom settings, if present. 
  107.       if (!shareProxiesPref.value) {
  108.         var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]);
  109.         var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port");
  110.         if (backupServerURLPref.hasUserValue) {
  111.           proxyServerURLPref.value = backupServerURLPref.value;
  112.           backupServerURLPref.reset();
  113.         }
  114.         if (backupPortPref.hasUserValue) {
  115.           proxyPortPref.value = backupPortPref.value;
  116.           backupPortPref.reset();
  117.         }
  118.       }
  119.  
  120.       proxyServerURLPref.updateElements();
  121.       proxyPortPref.updateElements();
  122.       proxyServerURLPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value;
  123.       proxyPortPref.disabled = proxyServerURLPref.disabled;
  124.     }
  125.     var socksVersionPref = document.getElementById("network.proxy.socks_version");
  126.     socksVersionPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value;
  127.     
  128.     return undefined;
  129.   },
  130.   
  131.   readProxyProtocolPref: function (aProtocol, aIsPort)
  132.   {
  133.     var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
  134.     if (shareProxiesPref.value) {
  135.       var pref = document.getElementById("network.proxy.http" + (aIsPort ? "_port" : ""));    
  136.       return pref.value;
  137.     }
  138.     
  139.     var backupPref = document.getElementById("network.proxy.backup." + aProtocol + (aIsPort ? "_port" : ""));
  140.     return backupPref.hasUserValue ? backupPref.value : undefined;
  141.   },
  142.  
  143.   reloadPAC: function ()
  144.   {
  145.     Components.classes["@mozilla.org/network/protocol-proxy-service;1"].
  146.         getService().reloadPAC();
  147.   },
  148.   
  149.   doAutoconfigURLFixup: function ()
  150.   {
  151.     var autoURL = document.getElementById("networkProxyAutoconfigURL");
  152.     var autoURLPref = document.getElementById("network.proxy.autoconfig_url");
  153.     var URIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
  154.                              .getService(Components.interfaces.nsIURIFixup);
  155.     try {
  156.       autoURLPref.value = autoURL.value = URIFixup.createFixupURI(autoURL.value, 0).spec;
  157.     } catch(ex) {}
  158.   },
  159.   
  160.   readHTTPProxyServer: function ()
  161.   {
  162.     var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
  163.     if (shareProxiesPref.value)
  164.       this.updateProtocolPrefs();
  165.     return undefined;
  166.   },
  167.   
  168.   readHTTPProxyPort: function ()
  169.   {
  170.     var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
  171.     if (shareProxiesPref.value)
  172.       this.updateProtocolPrefs();
  173.     return undefined;
  174.   }
  175. };
  176.