38
40
data && (d = data.QueryInterface(CI.nsISupports));
40
gObsSvc.notifyObservers(bool, topic, d);
42
gObsSvc.notifyObservers(bool, topic, d);
44
const exceptionSchemes = ['feed'];
47
var fileProtocolHandler = CC["@mozilla.org/network/protocol;1?name=file"].createInstance(CI["nsIFileProtocolHandler"]);
48
if ("undefined" != typeof(__LOCATION__)) {
53
self = fileProtocolHandler.getFileFromURLSpec(Components.Exception().filename);
55
var dir = self.parent; // the directory this file is in
56
var loader = CC["@mozilla.org/moz/jssubscript-loader;1"].createInstance(CI["mozIJSSubScriptLoader"]);
58
var filePath = dir.clone();
59
filePath.append("superadd.js");
60
loader.loadSubScript(fileProtocolHandler.getURLSpecFromFile(filePath));
63
dump("Error loading superadd.js\n");
43
67
// l is for lulu...
44
68
function foxyproxy() {this.wrappedJSObject = this;}
46
70
foxyproxy.prototype = {
49
73
_selectedProxy : null,
50
74
_selectedTabIndex : 0,
52
76
_initialized : false,
55
79
_toolsMenuNode : null,
56
80
_contextMenuNode : null,
57
81
_advancedMenus : false,
82
_previousMode : "patterns",
61
86
QueryInterface: function(aIID) {
62
if(!aIID.equals(CI.nsISupports) && !aIID.equals(CI.nsIObserver) && !aIID.equals(CI.nsISupportsWeakReference))
63
throw CR.NS_ERROR_NO_INTERFACE;
87
if(!aIID.equals(CI.nsISupports) && !aIID.equals(CI.nsIObserver) && !aIID.equals(CI.nsISupportsWeakReference)) {
88
throw CR.NS_ERROR_NO_INTERFACE;
67
__registration: function() {
68
return ({topics: ["app-startup", "xpcom-shutdown"],
69
observerName: "foxyproxy_catobserver",
70
contractId: "@leahscape.org/foxyproxy/service;1",
71
classId: Components.ID("{46466e13-16ab-4565-9924-20aac4d98c82}"),
72
constructor: foxyproxy,
73
className: "FoxyProxy Core"});
76
93
observe: function(subj, topic, data) {
78
95
case "app-startup":
79
gObsSvc.addObserver(this, "quit-application", false);
96
gObsSvc.addObserver(this, "quit-application", false);
80
97
gObsSvc.addObserver(this, "domwindowclosed", false);
81
98
//gObsSvc.addObserver(this, "http-on-modify-request", false);
82
99
this._loadStrings();
84
case "domwindowclosed":
101
case "domwindowclosed":
85
102
// Did the last browser window close? It could be that the DOM inspector, JS console,
86
103
// or the non-last browser window just closed. In that case, don't close FoxyProxy.
87
104
var wm = CC["@mozilla.org/appshell/window-mediator;1"].getService(CI.nsIWindowMediator);
88
var win = wm.getMostRecentWindow("navigator:browser");
105
var win = wm.getMostRecentWindow("navigator:browser") || wm.getMostRecentWindow("Songbird:Main");
90
107
this.closeAppWindows("foxyproxy", wm);
91
108
this.closeAppWindows("foxyproxy-quickadd", wm);
92
109
this.closeAppWindows("foxyproxy-options", wm);
125
142
var req = CC["@mozilla.org/xmlextras/xmlhttprequest;1"].
126
143
createInstance(CI.nsIXMLHttpRequest);
127
144
req.open("GET", "chrome://foxyproxy/content/strings.xml", false);
129
this.strings._entities = new Array();
146
this.strings._entities = new Array();
130
147
for (var i=0,e=req.responseXML.getElementsByTagName("i18n"); i<e.length; i++) {
131
148
var attrs = e.item(i).attributes;
132
149
this.strings._entities[attrs.getNamedItem("id").nodeValue] = attrs.getNamedItem("value").nodeValue;
136
closeAppWindows: function(type, wm) {
153
closeAppWindows: function(type, wm) {
137
154
var wm = CC["@mozilla.org/appshell/window-mediator;1"].getService(CI.nsIWindowMediator);
138
155
var e = wm.getEnumerator(type);
139
156
while (e.hasMoreElements()) {
140
157
e.getNext().close();
144
161
init : function() {
145
162
if (!this._initialized) {
146
163
this._initialized = true; // because @mozilla.org/file/directory_service;1 isn't available in init()
149
this.autoadd = new SuperAdd("autoadd");
150
this.quickadd = new QuickAdd("quickadd");
151
this.autoadd.init(this.getMessage("autoadd.pattern.label"), this);
166
this.autoadd = new SuperAdd();
167
this.quickadd = new QuickAdd();
168
this.autoadd.init(this.getMessage("autoadd.pattern.label"), this);
152
169
this.quickadd.init(this.getMessage("quickadd.pattern.label"), this);
154
171
var req = CC["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(CI.nsIXMLHttpRequest);
155
172
var settingsURI = this.getSettingsURI("uri-string");
156
req.open("GET", settingsURI, false);
173
req.open("GET", settingsURI, false);
158
var doc = req.responseXML, docElem = doc.documentElement;
159
if (docElem.nodeName == "parsererror") {
160
this.alert(null, this.getMessage("settings.error"));
161
// TODO: prompt user to overwrite?
175
var doc = req.responseXML;
176
if (!doc || doc.documentElement.nodeName == "parsererror") {
177
this.alert(null, this.getMessage("settings.error.2", [settingsURI, settingsURI]));
162
178
this.writeSettings(settingsURI);
165
this.fromDOM(doc, docElem);
181
this.fromDOM(doc, doc.documentElement);
168
184
<menu id="foxyproxy-context-menu-1" label="&foxyproxy.label;"
169
tooltiptext="&foxyproxy.tooltip;" accesskey="&foxyproxy.accesskey;" class="menu-iconic foxyproxybutton-small">
185
tooltiptext="&foxyproxy.tooltip;" accesskey="&foxyproxy.accesskey;" class="menu-iconic foxyproxybutton-small">
170
186
<menupopup id="foxyproxy-contextmenu-popup"
171
187
onpopupshowing="foxyproxy.onPopupShowing(this, event);"
172
188
onpopuphiding="foxyproxy.onPopupHiding();"/>
176
var doc = CC["@mozilla.org/xml/xml-document;1"].createInstance(CI.nsIDOMDocument);
192
var doc = CC["@mozilla.org/xml/xml-document;1"].createInstance(CI.nsIDOMDocument);
177
193
this._contextMenuNode = doc.createElement("menu");
178
this._contextMenuNode.setAttribute("id", "foxyproxy-context-menu-1");
179
this._contextMenuNode.setAttribute("label", "&foxyproxy.label;");
180
this._contextMenuNode.setAttribute("tooltiptext", "&foxyproxy.tooltip;");
181
this._contextMenuNode.setAttribute("accesskey", "&foxyproxy.accesskey;");
182
this._contextMenuNode.setAttribute("class", "menu-iconic foxyproxybutton-small");
194
this._contextMenuNode.setAttribute("id", "foxyproxy-context-menu-1");
195
this._contextMenuNode.setAttribute("label", "&foxyproxy.label;");
196
this._contextMenuNode.setAttribute("tooltiptext", "&foxyproxy.tooltip;");
197
this._contextMenuNode.setAttribute("accesskey", "&foxyproxy.accesskey;");
198
this._contextMenuNode.setAttribute("class", "menu-iconic foxyproxybutton-small");
183
199
var menupopup2 = doc.createElement("menupopup");
184
200
menupopup2.setAttribute("id", "foxyproxy-contextmenu-popup");
185
menupopup2.setAttribute("onpopupshowing", "foxyproxy.onPopupShowing(this, event);");
186
menupopup2.setAttribute("onpopuphiding", "foxyproxy.onPopupHiding();");
187
this._contextMenuNode.appendChild(menupopup2);
201
menupopup2.setAttribute("onpopupshowing", "foxyproxy.onPopupShowing(this, event);");
202
menupopup2.setAttribute("onpopuphiding", "foxyproxy.onPopupHiding();");
203
this._contextMenuNode.appendChild(menupopup2);
191
207
get contextMenuNode() {
192
208
return this._contextMenuNode.cloneNode(true);
195
211
get mode() { return this._mode; },
196
212
setMode : function(mode, writeSettings, init) {
197
// Possible modes are: patterns, _proxy_id_ (for "Use proxy xyz for all URLs), random, roundrobin, disabled
213
// Possible modes are: patterns, _proxy_id_ (for "Use proxy xyz for all URLs), random, roundrobin, disabled, previous.
214
// Note that "previous" isn't used anywhere but this method: it is translated into the previous mode then broadcasted.
215
if (mode == "previous") {
216
if (this.mode == "disabled")
217
mode = this.previousMode;
221
this._previousMode = this.mode;
198
223
this._selectedProxy = null; // todo: really shouldn't do this in case something tries to load right after this instruction
199
224
for (var i=0,len=this.proxies.length; i<len; i++) {
200
if (mode == this.proxies.item(i).id) {
201
this._selectedProxy = this.proxies.item(i);
202
this.proxies.item(i).enabled = true; // ensure it's enabled
225
var proxy = this.proxies.item(i);
226
if (mode == proxy.id) {
227
this._selectedProxy = proxy;
228
proxy.enabled = true; // ensure it's enabled
204
this.proxies.item(i).handleTimer(); // Leave this after "this.proxies.item(i).enabled = true" !
230
proxy.handleTimer(); // Leave this after "proxy.enabled = true" !
231
proxy.shouldLoadPAC() && proxy.autoconf.loadPAC();
207
233
this.toggleFilter(mode != "disabled");
234
mode=="disabled" && this.loadDefaultPAC();
209
236
writeSettings && this.writeSettings();
210
237
gBroadcast(this.autoadd._enabled, "foxyproxy-mode-change", this._mode);
240
loadDefaultPAC : function() {
241
// User has disabled FoxyProxy, so Firefox network.proxy.* preferences will be used.
242
// If Firefox is configured to use a PAC file, we need to force that PAC file to load.
243
// Firefox won't load it automatically except on startup and after
244
// network.proxy.autoconfig_retry_* seconds. Rather than make the user wait for that,
245
// we load the PAC file now.
246
var networkPrefs = this.getPrefsService("network.proxy."), usingPAC;
248
usingPAC = networkPrefs.getIntPref("type") == 2; // isn't there a const for this?
251
dump("FoxyProxy: network.proxy.type doesn't exist or can't be read\n");
254
// Don't use nsPIProtocolProxyService. From its comments: "[nsPIProtocolProxyService] exists purely as a
255
// hack to support the configureFromPAC method used by the preference panels in the various apps. Those
256
// apps need to be taught to just use the preferences API to "reload" the PAC file. Then, at that point,
257
// we can eliminate this interface completely."
259
// var pacURL = networkPrefs.getCharPref("autoconfig_url");
260
// var pps = Components.classes["@mozilla.org/network/protocol-proxy-service;1"]
261
//.getService(Components.interfaces.nsPIProtocolProxyService);
262
// pps.configureFromPAC(pacURL);
264
// Instead, change the prefs--the proxy service is observing and will reload the PAC
265
networkPrefs.setIntPref("type", 1);
266
networkPrefs.setIntPref("type", 2);
214
271
* This assumes mode order is:
215
272
* patterns, proxy1, ..., lastresort, random, roundrobin, disabled
222
279
else if (this._mode == "disabled") {
223
280
this.setMode("patterns", true);
225
282
else if (this._mode == "patterns") {
226
283
var p = this.proxies.item(0);
227
284
(!p || !p.enabled || !p.includeInCycle) && (p = _getNextInCycle(this.proxies.item(0).id));
228
this.setMode(p?p.id:"disabled", true);
285
this.setMode(p?p.id:"disabled", true);
231
288
var p = _getNextInCycle(this._mode);
232
289
this.setMode(p?p.id:"disabled", true);
234
291
function _getNextInCycle(start) {
235
292
for (var p=self.proxies.getNextById(start); p && !p.includeInCycle; p = self.proxies.getNextById(p.id));
240
297
toggleFilter : function(enabled) {
241
298
var ps = CC["@mozilla.org/network/protocol-proxy-service;1"]
242
299
.getService(CI.nsIProtocolProxyService);
243
300
ps.unregisterFilter(this); // safety - always remove first
244
301
enabled && ps.registerFilter(this, 0);
247
304
applyFilter : function(ps, uri, proxy) {
249
305
function _err(fp, info, extInfo) {
250
306
var def = fp.proxies.item(fp.proxies.length-1);
251
307
mp = gMatchingProxyFactory(def, null, spec, "err", extInfo?extInfo:info);
252
fp.notifier.alert(info, fp.getMessage("see.log"));
253
return def; // Failsafe: use lastresort proxy if nothing else was chosen
308
fp.notifier.alert(info, fp.getMessage("see.log"));
309
return def; // Failsafe: use lastresort proxy if nothing else was chosen
313
if (exceptionSchemes[uri.scheme]) return;
257
314
var spec = uri.spec;
258
315
var mp = this.applyMode(spec);
259
316
var ret = mp.proxy.getProxy(spec, uri.host, mp);
260
317
return ret ? ret : _err(this, this.getMessage("route.error"));
263
dump("applyFilter: " + e + "\n");
320
dump("applyFilter: " + e + "\n");
264
321
return _err(this, this.getMessage("route.exception", [""]), this.getMessage("route.exception", [": " + e]));
267
gObsSvc.notifyObservers(mp.proxy, "foxyproxy-throb", null);
324
gObsSvc.notifyObservers(mp.proxy, "foxyproxy-throb", null);
272
329
getPrefsService : function(str) {
273
330
return CC["@mozilla.org/preferences-service;1"].
274
331
getService(CI.nsIPrefService).getBranch(str);
277
334
// Returns settings URI in desired form
278
335
getSettingsURI : function(type) {
281
338
o = this.getPrefsService("extensions.foxyproxy.").getCharPref("settings");
341
dump("FoxyProxy: Unable to read preference extensions.foxyproxy.settings in getSettingsURI(). Checking for new installation.\n");
343
// The first time FP runs, "firstrun" does not exist (i.e., null || false). Subsequent times, "firstrun" == true.
344
// In other words, this pref is improperly named for its purpose. Better name is "notfirstrun".
345
var f = this.getPrefsService("extensions.foxyproxy.").getBoolPref("firstrun");
347
this.alert(null, this.getMessage("preferences.read.error.warning", ["extensions.foxyproxy.settings", "getSettingsURI()"]) + " " +
348
this.getMessage("preferences.read.error.fatal"));
285
354
o == this.PFF && (o = this.getDefaultPath());
286
355
var file = this.transformer(o, CI.nsIFile);
288
357
if (!file.exists()) {
289
358
this.writeSettings(file);
385
449
if (o instanceof CI.nsIFile) return handler.newFileURI(o);
386
450
if (o instanceof CI.nsIURI) return o;
387
return null; // unknown type
451
return null; // unknown type
392
// Create nsIFile from a string
457
// Create nsIFile from a string
393
458
createFile : function(str) {
394
459
var f = CC["@mozilla.org/file/local;1"].createInstance(CI.nsILocalFile);
395
460
f.initWithPath(str);
399
464
writeSettings : function(o) {
400
!o && (o = gFP.getPrefsService("extensions.foxyproxy.").getCharPref("settings"));
401
o = gFP.transformer(o, CI.nsIFile);
402
var foStream = CC["@mozilla.org/network/file-output-stream;1"].
403
createInstance(CI.nsIFileOutputStream);
404
foStream.init(o, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate
405
foStream.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", 39);
406
CC["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(CI.nsIDOMSerializer)
407
.serializeToStream(gFP.toDOM(), foStream, "UTF-8");
408
//foStream.write(str, str.length);
466
throw new Error("e");
468
catch (e) {dump (e.stack + "\n");}*/
471
o = gFP.getPrefsService("extensions.foxyproxy.").getCharPref("settings");
474
this.alert(null, this.getMessage("preferences.read.error.warning", ["extensions.foxyproxy.settings", "writeSettings()"]));
475
o = this.getDefaultPath();
479
var o2 = gFP.transformer(o, CI.nsIFile);
480
var foStream = CC["@mozilla.org/network/file-output-stream;1"].
481
createInstance(CI.nsIFileOutputStream);
482
foStream.init(o2, 0x02 | 0x08 | 0x20, 0664, 0); // write, create, truncate
483
foStream.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", 39);
484
CC["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(CI.nsIDOMSerializer)
485
.serializeToStream(gFP.toDOM(), foStream, "UTF-8");
486
//foStream.write(str, str.length);
490
this.alert(null, this.getMessage("settings.error.3", [o]));
412
494
get proxyDNS() { return this._proxyDNS; },
413
495
set proxyDNS(p) {
414
496
this._proxyDNS = p;
476
564
fromDOM : function(doc, node) {
477
565
this.statusbar.fromDOM(doc);
478
this.toolbar.fromDOM(doc);
479
this.logg.fromDOM(doc);
480
this._proxyDNS = node.getAttribute("proxyDNS") == "true";
481
this._toolsMenu = node.hasAttribute("toolsMenu") ?
482
node.getAttribute("toolsMenu") == "true" : true; // new for 2.0
483
this._contextMenu = node.hasAttribute("contextMenu") ?
484
node.getAttribute("contextMenu") == "true" : true; // new for 2.0
485
this._advancedMenus = node.hasAttribute("advancedMenus") ?
486
node.getAttribute("advancedMenus") == "true" : false; // new for 2.3--default to false if it doesn't exist
488
this._selectedTabIndex = node.getAttribute("selectedTabIndex") || "0";
489
this.proxies.fromDOM(doc, this);
490
this.setMode(node.hasAttribute("enabledState") ?
491
(node.getAttribute("enabledState") == "" ? "patterns" : node.getAttribute("enabledState")) :
492
node.getAttribute("mode"), false, true); // renamed to mode in 2.0
566
this.toolbar.fromDOM(doc);
567
this.logg.fromDOM(doc);
568
this._proxyDNS = gGetSafeAttrB(node, "proxyDNS", false);
569
this._toolsMenu = gGetSafeAttrB(node, "toolsMenu", true); // new for 2.0
570
this._contextMenu = gGetSafeAttrB(node, "contextMenu", true); // new for 2.0
571
this._advancedMenus = gGetSafeAttrB(node, "advancedMenus", false); // new for 2.3--default to false if it doesn't exist
572
this._selectedTabIndex = gGetSafeAttr(node, "selectedTabIndex", "0");
573
var mode = node.hasAttribute("enabledState") ?
574
(node.getAttribute("enabledState") == "" ? "disabled" : node.getAttribute("enabledState")) :
575
node.getAttribute("mode"); // renamed to mode in 2.0
576
this._previousMode = gGetSafeAttr(node, "previousMode", "patterns");
577
this.proxies.fromDOM(mode, doc, this);
578
this.setMode(mode, false, true);
493
579
this.random.fromDOM(doc, this);
494
this.autoadd.fromDOM(doc);
495
this.quickadd.fromDOM(doc);
580
this.autoadd.fromDOM(doc);
581
this.quickadd.fromDOM(doc);
496
582
this.warnings.fromDOM(doc);
499
585
toDOM : function() {
500
var doc = CC["@mozilla.org/xml/xml-document;1"].createInstance(CI.nsIDOMDocument);
501
var e = doc.createElement("foxyproxy");
586
var doc = CC["@mozilla.org/xml/xml-document;1"].createInstance(CI.nsIDOMDocument);
587
var e = doc.createElement("foxyproxy");
502
588
e.setAttribute("mode", this._mode);
503
589
e.setAttribute("selectedTabIndex", this._selectedTabIndex);
504
590
e.setAttribute("proxyDNS", this._proxyDNS);
505
e.setAttribute("toolsMenu", this._toolsMenu);
506
e.setAttribute("contextMenu", this._contextMenu);
507
e.setAttribute("advancedMenus", this._advancedMenus);
508
e.appendChild(this.random.toDOM(doc));
591
e.setAttribute("toolsMenu", this._toolsMenu);
592
e.setAttribute("contextMenu", this._contextMenu);
593
e.setAttribute("advancedMenus", this._advancedMenus);
594
e.setAttribute("previousMode", this._previousMode);
595
e.appendChild(this.random.toDOM(doc));
509
596
e.appendChild(this.statusbar.toDOM(doc));
510
e.appendChild(this.toolbar.toDOM(doc));
597
e.appendChild(this.toolbar.toDOM(doc));
511
598
e.appendChild(this.logg.toDOM(doc));
512
e.appendChild(this.warnings.toDOM(doc));
513
e.appendChild(this.autoadd.toDOM(doc));
514
e.appendChild(this.quickadd.toDOM(doc));
515
e.appendChild(this.proxies.toDOM(doc));
599
e.appendChild(this.warnings.toDOM(doc));
600
e.appendChild(this.autoadd.toDOM(doc));
601
e.appendChild(this.quickadd.toDOM(doc));
602
e.appendChild(this.proxies.toDOM(doc));
520
607
///////////////// random \\\\\\\\\\\\\\\\\\\\\\
523
610
_includeDirect : false,
524
_includeDisabled : false,
611
_includeDisabled : false,
526
613
get includeeDirect() { return this._includeDirect; },
527
614
set includeeDirect(e) {
528
615
this._includeDirect = e;
529
616
gFP.writeSettings();
532
619
get includeDisabled() { return this._includeDisabled; },
533
620
set includeDisabled(e) {
534
621
this._includeDisabled = e;
535
622
gFP.writeSettings();
538
625
toDOM : function(doc) {
539
626
var e = doc.createElement("random");
540
e.setAttribute("includeDirect", this._includeDirect);
541
e.setAttribute("includeDisabled", this._includeDisabled);
627
e.setAttribute("includeDirect", this._includeDirect);
628
e.setAttribute("includeDisabled", this._includeDisabled);
545
632
fromDOM : function(doc) {
546
633
var node = doc.getElementsByTagName("random")[0];
547
634
if (node) { // because this is new for 2.0
548
635
this._includeDirect = node.getAttribute("includeDirect") == "true";
549
this._includeDisabled = node.getAttribute("includeDisabled") == "true";
636
this._includeDisabled = node.getAttribute("includeDisabled") == "true";
554
641
///////////////// proxies \\\\\\\\\\\\\\\\\\\\\\
775
868
e.setAttribute("noURLs", this._noURLs);
776
869
e.setAttribute("header", this._templateHeader);
777
870
e.setAttribute("row", this._templateRow);
778
e.setAttribute("footer", this._templateFooter);
871
e.setAttribute("footer", this._templateFooter);
782
875
toHTML : function() {
783
876
// Doing the heading substitution here (over and over again instead of once in fromDOM()) permits users to switch locales w/o having to restart FF and
784
877
// the changes take effect immediately in FoxyProxy.
785
var self = this, sz = this.length, ret = this._templateHeader.replace(/\${timestamp-heading}|\${url-heading}|\${proxy-name-heading}|\${proxy-notes-heading}|\${pattern-name-heading}|\${pattern-heading}|\${pattern-type-heading}|\${pattern-color-heading}|\${pac-result-heading}|\${error-msg-heading}/gi,
878
var self = this, sz = this.length, ret = this._templateHeader.replace(/\${timestamp-heading}|\${url-heading}|\${proxy-name-heading}|\${proxy-notes-heading}|\${pattern-name-heading}|\${pattern-heading}|\${pattern-case-heading}|\${pattern-type-heading}|\${pattern-color-heading}|\${pac-result-heading}|\${error-msg-heading}/gi,
788
881
case "${timestamp-heading}": return gFP.getMessage("foxyproxy.tab.logging.timestamp.label");
789
882
case "${url-heading}": return gFP.getMessage("foxyproxy.tab.logging.url.label");
790
883
case "${proxy-name-heading}": return gFP.getMessage("foxyproxy.proxy.name.label");
791
case "${proxy-notes-heading}": return gFP.getMessage("foxyproxy.proxy.notes.label");
792
case "${pattern-name-heading}": return gFP.getMessage("foxyproxy.pattern.name.label");
793
case "${pattern-heading}": return gFP.getMessage("foxyproxy.pattern.label");
884
case "${proxy-notes-heading}": return gFP.getMessage("foxyproxy.proxy.notes.label");
885
case "${pattern-name-heading}": return gFP.getMessage("foxyproxy.pattern.name.label");
886
case "${pattern-heading}": return gFP.getMessage("foxyproxy.pattern.label");
887
case "${pattern-case-heading}": return gFP.getMessage("foxyproxy.casesensitive.label");
794
888
case "${pattern-type-heading}": return gFP.getMessage("foxyproxy.pattern.type.label");
795
case "${pattern-color-heading}": return gFP.getMessage("foxyproxy.whitelist.blacklist.label");
796
case "${pac-result-heading}": return gFP.getMessage("foxyproxy.pac.result.label");
797
case "${error-msg-heading}": return gFP.getMessage("foxyproxy.error.msg.label");
889
case "${pattern-color-heading}": return gFP.getMessage("foxyproxy.whitelist.blacklist.label");
890
case "${pac-result-heading}": return gFP.getMessage("foxyproxy.pac.result.label");
891
case "${error-msg-heading}": return gFP.getMessage("foxyproxy.error.msg.label");
960
1055
///////////////// notifier \\\\\\\\\\\\\\\\\\\\\\\\\\\
961
1056
// Thanks for the inspiration: InfoRSS extension (Didier Ernotte, 2005)
963
1058
alerts : function() {
965
return CC["@mozilla.org/alerts-service;1"].getService(CI.nsIAlertsService);
1060
return CC["@mozilla.org/alerts-service;1"].getService(CI.nsIAlertsService);
967
1062
catch(e) {return null;}
970
alert : function(title, text) {
1065
alert : function(title, text) {
971
1066
if (this.alerts)
972
1067
this.alerts.showAlertNotification("chrome://foxyproxy/content/images/foxyproxy-nocopy.gif", title, text, false, "", null);
974
1069
(!this.timer && (this.timer = CC["@mozilla.org/timer;1"].createInstance(CI.nsITimer)));
975
1070
this.timer.cancel();
976
1071
var wm = CC["@mozilla.org/appshell/window-mediator;1"].getService(CI.nsIWindowMediator);
977
var win = wm.getMostRecentWindow("navigator:browser");
1072
var win = wm.getMostRecentWindow("navigator:browser") || wm.getMostRecentWindow("Songbird:Main");
979
var doc = win.parent.document;
1074
var doc = win.parent.document;
980
1075
this.tooltip = doc.getElementById("foxyproxy-popup");
981
1076
this._removeChildren(this.tooltip);
982
1077
var grid = doc.createElement("grid");
983
1078
grid.setAttribute("flex", "1");
984
1079
this.tooltip.appendChild(grid);
986
1081
var columns = doc.createElement("columns");
987
columns.appendChild(doc.createElement("column"));
1082
columns.appendChild(doc.createElement("column"));
988
1083
grid.appendChild(columns);
990
1085
var rows = doc.createElement("rows");
991
1086
grid.appendChild(rows);
992
1087
this._makeHeaderRow(doc, title, rows);
993
1088
this._makeRow(doc, "", rows);
994
1089
this._makeRow(doc, text, rows);
995
1090
this.tooltip.showPopup(doc.getElementById("status-bar"), -1, -1, "tooltip", "topright","bottomright");
996
this.timer.initWithCallback(this, 5000, CI.nsITimer.TYPE_ONE_SHOT);
1091
this.timer.initWithCallback(this, 5000, CI.nsITimer.TYPE_ONE_SHOT);
998
1093
catch (e) { dump(e);/* in case win, win.parent, win.parent.document, tooltip, etc. don't exist */ gFP.alert(null, text);}
1002
1097
notify : function() {
1003
1098
this.tooltip.hidePopup();
1006
1101
_makeHeaderRow : function(doc, col, gridRows) {
1007
1102
var label = doc.createElement("label");
1008
label.setAttribute("value", col);
1103
label.setAttribute("value", col);
1009
1104
label.setAttribute("style", "font-weight: bold; text-decoration: underline; color: blue;");
1010
gridRows.appendChild(label);
1105
gridRows.appendChild(label);
1013
1108
_makeRow : function(doc, col1, gridRows) {
1014
1109
var gridRow = doc.createElement("row");
1015
1110
var label = doc.createElement("label");
1016
label.setAttribute("value", col1);
1111
label.setAttribute("value", col1);
1017
1112
gridRow.appendChild(label);
1018
gridRows.appendChild(gridRow);
1113
gridRows.appendChild(gridRow);
1021
1116
_removeChildren : function(node) {
1022
1117
if (node && node.firstChild) {
1023
1118
node.removeChild(node.firstChild);
1024
1119
this._removeChildren(node);
1029
1124
///////////////// statusbar \\\\\\\\\\\\\\\\\\\\\
1031
1126
_iconEnabled : true,
1032
_textEnabled : true,
1127
_textEnabled : true,
1033
1128
_leftClick : "options",
1034
1129
_middleClick : "cycle",
1035
_rightClick : "contextmenu",
1130
_rightClick : "contextmenu",
1037
1133
toDOM : function(doc) {
1038
1134
var e = doc.createElement("statusbar");
1039
1135
e.setAttribute("icon", this._iconEnabled); // new for 2.3 (used to be just "enabled")
1040
e.setAttribute("text", this._textEnabled); // new for 2.3 (used to be just "enabled")
1041
e.setAttribute("left", this._leftClick); // new for 2.5
1042
e.setAttribute("middle", this._middleClick); // new for 2.5
1043
e.setAttribute("right", this._rightClick); // new for 2.5
1136
e.setAttribute("text", this._textEnabled); // new for 2.3 (used to be just "enabled")
1137
e.setAttribute("left", this._leftClick); // new for 2.5
1138
e.setAttribute("middle", this._middleClick); // new for 2.5
1139
e.setAttribute("right", this._rightClick); // new for 2.5
1140
e.setAttribute("width", this._width); // new for 2.6.3
1047
1144
fromDOM : function(doc) {
1048
1145
var n = doc.getElementsByTagName("statusbar")[0];
1049
this._iconEnabled = gGetSafeAttrB(n, "icon", true);
1146
this._iconEnabled = gGetSafeAttrB(n, "icon", true);
1050
1147
this._textEnabled = gGetSafeAttrB(n, "text", true);
1051
1148
this._leftClick = gGetSafeAttr(n, "left", "options");
1052
1149
this._middleClick = gGetSafeAttr(n, "middle", "cycle");
1053
this._rightClick = gGetSafeAttr(n, "right", "contextmenu");
1150
this._rightClick = gGetSafeAttr(n, "right", "contextmenu");
1151
this._width = gGetSafeAttr(n, "width", 0);
1056
1154
get iconEnabled() { return this._iconEnabled; },
1057
1155
set iconEnabled(e) {
1058
1156
this._iconEnabled = e;
1059
1157
gFP.writeSettings();
1060
gBroadcast(e, "foxyproxy-statusbar-icon");
1061
e && gFP.setMode(gFP.mode, false, false);
1158
gBroadcast(e, "foxyproxy-statusbar-icon");
1159
e && gFP.setMode(gFP.mode, false, false); // todo: why is this here? can it be removed? it forces PAC to reload
1064
1162
get textEnabled() { return this._textEnabled; },
1065
1163
set textEnabled(e) {
1066
1164
this._textEnabled = e;
1067
1165
gFP.writeSettings();
1068
1166
gBroadcast(e, "foxyproxy-statusbar-text");
1069
e && gFP.setMode(gFP.mode, false, false);
1167
e && gFP.setMode(gFP.mode, false, false); // todo: why is this here? can it be removed? it forces PAC to reload
1072
1170
get leftClick() { return this._leftClick; },
1073
1171
set leftClick(e) {
1074
1172
this._leftClick = e;
1075
1173
gFP.writeSettings();
1078
1176
get middleClick() { return this._middleClick; },
1079
1177
set middleClick(e) {
1080
1178
this._middleClick = e;
1081
1179
gFP.writeSettings();
1084
1182
get rightClick() { return this._rightClick; },
1085
1183
set rightClick(e) {
1086
1184
this._rightClick = e;
1087
1185
gFP.writeSettings();
1188
get width() { return this._width; },
1191
if (isNaN(e)) e = 0;
1193
gFP.writeSettings();
1194
gBroadcast(e, "foxyproxy-statusbar-width");
1091
1198
///////////////// toolbar \\\\\\\\\\\\\\\\\\\\\
1093
1200
_leftClick : "options",
1094
1201
_middleClick : "cycle",
1095
_rightClick : "contextmenu",
1202
_rightClick : "contextmenu",
1097
1204
toDOM : function(doc) {
1098
1205
var e = doc.createElement("toolbar");
1099
e.setAttribute("left", this._leftClick); // new for 2.5
1100
e.setAttribute("middle", this._middleClick); // new for 2.5
1101
e.setAttribute("right", this._rightClick); // new for 2.5
1206
e.setAttribute("left", this._leftClick); // new for 2.5
1207
e.setAttribute("middle", this._middleClick); // new for 2.5
1208
e.setAttribute("right", this._rightClick); // new for 2.5
1105
1212
fromDOM : function(doc) {
1106
1213
var n = doc.getElementsByTagName("toolbar")[0];
1107
1214
this._leftClick = gGetSafeAttr(n, "left", "options");
1108
1215
this._middleClick = gGetSafeAttr(n, "middle", "cycle");
1109
this._rightClick = gGetSafeAttr(n, "right", "contextmenu");
1216
this._rightClick = gGetSafeAttr(n, "right", "contextmenu");
1112
1219
get leftClick() { return this._leftClick; },
1113
1220
set leftClick(e) {
1114
1221
this._leftClick = e;
1115
gFP.writeSettings();
1222
gFP.writeSettings();
1118
1225
get middleClick() { return this._middleClick; },
1119
1226
set middleClick(e) {
1120
1227
this._middleClick = e;
1121
1228
gFP.writeSettings();
1124
1231
get rightClick() { return this._rightClick; },
1125
1232
set rightClick(e) {
1126
1233
this._rightClick = e;
1127
1234
gFP.writeSettings();
1131
///////////////// strings \\\\\\\\\\\\\\\\\\\\\
1238
///////////////// strings \\\\\\\\\\\\\\\\\\\\\
1132
1239
getMessage : function(msg, ar) {
1134
1241
return this.strings.getMessage(msg, ar);
1156
1263
get noWildcards() { return this._noWildcards; },
1157
1264
set noWildcards(e) {
1158
1265
this._noWildcards = e;
1159
gFP.writeSettings();
1266
gFP.writeSettings();
1162
1269
toDOM : function(doc) {
1163
1270
var e = doc.createElement("warnings"); // new for 2.3
1164
e.setAttribute("no-wildcards", this._noWildcards);
1271
e.setAttribute("no-wildcards", this._noWildcards);
1168
1275
fromDOM : function(doc) {
1169
1276
var node = doc.getElementsByTagName("warnings")[0];
1170
1277
node && (this._noWildcards = node.getAttribute("no-wildcards") == "true");
1280
classID: Components.ID("{46466e13-16ab-4565-9924-20aac4d98c82}"),
1281
contractID: "@leahscape.org/foxyproxy/service;1",
1282
classDescription: "FoxyProxy Core"
1285
var gXpComObjects = [foxyproxy];
1286
var gCatObserverName = "foxyproxy_catobserver";
1287
var gCatContractId = foxyproxy.prototype.contractID;
1290
function NSGetModule(compMgr, fileSpec) {
1291
gModule._catObserverName = gCatObserverName;
1292
gModule._catContractId = gCatContractId;
1294
for (var i in gXpComObjects)
1295
gModule._xpComObjects[i] = new gFactoryHolder(gXpComObjects[i]);
1300
function gFactoryHolder(aObj) {
1301
this.CID = aObj.prototype.classID;
1302
this.contractID = aObj.prototype.contractID;
1303
this.className = aObj.prototype.classDescription;
1306
createInstance: function(aOuter, aIID)
1309
throw CR.NS_ERROR_NO_AGGREGATION;
1311
return (new this.constructor).QueryInterface(aIID);
1315
this.factory.constructor = aObj;
1318
registerSelf: function (aComponentManager, aFileSpec, aLocation, aType) {
1319
aComponentManager.QueryInterface(CI.nsIComponentRegistrar);
1320
for (var key in this._xpComObjects)
1322
var obj = this._xpComObjects[key];
1323
aComponentManager.registerFactoryLocation(obj.CID, obj.className,
1324
obj.contractID, aFileSpec, aLocation, aType);
1327
var catman = CC["@mozilla.org/categorymanager;1"].getService(CI.nsICategoryManager);
1328
catman.addCategoryEntry("app-startup", this._catObserverName, this._catContractId, true, true);
1329
catman.addCategoryEntry("xpcom-shutdown", this._catObserverName, this._catContractId, true, true);
1332
unregisterSelf: function(aCompMgr, aFileSpec, aLocation) {
1333
var catman = CC["@mozilla.org/categorymanager;1"].getService(CI.nsICategoryManager);
1334
catman.deleteCategoryEntry("app-startup", this._catObserverName, true);
1335
catman.deleteCategoryEntry("xpcom-shutdown", this._catObserverName, true);
1337
aComponentManager.QueryInterface(CI.nsIComponentRegistrar);
1338
for (var key in this._xpComObjects)
1340
var obj = this._xpComObjects[key];
1341
aComponentManager.unregisterFactoryLocation(obj.CID, aFileSpec);
1345
getClassObject: function(aComponentManager, aCID, aIID) {
1346
if (!aIID.equals(CI.nsIFactory))
1347
throw CR.NS_ERROR_NOT_IMPLEMENTED;
1349
for (var key in this._xpComObjects)
1351
if (aCID.equals(this._xpComObjects[key].CID))
1352
return this._xpComObjects[key].factory;
1355
throw CR.NS_ERROR_NO_INTERFACE;
1358
canUnload: function(aComponentManager) { return true; },
1361
_catObserverName: null,
1362
_catContractId: null
b'\\ No newline at end of file'