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
// See http://forums.mozillazine.org/viewtopic.php?t=308369
14
// Don't const the next line anymore because of the generic reg code
15
var CI = Components.interfaces, CC = Components.classes, CR = Components.results;
17
var proxyService = CC["@mozilla.org/network/protocol-proxy-service;1"].getService(CI.nsIProtocolProxyService);
18
function gQueryInterface(aIID) {
19
if(!aIID.equals(CI.nsISupports) && !aIID.equals(CI.nsISupportsWeakReference))
20
throw CR.NS_ERROR_NO_INTERFACE;
24
///////////////////////////// ManualConf class ///////////////////////
25
function ManualConf() {
26
this.wrappedJSObject = this;
28
(fp = CC["@leahscape.org/foxyproxy/service;1"].getService(CI.nsISupports).wrappedJSObject);
31
ManualConf.prototype = {
32
QueryInterface: gQueryInterface,
38
fromDOM : function(node) {
39
this._host = node.hasAttribute("host")? node.getAttribute("host") :
40
node.getAttribute("http") ? node.getAttribute("http"):
41
node.getAttribute("socks") ? node.getAttribute("socks"):
42
node.getAttribute("ssl") ? node.getAttribute("ssl"):
43
node.getAttribute("ftp") ? node.getAttribute("ftp"):
44
node.getAttribute("gopher") ? node.getAttribute("gopher"):""; //"host" is new for 2.5
46
this._port = node.hasAttribute("port")? node.getAttribute("port") :
47
node.getAttribute("httpport")? node.getAttribute("httpport"):
48
node.getAttribute("socksport")? node.getAttribute("socksport"):
49
node.getAttribute("sslport")? node.getAttribute("sslport"):
50
node.getAttribute("ftpport")? node.getAttribute("ftpport"):
51
node.getAttribute("gopherport")? node.getAttribute("gopherport"):""; // "port" is new for 2.5
53
this._socksversion = node.getAttribute("socksversion");
55
this._isSocks = node.hasAttribute("isSocks") ? node.getAttribute("isSocks") == "true" :
56
node.getAttribute("http") ? false:
57
node.getAttribute("ssl") ? false:
58
node.getAttribute("ftp") ? false:
59
node.getAttribute("gopher") ? false:
60
node.getAttribute("socks") ? true : false; // new for 2.5
65
toDOM : function(doc) {
66
var e = doc.createElement("manualconf");
67
e.setAttribute("host", this._host);
68
e.setAttribute("port", this._port);
69
e.setAttribute("socksversion", this._socksversion);
70
e.setAttribute("isSocks", this._isSocks);
74
_makeProxy : function() {
75
if (!this._host || !this._port) {
78
this.proxy = this._isSocks ? proxyService.newProxyInfo(this._socksversion == "5"?"socks":"socks4", this._host, this._port,
79
fp.proxyDNS ? CI.nsIProxyInfo.TRANSPARENT_PROXY_RESOLVES_HOST : 0, 0, null): // never ignore, never failover
80
proxyService.newProxyInfo("http", this._host, this._port, 0, 0, null);
83
get host() {return this._host;},
89
get port() {return this._port;},
95
get isSocks() {return this._isSocks;},
101
get socksversion() {return this._socksversion;},
102
set socksversion(e) {
103
this._socksversion = e;
106
classID: Components.ID("{457e4d50-f194-11da-8ad9-0800200c9a66}"),
107
contractID: "@leahscape.org/foxyproxy/manualconf;1",
108
classDescription: "FoxyProxy ManualConfiguration Component"
111
var gXpComObjects = [ManualConf];
112
var gCatObserverName = "foxyproxy_manualconf_catobserver";
113
var gCatContractId = ManualConf.prototype.contractID;
115
function NSGetModule(compMgr, fileSpec) {
116
gModule._catObserverName = gCatObserverName;
117
gModule._catContractId = gCatContractId;
119
for (var i in gXpComObjects)
120
gModule._xpComObjects[i] = new gFactoryHolder(gXpComObjects[i]);
125
function gFactoryHolder(aObj) {
126
this.CID = aObj.prototype.classID;
127
this.contractID = aObj.prototype.contractID;
128
this.className = aObj.prototype.classDescription;
131
createInstance: function(aOuter, aIID)
134
throw CR.NS_ERROR_NO_AGGREGATION;
136
return (new this.constructor).QueryInterface(aIID);
140
this.factory.constructor = aObj;
143
registerSelf: function (aComponentManager, aFileSpec, aLocation, aType) {
144
aComponentManager.QueryInterface(CI.nsIComponentRegistrar);
145
for (var key in this._xpComObjects)
147
var obj = this._xpComObjects[key];
148
aComponentManager.registerFactoryLocation(obj.CID, obj.className,
149
obj.contractID, aFileSpec, aLocation, aType);
153
unregisterSelf: function(aCompMgr, aFileSpec, aLocation) {
155
aComponentManager.QueryInterface(CI.nsIComponentRegistrar);
156
for (var key in this._xpComObjects)
158
var obj = this._xpComObjects[key];
159
aComponentManager.unregisterFactoryLocation(obj.CID, aFileSpec);
163
getClassObject: function(aComponentManager, aCID, aIID) {
164
if (!aIID.equals(CI.nsIFactory))
165
throw CR.NS_ERROR_NOT_IMPLEMENTED;
167
for (var key in this._xpComObjects)
169
if (aCID.equals(this._xpComObjects[key].CID))
170
return this._xpComObjects[key].factory;
173
throw CR.NS_ERROR_NO_INTERFACE;
176
canUnload: function(aComponentManager) { return true; },
179
_catObserverName: null,