1 /**
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 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK *****
37 */
38
39 var gConnectionsDialog = {
beforeAccept
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
proxyTypeChanged
74 proxyTypeChanged: function ()
75 {
76 var proxyTypePref = document.getElementById("network.proxy.type");
77
78 // Update http
79 var httpProxyURLPref = document.getElementById("network.proxy.http");
80 httpProxyURLPref.disabled = proxyTypePref.value != 1;
81 var httpProxyPortPref = document.getElementById("network.proxy.http_port");
82 httpProxyPortPref.disabled = proxyTypePref.value != 1;
83
84 // Now update the other protocols
85 this.updateProtocolPrefs();
86
87 var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
88 shareProxiesPref.disabled = proxyTypePref.value != 1;
89
90 var noProxiesPref = document.getElementById("network.proxy.no_proxies_on");
91 noProxiesPref.disabled = proxyTypePref.value != 1;
92
93 var autoconfigURLPref = document.getElementById("network.proxy.autoconfig_url");
94 autoconfigURLPref.disabled = proxyTypePref.value != 2;
95
96 #ifdef MOZILLA_1_8_BRANCH
97 var disableReloadPref = document.getElementById("pref.advanced.proxies.disable_button.reload");
98 disableReloadPref.disabled = proxyTypePref.value != 2;
99 },
updateReloadButton
100 #else
101 this.updateReloadButton();
102 },
103
104 updateReloadButton: function ()
105 {
106 // Disable the "Reload PAC" button if the selected proxy type is not PAC or
107 // if the current value of the PAC textbox does not match the value stored
108 // in prefs. Likewise, disable the reload button if PAC is not configured
109 // in prefs.
110
111 var typedURL = document.getElementById("networkProxyAutoconfigURL").value;
112 var proxyTypeCur = document.getElementById("network.proxy.type").value;
113
114 var prefs =
115 Components.classes["@mozilla.org/preferences-service;1"].
116 getService(Components.interfaces.nsIPrefBranch);
117 var pacURL = prefs.getCharPref("network.proxy.autoconfig_url");
118 var proxyType = prefs.getIntPref("network.proxy.type");
119
120 var disableReloadPref =
121 document.getElementById("pref.advanced.proxies.disable_button.reload");
122 disableReloadPref.disabled =
readProxyType
123 (proxyTypeCur != 2 || proxyType != 2 || typedURL != pacURL);
124 },
125 #endif
126
127 readProxyType: function ()
128 {
updateProtocolPrefs
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;
readProxyProtocolPref
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
reloadPAC
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 #ifdef MOZILLA_1_8_BRANCH
182 var autoURL = document.getElementById("networkProxyAutoconfigURL");
doAutoconfigURLFixup
183 var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"]
184 .getService(Components.interfaces.nsPIProtocolProxyService);
185 pps.configureFromPAC(autoURL.value);
186 #else
187 Components.classes["@mozilla.org/network/protocol-proxy-service;1"].
188 getService().reloadPAC();
189 #endif
190 },
191
192 doAutoconfigURLFixup: function ()
193 {
readHTTPProxyServer
194 var autoURL = document.getElementById("networkProxyAutoconfigURL");
195 var autoURLPref = document.getElementById("network.proxy.autoconfig_url");
196 var URIFixup = Components.classes["@mozilla.org/docshell/urifixup;1"]
197 .getService(Components.interfaces.nsIURIFixup);
198 try {
199 autoURLPref.value = autoURL.value = URIFixup.createFixupURI(autoURL.value, 0).spec;
200 } catch(ex) {}
201 },
readHTTPProxyPort
202
203 readHTTPProxyServer: function ()
204 {
205 var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
206 if (shareProxiesPref.value)
207 this.updateProtocolPrefs();
208 return undefined;
209 },
210
211 readHTTPProxyPort: function ()
212 {
213 var shareProxiesPref = document.getElementById("network.proxy.share_proxy_settings");
214 if (shareProxiesPref.value)
215 this.updateProtocolPrefs();
216 return undefined;
217 }
218 };