Uldis Bojars wrote:
Two question about Firefox extension development in XUL.
Related to Semantic Radar - an extension that I am developing:
1) Keeping variables for each tab/window
I need to keep the state (indicating of links to particular types of
RDF are present) for each window and tab. You can think of it as
similar to detecting presence of links to RSS feeds and then saving
them.
Looked at using global variables which are kept separate for each
browser window. But I see that they are shared between tabs which does
not help.
Q: How can an extension attach some variables to the current
window/tab?
There are a number of cases where this can be used - e.g., here instead
of wasting the time running detection ( detectRDF() )at every tab
change it would be done just once. A "naive" solution would be to add
it as an attribute to some XUL element - similar as currently used to
attach state information to the icom: item.setAttribute("mystate",
"on");
Hope there is a better solution.
Sounds like you want to store something per top-level document, not per
tab or window.
How should that behaviour react to, say DM modifications, or loading
the same page in two windows?
If you're worried about memory impact, you may want to do a service that
stores the last, say 12 recently used tabs, or something like that.
And purges entries on close or so.
Axel
2) Cleanup / Avoiding memory leaks
How to write the extension correctly and clean up to avoid memory
leaks?
My extension does the following calls on the initialisation:
getBrowser().addEventListener("load", detectRDF, true);
getBrowser().addEventListener("select", detectRDF, true);
();
getBrowser().addEventListener("unload", function(e) {
() }, false );
I hope it cleans up the observer when not needed. Do I also have to
unload event listeners and if yes - how? Also: the "unload" events
trigger each time when a page is closed - that is too often to do
removing of the resources used by the extension (I may be wrong here).
The same with registration of resources - when to do it? "load" event
is too often either.
E.g., in the preferences tutorial [1] the startup() is launched on
"load" events, causing [ ("", this, false); ] to
be called each time. While this probably does not do harm (as opposed
to not cleaning up and leaking memory) the question is - what is the
correct way to do startup and cleanup for Mozilla extensions?
[1]
If you want to see the extension in action, install it and go to [2-4].
You should see status bar icons appear to indicate presence of links to
RDF metadata. Pressing the icons will lead you to a browser for this
type of data.
[2] http://b4mad.net/datenbrei/
[3]
[4]
P.S. The link posted above is a development version. I should remove
information of compatiblity with Mozilla Suite or fix it before
releasing because the recent changes broke SemRadar's compatiblity with
it.
All feedback is welcome :)
Thanks,
Uldis
[ http://captsolo.net/info/ ]
dev-tech-xul mailing list
dev-tech-xul (AT) lists (DOT) mozilla.org