3
Copyright (C) 2006-2009 Eric H. Jung and LeahScape, Inc.
4
http://foxyproxy.mozdev.org/
3
Copyright (C) 2006-#%#% Eric H. Jung and LeahScape, Inc.
4
http://getfoxyproxy.org/
7
7
This source code is released under the GPL license,
8
8
available in the LICENSE file at the root of this installation
9
9
and also online at http://www.gnu.org/licenses/gpl.txt
12
// Thanks for the template, doron (http://www.nexgenmedia.net/docs/protocol/)
13
11
const kSCHEME = "relative";
14
const kPROTOCOL_NAME = "FoxyProxy Relative Protocol";
15
const kPROTOCOL_CONTRACTID = "@mozilla.org/network/protocol;1?name=" + kSCHEME;
16
const kPROTOCOL_CID = Components.ID("22ed2962-a8ec-11dc-8314-0800200c9a66");
17
var CI = Components.interfaces, CC = Components.classes, CR = Components.results;
12
const CI = Components.interfaces;
13
const CC = Components.classes
14
const CR = Components.results;
20
const kSIMPLEURI_CONTRACTID = "@mozilla.org/network/simple-uri;1";
21
16
const kIOSERVICE_CONTRACTID = "@mozilla.org/network/io-service;1";
22
const nsISupports = Components.interfaces.nsISupports;
23
const nsIIOService = Components.interfaces.nsIIOService;
24
const nsIProtocolHandler = Components.interfaces.nsIProtocolHandler;
25
const nsIURI = Components.interfaces.nsIURI;
26
17
const IOS = CC[kIOSERVICE_CONTRACTID].
27
getService(nsIIOService).getProtocolHandler("file").
28
QueryInterface(CI.nsIFileProtocolHandler);
18
getService(CI.nsIIOService).getProtocolHandler("file").
19
QueryInterface(CI.nsIFileProtocolHandler);
20
Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
30
22
function Protocol() {}
32
23
Protocol.prototype = {
33
QueryInterface: function(iid) {
34
if (!iid.equals(nsIProtocolHandler) &&
35
!iid.equals(nsISupports))
36
throw Components.results.NS_ERROR_NO_INTERFACE;
42
protocolFlags: nsIProtocolHandler.URI_DANGEROUS_TO_LOAD,
26
protocolFlags: CI.nsIProtocolHandler.URI_DANGEROUS_TO_LOAD,
44
28
allowPort: function(port, scheme) {
48
32
newURI: function(spec, charset, baseURI) {
49
var uri = Components.classes[kSIMPLEURI_CONTRACTID].createInstance(nsIURI);
33
var uri = CC["@mozilla.org/network/simple-uri;1"].createInstance(CI.nsIURI);
68
52
for (var i=1,sz=parts.length; i<sz; i++)
69
53
file.appendRelativePath(parts[i]);
70
54
var pHandler = CC[kIOSERVICE_CONTRACTID].
71
getService(nsIIOService).getProtocolHandler("file").
55
getService(CI.nsIIOService).getProtocolHandler("file").
72
56
QueryInterface(CI.nsIFileProtocolHandler);
73
57
return pHandler.newChannel(pHandler.newFileURI(file, null, null));
77
var ProtocolFactory = new Object();
79
ProtocolFactory.createInstance = function (outer, iid) {
81
throw Components.results.NS_ERROR_NO_AGGREGATION;
83
if (!iid.equals(nsIProtocolHandler) &&
84
!iid.equals(nsISupports))
85
throw Components.results.NS_ERROR_NO_INTERFACE;
87
return new Protocol();
60
QueryInterface: XPCOMUtils.generateQI([CI.nsISupports, CI.nsIProtocolHandler]),
61
classDescription: "FoxyProxy Relative Component",
62
classID: Components.ID("{22ed2962-a8ec-11dc-8314-0800200c9a66}"),
63
contractID: "@mozilla.org/network/protocol;1?name=" + kSCHEME
91
* JS XPCOM boilerplate component registration code.
67
* XPCOMUtils.generateNSGetFactory was introduced in Mozilla 2 (Firefox 4)
68
* XPCOMUtils.generateNSGetModule is for Mozilla 1.9.2 and earlier (Firefox 3.6)
93
var prochandler = new Object();
95
prochandler.registerSelf = function (compMgr, fileSpec, location, type) {
96
compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
97
compMgr.registerFactoryLocation(kPROTOCOL_CID,
105
prochandler.getClassObject = function (compMgr, cid, iid) {
106
if (!cid.equals(kPROTOCOL_CID))
107
throw Components.results.NS_ERROR_NO_INTERFACE;
109
if (!iid.equals(Components.interfaces.nsIFactory))
110
throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
112
return ProtocolFactory;
115
prochandler.canUnload = function (compMgr) {
119
function NSGetModule(compMgr, fileSpec){
70
if (XPCOMUtils.generateNSGetFactory)
71
var NSGetFactory = XPCOMUtils.generateNSGetFactory([Protocol]);
73
var NSGetModule = XPCOMUtils.generateNSGetModule([Protocol]);