Browse Source

Update factory in bootstrap.js.

Brendan Dahl 13 years ago
parent
commit
72e6dbebaa
  1. 53
      extensions/firefox/bootstrap.js

53
extensions/firefox/bootstrap.js vendored

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

Loading…
Cancel
Save