connection.js
Go to the documentation of this file.
1 # -*- Mode: Java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 # ***** BEGIN LICENSE BLOCK *****
3 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 #
5 # The contents of this file are subject to the Mozilla Public License Version
6 # 1.1 (the "License"); you may not use this file except in compliance with
7 # the License. You may obtain a copy of the License at
8 # http://www.mozilla.org/MPL/
9 #
10 # Software distributed under the License is distributed on an "AS IS" basis,
11 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 # for the specific language governing rights and limitations under the
13 # License.
14 #
15 # The Original Code is the Firefox Preferences System.
16 #
17 # The Initial Developer of the Original Code is
18 # Ben Goodger.
19 # Portions created by the Initial Developer are Copyright (C) 2005
20 # the Initial Developer. All Rights Reserved.
21 #
22 # Contributor(s):
23 # Ben Goodger <ben@mozilla.org>
24 #
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
36 #
37 # ***** END LICENSE BLOCK *****
38 
40  beforeAccept: function ()
41  {
42  var proxyTypePref = document.getElementById("network.proxy.type");
43  if (proxyTypePref.value == 2) {
44  this.doAutoconfigURLFixup();
45  return true;
46  }
47 
48  if (proxyTypePref.value != 1)
49  return true;
50 
51  var httpProxyURLPref = document.getElementById("network.proxy.http");
52  var httpProxyPortPref = document.getElementById("network.proxy.http_port");
53  var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
54  if (shareProxiesPref.value) {
55  var proxyPrefs = ["ssl", "ftp", "socks", "gopher"];
56  for (var i = 0; i < proxyPrefs.length; ++i) {
57  var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]);
58  var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port");
59  var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]);
60  var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port");
61  backupServerURLPref.value = proxyServerURLPref.value;
62  backupPortPref.value = proxyPortPref.value;
63  proxyServerURLPref.value = httpProxyURLPref.value;
64  proxyPortPref.value = httpProxyPortPref.value;
65  }
66  }
67 
68  var noProxiesPref = document.getElementById("network.proxy.no_proxies_on");
69  noProxiesPref.value = noProxiesPref.value.replace(/[;]/g,',');
70 
71  return true;
72  },
73 
74  checkForSystemProxy: function ()
75  {
76  if ("@mozilla.org/system-proxy-settings;1" in Components.classes)
77  document.getElementById("systemPref").removeAttribute("hidden");
78  },
79 
80  proxyTypeChanged: function ()
81  {
82  var proxyTypePref = document.getElementById("network.proxy.type");
83 
84  // Update http
85  var httpProxyURLPref = document.getElementById("network.proxy.http");
86  httpProxyURLPref.disabled = proxyTypePref.value != 1;
87  var httpProxyPortPref = document.getElementById("network.proxy.http_port");
88  httpProxyPortPref.disabled = proxyTypePref.value != 1;
89 
90  // Now update the other protocols
91  this.updateProtocolPrefs();
92 
93  var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
94  shareProxiesPref.disabled = proxyTypePref.value != 1;
95 
96  var noProxiesPref = document.getElementById("network.proxy.no_proxies_on");
97  noProxiesPref.disabled = proxyTypePref.value != 1;
98 
99  var autoconfigURLPref = document.getElementById("network.proxy.autoconfig_url");
100  autoconfigURLPref.disabled = proxyTypePref.value != 2;
101 
102  this.updateReloadButton();
103  },
104 
105  updateReloadButton: function ()
106  {
107  // Disable the "Reload PAC" button if the selected proxy type is not PAC or
108  // if the current value of the PAC textbox does not match the value stored
109  // in prefs. Likewise, disable the reload button if PAC is not configured
110  // in prefs.
111 
112  var typedURL = document.getElementById("networkProxyAutoconfigURL").value;
113  var proxyTypeCur = document.getElementById("network.proxy.type").value;
114 
115  var prefs =
116  Components.classes["@mozilla.org/preferences-service;1"].
117  getService(Components.interfaces.nsIPrefBranch);
118  var pacURL = prefs.getCharPref("network.proxy.autoconfig_url");
119  var proxyType = prefs.getIntPref("network.proxy.type");
120 
121  var disableReloadPref =
122  document.getElementById("pref.advanced.proxies.disable_button.reload");
123  disableReloadPref.disabled =
124  (proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL);
125  },
126 
127  readProxyType: function ()
128  {
129  this.proxyTypeChanged();
130  return undefined;
131  },
132 
133  updateProtocolPrefs: function ()
134  {
135  var proxyTypePref = document.getElementById("network.proxy.type");
136  var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
137  var proxyPrefs = ["ssl", "ftp", "socks", "gopher"];
138  for (var i = 0; i < proxyPrefs.length; ++i) {
139  var proxyServerURLPref = document.getElementById("network.proxy." + proxyPrefs[i]);
140  var proxyPortPref = document.getElementById("network.proxy." + proxyPrefs[i] + "_port");
141 
142  // Restore previous per-proxy custom settings, if present.
143  if (!shareProxiesPref.value) {
144  var backupServerURLPref = document.getElementById("network.proxy.backup." + proxyPrefs[i]);
145  var backupPortPref = document.getElementById("network.proxy.backup." + proxyPrefs[i] + "_port");
146  if (backupServerURLPref.hasUserValue) {
147  proxyServerURLPref.value = backupServerURLPref.value;
148  backupServerURLPref.reset();
149  }
150  if (backupPortPref.hasUserValue) {
151  proxyPortPref.value = backupPortPref.value;
152  backupPortPref.reset();
153  }
154  }
155 
156  proxyServerURLPref.updateElements();
157  proxyPortPref.updateElements();
158  proxyServerURLPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value;
159  proxyPortPref.disabled = proxyServerURLPref.disabled;
160  }
161  var socksVersionPref = document.getElementById("network.proxy.socks_version");
162  socksVersionPref.disabled = proxyTypePref.value != 1 || shareProxiesPref.value;
163 
164  return undefined;
165  },
166 
167  readProxyProtocolPref: function (aProtocol, aIsPort)
168  {
169  var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
170  if (shareProxiesPref.value) {
171  var pref = document.getElementById("network.proxy.http" + (aIsPort ? "_port" : ""));
172  return pref.value;
173  }
174 
175  var backupPref = document.getElementById("network.proxy.backup." + aProtocol + (aIsPort ? "_port" : ""));
176  return backupPref.hasUserValue ? backupPref.value : undefined;
177  },
178 
179  reloadPAC: function ()
180  {
181  Components.classes["@mozilla.org/network/protocol-proxy-service;1"].
182  getService().reloadPAC();
183  },
184 
185  doAutoconfigURLFixup: function ()
186  {
187  var autoURL = document.getElementById("networkProxyAutoconfigURL");
188  var autoURLPref = document.getElementById("network.proxy.autoconfig_url");
189  var URIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
190  .getService(Components.interfaces.nsIURIFixup);
191  try {
192  autoURLPref.value = autoURL.value = URIFixup.createFixupURI(autoURL.value, 0).spec;
193  } catch(ex) {}
194  },
195 
196  readHTTPProxyServer: function ()
197  {
198  var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
199  if (shareProxiesPref.value)
200  this.updateProtocolPrefs();
201  return undefined;
202  },
203 
204  readHTTPProxyPort: function ()
205  {
206  var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
207  if (shareProxiesPref.value)
208  this.updateProtocolPrefs();
209  return undefined;
210  }
211 };
var gConnectionsDialog
Definition: connection.js:39
var pref
Definition: openLocation.js:44
getService(Ci.sbIFaceplateManager)
var prefs
Definition: FeedWriter.js:1169
_getSelectedPageStyle s i