aboutsummaryrefslogtreecommitdiff
path: root/components/redirector.component.js
diff options
context:
space:
mode:
authorEinar Egilsson2009-10-16 08:11:33 +0000
committerEinar Egilsson2009-10-16 08:11:33 +0000
commit372aa4eee4e9b0b0a930d83a378502e9cec2e786 (patch)
tree1ca3dc9a5aed593fab4f671a1e3c9a87d51c59e0 /components/redirector.component.js
parent6177295e1d9a9ebba5acc68df4800d8557b22cab (diff)
Greatly simplified XPCOM plumbing
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@270 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'components/redirector.component.js')
-rw-r--r--components/redirector.component.js118
1 files changed, 24 insertions, 94 deletions
diff --git a/components/redirector.component.js b/components/redirector.component.js
index bebae88..6dce455 100644
--- a/components/redirector.component.js
+++ b/components/redirector.component.js
@@ -1,112 +1,42 @@
//// $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;
+Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
+Ci = Components.interfaces;
+Cr = Components.results;
+Cc = Components.classes;
+const loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
function Redirector() {
this.init();
+ this.wrappedJSObject = this;
}
-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)
+ 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;
- }
- dump("\n\nCreateInstance:\n");
- if (!(iid.equals(Ci.nsIContentPolicy) || iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIChannelEventSink))) {
- Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
- return null;
- }
- dump("\n IID: " + iid);
- dump("\n");
- dump("\n nsIContentPolicy: " + iid.equals(Ci.nsIContentPolicy));
- dump("\n nsISupports: " + iid.equals(Ci.nsISupports));
- dump("\n nsIChannelEventSink: " + iid.equals(Ci.nsIChannelEventSink));
- 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;
- }
-}
+//Add the xpcom stuff to the prototype
+var xpcomInfo = Redirector.prototype;
+xpcomInfo.classDescription = "Redirector Component";
+xpcomInfo.classID = Components.ID("{b7a7a54f-0581-47ff-b086-d6920cb7a3f7}");
+xpcomInfo.contractID = "@einaregilsson.com/redirector;1";
+xpcomInfo._xpcom_categories = [{category:'content-policy'},{category:'net-channel-event-sinks'}];
+xpcomInfo.QueryInterface = XPCOMUtils.generateQI([Ci.nsIContentPolicy, Ci.nsIChannelEventSink]);
+xpcomInfo._xpcom_factory = {
+ createInstance: function(outer, iid) {
+ if (outer) throw Cr.NS_ERROR_NO_AGGREGATION;
+ return redirector.QueryInterface(iid);
+ }
+};
-Redirector.prototype.QueryInterface = function(iid) {
- if (iid.equals(Ci.nsISupports) || iid.equals(Ci.nsIChannelEventSink) || iid.equals(Ci.nsIContentPolicy)) {
- return this;
- }
- Components.returnCode = Cr.NS_ERROR_NO_INTERFACE;
- return null;
+function NSGetModule(compMgr, fileSpec) {
+ return XPCOMUtils.generateModule([Redirector]);
}
-/*
- * 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("net-channel-event-sinks", CSSB_CONTRACTID, CSSB_CONTRACTID, true, true);
- 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);
- Cc["@mozilla.org/categorymanager;1"].getService(Ci.nsICategoryManager).deleteCategoryEntry("net-channel-event-sinks", CSSB_CONTRACTID, true);
- },
-
- getClassObject: function(compMgr, cid, iid) {
- dump("\nGetClassObject: " + cid + ", iid: " + 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;
-} \ No newline at end of file
+const redirector = new Redirector();