1 const nsISupports = Components.interfaces.nsISupports;
2 const nsICategoryManager = Components.interfaces.nsICategoryManager;
3 const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
4 const nsIContentPolicy = Components.interfaces.nsIContentPolicy;
5 const nsIFactory = Components.interfaces.nsIFactory;
6 const nsIModule = Components.interfaces.nsIModule;
7 const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
9 const WINDOW_MAIN = "eg_main"
11 const fe_contractID = "@mozilla.org/content-policy;1?type=egfe";
12 const fe_CID = Components.ID("{D969ED61-DF4C-FA12-A2A6-70AA94C222FB}");
13 // category names are sorted alphabetically. Typical command-line handlers use a
14 // category that begins with the letter "m".
15 const fe_category = "m-egfe";
17 const myAppHandler = {
19 shouldLoad: function(contentType, contentLocation, requestOrigin, node, mimeTypeGuess, extra)
21 if (contentType == nsIContentPolicy.TYPE_DOCUMENT) {
22 var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"].
23 getService(Components.interfaces.nsIWindowMediator);
24 var targetWindow = wm.getMostRecentWindow("eg_main");
25 if (targetWindow != null) {
26 var host = targetWindow.G.data.server_unadorned;
27 if(host && (contentLocation.scheme == 'http' || contentLocation.scheme == 'https') && contentLocation.host != host) {
28 // first construct an nsIURI object using the ioservice
29 var ioservice = Components.classes["@mozilla.org/network/io-service;1"]
30 .getService(Components.interfaces.nsIIOService);
32 var uriToOpen = ioservice.newURI(contentLocation.spec, null, null);
34 var extps = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"]
35 .getService(Components.interfaces.nsIExternalProtocolService);
38 extps.loadURI(uriToOpen, null);
40 return nsIContentPolicy.REJECT_REQUEST;
44 return nsIContentPolicy.ACCEPT;
47 shouldProcess: function(contentType, contentLocation, requestOrigin, insecNode, mimeType, extra)
49 return nsIContentPolicy.ACCEPT;
53 QueryInterface : function fe_QI(iid)
55 if (iid.equals(nsIContentPolicy) ||
56 iid.equals(nsIFactory) ||
57 iid.equals(nsISupports))
60 throw Components.results.NS_ERROR_NO_INTERFACE;
65 createInstance : function fe_CI(outer, iid)
68 throw Components.results.NS_ERROR_NO_AGGREGATION;
70 return this.QueryInterface(iid);
73 lockFactory : function fe_lock(lock)
80 * The XPCOM glue that implements nsIModule
82 const myAppHandlerModule = {
84 QueryInterface : function mod_QI(iid)
86 if (iid.equals(nsIModule) ||
87 iid.equals(nsISupports))
90 throw Components.results.NS_ERROR_NO_INTERFACE;
94 getClassObject : function mod_gch(compMgr, cid, iid)
96 if (cid.equals(fe_CID))
97 return myAppHandler.QueryInterface(iid);
99 throw Components.results.NS_ERROR_NOT_REGISTERED;
102 registerSelf : function mod_regself(compMgr, fileSpec, location, type)
104 compMgr.QueryInterface(nsIComponentRegistrar);
106 compMgr.registerFactoryLocation(fe_CID,
113 var catMan = Components.classes["@mozilla.org/categorymanager;1"].
114 getService(nsICategoryManager);
115 catMan.addCategoryEntry("content-policy",
117 fe_contractID, true, true);
120 unregisterSelf : function mod_unreg(compMgr, location, type)
122 compMgr.QueryInterface(nsIComponentRegistrar);
123 compMgr.unregisterFactoryLocation(fe_CID, location);
125 var catMan = Components.classes["@mozilla.org/categorymanager;1"].
126 getService(nsICategoryManager);
127 catMan.deleteCategoryEntry("content-policy", fe_category);
130 canUnload : function (compMgr)
136 /* The NSGetModule function is the magic entry point that XPCOM uses to find what XPCOM objects
137 * this component provides
139 function NSGetModule(comMgr, fileSpec)
141 return myAppHandlerModule;