]> git.parisson.com Git - pdf.js.git/commitdiff
Update factory in bootstrap.js.
authorBrendan Dahl <brendan.dahl@gmail.com>
Mon, 4 Jun 2012 16:45:09 +0000 (09:45 -0700)
committerBrendan Dahl <brendan.dahl@gmail.com>
Mon, 4 Jun 2012 16:45:09 +0000 (09:45 -0700)
extensions/firefox/bootstrap.js

index 5bf66d444c00d6ca93268f97c05c045d057c5c76..a5f4bd282ca40837375a4890dea182f70818f9d7 100644 (file)
@@ -11,6 +11,7 @@ let Ci = Components.interfaces;
 let Cm = Components.manager;
 let Cu = Components.utils;
 
+Cu.import('resource://gre/modules/XPCOMUtils.jsm');
 Cu.import('resource://gre/modules/Services.jsm');
 
 function getBoolPref(pref, def) {
@@ -34,35 +35,37 @@ function log(str) {
   dump(str + '\n');
 }
 
-// Register/unregister a class as a component.
+// Register/unregister a constructor as a component.
 let Factory = {
-  registrar: null,
-  aClass: null,
-  register: function(aClass) {
-    if (this.aClass) {
-      log('Cannot register more than one class');
-      return;
-    }
-    this.registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
-    this.aClass = aClass;
-    var proto = aClass.prototype;
-    this.registrar.registerFactory(proto.classID, proto.classDescription,
-      proto.contractID, this);
+  QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory]),
+  _targetConstructor: null,
+
+  register: function register(targetConstructor) {
+    this._targetConstructor = targetConstructor;
+    var proto = targetConstructor.prototype;
+    var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
+    registrar.registerFactory(proto.classID, proto.classDescription,
+                              proto.contractID, this);
   },
-  unregister: function() {
-    if (!this.aClass) {
-      log('Class was never registered.');
-      return;
-    }
-    var proto = this.aClass.prototype;
-    this.registrar.unregisterFactory(proto.classID, this);
-    this.aClass = null;
+
+  unregister: function unregister() {
+    var proto = this._targetConstructor.prototype;
+    var registrar = Cm.QueryInterface(Ci.nsIComponentRegistrar);
+    registrar.unregisterFactory(proto.classID, this);
+    this._targetConstructor = null;
   },
-  // nsIFactory::createInstance
-  createInstance: function(outer, iid) {
-    if (outer !== null)
+
+  // nsIFactory
+  createInstance: function createInstance(aOuter, iid) {
+    if (aOuter !== null)
       throw Cr.NS_ERROR_NO_AGGREGATION;
-    return (new (this.aClass)).QueryInterface(iid);
+    return (new (this._targetConstructor)).QueryInterface(iid);
+  },
+
+  // nsIFactory
+  lockFactory: function lockFactory(lock) { 
+    // No longer used as of gecko 1.7.
+    throw Cr.NS_ERROR_NOT_IMPLEMENTED;
   }
 };