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

« back to all changes in this revision

Viewing changes to components/manualconf.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
// See http://forums.mozillazine.org/viewtopic.php?t=308369
 
13
 
 
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;
 
16
var fp = null;
 
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;
 
21
  return this;
 
22
}
 
23
 
 
24
///////////////////////////// ManualConf class ///////////////////////
 
25
function ManualConf() {
 
26
  this.wrappedJSObject = this;
 
27
  !fp && 
 
28
        (fp = CC["@leahscape.org/foxyproxy/service;1"].getService(CI.nsISupports).wrappedJSObject);   
 
29
}
 
30
 
 
31
ManualConf.prototype = {
 
32
  QueryInterface: gQueryInterface,
 
33
  _host: "",
 
34
  _port: "",
 
35
  _socksversion: "5",
 
36
  _isSocks: false,
 
37
                
 
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
 
45
 
 
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
 
52
        
 
53
    this._socksversion = node.getAttribute("socksversion");
 
54
 
 
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
 
61
        
 
62
          this._makeProxy();
 
63
  },
 
64
 
 
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);    
 
71
    return e;
 
72
  },  
 
73
 
 
74
  _makeProxy : function() {
 
75
        if (!this._host || !this._port) {
 
76
                return;
 
77
        }
 
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);
 
81
  },
 
82
 
 
83
  get host() {return this._host;},
 
84
  set host(e) {
 
85
        this._host = e;
 
86
        this._makeProxy();
 
87
  },  
 
88
 
 
89
  get port() {return this._port;},
 
90
  set port(e) {
 
91
        this._port = e;
 
92
        this._makeProxy();
 
93
  },
 
94
     
 
95
  get isSocks() {return this._isSocks;},
 
96
  set isSocks(e) {
 
97
        this._isSocks = e;
 
98
        this._makeProxy();
 
99
  },
 
100
 
 
101
  get socksversion() {return this._socksversion;},
 
102
  set socksversion(e) {
 
103
        this._socksversion = e;
 
104
        this._makeProxy();
 
105
  },
 
106
        classID: Components.ID("{457e4d50-f194-11da-8ad9-0800200c9a66}"),
 
107
        contractID: "@leahscape.org/foxyproxy/manualconf;1",
 
108
        classDescription: "FoxyProxy ManualConfiguration Component"         
 
109
};
 
110
 
 
111
var gXpComObjects = [ManualConf];
 
112
var gCatObserverName = "foxyproxy_manualconf_catobserver";
 
113
var gCatContractId = ManualConf.prototype.contractID;
 
114
 
 
115
function NSGetModule(compMgr, fileSpec) {
 
116
        gModule._catObserverName = gCatObserverName;
 
117
        gModule._catContractId = gCatContractId;
 
118
        
 
119
        for (var i in gXpComObjects)
 
120
                gModule._xpComObjects[i] = new gFactoryHolder(gXpComObjects[i]);
 
121
                
 
122
        return gModule;
 
123
}
 
124
 
 
125
function gFactoryHolder(aObj) {
 
126
        this.CID        = aObj.prototype.classID;
 
127
        this.contractID = aObj.prototype.contractID;
 
128
        this.className  = aObj.prototype.classDescription;
 
129
        this.factory =
 
130
        {
 
131
                createInstance: function(aOuter, aIID)
 
132
                {
 
133
                        if (aOuter)
 
134
                                throw CR.NS_ERROR_NO_AGGREGATION;
 
135
                                
 
136
                        return (new this.constructor).QueryInterface(aIID);
 
137
                }
 
138
        };
 
139
        
 
140
        this.factory.constructor = aObj;
 
141
}
 
142
var gModule = {
 
143
        registerSelf: function (aComponentManager, aFileSpec, aLocation, aType) {
 
144
                aComponentManager.QueryInterface(CI.nsIComponentRegistrar);
 
145
                for (var key in this._xpComObjects)
 
146
                {
 
147
                        var obj = this._xpComObjects[key];
 
148
                        aComponentManager.registerFactoryLocation(obj.CID, obj.className,
 
149
                        obj.contractID, aFileSpec, aLocation, aType);
 
150
                }
 
151
        },
 
152
 
 
153
        unregisterSelf: function(aCompMgr, aFileSpec, aLocation) {
 
154
                
 
155
                aComponentManager.QueryInterface(CI.nsIComponentRegistrar);
 
156
                for (var key in this._xpComObjects)
 
157
                {
 
158
                        var obj = this._xpComObjects[key];
 
159
                        aComponentManager.unregisterFactoryLocation(obj.CID, aFileSpec);
 
160
                }
 
161
        },
 
162
 
 
163
        getClassObject: function(aComponentManager, aCID, aIID) {
 
164
                if (!aIID.equals(CI.nsIFactory))
 
165
                        throw CR.NS_ERROR_NOT_IMPLEMENTED;
 
166
                
 
167
                for (var key in this._xpComObjects)
 
168
                {
 
169
                        if (aCID.equals(this._xpComObjects[key].CID))
 
170
                                return this._xpComObjects[key].factory;
 
171
                }
 
172
        
 
173
                throw CR.NS_ERROR_NO_INTERFACE;
 
174
        },
 
175
 
 
176
        canUnload: function(aComponentManager) { return true; },
 
177
        
 
178
        _xpComObjects: {},
 
179
        _catObserverName: null,
 
180
        _catContractId: null
 
181
};