~ubuntu-branches/ubuntu/hardy/foxyproxy/hardy-updates

« back to all changes in this revision

Viewing changes to chrome/content/addeditproxy.js

  • Committer: Bazaar Package Importer
  • Author(s): Sasa Bodiroza
  • Date: 2008-04-09 13:55:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080409135500-x7u28czocbidxpmg
Tags: 2.7.2-0ubuntu1
* New upstream release. (LP: #212875)
* Improved packaging to make use of xpi.mk
* debian/control: 
  - Updated Maintainer field according to DebianMaintainerField spec
  - s/IceWeasel/Firefox/ in description
* debian/copyright: 
  - Updated copyright years
  - Updated packaging copyright
  - Added notice about xpi.mk packaging
  - Getting the source differs for this upload, added notice
* install.rdf: Bumped maxVersion to 3.0.*

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
  FoxyProxy
 
3
  Copyright (C) 2006-2008 Eric H. Jung and LeahScape, Inc.
 
4
  http://foxyproxy.mozdev.org/
 
5
  eric.jung@yahoo.com
 
6
 
 
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
 
10
**/
 
11
 
 
12
var urlsTree, proxy, foxyproxy, autoconfurl, overlay, isWindows;
 
13
const CI = Components.interfaces, CC = Components.classes;
 
14
 
 
15
function onLoad() {
 
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");
 
25
  }
 
26
  else
 
27
    urlsTree = document.getElementById("urlsTree");
 
28
 
 
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;
 
44
 
 
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;
 
50
  }
 
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;
 
55
 
 
56
  _updateView();
 
57
  sizeToContent();
 
58
}
 
59
 
 
60
function trim(s) {
 
61
        return s.replace(/^\s*|\s*$/g, "");
 
62
}
 
63
 
 
64
function onOK() {
 
65
  var name = trim(document.getElementById("proxyname").value);
 
66
  if (!name) {
 
67
    foxyproxy.alert(this, foxyproxy.getMessage("proxy.name.required"));
 
68
    return false;
 
69
  }
 
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;
 
76
  if (enabled) {
 
77
    if (mode == "auto") {
 
78
            if (!_checkUri())
 
79
                return false;
 
80
    }
 
81
    else if (mode == "manual") {
 
82
        if (!host) {
 
83
                if (!port) {
 
84
                            foxyproxy.alert(this, foxyproxy.getMessage("nohostport"));
 
85
                            return false;
 
86
                }
 
87
                    foxyproxy.alert(this, foxyproxy.getMessage("nohost2"));
 
88
                    return false;
 
89
        }
 
90
        else if (!port) {
 
91
                    foxyproxy.alert(this, foxyproxy.getMessage("noport2"));
 
92
                    return false;
 
93
                  }
 
94
                }
 
95
  }
 
96
 
 
97
        if (!hasWhite() &&
 
98
                !overlay.ask(this, foxyproxy.getMessage((window.arguments[0].inn.torwiz ? "torwiz.nopatterns.2" : "no.white.patterns.2")))) return false;
 
99
 
 
100
  proxy.name = name;
 
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;
 
108
 
 
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();
 
118
 
 
119
  window.arguments[0].out = {proxy:proxy};
 
120
  return true;
 
121
}
 
122
 
 
123
function hasWhite() {
 
124
  return proxy.matches.some(function(m){return m.enabled && !m.isBlackList;});
 
125
}
 
126
 
 
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
 
135
        }
 
136
        try {
 
137
    //return foxyproxy.newURI(url);
 
138
    return CC["@mozilla.org/network/io-service;1"]
 
139
      .getService(CI.nsIIOService).newURI(url, "UTF-8", null);
 
140
  }
 
141
  catch(e) {
 
142
    foxyproxy.alert(this, foxyproxy.getMessage("invalid.url"));
 
143
    return false;
 
144
  }
 
145
}
 
146
 
 
147
function onAddEdit(isNew) {
 
148
  var idx = urlsTree.currentIndex;
 
149
  if (!isNew && idx == -1) return; // safety; may not be necessary anymore
 
150
 
 
151
  var params = isNew ?
 
152
    {inn:{overlay:overlay, name:"", pattern:"", regex:false, black:false, enabled:true}, out:null} :
 
153
 
 
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};
 
159
 
 
160
  window.openDialog("chrome://foxyproxy/content/pattern.xul", "",
 
161
    "chrome, dialog, modal, resizable=yes", params).focus();
 
162
 
 
163
  if (params.out) {
 
164
    params = params.out;
 
165
    var match = isNew ? CC["@leahscape.org/foxyproxy/match;1"].createInstance(CI.nsISupports).wrappedJSObject : proxy.matches[idx];
 
166
    
 
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;
 
173
    
 
174
   if (isNew)
 
175
     proxy.matches.push(match);
 
176
            
 
177
   _updateView();
 
178
        // Select item
 
179
        urlsTree.view.selection.select(isNew?urlsTree.view.rowCount-1 : urlsTree.currentIndex);
 
180
  }
 
181
}
 
182
 
 
183
function setButtons() {
 
184
  document.getElementById("tree-row-selected").setAttribute("disabled", urlsTree.currentIndex == -1);
 
185
  onAutoConfUrlInput();
 
186
}
 
187
 
 
188
function _updateView() {
 
189
  // Redraw the tree
 
190
  urlsTree.view = {
 
191
    rowCount : proxy.matches.length,
 
192
    getCellText : function(row, column) {
 
193
      var s = column.id ? column.id : column;
 
194
      switch(s) {
 
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");
 
200
      }
 
201
    },
 
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; }
 
216
 
 
217
  };
 
218
  setButtons();
 
219
}
 
220
 
 
221
function onRemove() {
 
222
  // Store cur selection
 
223
  var sel = urlsTree.currentIndex;
 
224
  proxy.removeMatch(proxy.matches[sel]);
 
225
  _updateView();
 
226
  // Reselect the next appropriate item
 
227
        urlsTree.view.selection.select(sel+1>urlsTree.view.rowCount ? urlsTree.view.rowCount-1:sel);
 
228
}
 
229
 
 
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();
 
239
  }
 
240
  else if (mode == "direct") {
 
241
    document.getElementById("disabled-broadcaster").setAttribute("disabled", "true");
 
242
                document.getElementById("autoconf-broadcaster1").setAttribute("disabled", "true");
 
243
  }
 
244
  else {
 
245
    document.getElementById("disabled-broadcaster").removeAttribute("disabled");
 
246
    document.getElementById("autoconf-broadcaster1").setAttribute("disabled", "true");
 
247
  }
 
248
}
 
249
 
 
250
function onHelp() {
 
251
  foxyproxy_common.openAndReuseOneTabPerURL("http://foxyproxy.mozdev.org/quickstart.html");
 
252
}
 
253
 
 
254
function onViewAutoConf() {
 
255
  var w, p = _checkUri();
 
256
        p &&
 
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
 
259
}
 
260
 
 
261
function onTestAutoConf() {
 
262
        if (_checkUri()) {
 
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);
 
267
    autoConf.loadPAC();
 
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]));
 
272
        }
 
273
}
 
274
 
 
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");
 
281
  else
 
282
    b.setAttribute("disabled", "true");
 
283
}
 
284
 
 
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();
 
295
  }
 
296
}
 
297
 
 
298
function onUrlsTreeMenuPopupShowing() {
 
299
        document.getElementById("enabledPopUpMenuItem").setAttribute("checked", proxy.matches[urlsTree.currentIndex].enabled);
 
300
}
 
301
 
 
302
function toggleEnabled() {
 
303
        proxy.matches[urlsTree.currentIndex].enabled = !proxy.matches[urlsTree.currentIndex].enabled;
 
304
  _updateView();
 
305
}
 
306
 
 
307
function onWildcardReference() {
 
308
        document.getElementById('wildcardReferencePopup').showPopup(document.getElementById('wildcardRefBtn'), -1, -1, 'popup', 'bottomleft', 'topleft');
 
309
}
 
310
 
 
311
function onIsSocks(checked) {
 
312
        document.getElementById("socks5").disabled = document.getElementById("socks4").disabled = !checked;
 
313
}
 
 
b'\\ No newline at end of file'