DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
XTF: An eXtensible Tag Framework

XTF allows you to extend Mozilla by implementing new XML elements in
XPCOM modules. It is not a C++-version of XBL: XTF elements can be
written in any XPCOM-compatible language. I myself tend to write most
elements in JavaScript.

XTF support needs to be explicitly switched on for Mozilla builds by
specifying the configure option '--enable-xtf' (add "ac_add_options
--enabl-xtf" to your .mozconfig).

To serve a particular namespace "urn:mycompany:mynamespace" with your
own XTF elements, create an XPCOM component that implements the
interface nsIXTFElementFactory, and register it with the component
manager under the contract id
Whenever Mozilla encounters a tag in your namespace it will call your
factory's 'createElement()' function.  This function should either
return a new xtf element (an object implementing 'nsIXTFElement' and
some other interfaces, depending on type and required features), or
'null'. In the later case, the implementation will build a generic XML

All interfaces relevant to XTF factory modules and XTF elements can be
found in mozilla/content/xtf/public/.  The implementation code itself
is mainly spread over the directories mozilla/content/xtf/ and

Binding outermost elements (document elements)

Binding of outermost elements is not (yet) supported. Depending on
what you use xtf elements for, this might or might not be a
problem. If you use xtf to implement a whole new language, rather than
just widgets that will get used in html, xul, or svg docs, then you'll
probably want to wrap up your documents in an xml element for which
you provide some style (e.g. via a ua style sheet), so that things get
displayed instead of pretty printed. This outermost element can be in
your xtf-served namespace, as long as your xtf factory returns a
failure for this element's tagname. The implementation will then
generate a generic XML element for this element.


When using XTF elements in XUL documents, note that the owner document
(both wrapper.ownerDocument & wrapper.elementNode.ownerDocument) will
be null at the time of the onCreated() call. (For XML and SVG
documents, at least wrapper.ownerDocument should be non-null.)  This
is unfortunate, since it is often advantageous to build the visual
content tree at the time of the onCreated() call and not wait until
the visual content is explicitly requested, so that attributes set on
the xtf element can be mapped directly to elements in the visual
content tree. It is possible to build the content tree using a
different document than the ultimate target document, but this in turn
leads to some subtleties with XBL-bound content - see below.


XTF elements generally behave well in conjunction with XBL. There are
a few issues when using XBL-bound elements in an XTFVisual's
visualContent that arise from the fact that XBL bindings are attached
to elements at layout-time rather than content-tree contruction time:
Accessing an XBL-bound element's interfaces or JS object before
layout-time usually doesn't yield the expected result. E.g. a listbox
won't have the members 'appendItem', 'clearSelection', etc. before
layout-time, even if QI'ed for nsIDOMXULMenuListElement. Worse, if the
visual content has been constructed in a different document (because
the target doc wasn't available at the time of content tree
construction time - see above), then the JS object obtained before
layout time will be different to the one that will ultimately receive
the bound implementation, i.e. even QI'ing at a later stage will
fail. To work around these issues, XBL-bound content should a) either
be build as late as possible (i.e. when requested by the wrapper with
a call to nsIXTFVisual::GetVisualContent()) or b) if this is not a
possibility (e.g. because you would like to map attributes directly
into the visual content tree), all JS object references to the element
should be re-resolved at the time of the first layout (listen in to
DidLayout() notifications).


For xtf elements written in JS (and possibly C++ as well),
constructing a visual's visualContent using the same document as the
visual's leads to some nasty reference cycle which prevents the
wrapper, inner xtf element, anonymous content and possibly the whole
document from ever getting destroyed. A workaround is to construct the
visualContent in a different document (e.g. setting the document in
nsXMLContentBuilder to null, or not setting the document at all, will
lead to new content being build in a new temporary document).

XBL-bound elements behave strangely if *any* XUL content underneath
them is accessed from JS too early.

   <label value="label text"/>

If the JS-implemented xtf element 'foo' accesses any xul content
before it receives the 'didLayout' notification, the groupbox will not
be properly build (it will not contain the label text). 'Accessing xul
content' includes any operation that leads to a js wrapper being
constructed for a xul element. E.g. if the xtf element listens in to
parentChanged-notifications, a wrapper will be build for the
notification's 'parent' parameter and groupbox construction
mysteriously fails.

Some XUL interfaces can't be used via XPCOM and thus might not work as
expected. E.g. menulist's
nsIDOMXULSelectControlElement::insertItemAt() is supposed to return an
element of type nsIDOMXULSelectControlItemElement. However, since
menulist's XBL implementation of insertItemAt creates a xul element
which will only be bound when the next asynchronous layout occurs,
QI'ing to nsIDOMXULSelectControlItemElement fails. The result is that
the method call always fails when invoked through XPCOM.  A pragmatic
solution would be to change the XUL interface signatures to return
nsIDOMXULElement instead of nsIDOMXULSelectControlItemElement.

QI'ing a JS-implemented xtf element's wrapper from JS as in 


occasionally hits the assertion

  ###!!! ASSERTION: tearoff not empty in dtor: 
  file /home/alex/devel/mozilla/js/src/xpconnect/src/xpcinlines.h, line 627

with the result that the QI succeeds (i.e. doesn't throw an exception)
but the interface methods/properties aren't available on the element
after the QI, even though element implements the given interface.

This seems to happen if GC kicks in *afer* the xtf element is being
queried for its interface ( resulting in the creation of an
nsXTFInterfaceAggregator) but *before* the nsXTFInterfaceAggregator
has been wrapped for JS use by XPCConvert::NativeData2JS().

The workaround is to a) either expose the interface via
getScriptingInterfaces (in which case it will be available to JS
callers automatically), or b) call QI until the interface is correctly
installed, e.g.:

  while (!element.inner)

With this code the QI should succeed in the first or second iteration.

07. October 2004 Alex Fritze <alex@croczilla.com>