1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
//// $Id$
const CSSB_CONTRACTID = "@einaregilsson.com/redirector;1";
const CSSB_CID = Components.ID("{b7a7a54f-0581-47ff-b086-d6920cb7a3f7}");
var Cc = Components.classes;
var Ci = Components.interfaces;
var Cr = Components.results;
var nsIContentPolicy = Ci.nsIContentPolicy;
function Redirector() {
this.init();
}
const loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
try {
loader.loadSubScript('chrome://redirector/content/code/redirector.prototype.js');
loader.loadSubScript('chrome://redirector/content/code/redirect.js');
loader.loadSubScript('chrome://redirector/content/code/prefs.js');
} catch(e) {
for (i in e)
Cc["@mozilla.org/consoleservice;1"].getService(Ci.nsIConsoleService).logStringMessage('REDIRECTOR: Loading Redirector implementation failed: ' + i + e[i]);
}
/*
* Factory object
*/
var redirectorInstance = null;
const factory = {
// nsIFactory interface implementation
createInstance: function(outer, iid) {
if (outer != null) {
Components.returnCode = Cr.NS_ERROR_NO_AGGREGATION;
return null;
}
if (!iid.equals(Ci.nsIContentPolicy) &&
!iid.equals(Ci.nsISupports)) {
Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
return null;
}
if(!redirectorInstance) {
redirectorInstance = new Redirector();
redirectorInstance.wrappedJSObject = redirectorInstance;
}
return redirectorInstance;
},
// nsISupports interface implementation
QueryInterface: function(iid) {
if (iid.equals(Ci.nsISupports) ||
iid.equals(Ci.nsIModule) ||
iid.equals(Ci.nsIFactory)) {
return this;
}
Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
return null;
}
}
/*
* Module object
*/
const module = {
registerSelf: function(compMgr, fileSpec, location, type) {
compMgr = compMgr.QueryInterface(Ci.nsIComponentRegistrar);
compMgr.registerFactoryLocation(CSSB_CID,
"Redirector content policy",
CSSB_CONTRACTID,
fileSpec, location, type);
var catman = Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager);
catman.addCategoryEntry("content-policy", CSSB_CONTRACTID, CSSB_CONTRACTID, true, true);
},
unregisterSelf: function(compMgr, fileSpec, location) {
compMgr.QueryInterface(Ci.nsIComponentRegistrar).unregisterFactoryLocation(CSSB_CID, fileSpec);
Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager).deleteCategoryEntry("content-policy", CSSB_CONTRACTID, true);
},
getClassObject: function(compMgr, cid, iid) {
if (cid.equals(CSSB_CID)) {
return factory;
}
Components.returnCode = Cr.NS_ERROR_NOT_REGISTERED;
return null;
},
canUnload: function(compMgr) {
return true;
}
};
function NSGetModule(comMgr, fileSpec) {
return module;
}
|