3
Copyright (C) 2006-2008 Eric H. Jung and LeahScape, Inc.
4
http://foxyproxy.mozdev.org/
7
This source code is released under the GPL license,
8
available in the LICENSE file at the root of this installation
9
and also online at http://www.gnu.org/licenses/gpl.txt
12
var urlsTree, proxy, foxyproxy, autoconfurl, overlay, isWindows;
13
const CI = Components.interfaces, CC = Components.classes;
16
isWindows = CC["@mozilla.org/xre/app-info;1"].getService(CI.nsIXULRuntime).OS == "WINNT";
17
overlay = foxyproxy_common.getMostRecentWindow().foxyproxy;
18
autoconfurl = document.getElementById("autoconfurl");
19
foxyproxy = CC["@leahscape.org/foxyproxy/service;1"]
20
.getService(CI.nsISupports).wrappedJSObject;
21
if (window.arguments[0].inn.torwiz) {
22
document.getElementById("torwiz-broadcaster").hidden = true;
23
document.getElementById("not-torwiz-broadcaster").hidden = false;
24
urlsTree = document.getElementById("torWizUrlsTree");
27
urlsTree = document.getElementById("urlsTree");
29
proxy = window.arguments[0].inn.proxy;
30
document.getElementById("proxyname").value = proxy.name;
31
document.getElementById("proxynotes").value = proxy.notes;
32
document.getElementById("animatedIcons").checked = proxy.animatedIcons;
33
document.getElementById("cycleEnabled").checked = proxy.includeInCycle;
34
document.getElementById("tabs").selectedIndex = proxy.selectedTabIndex;
35
document.getElementById("proxyenabled").checked = proxy.enabled;
36
document.getElementById("mode").value = proxy.mode;
37
toggleMode(proxy.mode);
38
document.getElementById("host").value = proxy.manualconf.host;
39
document.getElementById("port").value = proxy.manualconf.port;
40
document.getElementById("isSocks").checked = proxy.manualconf.isSocks;
41
onIsSocks(proxy.mode == "manual" && proxy.manualconf.isSocks);
42
document.getElementById("socksversion").value = proxy.manualconf.socksversion;
43
autoconfurl.value = proxy.autoconf.url;
45
if (proxy.lastresort) {
46
document.getElementById("default-proxy-broadcaster").setAttribute("disabled", "true");
47
document.getElementById("proxyname").disabled =
48
document.getElementById("proxynotes").disabled = true;
49
document.getElementById("patternstab").hidden = true;
51
document.getElementById("pacLoadNotificationEnabled").checked = proxy.autoconf.loadNotification;
52
document.getElementById("pacErrorNotificationEnabled").checked = proxy.autoconf.errorNotification;
53
document.getElementById("autoConfURLReloadEnabled").checked = proxy.autoconf.autoReload;
54
document.getElementById("autoConfReloadFreq").value = proxy.autoconf.reloadFreqMins;
61
return s.replace(/^\s*|\s*$/g, "");
65
var name = trim(document.getElementById("proxyname").value);
67
foxyproxy.alert(this, foxyproxy.getMessage("proxy.name.required"));
70
var enabled = document.getElementById("proxyenabled").checked,
71
host = trim(document.getElementById("host").value),
72
port = document.getElementById("port").value,
73
url = trim(autoconfurl.value),
74
reloadfreq = document.getElementById("autoConfReloadFreq").value;
75
var mode = document.getElementById("mode").value;
81
else if (mode == "manual") {
84
foxyproxy.alert(this, foxyproxy.getMessage("nohostport"));
87
foxyproxy.alert(this, foxyproxy.getMessage("nohost2"));
91
foxyproxy.alert(this, foxyproxy.getMessage("noport2"));
98
!overlay.ask(this, foxyproxy.getMessage((window.arguments[0].inn.torwiz ? "torwiz.nopatterns.2" : "no.white.patterns.2")))) return false;
101
proxy.notes = document.getElementById("proxynotes").value;
102
proxy.selectedTabIndex = document.getElementById("tabs").selectedIndex;
103
proxy.autoconf.url = url;
104
proxy.autoconf.loadNotification = document.getElementById("pacLoadNotificationEnabled").checked;
105
proxy.autoconf.errorNotification = document.getElementById("pacErrorNotificationEnabled").checked;
106
proxy.autoconf.autoReload = document.getElementById("autoConfURLReloadEnabled").checked;
107
proxy.autoconf.reloadFreqMins = reloadfreq;
109
proxy.mode = mode; // set this first to control PAC loading
110
proxy.enabled = enabled;
111
proxy.manualconf.host = host;
112
proxy.manualconf.port = port;
113
proxy.manualconf.isSocks = document.getElementById("isSocks").checked;
114
proxy.manualconf.socksversion = document.getElementById("socksversion").value;
115
proxy.animatedIcons = document.getElementById("animatedIcons").checked;
116
proxy.includeInCycle = document.getElementById("cycleEnabled").checked;
117
proxy.afterPropertiesSet();
119
window.arguments[0].out = {proxy:proxy};
123
function hasWhite() {
124
return proxy.matches.some(function(m){return m.enabled && !m.isBlackList;});
127
function _checkUri() {
128
var url = trim(autoconfurl.value);
129
if (url.indexOf("://") == -1) {
130
// User didn't specify a scheme, so assume he means file:///
131
url = url.replace(/\\/g,"/"); // replaces backslashes with forward slashes; probably not strictly necessary
132
if (url[0] != "\\" && url[0] != "/") url="/"+url; // prepend a leading slash if necessary
133
url="file:///" + (isWindows?"C:":"") + url;
134
autoconfurl.value = url; // copy back to the UI
137
//return foxyproxy.newURI(url);
138
return CC["@mozilla.org/network/io-service;1"]
139
.getService(CI.nsIIOService).newURI(url, "UTF-8", null);
142
foxyproxy.alert(this, foxyproxy.getMessage("invalid.url"));
147
function onAddEdit(isNew) {
148
var idx = urlsTree.currentIndex;
149
if (!isNew && idx == -1) return; // safety; may not be necessary anymore
152
{inn:{overlay:overlay, name:"", pattern:"", regex:false, black:false, enabled:true}, out:null} :
154
{inn:{overlay:overlay, name:proxy.matches[idx].name,
155
pattern:proxy.matches[idx].pattern, regex:proxy.matches[idx].isRegEx,
156
black:proxy.matches[idx].isBlackList,
157
enabled:proxy.matches[idx].enabled,
158
caseSensitive:proxy.matches[idx].caseSensitive}, out:null};
160
window.openDialog("chrome://foxyproxy/content/pattern.xul", "",
161
"chrome, dialog, modal, resizable=yes", params).focus();
165
var match = isNew ? CC["@leahscape.org/foxyproxy/match;1"].createInstance(CI.nsISupports).wrappedJSObject : proxy.matches[idx];
167
match.name = params.name;
168
match.pattern = params.pattern;
169
match.isRegEx = params.isRegEx;
170
match.isBlackList = params.isBlackList;
171
match.enabled = params.isEnabled;
172
match.caseSensitive = params.caseSensitive;
175
proxy.matches.push(match);
179
urlsTree.view.selection.select(isNew?urlsTree.view.rowCount-1 : urlsTree.currentIndex);
183
function setButtons() {
184
document.getElementById("tree-row-selected").setAttribute("disabled", urlsTree.currentIndex == -1);
185
onAutoConfUrlInput();
188
function _updateView() {
191
rowCount : proxy.matches.length,
192
getCellText : function(row, column) {
193
var s = column.id ? column.id : column;
195
case "nameCol":return proxy.matches[row].name;
196
case "patternCol":return proxy.matches[row].pattern;
197
case "patternTypeCol":return foxyproxy.getMessage(proxy.matches[row].isRegEx ? "foxyproxy.regex.label" : "foxyproxy.wildcard.label");
198
case "blackCol":return foxyproxy.getMessage(proxy.matches[row].isBlackList ? "foxyproxy.blacklist.label" : "foxyproxy.whitelist.label");
199
case "caseSensitiveCol":return foxyproxy.getMessage(proxy.matches[row].caseSensitive ? "yes" : "no");
202
setCellValue: function(row, col, val) {proxy.matches[row].enabled = val;},
203
getCellValue: function(row, col) {return proxy.matches[row].enabled;},
204
isSeparator: function(aIndex) { return false; },
205
isSorted: function() { return false; },
206
isEditable: function(row, col) { return false; },
207
isContainer: function(aIndex) { return false; },
208
setTree: function(aTree){},
209
getImageSrc: function(aRow, aColumn) {return null;},
210
getProgressMode: function(aRow, aColumn) {},
211
cycleHeader: function(aColId, aElt) {},
212
getRowProperties: function(aRow, aColumn, aProperty) {},
213
getColumnProperties: function(aColumn, aColumnElement, aProperty) {},
214
getCellProperties: function(aRow, aProperty) {},
215
getLevel: function(row){ return 0; }
221
function onRemove() {
222
// Store cur selection
223
var sel = urlsTree.currentIndex;
224
proxy.removeMatch(proxy.matches[sel]);
226
// Reselect the next appropriate item
227
urlsTree.view.selection.select(sel+1>urlsTree.view.rowCount ? urlsTree.view.rowCount-1:sel);
230
function toggleMode(mode) {
231
// Next line--buggy in FF 1.5.0.1--makes fields enabled but readonly
232
// document.getElementById("disabled-broadcaster").setAttribute("disabled", mode == "auto" ? "true" : "false");
233
// Call removeAttribute() instead of setAttribute("disabled", "false") or setAttribute("disabled", false);
234
// Thanks, Andy McDonald.
235
if (mode == "auto") {
236
document.getElementById("autoconf-broadcaster1").removeAttribute("disabled");
237
document.getElementById("disabled-broadcaster").setAttribute("disabled", "true");
238
onAutoConfUrlInput();
240
else if (mode == "direct") {
241
document.getElementById("disabled-broadcaster").setAttribute("disabled", "true");
242
document.getElementById("autoconf-broadcaster1").setAttribute("disabled", "true");
245
document.getElementById("disabled-broadcaster").removeAttribute("disabled");
246
document.getElementById("autoconf-broadcaster1").setAttribute("disabled", "true");
251
foxyproxy_common.openAndReuseOneTabPerURL("http://foxyproxy.mozdev.org/quickstart.html");
254
function onViewAutoConf() {
255
var w, p = _checkUri();
257
(w=open("view-source:" + p.spec, "", "scrollbars,resizable,modal,chrome,dialog=no,width=450,height=425").focus());
258
w && (w.windowtype="foxyproxy-options"); // set windowtype so it's forced to close when last browser closes
261
function onTestAutoConf() {
263
var autoConf = CC["@leahscape.org/foxyproxy/autoconf;1"].createInstance(CI.nsISupports).wrappedJSObject;
264
autoConf.owner = {name: "Test", enabled: true};
265
autoConf.url = autoconfurl.value;
266
autoConf._resolver = CC["@mozilla.org/network/proxy-auto-config;1"].createInstance(CI.nsIProxyAutoConfig);
268
var none=foxyproxy.getMessage("none");
269
foxyproxy.alert(this, autoConf.owner.enabled ?
270
foxyproxy.getMessage("autoconfurl.test.success") :
271
foxyproxy.getMessage("autoconfurl.test.fail", [autoConf.status, autoConf.error?autoConf.error:none]));
275
function onAutoConfUrlInput() {
276
// setAttribute("disabled", true) buggy in FF 1.5.0.4 for the way i've setup the cmd
277
// so must use removeAttribute()
278
var b = document.getElementById("autoconf-broadcaster2");
279
if (autoconfurl.value.length > 0)
280
b.removeAttribute("disabled");
282
b.setAttribute("disabled", "true");
285
function onSelectAutoConf() {
286
const nsIFilePicker = CI.nsIFilePicker;
287
var p = CC["@mozilla.org/filepicker;1"].createInstance(nsIFilePicker);
288
p.init(window, foxyproxy.getMessage("pac.select"), nsIFilePicker.modeOpen);
289
p.appendFilters(nsIFilePicker.filterAll);
290
p.appendFilter(foxyproxy.getMessage("pac.files"), "*.pac");
291
p.defaultExtension = "pac";
292
if (p.show() != nsIFilePicker.returnCancel) {
293
autoconfurl.value = foxyproxy.transformer(p.file, "uri-string");
294
onAutoConfUrlInput();
298
function onUrlsTreeMenuPopupShowing() {
299
document.getElementById("enabledPopUpMenuItem").setAttribute("checked", proxy.matches[urlsTree.currentIndex].enabled);
302
function toggleEnabled() {
303
proxy.matches[urlsTree.currentIndex].enabled = !proxy.matches[urlsTree.currentIndex].enabled;
307
function onWildcardReference() {
308
document.getElementById('wildcardReferencePopup').showPopup(document.getElementById('wildcardRefBtn'), -1, -1, 'popup', 'bottomleft', 'topleft');
311
function onIsSocks(checked) {
312
document.getElementById("socks5").disabled = document.getElementById("socks4").disabled = !checked;
b'\\ No newline at end of file'