Brendan Eich wrote:
Kyle wrote:
I'm writing a chrome extension that currently creates an instance of an object when an overlay is loaded. This currently means that a new instance is created for every window that contains the overlay.
I would prefer to be able to create a single instance of the object when the Mozilla starts, and make reference to this instance when other windows are created. This also means that I would like to keep the instance alive after the overlay that created it has been destroyed.
This should just be a simple Singleton model. Is there some type of
registry I can use to store and retrieve a reference to this object
each time the overlay loads, and does anyone have any examples of a
similar implementation? Thanks you,
You want to write an XPCOM component in JS, and call it via XPConnect. Many examples exist. See http://lxr.mozilla.org/mozilla/source/xpcom/sample/nsSample.js, http://lxr.mozilla.org/mozilla/source/toolkit/mozapps/update/src/nsBackgroundUpdateService.js, http://lxr.mozilla.org/mozilla/source/toolkit/mozapps/extensions/src/nsExtensionManager.js.in, and others (http://lxr.mozilla.org/mozilla/search?string=createInstance%3A).
So the better newsgroup, I think, is m.xpcom. Cross-posting with followup-to: set.
/be
In order to store and retrieve objects, you can do this:
var props = Components.classesByID["{4de2bc90-b1bf-11d3-93b6-00104ba0fd40}"].getService(Components.interfaces.nsIProperties);
var wrapper = props.get("key", Components.interfaces.nsIFoo);
The class id above is an implementation of nsIProperties in XPCOM that you can use. This interface allows you to set and get arbatrary nsISupport objects.
Hope this helps, Doug
_______________________________________________ Mozilla-xpcom mailing list [EMAIL PROTECTED] http://mail.mozilla.org/listinfo/mozilla-xpcom
