I’m writing an extension to implement a currently-unimplemented HTML tag in Mozilla/Firefox. I can’t say what it is; the smart among you may work it out, but if you do please keep it to yourselves :-)
My original plan was to define an XBL implementation of the tag and just bind it on. This plan is simple, but unfortunately it doesn’t work. Implementing the tag requires using Mozilla platform features accessed via Components.classes, and as far as I can see, there is no way of applying an XBL binding to a tag in the content area in such a way that the XBL code is privileged – even if the binding uses a chrome:// URL to bind.
So, after much head-scratching and help from Boris Zbarsky, the current, horrible implementation strategy is as follows:
- Overlay browser.xul to add a script
- That script registers a handler for window.onload
- The onload handler adds a “_helper” member to the window.content.document object,
which exposes useful methods for implementing <tag>
- This document._helper object is visible from the content
- Add a selector to ua.css (by appending to the file – ick) to bind my (unprivileged) binding to <tag>
- The binding gets invoked when a <tag> is seen
- The binding constructor also registers an onload handler, as the _helper
object is not available at binding construction time (because the onload handler mentioned above hasn’t yet fired)
- This onload handler eventually fires and calls methods on the now-present
document._helper to deal with initial state of <tag>
- Methods on the binding call methods on document._helper as necessary to deal with
scripted changes to <tag>
What do you think? Am I insane? Is there a better way?
Possible improvements I don’t know how to do:
- Find a way to make the _helper object available permanently, even while the page is loading.
- Find a way to inject the binding rule without messing with ua.css.