Bug 412320 - Try code-generation for QI impls, r=roc+luser
authorbenjamin@smedbergs.us
Fri, 25 Jan 2008 09:14:48 -0800
changeset 10671 4c4e35fa5f5b2c3258046cc59cbc7a9301499ac6
parent 10670 797060f3559c6d686bc1e9c7957753839b7bc39a
child 10672 cb37bacd8f1fcbb6058a58b36fee20fbe5c99fab
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs412320
milestone1.9b3pre
Bug 412320 - Try code-generation for QI impls, r=roc+luser
config/config.mk
config/rules.mk
content/base/src/Makefile.in
content/base/src/contentbase.gqi
content/base/src/nsDocument.cpp
content/base/src/nsDocument.h
content/base/src/nsGenericElement.cpp
content/html/content/public/nsIFrameSetElement.h
content/html/content/src/Makefile.in
content/html/content/src/htmlcontent.gqi
content/html/content/src/htmlgenericelement.gqi
content/html/content/src/nsGenericHTMLElement.cpp
content/html/content/src/nsGenericHTMLElement.h
content/html/content/src/nsHTMLAnchorElement.cpp
content/html/content/src/nsHTMLAnchorElement.h
content/html/content/src/nsHTMLDivElement.cpp
content/html/content/src/nsHTMLDivElement.h
content/html/content/src/nsHTMLFrameElement.cpp
content/html/content/src/nsHTMLFrameElement.h
content/html/content/src/nsHTMLFrameSetElement.cpp
content/html/content/src/nsHTMLFrameSetElement.h
content/html/content/src/nsHTMLIFrameElement.cpp
content/html/content/src/nsHTMLIFrameElement.h
content/html/content/src/nsHTMLSpanElement.cpp
content/html/content/src/nsHTMLSpanElement.h
content/html/document/src/Makefile.in
content/html/document/src/htmldocument.gqi
content/html/document/src/nsHTMLDocument.cpp
xpcom/base/gqi.py
xpcom/components/Makefile.in
xpcom/components/nsCategoryManager.cpp
xpcom/components/nsCategoryManager.h
xpcom/components/nsComponentManager.cpp
xpcom/components/nsComponentManager.h
xpcom/components/nsNativeComponentLoader.cpp
xpcom/components/xpcomcomponents.gqi
xpcom/ds/Makefile.in
xpcom/ds/nsArray.cpp
xpcom/ds/nsAtomTable.cpp
xpcom/ds/nsByteBuffer.cpp
xpcom/ds/nsHashPropertyBag.cpp
xpcom/ds/nsHashPropertyBag.h
xpcom/ds/nsIByteBuffer.h
xpcom/ds/nsINIParserImpl.cpp
xpcom/ds/nsINIParserImpl.h
xpcom/ds/nsIUnicharBuffer.h
xpcom/ds/nsObserverList.cpp
xpcom/ds/nsPersistentProperties.cpp
xpcom/ds/nsStaticAtom.h
xpcom/ds/nsStringEnumerator.cpp
xpcom/ds/nsStringEnumerator.h
xpcom/ds/nsSupportsArray.cpp
xpcom/ds/nsSupportsArray.h
xpcom/ds/nsSupportsArrayEnumerator.cpp
xpcom/ds/nsSupportsPrimitives.cpp
xpcom/ds/nsUnicharBuffer.cpp
xpcom/ds/nsVariant.cpp
xpcom/ds/xpcomds.gqi
--- a/config/config.mk
+++ b/config/config.mk
@@ -515,17 +515,17 @@ XPIDL_COMPILE 	= $(CYGWIN_WRAPPER) $(LIB
 XPIDL_LINK	= $(CYGWIN_WRAPPER) $(LIBXUL_DIST)/bin/xpt_link$(BIN_SUFFIX)
 endif
 
 # Java macros
 JAVA_GEN_DIR  = _javagen
 JAVA_DIST_DIR = $(DEPTH)/$(JAVA_GEN_DIR)
 JAVA_IFACES_PKG_NAME = org/mozilla/interfaces
 
-REQ_INCLUDES	= $(foreach d,$(REQUIRES),-I$(DIST)/include/$d) -I$(DIST)/include 
+REQ_INCLUDES	= -I$(srcdir) -I. $(foreach d,$(REQUIRES),-I$(DIST)/include/$d) -I$(DIST)/include 
 ifdef LIBXUL_SDK
 REQ_INCLUDES_SDK = $(foreach d,$(REQUIRES),-I$(LIBXUL_SDK)/include/$d) -I$(LIBXUL_SDK)/include
 endif
 
 INCLUDES	= $(LOCAL_INCLUDES) $(REQ_INCLUDES) $(REQ_INCLUDES_SDK) -I$(PUBLIC) $(OS_INCLUDES)
 
 ifndef MOZILLA_INTERNAL_API
 INCLUDES	+= -I$(LIBXUL_DIST)/sdk/include
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -112,16 +112,20 @@ EXPAND_LIBNAME = $(addprefix -l,$(1))
 EXPAND_LIBNAME_PATH = -L$(2) $(addprefix -l,$(1))
 EXPAND_MOZLIBNAME = $(addprefix -l,$(1))
 endif
 
 ifdef EXTRA_DSO_LIBS
 EXTRA_DSO_LIBS	:= $(call EXPAND_MOZLIBNAME,$(EXTRA_DSO_LIBS))
 endif
 
+ifdef GQI_SRCS
+CPPSRCS += $(GQI_SRCS:.gqi=QI.cpp)
+endif
+
 #
 # Library rules
 #
 # If BUILD_STATIC_LIBS or FORCE_STATIC_LIB is set, build a static library.
 # Otherwise, build a shared library.
 #
 
 ifndef LIBRARY
@@ -1183,16 +1187,19 @@ endef
 
 MAKE_DEPS_AUTO_CC = $(MAKE_DEPS_AUTO)
 MAKE_DEPS_AUTO_CXX = $(MAKE_DEPS_AUTO)
 
 endif # COMPILER_DEPEND
 
 endif # MOZ_AUTO_DEPS
 
+%QI.cpp: %.gqi $(topsrcdir)/xpcom/base/gqi.py
+	$(PYTHON) $(topsrcdir)/xpcom/base/gqi.py $(INCLUDES) -I $(IDL_DIR) -o $@ -D $(MDDEPDIR)/$(@F).pp $<
+
 # Rules for building native targets must come first because of the host_ prefix
 host_%.$(OBJ_SUFFIX): %.c Makefile Makefile.in
 	$(REPORT_BUILD)
 	$(ELOG) $(HOST_CC) $(HOST_OUTOPTION)$@ -c $(HOST_CFLAGS) $(INCLUDES) $(NSPR_CFLAGS) $(_VPATH_SRCS)
 
 host_%.$(OBJ_SUFFIX): %.cpp Makefile Makefile.in
 	$(REPORT_BUILD)
 	$(ELOG) $(HOST_CXX) $(HOST_OUTOPTION)$@ -c $(HOST_CXXFLAGS) $(INCLUDES) $(NSPR_CFLAGS) $(_VPATH_SRCS)
--- a/content/base/src/Makefile.in
+++ b/content/base/src/Makefile.in
@@ -160,16 +160,18 @@ CPPSRCS		= \
 		nsTextFragment.cpp \
 		nsTextNode.cpp \
 		nsTreeWalker.cpp \
 		nsXMLContentSerializer.cpp \
 		nsXMLHttpRequest.cpp \
 		nsXMLNameSpaceMap.cpp \
 		$(NULL)
 
+GQI_SRCS = contentbase.gqi
+
 # we don't want the shared lib, but we want to force the creation of a
 # static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES	+= \
 		-I$(srcdir)/../../events/src \
new file mode 100644
--- /dev/null
+++ b/content/base/src/contentbase.gqi
@@ -0,0 +1,99 @@
+%import-idl "nsIDOM3Node.idl"
+%import-idl "nsIDOMNSElement.idl"
+%import-idl "nsIDOMEventTarget.idl"
+%import-idl "nsIDOM3EventTarget.idl"
+%import-idl "nsIDOMNSEventTarget.idl"
+%import-idl "nsIWeakReference.idl"
+%import-idl "nsIDOMDocument.idl"
+%import-idl "nsIDOM3Document.idl"
+%import-idl "nsIDOMNSDocument.idl"
+%import-idl "nsIDOMDocumentEvent.idl"
+%import-idl "nsIDOM3DocumentEvent.idl"
+%import-idl "nsIDOMDocumentStyle.idl"
+%import-idl "nsIDOMNSDocumentStyle.idl"
+%import-idl "nsIDOMDocumentView.idl"
+%import-idl "nsIDOMDocumentRange.idl"
+%import-idl "nsIDOMDocumentTraversal.idl"
+%import-idl "nsIDOMDocumentXBL.idl"
+%import-idl "nsIDOMXPathEvaluator.idl"
+
+%pseudo-iid nsIContent fba9aa39-016e-4d5d-ab62-22a1b84a3c7b
+%pseudo-iid nsINode cf677826-d7f1-4ec5-bf3a-d41811ac5846
+%pseudo-iid nsPIDOMEventTarget 44a6597b-9fc3-4a8d-b7a4-d9009abf9d15
+%pseudo-iid nsIDocument 626d86d2-615f-4a12-94d8-e3db3a298372
+%pseudo-iid nsIScriptObjectPrincipal 3eedba38-8d22-41e1-817a-0e43e165b664
+%pseudo-iid nsIMutationObserver 32e68316-67d4-44a5-8d35-0d390fa9df11
+%pseudo-iid nsIXPathEvaluatorInternal  b4b72daa-65d6-440f-b608-e2ee9a82f313
+%pseudo-iid nsIRadioGroupContainer 06de7839-d0db-47d3-8290-3cb8622ed966
+
+%{C++
+#include "nsGenericElement.h"
+#include "nsDocument.h"
+#include "nsIXPathEvaluatorInternal.h"
+#include "nsDOMCID.h"
+#include "nsComponentManagerUtils.h"
+%}
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGenericElement)
+  NS_INTERFACE_MAP_ENTRY(nsIContent)
+  NS_INTERFACE_MAP_ENTRY(nsINode)
+  NS_INTERFACE_MAP_ENTRY(nsPIDOMEventTarget)
+  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this))
+  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNSElement, new nsNSElementTearoff(this))
+  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMEventTarget,
+                                 nsDOMEventRTTearoff::Create(this))
+  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3EventTarget,
+                                 nsDOMEventRTTearoff::Create(this))
+  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNSEventTarget,
+                                 nsDOMEventRTTearoff::Create(this))
+  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
+                                 new nsNodeSupportsWeakRefTearoff(this))
+  // nsNodeSH::PreCreate() depends on the identity pointer being the
+  // same as nsINode (which nsIContent inherits), so if you change the
+  // below line, make sure nsNodeSH::PreCreate() still does the right
+  // thing!
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
+NS_INTERFACE_MAP_END
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsDocument)
+  NS_INTERFACE_MAP_ENTRY(nsINode)
+  NS_INTERFACE_MAP_ENTRY(nsIDocument)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMDocument)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMNSDocument)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentEvent)
+  NS_INTERFACE_MAP_ENTRY(nsIDOM3DocumentEvent)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentStyle)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMNSDocumentStyle)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentView)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentRange)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentTraversal)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentXBL)
+  NS_INTERFACE_MAP_ENTRY(nsIScriptObjectPrincipal)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
+  NS_INTERFACE_MAP_ENTRY(nsIDOM3EventTarget)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMNSEventTarget)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
+  NS_INTERFACE_MAP_ENTRY(nsPIDOMEventTarget)
+  NS_INTERFACE_MAP_ENTRY(nsIDOM3Node)
+  NS_INTERFACE_MAP_ENTRY(nsIDOM3Document)
+  NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
+  NS_INTERFACE_MAP_ENTRY(nsIRadioGroupContainer)
+  NS_INTERFACE_MAP_ENTRY(nsIMutationObserver)
+  // nsNodeSH::PreCreate() depends on the identity pointer being the
+  // same as nsINode (which nsIDocument inherits), so if you change
+  // the below line, make sure nsNodeSH::PreCreate() still does the
+  // right thing!
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDocument)
+
+  NS_INTERFACE_MAP_ENTRY_LITERAL(nsIDOMXPathEvaluator, nsIXPathEvaluatorInternal)
+    if (!mXPathEvaluatorTearoff) {
+      nsresult rv;
+      mXPathEvaluatorTearoff =
+        do_CreateInstance(NS_XPATH_EVALUATOR_CONTRACTID,
+                          static_cast<nsIDocument *>(this), &rv);
+      NS_ENSURE_SUCCESS(rv, rv);
+    }
+
+    return mXPathEvaluatorTearoff->QueryInterface(aIID, aResult);
+  END
+NS_INTERFACE_MAP_END
--- a/content/base/src/nsDocument.cpp
+++ b/content/base/src/nsDocument.cpp
@@ -878,64 +878,16 @@ nsDocument::~nsDocument()
 
   delete mHeaderData;
   delete mBoxObjectTable;
   delete mContentWrapperHash;
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsDocument)
 
-NS_INTERFACE_TABLE_HEAD(nsDocument)
-  NS_INTERFACE_TABLE_BEGIN
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsINode)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDocument)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMDocument)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMNSDocument)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMDocumentEvent)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOM3DocumentEvent)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMDocumentStyle)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMNSDocumentStyle)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMDocumentView)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMDocumentRange)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMDocumentTraversal)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMDocumentXBL)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIScriptObjectPrincipal)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMEventTarget)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOM3EventTarget)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMNSEventTarget)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOMNode)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsPIDOMEventTarget)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOM3Node)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIDOM3Document)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsISupportsWeakReference)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIRadioGroupContainer)
-    NS_INTERFACE_TABLE_ENTRY(nsDocument, nsIMutationObserver)
-    // nsNodeSH::PreCreate() depends on the identity pointer being the
-    // same as nsINode (which nsIDocument inherits), so if you change
-    // the below line, make sure nsNodeSH::PreCreate() still does the
-    // right thing!
-    NS_INTERFACE_TABLE_ENTRY_AMBIGUOUS(nsDocument, nsISupports, nsIDocument)
-  NS_INTERFACE_TABLE_END
-  NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsDocument)
-  if (aIID.Equals(NS_GET_IID(nsIDOMXPathEvaluator)) ||
-      aIID.Equals(NS_GET_IID(nsIXPathEvaluatorInternal))) {
-    if (!mXPathEvaluatorTearoff) {
-      nsresult rv;
-      mXPathEvaluatorTearoff =
-        do_CreateInstance(NS_XPATH_EVALUATOR_CONTRACTID,
-                          static_cast<nsIDocument *>(this), &rv);
-      NS_ENSURE_SUCCESS(rv, rv);
-    }
-
-    return mXPathEvaluatorTearoff->QueryInterface(aIID, aInstancePtr);
-  }
-  else
-NS_INTERFACE_MAP_END
-
-
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsDocument, nsIDocument)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS_WITH_DESTROY(nsDocument, 
                                                         nsIDocument,
                                                         nsNodeUtils::LastRelease(this))
 
 
 PR_STATIC_CALLBACK(PLDHashOperator)
 SubDocTraverser(PLDHashTable *table, PLDHashEntryHdr *hdr, PRUint32 number,
--- a/content/base/src/nsDocument.h
+++ b/content/base/src/nsDocument.h
@@ -793,17 +793,17 @@ protected:
 
   nsCOMPtr<nsIScriptEventManager> mScriptEventManager;
 
   nsString mBaseTarget;
 
   // Our update nesting level
   PRUint32 mUpdateNestLevel;
 
-private:
+protected:
   friend class nsUnblockOnloadEvent;
 
   void PostUnblockOnloadEvent();
   void DoUnblockOnload();
 
   /**
    * See if aDocument is a child of this.  If so, return the frame element in
    * this document that holds currentDoc (or an ancestor).
--- a/content/base/src/nsGenericElement.cpp
+++ b/content/base/src/nsGenericElement.cpp
@@ -3444,38 +3444,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(
     if (slots) {
       cb.NoteXPCOMChild(slots->mAttributeMap.get());
       if (tmp->IsNodeOfType(nsINode::eXUL))
         cb.NoteXPCOMChild(slots->mControllers);
     }
   }
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-
-NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsGenericElement)
-  NS_INTERFACE_MAP_ENTRY(nsIContent)
-  NS_INTERFACE_MAP_ENTRY(nsINode)
-  NS_INTERFACE_MAP_ENTRY(nsPIDOMEventTarget)
-  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this))
-  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNSElement, new nsNSElementTearoff(this))
-  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMEventTarget,
-                                 nsDOMEventRTTearoff::Create(this))
-  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3EventTarget,
-                                 nsDOMEventRTTearoff::Create(this))
-  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNSEventTarget,
-                                 nsDOMEventRTTearoff::Create(this))
-  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
-                                 new nsNodeSupportsWeakRefTearoff(this))
-  // nsNodeSH::PreCreate() depends on the identity pointer being the
-  // same as nsINode (which nsIContent inherits), so if you change the
-  // below line, make sure nsNodeSH::PreCreate() still does the right
-  // thing!
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
-NS_INTERFACE_MAP_END
-
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsGenericElement, nsIContent)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS_WITH_DESTROY(nsGenericElement, 
 							nsIContent,
 							nsNodeUtils::LastRelease(this))
 
 nsresult
 nsGenericElement::PostQueryInterface(REFNSIID aIID, void** aInstancePtr)
 {
--- a/content/html/content/public/nsIFrameSetElement.h
+++ b/content/html/content/public/nsIFrameSetElement.h
@@ -35,16 +35,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsIFramesetElement_h___
 #define nsIFramesetElement_h___
 
 #include "nsISupports.h"
+#include "nsCoord.h"
 
 // IID for the nsIFramesetElement interface
 #define NS_IFRAMESETELEMENT_IID \
 { 0xeefe0fe5, 0x44ac, 0x4d7f, \
   { 0xa7, 0x51, 0xf4, 0xaa, 0x5f, 0x22, 0xb0, 0xbf } }
 
 /**
  * The nsFramesetUnit enum is used to denote the type of each entry
--- a/content/html/content/src/Makefile.in
+++ b/content/html/content/src/Makefile.in
@@ -128,16 +128,18 @@ CPPSRCS		= \
 		nsHTMLTableColElement.cpp \
 		nsHTMLTableRowElement.cpp \
 		nsHTMLTableSectionElement.cpp \
 		nsHTMLTextAreaElement.cpp \
 		nsHTMLTitleElement.cpp \
                 nsTextRectangle.cpp \
 		$(NULL)
 
+GQI_SRCS = htmlcontent.gqi
+
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
 
 INCLUDES	+= \
 		-I$(srcdir)/../../../base/src \
 		-I$(srcdir)/../../../events/src \
new file mode 100644
--- /dev/null
+++ b/content/html/content/src/htmlcontent.gqi
@@ -0,0 +1,55 @@
+%import "htmlgenericelement.gqi"
+
+%import-idl "nsIDOMHTMLAnchorElement.idl"
+%import-idl "nsIDOMNSHTMLAnchorElement2.idl"
+%import-idl "nsIDOMHTMLDivElement.idl"
+%import-idl "nsIDOMHTMLFrameElement.idl"
+%import-idl "nsIDOMHTMLFrameSetElement.idl"
+%import-idl "nsIDOMHTMLIFrameElement.idl"
+
+%{C++
+#include "nsHTMLAnchorElement.h"
+#include "nsHTMLDivElement.h"
+#include "nsHTMLSpanElement.h"
+#include "nsHTMLFrameElement.h"
+#include "nsHTMLFrameSetElement.h"
+#include "nsHTMLIFrameElement.h"
+%}
+
+%pseudo-iid nsILink 0c212bc4-fcd7-479d-8c3f-3be8e6787450
+%pseudo-iid nsIFrameSetElement eefe0fe5-44ac-4d7f-a751-f4aa5f22b0bf
+
+NS_INTERFACE_MAP_BEGIN(nsHTMLAnchorElement, nsGenericHTMLElement)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLAnchorElement)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLAnchorElement)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLAnchorElement2)
+  NS_INTERFACE_MAP_ENTRY(nsILink)
+  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLAnchorElement)
+NS_INTERFACE_MAP_END
+
+NS_INTERFACE_MAP_BEGIN(nsHTMLDivElement, nsGenericHTMLElement)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDivElement)
+  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLDivElement)
+NS_INTERFACE_MAP_END
+
+NS_INTERFACE_MAP_BEGIN(nsHTMLSpanElement, nsGenericHTMLElement)
+  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLSpanElement)
+NS_INTERFACE_MAP_END
+
+NS_INTERFACE_MAP_BEGIN(nsHTMLFrameElement, nsGenericHTMLFrameElement)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFrameElement)
+  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLFrameElement)
+NS_INTERFACE_MAP_END
+
+NS_INTERFACE_MAP_BEGIN(nsHTMLFrameSetElement, nsGenericHTMLElement)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLFrameSetElement)
+  NS_INTERFACE_MAP_ENTRY(nsIFrameSetElement)
+  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLFrameSetElement)
+NS_INTERFACE_MAP_END
+
+NS_INTERFACE_MAP_BEGIN(nsHTMLIFrameElement, nsGenericHTMLFrameElement)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLIFrameElement)
+  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLIFrameElement)
+NS_INTERFACE_MAP_END
+
+
new file mode 100644
--- /dev/null
+++ b/content/html/content/src/htmlgenericelement.gqi
@@ -0,0 +1,35 @@
+// Note: nsGenericHTMLElement does not implement QI directly... this declaration is here only
+// so that subclasses have the correct list
+
+%import "contentbase.gqi"
+
+%import-idl "nsIDOMNSHTMLElement.idl"
+%import-idl "nsIDOMElementCSSInlineStyle.idl"
+%import-idl "nsIDOMHTMLElement.idl"
+%import-idl "nsIDOMNSHTMLFrameElement.idl"
+%import-idl "nsIFrameLoader.idl"
+
+%{C++
+#include "nsGenericHTMLElement.h"
+%}
+
+NS_INTERFACE_MAP_BEGIN(nsGenericHTMLElement, nsGenericElement)
+  // nsGenericHTMLElement doesn't implement nsIDOMHTMLElement, but all
+  // subclasses do, and we only use this declaration for subclasses
+  NS_FUTURE_INTERFACE_MAP_ENTRY(nsIDOMHTMLElement)
+  NS_FUTURE_INTERFACE_MAP_ENTRY(nsIDOMNode)
+  NS_FUTURE_INTERFACE_MAP_ENTRY(nsIDOMElement)
+
+  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNSHTMLElement,
+                                 new nsGenericHTMLElementTearoff(this))
+  NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMElementCSSInlineStyle,
+                                 new nsGenericHTMLElementTearoff(this))
+  NS_INTERFACE_MAP_UNFOUND
+    return PostQueryInterface(aIID, aResult);
+  END
+NS_INTERFACE_MAP_END
+
+NS_INTERFACE_MAP_BEGIN(nsGenericHTMLFrameElement, nsGenericHTMLElement)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLFrameElement)
+  NS_INTERFACE_MAP_ENTRY(nsIFrameLoaderOwner)
+NS_INTERFACE_MAP_END
--- a/content/html/content/src/nsGenericHTMLElement.cpp
+++ b/content/html/content/src/nsGenericHTMLElement.cpp
@@ -174,40 +174,16 @@ nsGenericHTMLElement::Init(nsINodeInfo *
   GEUS_ElementCreated(aNodeInfo);
 
   return nsGenericHTMLElementBase::Init(aNodeInfo);
 }
 
 #endif
 
 
-class nsGenericHTMLElementTearoff : public nsIDOMNSHTMLElement,
-                                    public nsIDOMElementCSSInlineStyle
-{
-  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
-
-  nsGenericHTMLElementTearoff(nsGenericHTMLElement *aElement)
-    : mElement(aElement)
-  {
-  }
-
-  virtual ~nsGenericHTMLElementTearoff()
-  {
-  }
-
-  NS_FORWARD_NSIDOMNSHTMLELEMENT(mElement->)
-  NS_FORWARD_NSIDOMELEMENTCSSINLINESTYLE(mElement->)
-
-  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsGenericHTMLElementTearoff,
-                                           nsIDOMNSHTMLElement)
-
-private:
-  nsCOMPtr<nsGenericHTMLElement> mElement;
-};
-
 NS_IMPL_CYCLE_COLLECTION_1(nsGenericHTMLElementTearoff, mElement)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF_AMBIGUOUS(nsGenericHTMLElementTearoff,
                                           nsIDOMNSHTMLElement)
 NS_IMPL_CYCLE_COLLECTING_RELEASE_AMBIGUOUS(nsGenericHTMLElementTearoff,
                                            nsIDOMNSHTMLElement)
 
 NS_INTERFACE_TABLE_HEAD(nsGenericHTMLElementTearoff)
@@ -2874,23 +2850,16 @@ nsGenericHTMLFrameElement::~nsGenericHTM
 }
 
 NS_IMPL_CYCLE_COLLECTION_CLASS(nsGenericHTMLFrameElement)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(nsGenericHTMLFrameElement,
                                                   nsGenericHTMLElement)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR(mFrameLoader)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
-NS_INTERFACE_TABLE_HEAD(nsGenericHTMLFrameElement)
-  NS_INTERFACE_TABLE_INHERITED2(nsGenericHTMLFrameElement,
-                                nsIDOMNSHTMLFrameElement,
-                                nsIFrameLoaderOwner)
-  NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(nsGenericHTMLFrameElement)
-NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
-
 nsresult
 nsGenericHTMLFrameElement::GetContentDocument(nsIDOMDocument** aContentDocument)
 {
   NS_PRECONDITION(aContentDocument, "Null out param");
   *aContentDocument = nsnull;
 
   nsCOMPtr<nsIDOMWindow> win;
   GetContentWindow(getter_AddRefs(win));
--- a/content/html/content/src/nsGenericHTMLElement.h
+++ b/content/html/content/src/nsGenericHTMLElement.h
@@ -40,16 +40,18 @@
 
 #include "nsMappedAttributeElement.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsINameSpaceManager.h"  // for kNameSpaceID_None
 #include "nsIFormControl.h"
 #include "nsIDOMNSHTMLFrameElement.h"
 #include "nsFrameLoader.h"
 #include "nsGkAtoms.h"
+#include "nsIDOMElementCSSInlineStyle.h"
+#include "nsIDOMNSHTMLElement.h"
 
 class nsIDOMAttr;
 class nsIDOMEventListener;
 class nsIDOMNodeList;
 class nsIFrame;
 class nsIStyleRule;
 class nsChildContentList;
 class nsDOMCSSDeclaration;
@@ -892,19 +894,16 @@ class nsGenericHTMLFrameElement : public
 {
 public:
   nsGenericHTMLFrameElement(nsINodeInfo *aNodeInfo)
     : nsGenericHTMLElement(aNodeInfo)
   {
   }
   virtual ~nsGenericHTMLFrameElement();
 
-  // nsISupports
-  NS_IMETHOD QueryInterface(REFNSIID aIID, void** aInstancePtr);
-
   // nsIDOMNSHTMLFrameElement
   NS_DECL_NSIDOMNSHTMLFRAMEELEMENT
 
   // nsIFrameLoaderOwner
   NS_DECL_NSIFRAMELOADEROWNER
 
   // nsIContent
   virtual PRBool IsFocusable(PRInt32 *aTabIndex = nsnull);
@@ -935,16 +934,40 @@ protected:
   // it makes sense.
   nsresult EnsureFrameLoader();
   nsresult LoadSrc();
   nsresult GetContentDocument(nsIDOMDocument** aContentDocument);
 
   nsCOMPtr<nsIFrameLoader> mFrameLoader;
 };
 
+class nsGenericHTMLElementTearoff : public nsIDOMNSHTMLElement,
+                                    public nsIDOMElementCSSInlineStyle
+{
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+
+  nsGenericHTMLElementTearoff(nsGenericHTMLElement *aElement)
+    : mElement(aElement)
+  {
+  }
+
+  virtual ~nsGenericHTMLElementTearoff()
+  {
+  }
+
+  NS_FORWARD_NSIDOMNSHTMLELEMENT(mElement->)
+  NS_FORWARD_NSIDOMELEMENTCSSINLINESTYLE(mElement->)
+
+  NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsGenericHTMLElementTearoff,
+                                           nsIDOMNSHTMLElement)
+
+private:
+  nsCOMPtr<nsGenericHTMLElement> mElement;
+};
+
 //----------------------------------------------------------------------
 
 /**
  * A macro to implement the NS_NewHTMLXXXElement() functions.
  */
 #define NS_IMPL_NS_NEW_HTML_ELEMENT(_elementName)                            \
 nsGenericHTMLElement*                                                        \
 NS_NewHTML##_elementName##Element(nsINodeInfo *aNodeInfo, PRBool aFromParser)\
--- a/content/html/content/src/nsHTMLAnchorElement.cpp
+++ b/content/html/content/src/nsHTMLAnchorElement.cpp
@@ -31,16 +31,18 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
+
+#include "nsHTMLAnchorElement.h"
 #include "nsCOMPtr.h"
 #include "nsReadableUtils.h"
 #include "nsUnicharUtils.h"
 #include "nsIDOMHTMLAnchorElement.h"
 #include "nsIDOMNSHTMLAnchorElement2.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIHTMLDocument.h"
 #include "nsGenericHTMLElement.h"
@@ -58,88 +60,20 @@
 // For GetText().
 #include "nsIContentIterator.h"
 #include "nsIDOMText.h"
 #include "nsIEnumerator.h"
 
 #include "nsCOMPtr.h"
 #include "nsIPresShell.h"
 #include "nsIDocument.h"
+#include "nsHTMLAnchorElement.h"
 
 nsresult NS_NewContentIterator(nsIContentIterator** aInstancePtrResult);
 
-class nsHTMLAnchorElement : public nsGenericHTMLElement,
-                            public nsIDOMHTMLAnchorElement,
-                            public nsIDOMNSHTMLAnchorElement2,
-                            public nsILink
-{
-public:
-  nsHTMLAnchorElement(nsINodeInfo *aNodeInfo);
-  virtual ~nsHTMLAnchorElement();
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-
-  // nsIDOMNode
-  NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
-
-  // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
-
-  // nsIDOMHTMLElement
-  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
-
-  // nsIDOMHTMLAnchorElement
-  NS_DECL_NSIDOMHTMLANCHORELEMENT  
-
-  // nsIDOMNSHTMLAnchorElement
-  NS_DECL_NSIDOMNSHTMLANCHORELEMENT
-
-  // nsIDOMNSHTMLAnchorElement2
-  NS_DECL_NSIDOMNSHTMLANCHORELEMENT2
-
-  // nsILink
-  NS_IMETHOD GetLinkState(nsLinkState &aState);
-  NS_IMETHOD SetLinkState(nsLinkState aState);
-  NS_IMETHOD GetHrefURI(nsIURI** aURI);
-  NS_IMETHOD LinkAdded() { return NS_OK; }
-  NS_IMETHOD LinkRemoved() { return NS_OK; }
-
-  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
-                              nsIContent* aBindingParent,
-                              PRBool aCompileEventHandlers);
-  virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
-                              PRBool aNullParent = PR_TRUE);
-  virtual void SetFocus(nsPresContext* aPresContext);
-  virtual PRBool IsFocusable(PRBool *aTabIndex = nsnull);
-
-  virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
-  virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
-  virtual PRBool IsLink(nsIURI** aURI) const;
-  virtual void GetLinkTarget(nsAString& aTarget);
-
-  nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
-                   const nsAString& aValue, PRBool aNotify)
-  {
-    return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
-  }
-  virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
-                           nsIAtom* aPrefix, const nsAString& aValue,
-                           PRBool aNotify);
-  virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
-                             PRBool aNotify);
-
-  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-
-protected:
-  // The cached visited state
-  nsLinkState mLinkState;
-};
-
-
 NS_IMPL_NS_NEW_HTML_ELEMENT(Anchor)
 
 
 nsHTMLAnchorElement::nsHTMLAnchorElement(nsINodeInfo *aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo),
     mLinkState(eLinkState_Unknown)
 {
 }
@@ -148,29 +82,18 @@ nsHTMLAnchorElement::~nsHTMLAnchorElemen
 {
 }
 
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLAnchorElement, nsGenericElement) 
 NS_IMPL_RELEASE_INHERITED(nsHTMLAnchorElement, nsGenericElement) 
 
 
-// QueryInterface implementation for nsHTMLAnchorElement
-NS_HTML_CONTENT_INTERFACE_TABLE_HEAD(nsHTMLAnchorElement, nsGenericHTMLElement)
-  NS_INTERFACE_TABLE_INHERITED4(nsHTMLAnchorElement,
-                                nsIDOMHTMLAnchorElement,
-                                nsIDOMNSHTMLAnchorElement,
-                                nsIDOMNSHTMLAnchorElement2,
-                                nsILink)
-NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLAnchorElement)
-
-
 NS_IMPL_ELEMENT_CLONE(nsHTMLAnchorElement)
 
-
 NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Charset, charset)
 NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Coords, coords)
 NS_IMPL_URI_ATTR(nsHTMLAnchorElement, Href, href)
 NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Hreflang, hreflang)
 NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Name, name)
 NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Rel, rel)
 NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Rev, rev)
 NS_IMPL_STRING_ATTR(nsHTMLAnchorElement, Shape, shape)
new file mode 100644
--- /dev/null
+++ b/content/html/content/src/nsHTMLAnchorElement.h
@@ -0,0 +1,116 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Daniel Glazman <glazman@netscape.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsHTMLAnchorElement_h__
+#define nsHTMLAnchorElement_h__
+
+#include "nsGenericHTMLElement.h"
+#include "nsIDOMHTMLAnchorElement.h"
+#include "nsIDOMNSHTMLAnchorElement2.h"
+#include "nsILink.h"
+
+class nsHTMLAnchorElement : public nsGenericHTMLElement,
+                            public nsIDOMHTMLAnchorElement,
+                            public nsIDOMNSHTMLAnchorElement2,
+                            public nsILink
+{
+public:
+  nsHTMLAnchorElement(nsINodeInfo *aNodeInfo);
+  virtual ~nsHTMLAnchorElement();
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIDOMNode
+  NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
+
+  // nsIDOMElement
+  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+
+  // nsIDOMHTMLElement
+  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
+
+  // nsIDOMHTMLAnchorElement
+  NS_DECL_NSIDOMHTMLANCHORELEMENT  
+
+  // nsIDOMNSHTMLAnchorElement
+  NS_DECL_NSIDOMNSHTMLANCHORELEMENT
+
+  // nsIDOMNSHTMLAnchorElement2
+  NS_DECL_NSIDOMNSHTMLANCHORELEMENT2
+
+  // nsILink
+  NS_IMETHOD GetLinkState(nsLinkState &aState);
+  NS_IMETHOD SetLinkState(nsLinkState aState);
+  NS_IMETHOD GetHrefURI(nsIURI** aURI);
+  NS_IMETHOD LinkAdded() { return NS_OK; }
+  NS_IMETHOD LinkRemoved() { return NS_OK; }
+
+  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
+                              nsIContent* aBindingParent,
+                              PRBool aCompileEventHandlers);
+  virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
+                              PRBool aNullParent = PR_TRUE);
+  virtual void SetFocus(nsPresContext* aPresContext);
+  virtual PRBool IsFocusable(PRBool *aTabIndex = nsnull);
+
+  virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
+  virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
+  virtual PRBool IsLink(nsIURI** aURI) const;
+  virtual void GetLinkTarget(nsAString& aTarget);
+
+  nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
+                   const nsAString& aValue, PRBool aNotify)
+  {
+    return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
+  }
+  virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
+                           nsIAtom* aPrefix, const nsAString& aValue,
+                           PRBool aNotify);
+  virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
+                             PRBool aNotify);
+
+  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
+
+protected:
+  // The cached visited state
+  nsLinkState mLinkState;
+};
+
+#endif
--- a/content/html/content/src/nsHTMLDivElement.cpp
+++ b/content/html/content/src/nsHTMLDivElement.cpp
@@ -29,79 +29,40 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-#include "nsIDOMHTMLDivElement.h"
+
+#include "nsHTMLDivElement.h"
 #include "nsIDOMEventTarget.h"
-#include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsMappedAttributes.h"
 
-class nsHTMLDivElement : public nsGenericHTMLElement,
-                         public nsIDOMHTMLDivElement
-{
-public:
-  nsHTMLDivElement(nsINodeInfo *aNodeInfo);
-  virtual ~nsHTMLDivElement();
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-
-  // nsIDOMNode
-  NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
-
-  // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
-
-  // nsIDOMHTMLElement
-  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
-
-  // nsIDOMHTMLDivElement
-  NS_DECL_NSIDOMHTMLDIVELEMENT
-
-  virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
-                                nsIAtom* aAttribute,
-                                const nsAString& aValue,
-                                nsAttrValue& aResult);
-  NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
-  virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
-  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-};
-
-
 NS_IMPL_NS_NEW_HTML_ELEMENT(Div)
 
 
 nsHTMLDivElement::nsHTMLDivElement(nsINodeInfo *aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 nsHTMLDivElement::~nsHTMLDivElement()
 {
 }
 
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLDivElement, nsGenericElement) 
 NS_IMPL_RELEASE_INHERITED(nsHTMLDivElement, nsGenericElement) 
 
-
-
-// QueryInterface implementation for nsHTMLDivElement
-NS_HTML_CONTENT_INTERFACE_TABLE_HEAD(nsHTMLDivElement, nsGenericHTMLElement)
-  NS_INTERFACE_TABLE_INHERITED1(nsHTMLDivElement, nsIDOMHTMLDivElement)
-NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLDivElement)
-
 NS_IMPL_ELEMENT_CLONE(nsHTMLDivElement)
 
 
 NS_IMPL_STRING_ATTR(nsHTMLDivElement, Align, align)
 
 
 PRBool
 nsHTMLDivElement::ParseAttribute(PRInt32 aNamespaceID,
new file mode 100644
--- /dev/null
+++ b/content/html/content/src/nsHTMLDivElement.h
@@ -0,0 +1,75 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsHTMLDivElement_h__
+#define nsHTMLDivElement_h__
+
+#include "nsIDOMHTMLDivElement.h"
+#include "nsGenericHTMLElement.h"
+
+class nsHTMLDivElement : public nsGenericHTMLElement,
+                         public nsIDOMHTMLDivElement
+{
+public:
+  nsHTMLDivElement(nsINodeInfo *aNodeInfo);
+  virtual ~nsHTMLDivElement();
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIDOMNode
+  NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
+
+  // nsIDOMElement
+  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+
+  // nsIDOMHTMLElement
+  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
+
+  // nsIDOMHTMLDivElement
+  NS_DECL_NSIDOMHTMLDIVELEMENT
+
+  virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
+                                nsIAtom* aAttribute,
+                                const nsAString& aValue,
+                                nsAttrValue& aResult);
+  NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
+  virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
+  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
+};
+
+#endif
--- a/content/html/content/src/nsHTMLFrameElement.cpp
+++ b/content/html/content/src/nsHTMLFrameElement.cpp
@@ -29,82 +29,40 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-#include "nsIDOMHTMLFrameElement.h"
-#include "nsGenericHTMLElement.h"
+
+#include "nsHTMLFrameElement.h"
 #include "nsGkAtoms.h"
 #include "nsIPresShell.h"
 #include "nsIDocument.h"
 #include "nsIDOMDocument.h"
 #include "nsDOMError.h"
 
-
-class nsHTMLFrameElement : public nsGenericHTMLFrameElement,
-                           public nsIDOMHTMLFrameElement
-{
-public:
-  nsHTMLFrameElement(nsINodeInfo *aNodeInfo);
-  virtual ~nsHTMLFrameElement();
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-
-  // nsIDOMNode
-  NS_FORWARD_NSIDOMNODE(nsGenericHTMLFrameElement::)
-
-  // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
-
-  // nsIDOMHTMLElement
-  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
-
-  // nsIDOMHTMLFrameElement
-  NS_DECL_NSIDOMHTMLFRAMEELEMENT
-
-  // nsIContent
-  virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
-                                nsIAtom* aAttribute,
-                                const nsAString& aValue,
-                                nsAttrValue& aResult);
-  NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
-  nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
-  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-};
-
-
 NS_IMPL_NS_NEW_HTML_ELEMENT(Frame)
 
 
 nsHTMLFrameElement::nsHTMLFrameElement(nsINodeInfo *aNodeInfo)
   : nsGenericHTMLFrameElement(aNodeInfo)
 {
 }
 
 nsHTMLFrameElement::~nsHTMLFrameElement()
 {
 }
 
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLFrameElement, nsGenericElement)
 NS_IMPL_RELEASE_INHERITED(nsHTMLFrameElement, nsGenericElement)
 
-
-// QueryInterface implementation for nsHTMLFrameElement
-NS_HTML_CONTENT_INTERFACE_TABLE_HEAD(nsHTMLFrameElement,
-                                     nsGenericHTMLFrameElement)
-  NS_INTERFACE_TABLE_INHERITED1(nsHTMLFrameElement, nsIDOMHTMLFrameElement)
-NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLFrameElement)
-
-
 NS_IMPL_ELEMENT_CLONE(nsHTMLFrameElement)
 
 
 NS_IMPL_STRING_ATTR(nsHTMLFrameElement, FrameBorder, frameborder)
 NS_IMPL_URI_ATTR(nsHTMLFrameElement, LongDesc, longdesc)
 NS_IMPL_STRING_ATTR(nsHTMLFrameElement, MarginHeight, marginheight)
 NS_IMPL_STRING_ATTR(nsHTMLFrameElement, MarginWidth, marginwidth)
 NS_IMPL_STRING_ATTR(nsHTMLFrameElement, Name, name)
new file mode 100644
--- /dev/null
+++ b/content/html/content/src/nsHTMLFrameElement.h
@@ -0,0 +1,76 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsHTMLFrameElement_h__
+#define nsHTMLFrameElement_h__
+
+#include "nsIDOMHTMLFrameElement.h"
+#include "nsGenericHTMLElement.h"
+
+class nsHTMLFrameElement : public nsGenericHTMLFrameElement,
+                           public nsIDOMHTMLFrameElement
+{
+public:
+  nsHTMLFrameElement(nsINodeInfo *aNodeInfo);
+  virtual ~nsHTMLFrameElement();
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIDOMNode
+  NS_FORWARD_NSIDOMNODE(nsGenericHTMLFrameElement::)
+
+  // nsIDOMElement
+  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
+
+  // nsIDOMHTMLElement
+  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
+
+  // nsIDOMHTMLFrameElement
+  NS_DECL_NSIDOMHTMLFRAMEELEMENT
+
+  // nsIContent
+  virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
+                                nsIAtom* aAttribute,
+                                const nsAString& aValue,
+                                nsAttrValue& aResult);
+  NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
+  nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
+  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
+};
+
+#endif
--- a/content/html/content/src/nsHTMLFrameSetElement.cpp
+++ b/content/html/content/src/nsHTMLFrameSetElement.cpp
@@ -29,101 +29,25 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-#include "nsIDOMHTMLFrameSetElement.h"
+
+#include "nsHTMLFrameSetElement.h"
 #include "nsIDOMEventTarget.h"
-#include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
-#include "nsIFrameSetElement.h"
 #include "nsIHTMLDocument.h"
 #include "nsIDocument.h"
 
-class nsHTMLFrameSetElement : public nsGenericHTMLElement,
-                              public nsIDOMHTMLFrameSetElement,
-                              public nsIFrameSetElement
-{
-public:
-  nsHTMLFrameSetElement(nsINodeInfo *aNodeInfo);
-  virtual ~nsHTMLFrameSetElement();
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-
-  // nsIDOMNode
-  NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
-
-  // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
-
-  // nsIDOMHTMLElement
-  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
-
-  // nsIDOMHTMLFrameSetElement
-  NS_DECL_NSIDOMHTMLFRAMESETELEMENT
-
-  // These override the SetAttr methods in nsGenericHTMLElement (need
-  // both here to silence compiler warnings).
-  nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
-                   const nsAString& aValue, PRBool aNotify)
-  {
-    return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
-  }
-  virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
-                           nsIAtom* aPrefix, const nsAString& aValue,
-                           PRBool aNotify);
-
-  // nsIFramesetElement
-  NS_IMETHOD GetRowSpec(PRInt32 *aNumValues, const nsFramesetSpec** aSpecs);
-  NS_IMETHOD GetColSpec(PRInt32 *aNumValues, const nsFramesetSpec** aSpecs);
-
-  virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
-                                nsIAtom* aAttribute,
-                                const nsAString& aValue,
-                                nsAttrValue& aResult);
-  virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
-                                              PRInt32 aModType) const;
-
-  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-
-private:
-  nsresult ParseRowCol(const nsAString& aValue,
-                       PRInt32&         aNumSpecs,
-                       nsFramesetSpec** aSpecs);
-
-  /**
-   * The number of size specs in our "rows" attr
-   */
-  PRInt32          mNumRows;
-  /**
-   * The number of size specs in our "cols" attr
-   */
-  PRInt32          mNumCols;
-  /**
-   * The style hint to return for the rows/cols attrs in
-   * GetAttributeChangeHint
-   */
-  nsChangeHint      mCurrentRowColHint;
-  /**
-   * The parsed representation of the "rows" attribute
-   */
-  nsAutoArrayPtr<nsFramesetSpec>  mRowSpecs; // parsed, non-computed dimensions
-  /**
-   * The parsed representation of the "cols" attribute
-   */
-  nsAutoArrayPtr<nsFramesetSpec>  mColSpecs; // parsed, non-computed dimensions
-};
-
 NS_IMPL_NS_NEW_HTML_ELEMENT(FrameSet)
 
 
 nsHTMLFrameSetElement::nsHTMLFrameSetElement(nsINodeInfo *aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo), mNumRows(0), mNumCols(0),
     mCurrentRowColHint(NS_STYLE_HINT_REFLOW)
 {
 }
@@ -132,25 +56,16 @@ nsHTMLFrameSetElement::~nsHTMLFrameSetEl
 {
 }
 
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLFrameSetElement, nsGenericElement) 
 NS_IMPL_RELEASE_INHERITED(nsHTMLFrameSetElement, nsGenericElement) 
 
 
-// QueryInterface implementation for nsHTMLFrameSetElement
-NS_HTML_CONTENT_INTERFACE_TABLE_HEAD(nsHTMLFrameSetElement,
-                                      nsGenericHTMLElement)
-  NS_INTERFACE_TABLE_INHERITED2(nsHTMLFrameSetElement,
-                                nsIDOMHTMLFrameSetElement,
-                                nsIFrameSetElement)
-NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLFrameSetElement)
-
-
 NS_IMPL_ELEMENT_CLONE(nsHTMLFrameSetElement)
 
 
 NS_IMPL_STRING_ATTR(nsHTMLFrameSetElement, Cols, cols)
 NS_IMPL_STRING_ATTR(nsHTMLFrameSetElement, Rows, rows)
 
 nsresult
 nsHTMLFrameSetElement::SetAttr(PRInt32 aNameSpaceID,
new file mode 100644
--- /dev/null
+++ b/content/html/content/src/nsHTMLFrameSetElement.h
@@ -0,0 +1,120 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsHTMLFrameSetElement_h__
+#define nsHTMLFrameSetElement_h__
+
+#include "nsIDOMHTMLFrameSetElement.h"
+#include "nsIFrameSetElement.h"
+#include "nsGenericHTMLElement.h"
+
+class nsHTMLFrameSetElement : public nsGenericHTMLElement,
+                              public nsIDOMHTMLFrameSetElement,
+                              public nsIFrameSetElement
+{
+public:
+  nsHTMLFrameSetElement(nsINodeInfo *aNodeInfo);
+  virtual ~nsHTMLFrameSetElement();
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIDOMNode
+  NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
+
+  // nsIDOMElement
+  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+
+  // nsIDOMHTMLElement
+  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
+
+  // nsIDOMHTMLFrameSetElement
+  NS_DECL_NSIDOMHTMLFRAMESETELEMENT
+
+  // These override the SetAttr methods in nsGenericHTMLElement (need
+  // both here to silence compiler warnings).
+  nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
+                   const nsAString& aValue, PRBool aNotify)
+  {
+    return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
+  }
+  virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
+                           nsIAtom* aPrefix, const nsAString& aValue,
+                           PRBool aNotify);
+
+  // nsIFramesetElement
+  NS_IMETHOD GetRowSpec(PRInt32 *aNumValues, const nsFramesetSpec** aSpecs);
+  NS_IMETHOD GetColSpec(PRInt32 *aNumValues, const nsFramesetSpec** aSpecs);
+
+  virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
+                                nsIAtom* aAttribute,
+                                const nsAString& aValue,
+                                nsAttrValue& aResult);
+  virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
+                                              PRInt32 aModType) const;
+
+  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
+
+private:
+  nsresult ParseRowCol(const nsAString& aValue,
+                       PRInt32&         aNumSpecs,
+                       nsFramesetSpec** aSpecs);
+
+  /**
+   * The number of size specs in our "rows" attr
+   */
+  PRInt32          mNumRows;
+  /**
+   * The number of size specs in our "cols" attr
+   */
+  PRInt32          mNumCols;
+  /**
+   * The style hint to return for the rows/cols attrs in
+   * GetAttributeChangeHint
+   */
+  nsChangeHint      mCurrentRowColHint;
+  /**
+   * The parsed representation of the "rows" attribute
+   */
+  nsAutoArrayPtr<nsFramesetSpec>  mRowSpecs; // parsed, non-computed dimensions
+  /**
+   * The parsed representation of the "cols" attribute
+   */
+  nsAutoArrayPtr<nsFramesetSpec>  mColSpecs; // parsed, non-computed dimensions
+};
+
+#endif
--- a/content/html/content/src/nsHTMLIFrameElement.cpp
+++ b/content/html/content/src/nsHTMLIFrameElement.cpp
@@ -29,84 +29,43 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-#include "nsIDOMHTMLIFrameElement.h"
-#include "nsGenericHTMLElement.h"
+
+#include "nsHTMLIFrameElement.h"
 #include "nsGkAtoms.h"
 #include "nsPresContext.h"
 #include "nsIPresShell.h"
 #include "nsIDocument.h"
 #include "nsMappedAttributes.h"
 #include "nsDOMError.h"
 #include "nsRuleData.h"
 #include "nsStyleConsts.h"
 
-class nsHTMLIFrameElement : public nsGenericHTMLFrameElement,
-                            public nsIDOMHTMLIFrameElement
-{
-public:
-  nsHTMLIFrameElement(nsINodeInfo *aNodeInfo);
-  virtual ~nsHTMLIFrameElement();
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-
-  // nsIDOMNode
-  NS_FORWARD_NSIDOMNODE(nsGenericHTMLFrameElement::)
-
-  // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
-
-  // nsIDOMHTMLElement
-  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
-
-  // nsIDOMHTMLIFrameElement
-  NS_DECL_NSIDOMHTMLIFRAMEELEMENT
-
-  // nsIContent
-  virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
-                                nsIAtom* aAttribute,
-                                const nsAString& aValue,
-                                nsAttrValue& aResult);
-  NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
-  virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
-
-  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-};
-
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(IFrame)
 
-
 nsHTMLIFrameElement::nsHTMLIFrameElement(nsINodeInfo *aNodeInfo)
   : nsGenericHTMLFrameElement(aNodeInfo)
 {
 }
 
 nsHTMLIFrameElement::~nsHTMLIFrameElement()
 {
 }
 
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLIFrameElement,nsGenericElement)
 NS_IMPL_RELEASE_INHERITED(nsHTMLIFrameElement,nsGenericElement)
 
-// QueryInterface implementation for nsHTMLIFrameElement
-NS_HTML_CONTENT_INTERFACE_TABLE_HEAD(nsHTMLIFrameElement,
-                                     nsGenericHTMLFrameElement)
-  NS_INTERFACE_TABLE_INHERITED1(nsHTMLIFrameElement, nsIDOMHTMLIFrameElement)
-NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLIFrameElement)
-
-
 NS_IMPL_ELEMENT_CLONE(nsHTMLIFrameElement)
 
 
 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Align, align)
 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, FrameBorder, frameborder)
 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, Height, height)
 NS_IMPL_URI_ATTR(nsHTMLIFrameElement, LongDesc, longdesc)
 NS_IMPL_STRING_ATTR(nsHTMLIFrameElement, MarginHeight, marginheight)
new file mode 100644
--- /dev/null
+++ b/content/html/content/src/nsHTMLIFrameElement.h
@@ -0,0 +1,78 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsHTMLIFrameElement_h__
+#define nsHTMLIFrameElement_h__
+
+#include "nsIFrameSetElement.h"
+#include "nsGenericHTMLElement.h"
+#include "nsIDOMHTMLIFrameElement.h"
+
+class nsHTMLIFrameElement : public nsGenericHTMLFrameElement,
+                            public nsIDOMHTMLIFrameElement
+{
+public:
+  nsHTMLIFrameElement(nsINodeInfo *aNodeInfo);
+  virtual ~nsHTMLIFrameElement();
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIDOMNode
+  NS_FORWARD_NSIDOMNODE(nsGenericHTMLFrameElement::)
+
+  // nsIDOMElement
+  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLFrameElement::)
+
+  // nsIDOMHTMLElement
+  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLFrameElement::)
+
+  // nsIDOMHTMLIFrameElement
+  NS_DECL_NSIDOMHTMLIFRAMEELEMENT
+
+  // nsIContent
+  virtual PRBool ParseAttribute(PRInt32 aNamespaceID,
+                                nsIAtom* aAttribute,
+                                const nsAString& aValue,
+                                nsAttrValue& aResult);
+  NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
+  virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const;
+
+  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
+};
+
+#endif
--- a/content/html/content/src/nsHTMLSpanElement.cpp
+++ b/content/html/content/src/nsHTMLSpanElement.cpp
@@ -29,73 +29,40 @@
  * under the terms of either the GPL or the LGPL, and not to allow others to
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
-#include "nsIDOMHTMLElement.h"
+
+#include "nsHTMLSpanElement.h"
 #include "nsIDOMEventTarget.h"
-#include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
 #include "nsPresContext.h"
 #include "nsIAtom.h"
 #include "nsRuleData.h"
 
-class nsHTMLSpanElement : public nsGenericHTMLElement,
-                          public nsIDOMHTMLElement
-{
-public:
-  nsHTMLSpanElement(nsINodeInfo *aNodeInfo);
-  virtual ~nsHTMLSpanElement();
-
-  // nsISupports
-  NS_DECL_ISUPPORTS_INHERITED
-
-  // nsIDOMNode
-  NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
-
-  // nsIDOMElement
-  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
-
-  // nsIDOMHTMLElement
-  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
-
-  virtual nsresult GetInnerHTML(nsAString& aInnerHTML);
-  virtual nsresult SetInnerHTML(const nsAString& aInnerHTML);
-
-  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
-};
-
-
 NS_IMPL_NS_NEW_HTML_ELEMENT(Span)
 
-
 nsHTMLSpanElement::nsHTMLSpanElement(nsINodeInfo *aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
 {
 }
 
 nsHTMLSpanElement::~nsHTMLSpanElement()
 {
 }
 
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLSpanElement, nsGenericElement)
 NS_IMPL_RELEASE_INHERITED(nsHTMLSpanElement, nsGenericElement)
 
-
-// QueryInterface implementation for nsHTMLSpanElement
-NS_HTML_CONTENT_INTERFACE_TABLE_HEAD(nsHTMLSpanElement, nsGenericHTMLElement)
-NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLSpanElement)
-
-
 NS_IMPL_ELEMENT_CLONE(nsHTMLSpanElement)
 
 
 nsresult
 nsHTMLSpanElement::GetInnerHTML(nsAString& aInnerHTML)
 {
   if (mNodeInfo->Equals(nsGkAtoms::xmp) ||
       mNodeInfo->Equals(nsGkAtoms::plaintext)) {
new file mode 100644
--- /dev/null
+++ b/content/html/content/src/nsHTMLSpanElement.h
@@ -0,0 +1,69 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Mozilla Communicator client code.
+ *
+ * The Initial Developer of the Original Code is
+ * Netscape Communications Corporation.
+ * Portions created by the Initial Developer are Copyright (C) 1998
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either of the GNU General Public License Version 2 or later (the "GPL"),
+ * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#ifndef nsHTMLSpanElement_h__
+#define nsHTMLSpanElement_h__
+
+#include "nsIDOMHTMLElement.h"
+#include "nsGenericHTMLElement.h"
+
+class nsHTMLSpanElement : public nsGenericHTMLElement,
+                          public nsIDOMHTMLElement
+{
+public:
+  nsHTMLSpanElement(nsINodeInfo *aNodeInfo);
+  virtual ~nsHTMLSpanElement();
+
+  // nsISupports
+  NS_DECL_ISUPPORTS_INHERITED
+
+  // nsIDOMNode
+  NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
+
+  // nsIDOMElement
+  NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
+
+  // nsIDOMHTMLElement
+  NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
+
+  virtual nsresult GetInnerHTML(nsAString& aInnerHTML);
+  virtual nsresult SetInnerHTML(const nsAString& aInnerHTML);
+
+  virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
+};
+
+#endif
--- a/content/html/document/src/Makefile.in
+++ b/content/html/document/src/Makefile.in
@@ -86,16 +86,18 @@ CPPSRCS		= \
 		nsHTMLDocument.cpp \
 		nsMediaDocument.cpp \
 		nsPluginDocument.cpp \
 		nsImageDocument.cpp \
 		nsWyciwygChannel.cpp \
 		nsWyciwygProtocolHandler.cpp \
 		$(NULL)
 
+GQI_SRCS = htmldocument.gqi
+
 EXPORTS		= \
 		nsIHTMLDocument.h \
 		$(NULL)
 
 # we don't want the shared lib, but we want to force the creation of a static lib.
 FORCE_STATIC_LIB = 1
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/content/html/document/src/htmldocument.gqi
@@ -0,0 +1,17 @@
+%import "contentbase.gqi"
+
+%import-idl "nsIDOMHTMLDocument.idl"
+%import-idl "nsIDOMNSHTMLDocument.idl"
+
+%{C++
+#include "nsHTMLDocument.h"
+%}
+
+%pseudo-iid nsIHTMLDocument 61e989a8-70cd-4582-845e-6e5e12559a83
+
+NS_INTERFACE_MAP_BEGIN(nsHTMLDocument, nsDocument)
+  NS_INTERFACE_MAP_ENTRY(nsIHTMLDocument)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLDocument)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMNSHTMLDocument)
+  NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(HTMLDocument)
+NS_INTERFACE_MAP_END
--- a/content/html/document/src/nsHTMLDocument.cpp
+++ b/content/html/document/src/nsHTMLDocument.cpp
@@ -411,28 +411,16 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mForms, nsIDOMNodeList)
   NS_IMPL_CYCLE_COLLECTION_TRAVERSE_NSCOMPTR_AMBIGUOUS(mFormControls,
                                                        nsIDOMNodeList)
 NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 
 NS_IMPL_ADDREF_INHERITED(nsHTMLDocument, nsDocument)
 NS_IMPL_RELEASE_INHERITED(nsHTMLDocument, nsDocument)
 
-
-// QueryInterface implementation for nsHTMLDocument
-NS_INTERFACE_TABLE_HEAD_CYCLE_COLLECTION_INHERITED(nsHTMLDocument)
-  NS_INTERFACE_TABLE_INHERITED3(nsHTMLDocument,
-                                nsIHTMLDocument,
-                                nsIDOMHTMLDocument,
-                                nsIDOMNSHTMLDocument)
-  NS_INTERFACE_TABLE_TO_MAP_SEGUE
-  NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(HTMLDocument)
-NS_INTERFACE_MAP_END_INHERITING(nsDocument)
-
-
 nsresult
 nsHTMLDocument::Init()
 {
   nsresult rv = nsDocument::Init();
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Now reset the case-sensitivity of the CSSLoader, since we default
   // to being HTML, not XHTML.  Also, reset the compatibility mode to
new file mode 100644
--- /dev/null
+++ b/xpcom/base/gqi.py
@@ -0,0 +1,788 @@
+# -*- Mode: Python: tab-width: 8; indent-tabs-mode: nil; python-indent: 4 -*-
+
+"""Implement QueryInterface using optimized generated code."""
+
+import os, errno, re, sys, sets
+
+# Global controlling debug output to sys.stderr
+debug = False
+
+def findfile(f, curfile, includedirs):
+    """Find a file 'f' by looking in the directory of the current file
+    and then in all directories specified by -I until it is found. Returns
+    the path of the file that was found.
+
+    @raises IOError is the file is not found."""
+
+    sdirs = [os.path.dirname(curfile)]
+    sdirs.extend(includedirs)
+
+    for dir in sdirs:
+        t = os.path.join(dir, f)
+        if os.path.exists(t):
+            return t
+
+    raise IOError(errno.ENOENT, "File not found", f)
+
+# Giant parsing loop: parse input files into the internal representation,
+# keeping track of file/line numbering information. This iterator automatically
+# skips blank lines and lines beginning with //
+
+class IterFile(object):
+    def __init__(self, file):
+        self._file = file
+        self._iter = open(file)
+        self._lineno = 0
+
+    def __iter__(self):
+        return self
+
+    def next(self):
+        self._lineno += 1
+        line = self._iter.next().strip()
+        if line == '' or line.startswith('//'):
+            return self.next()
+        return line
+
+    def loc(self):
+        return "%s:%i" % (self._file, self._lineno)
+
+class uniqdict(dict):
+    """A subclass of dict that will throw an error if you attempt to set the same key to different values."""
+    def __setitem__(self, key, value):
+        if key in self and not value == self[key]:
+            raise IndexError('Key "%s" already present in uniqdict' % key)
+
+        dict.__setitem__(self, key, value)
+
+    def update(self, d):
+        for key, value in d.iteritems():
+            if key in self and not value == self[key]:
+                raise IndexError('Key "%s" already present in uniqdict' % key)
+
+        dict.update(self, d)
+
+def dump_hex_tuple(t):
+    return "(%s)" % ", ".join(["%#x" % i for i in t])
+
+class UUID(object):
+    def __init__(self, name, iidstr, pseudo=False, base=None):
+        """This method *assumes* that the UUID is validly formed."""
+        self.name = name
+        self.pseudo = pseudo
+        self.base = base
+
+        # iid is in 32-16-16-8*8 format, as hex *strings*
+        iid = (iidstr[0:8], iidstr[9:13], iidstr[14:18],
+               iidstr[19:21], iidstr[21:23], iidstr[24:26], iidstr[26:28],
+               iidstr[28:30], iidstr[30:32], iidstr[32:34], iidstr[34:36])
+
+        self.iid = iid
+
+        # (big_endian_words, little_endian_words)
+        self.words = (
+            (int(iid[0], 16),
+             int(iid[1] + iid[2], 16),
+             int("".join([iid[i] for i in xrange(3, 7)]), 16),
+             int("".join([iid[i] for i in xrange(7, 11)]), 16)),
+            (int(iid[0], 16),
+             int(iid[2] + iid[1], 16),
+             int("".join([iid[i] for i in xrange(6, 2, -1)]), 16),
+             int("".join([iid[i] for i in xrange(10, 6, -1)]), 16)))
+
+        if debug:
+            print >>sys.stderr, "%r" % self
+            print >>sys.stderr, "  bigendian: %s" % dump_hex_tuple(self.words[False])
+            print >>sys.stderr, "  littleendian: %r" % dump_hex_tuple(self.words[True])
+
+    def __eq__(self, uuid):
+        return self.iid == uuid.iid and self.name == uuid.name
+
+    def __repr__(self):
+        return """UUID(%r, "%s-%s-%s-%s-%s", pseudo=%r, base=%r)""" % (
+            self.name, self.iid[0], self.iid[1], self.iid[2], self.iid[3] + self.iid[4],
+            "".join([self.iid[i] for i in xrange(5, 11)]), self.pseudo, self.base)
+
+    def asstruct(self):
+        return "{ 0x%s, 0x%s, 0x%s, { 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s, 0x%s } }" % self.iid
+
+    def runtime_assertion(self):
+        if self.pseudo:
+            return """
+            static const nsID kGQI_%(iname)s = %(struct)s;
+            NS_ASSERTION(NS_GET_IID(%(iname)s).Equals(kGQI_%(iname)s),
+                         "GQI pseudo-IID doesn't match reality.");
+            """ % {
+                'iname': self.name,
+                'struct': self.asstruct()
+                }
+        else:
+            return ""
+
+_uuid_pattern_string = r'[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}'
+
+_includefinder = re.compile(r'#include\s+(?:"|\<)(?P<filename>[a-z\.\-\_0-9]+)(?:"|\>)\s*$', re.I)
+_uuidfinder = re.compile(r'uuid\((?P<iid>' + _uuid_pattern_string + r')\)', re.I)
+_namefinder = re.compile(r'interface\s+(?P<interface>[A-Za-z_0-9]+)\s+:\s+(?P<base>[A-Za-z]+)')
+
+def importidl(file, includedirs):
+    """Parse an IDL file. Returns (mapofiids, setofdeps)"""
+
+    iids = {}
+    deps = sets.Set()
+    deps.add(file)
+
+    f = IterFile(file)
+    for line in f:
+        if line.startswith('%{'):
+            # Skip literal IDL blocks such as %{C++ %}
+            for line in f:
+                if line.startswith('%}'):
+                    break
+            continue
+
+        m = _includefinder.match(line)
+        if m is not None:
+            importediids, importeddeps = importidl(findfile(m.group('filename'), file, includedirs), includedirs)
+            iids.update(importediids)
+            deps |= importeddeps
+            continue
+
+        m = _uuidfinder.search(line)
+        if m is not None:
+            iid = m.group('iid')
+            line = f.next()
+            if line == 'interface nsISupports {':
+                iids['nsISupports'] = UUID('nsISupports', iid)
+            else:
+                m = _namefinder.match(line)
+                if m is None:
+                    raise Exception("%s: expected interface" % f.loc())
+
+                iids[m.group('interface')] = \
+                    UUID(m.group('interface'), iid, base=m.group('base'))
+
+    return iids, deps
+
+def gqi(ifaces, endian):
+    """Find an algorithm that uniquely identifies interfaces by a single
+    word. Returns (indexfunction, table)"""
+    for bits in xrange(3, 10):
+        bitmask = (1 << bits) - 1
+        for word in xrange(0, 4):
+            for sh in xrange(0, 33 - bits):
+                shmask = bitmask << sh
+
+                # print "Trying word: %i, bits: %i, shift: %i" % (word, bits, sh)
+                # print "Bitmask: %x" % (bitmask)
+                # print "Shifter mask: %x" % (shmask)
+
+                l = list([None for i in xrange(0, 1 << bits)])
+                try:
+                    for i in xrange(0, len(ifaces)):
+                        n = (ifaces[i].uuid.words[endian][word] & shmask) >> sh
+                        if l[n] is not None:
+                            # print "found conflict, index %i" % n
+                            # print "old iface: %s" % l[n].uuid
+                            # print "new iface: %s" % i.uuid
+                            raise IndexError()
+
+                        l[n] = i
+
+                except IndexError:
+                    continue
+    
+                # If we got here, we're ok... create the table we want
+                indexfunc = "(reinterpret_cast<const PRUint32*>(&aIID)[%i] & 0x%x) >> %i" % (word, shmask, sh)
+                return indexfunc, l
+
+    raise Exception("No run of 9 bits within a word was unique!: interfaces: %s" % [i.uuid for i in ifaces])
+
+def basecast(item, baselist):
+    """Returns a string where an item is static_cast through a list of bases."""
+    for base in baselist:
+        item = "static_cast<%s*>(%s)" % (base, item)
+
+    return item
+
+class QIImpl(object):
+    _default_unfound = """
+      *aResult = nsnull;
+      return NS_NOINTERFACE;
+    """
+
+    _qiimpl = """
+    enum %(cname)s_QIActionType {
+      %(actionenums)s
+    };
+
+    struct %(cname)s_QIAction {
+      const nsID *iid;
+      %(actiontype)s
+      union {
+        void *ptr;
+        %(actiondata)s
+      } data;
+    };
+
+    NS_IMETHODIMP %(cname)s::QueryInterface(REFNSIID aIID, void **aResult)
+    {
+#ifdef DEBUG
+      %(pseudoassertions)s
+#endif
+
+      static const PRUint8 kLookupTable[] = {
+#ifdef IS_BIG_ENDIAN
+        %(biglookup)s
+#else
+        %(littlelookup)s
+#endif
+      };
+
+      static const %(cname)s_QIAction kActionTable[] = {
+        %(actiontable)s
+      };
+
+      nsISupports* found = nsnull;
+      const %(cname)s_QIAction *entry;
+      PRUint32 index =
+#ifdef IS_BIG_ENDIAN
+        %(bigindexfunc)s;
+#else
+        %(littleindexfunc)s;
+#endif
+
+      PRUint8 action = kLookupTable[index];
+      if (action == 0xFF)
+        goto unfound;
+
+      entry = kActionTable + action;
+      if (!entry->iid->Equals(aIID))
+        goto unfound;
+
+      %(actioncode)s
+
+      NS_NOTREACHED("Unhandled case?");
+
+      %(nullcheck)s
+
+    exit_addref:
+      NS_ASSERTION(found, "Interface should have been found by now.");
+      found->AddRef();
+      *aResult = found;
+      return NS_OK;
+
+    unfound:
+      %(unfound)s
+    }"""
+
+    _datatypes = """
+        %(type)s %(name)s;
+    """
+
+    _actiontable_entry = """
+        {
+          &NS_GET_IID(%(iname)s),
+          %(enumtype)s
+          %(emitTable)s
+        },
+    """
+
+    _actioncode_multi = """
+      switch (entry->action) {
+      %s
+      }
+    """
+
+    _actioncode_multi_entry = """
+      case %(cname)s_%(enumtype)s:
+        %(setResult)s
+    """
+
+    _nullcheck = """
+    exit_nullcheck_addref:
+      if (!found)
+        return NS_ERROR_OUT_OF_MEMORY;
+    """
+
+    _refcounting = """
+    NS_IMPL_%(threadsafe)sADDREF(%(cname)s)
+    NS_IMPL_%(threadsafe)sRELEASE(%(cname)s)
+    """
+
+    def __init__(self, cname, ifaces, emitrefcount=False,
+                 threadsafe="", unfound=None, base=None):
+        self.cname = cname
+        self.emitrefcount = emitrefcount
+        self.threadsafe = threadsafe
+        self.base = base
+        self.ifaces = ifaces
+        self.unfound = unfound
+
+        # ensure that interfaces are not duplicated
+        ifdict = uniqdict()
+        for i, baselist in self.iter_all_ifaces():
+            ifdict[i.uuid.name] = i
+
+    def iter_self_and_bases(self):
+        """yields (impl, baselist) for all bases"""
+        impl = self
+        baselist = []
+        
+        while impl is not None:
+            baselist = list(baselist)
+            baselist.append(impl.cname)
+            yield impl, baselist
+            impl = impl.base
+
+    def iter_all_ifaces(self):
+        """yields (iface, baselist) for all interfaces"""
+        for impl, baselist in self.iter_self_and_bases():
+            for i in impl.ifaces:
+                yield i, baselist
+
+    def output(self, fd):
+        unfound = None
+        for impl, baselist in self.iter_self_and_bases():
+            if impl.unfound is not None:
+                unfound = impl.unfound
+                break
+
+        if unfound is None:
+            unfound = self._default_unfound
+
+        needsnullcheck = False
+        actions = sets.Set()
+        types = uniqdict()
+        for i, baselist in self.iter_all_ifaces():
+            action = i.action
+            actions.add(action)
+            if action.needsnullcheck:
+                needsnullcheck = True
+
+            if action.datatype:
+                types[action.varname] = action.datatype
+
+        actionenums = ", ".join(["%s_%s" % (self.cname, action.enumtype)
+                                 for action in actions])
+
+        # types.ptr is explicitly first (for initialization), so delete it
+        types.pop('ptr', None)
+
+        actiondata = "".join([self._datatypes % {'type': type,
+                                                 'name': name}
+                              for name, type in types.iteritems()])
+
+        # list of (i, baselist)
+        ilist = [i for i in self.iter_all_ifaces()]
+
+        pseudoassertions = "".join([i.uuid.runtime_assertion()
+                                    for i, baselist in ilist])
+
+        bigindexfunc, bigitable = gqi([iface for iface, baselist in ilist], False)
+        littleindexfunc, littleitable = gqi([iface for iface, baselist in ilist], True)
+
+        # (falseval, trueval)[conditional expression] is the python
+        # ternary operator
+        biglookup = ",\n".join([(str(i), "0xFF")[i is None]
+                                for i in bigitable])
+        littlelookup = ",\n".join([(str(i), "0xFF")[i is None]
+                                   for i in littleitable])
+
+        if len(actions) > 1:
+            actiontype = "%s_QIActionType action;" % self.cname
+            enumtype = "%(cname)s_%(enumtype)s,"
+        else:
+            actiontype = ""
+            enumtype = ""
+
+        actiontable = "".join([self._actiontable_entry %
+               {'enumtype': enumtype % {'cname': self.cname, 
+                                        'enumtype': iface.action.enumtype},
+                'iname': iface.uuid.name,
+                'emitTable': iface.emitTable(self.cname, baselist)}
+                               for iface, baselist in ilist])
+
+        if len(actions) == 1:
+            actioncode = iter(actions).next().setResult % {
+                'classname': self.cname
+                }
+        else:
+            actioncode = self._actioncode_multi % (
+                "".join([self._actioncode_multi_entry % {
+                            'cname': self.cname,
+                            'enumtype': action.enumtype,
+                            'setResult': action.setResult % {'classname': self.cname}}
+                         for action in actions])
+                )
+                
+        if needsnullcheck:
+            nullcheck = self._nullcheck
+        else:
+            nullcheck = ""
+
+        print >>fd, self._qiimpl % {
+            'cname': self.cname,
+            'actionenums': actionenums,
+            'actiontype': actiontype,
+            'actiondata': actiondata,
+            'pseudoassertions': pseudoassertions,
+            'biglookup': biglookup,
+            'littlelookup': littlelookup,
+            'actiontable': actiontable,
+            'bigindexfunc': bigindexfunc,
+            'littleindexfunc': littleindexfunc,
+            'actioncode': actioncode,
+            'nullcheck': nullcheck,
+            'unfound': unfound
+            }
+
+        if self.emitrefcount:
+            print >>fd, self._refcounting % {
+                'threadsafe': self.threadsafe,
+                'cname': self.cname
+                }
+
+class PointerAction(object):
+    enumtype = "STATIC_POINTER"
+    datatype = "void*"
+    varname  = "ptr"
+    setResult = """*aResult = entry->data.ptr;
+                   return NS_OK;"""
+    needsnullcheck = False
+
+nsCycleCollectionParticipant = UUID("nsCycleCollectionParticipant", "9674489b-1f6f-4550-a730-ccaedd104cf9", pseudo=True)
+
+class CCParticipantResponse(object):
+    action = PointerAction
+
+    def __init__(self, classname):
+        self.classname = classname
+        self.uuid = nsCycleCollectionParticipant
+
+    def emitTable(self, classname, baselist):
+        return "{ &NS_CYCLE_COLLECTION_NAME(%s) }" % classname
+
+class TearoffResponse(object):
+    """Because each tearoff is different, this response is its own action."""
+    datatype = None
+    needsnullcheck = True
+
+    def __init__(self, uuid, allocator):
+        self.setResult = """
+            found = static_cast<%s*>(%s);
+            goto exit_nullcheck_addref;
+    """ % (uuid.name, allocator)
+        self.uuid = uuid
+        self.action = self
+        self.enumtype = "NS_TEAROFF_%s" % uuid.name
+
+    def emitTable(self, classname, baselist):
+        return "{0}"
+
+nsCycleCollectionISupports = UUID("nsCycleCollectionISupports", "c61eac14-5f7a-4481-965e-7eaa6effa85f", pseudo=True)
+
+class CCSupportsAction(object):
+    enumtype = "CC_ISUPPORTS"
+    datatype = None
+    setResult = """
+        found = NS_CYCLE_COLLECTION_CLASSNAME(%(classname)s)::Upcast(this);
+        goto exit_nullcheck_addref;
+    """
+    needsnullcheck = True
+
+class CCISupportsResponse(object):
+    action = CCSupportsAction
+
+    def __init__(self, classname):
+        self.classname = classname
+        self.uuid = nsCycleCollectionISupports
+
+    def emitTable(self, classname, baselist):
+        return "{ 0 }"
+
+nsIClassInfo = UUID("nsIClassInfo", "986c11d0-f340-11d4-9075-0010a4e73d9a", pseudo=True)
+
+class DOMCIResult(object):
+    datatype = None
+    enumtype = "DOMCI"
+    needsnullcheck = True
+
+    def __init__(self, domciname):
+        self.action = self
+        self.uuid = nsIClassInfo
+        self.setResult = """
+      found = NS_GetDOMClassInfoInstance(eDOMClassInfo_%s_id);
+      goto exit_nullcheck_addref;
+    """ % domciname
+
+    def emitTable(self, classname, baselist):
+        return "{ 0 }"
+
+class OffsetAction(object):
+    enumtype = "OFFSET_THIS_ADDREF"
+    datatype = "PRUint32"
+    varname  = "offset"
+    setResult = """
+        found = reinterpret_cast<nsISupports*>(reinterpret_cast<char*>(this) + entry->data.offset);
+        goto exit_addref;
+    """
+    needsnullcheck = False
+
+class OffsetThisQIResponse(object):
+    action = OffsetAction
+
+    def __init__(self, uuid):
+        self.uuid = uuid
+
+    def emitTable(self, classname, baselist):
+        casted = basecast("((%s*) 0x1000)" % classname, baselist)
+
+        return """
+   { reinterpret_cast<void*>(
+       reinterpret_cast<char*>(
+         static_cast<%(iname)s*>(%(casted)s)) -
+       reinterpret_cast<char*>(%(casted)s))
+   }""" % { 'casted': casted,
+            'iname': self.uuid.name }
+
+class OffsetFutureThisQIResponse(OffsetThisQIResponse):
+    action = OffsetAction
+
+    def __init__(self, uuid):
+        self.uuid = uuid
+
+    def emitTable(self, classname, baselist):
+        casted = "((%s*) 0x1000)" % classname
+
+        return """
+   { reinterpret_cast<void*>(
+       reinterpret_cast<char*>(
+         static_cast<%(iname)s*>(%(casted)s)) -
+       reinterpret_cast<char*>(%(casted)s))
+   }""" % { 'casted': casted,
+            'iname': self.uuid.name }
+
+class OffsetThisQIResponseAmbiguous(OffsetThisQIResponse):
+    def __init__(self, uuid, intermediate):
+        self.intermediate = intermediate
+        OffsetThisQIResponse.__init__(self, uuid)
+
+    def emitTable(self, classname, baselist):
+        casted = basecast("((%s*) 0x1000)" % classname, baselist)
+
+        return """
+   { reinterpret_cast<void*>(
+       reinterpret_cast<char*>(
+         static_cast<%(iname)s*>(
+           static_cast<%(intermediate)s*>(%(casted)s))) -
+       reinterpret_cast<char*>(%(casted)s))
+   }""" % \
+            { 'casted': casted,
+              'iname': self.uuid.name,
+              'intermediate': self.intermediate.name }
+
+class LiteralAction(object):
+    datatype = None
+    def __init__(self, uname, code):
+        self.enumtype = "LITERAL_CODE_%s" % uname
+        self.setResult = code
+        self.needsnullcheck = code.find('exit_nullcheck_addref') != -1
+
+class LiteralResponse(object):
+    def __init__(self, action, uuid):
+        self.action = action
+        self.uuid = uuid
+
+    def emitTable(self, cname, baselist):
+        return "{0}"
+
+_map_entry = re.compile(r'(?P<action>[A-Z_]+)\((?P<list>.*)\)$')
+_split_commas = re.compile(r'\s*,\s*')
+
+def build_map(f, cname, iids):
+    """Parse the body of an NS_INTERFACE_MAP and return (members, unfound)"""
+    unfound = None
+    members = []
+    for line in f:
+        if line == 'NS_INTERFACE_MAP_END':
+            return (members, unfound)
+
+        if line == 'NS_INTERFACE_MAP_UNFOUND':
+            unfound = ''
+            for line in f:
+                if line == 'END':
+                    break
+                unfound += line
+            continue
+
+        if line.find(')') == -1:
+            for line2 in f:
+                line += line2
+                if line.find(')') != -1:
+                    break
+
+        m = _map_entry.match(line)
+        if m is None:
+            raise Exception("%s: Unparseable interface map entry" % f.loc())
+
+        items = _split_commas.split(m.group('list'))
+
+        action = m.group('action')
+        if action == 'NS_INTERFACE_MAP_ENTRY':
+            iname, = items
+            members.append(OffsetThisQIResponse(iids[iname]))
+        elif action == 'NS_FUTURE_INTERFACE_MAP_ENTRY':
+            iname, = items
+            members.append(OffsetFutureThisQIResponse(iids[iname]))
+        elif action == 'NS_INTERFACE_MAP_ENTRY_AMBIGUOUS':
+            iname, intermediate = items
+            members.append(OffsetThisQIResponseAmbiguous(iids[iname], iids[intermediate]))
+        elif action == 'NS_INTERFACE_MAP_ENTRY_TEAROFF':
+            iname, allocator = items
+            members.append(TearoffResponse(iids[iname], allocator))
+        elif action == 'NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO':
+            domciname, = items
+            members.append(DOMCIResult(domciname))
+        elif action == 'NS_INTERFACE_MAP_ENTRY_LITERAL':
+            code = ''
+            for line in f:
+                if line == 'END':
+                    break
+                code += line
+            
+            a = LiteralAction(items[0], code)
+            for iname in items:
+                iface = iids[iname]
+                members.append(LiteralResponse(a, iface))
+        else:
+            raise Exception("%s: Unexpected interface map entry" % f.loc())
+
+    raise Exception("%s: Unexpected EOF" % f.loc())
+
+_import = re.compile(r'%(?P<type>import|import-idl)\s+(?:"|\<)(?P<filename>[a-z\.\-\_0-9]+)(?:"|\>)\s*$', re.I)
+_impl_qi = re.compile(r'NS_IMPL_(?P<threadsafe>THREADSAFE_)?(?P<type>QUERY_INTERFACE|ISUPPORTS)(?:\d+)\((?P<bases>.*)\)\s*$')
+_pseudoiid = re.compile(r'%pseudo-iid\s+(?P<name>[a-z_0-9]+)\s+(?P<iid>' + _uuid_pattern_string + r')\s*$', re.I)
+_map_begin = re.compile(r'NS_INTERFACE_MAP_BEGIN(?P<cc>_CYCLE_COLLECTION)?\((?P<classname>[A-Za-z0-9+]+)(?:\s*,\s*(?P<base>[A-Za-z0-9+]+))?\)$')
+
+def parsefile(file, fd, includedirs):
+    """Parse a file, returning a (map of name->QIImpls, set of deps)
+    %{C++ blocks are printed immediately to fd."""
+
+    iids = uniqdict()
+    impls = uniqdict()
+    imported = uniqdict()
+    deps = sets.Set()
+    deps.add(file)
+
+    f = IterFile(file)
+    for line in f:
+        if len(line) == 0:
+            continue
+
+        if line == "%{C++":
+            for line in f:
+                if line == "%}":
+                    break
+                print >>fd, line
+            continue
+
+        m = _pseudoiid.match(line)
+        if m is not None:
+            uuid = UUID(m.group('name'), m.group('iid'), pseudo=True)
+            iids[m.group('name')] = uuid
+            continue
+
+        m = _import.match(line)
+        if m is not None:
+            if m.group('type') == 'import':
+                newimpls, newdeps = parsefile(findfile(m.group('filename'), file, includedirs), fd, includedirs)
+                imported.update(newimpls)
+                deps |= newdeps
+            else:
+                newiids, newdeps = importidl(findfile(m.group('filename'), file, includedirs), includedirs)
+                iids.update(newiids)
+                deps |= newdeps
+                print >>fd, '#include "%s"' % m.group('filename').replace('.idl', '.h')
+            continue
+
+        if line.find('NS_IMPL_') != -1:
+            if line.find(')') == -1:
+                for follow in f:
+                    line += follow
+                    if follow.find(')') != -1:
+                        break
+
+                if line.find(')') == -1:
+                    raise Exception("%s: Unterminated NS_IMPL_ call" % f.loc())
+
+            m = _impl_qi.match(line)
+            if m is None:
+                raise Exception("%s: Unparseable NS_IMPL_ call" % f.loc())
+
+            bases = _split_commas.split(m.group('bases'))
+            cname = bases.pop(0)
+            baseuuids = [iids[name] for name in bases]
+            ifaces = [OffsetThisQIResponse(uuid) for uuid in baseuuids]
+            ifaces.append(OffsetThisQIResponseAmbiguous(iids['nsISupports'], ifaces[0].uuid))
+            q = QIImpl(cname, ifaces,
+                       emitrefcount=(m.group('type') == 'ISUPPORTS'),
+                       threadsafe=m.group('threadsafe') or '')
+            impls[cname] = q
+            continue
+
+        m = _map_begin.match(line)
+        if m is not None:
+            members, unfound = build_map(f, m.group('classname'), iids)
+            if m.group('cc') is not None:
+                members.append(CCParticipantResponse(m.group('classname')))
+                members.append(CCISupportsResponse(m.group('classname')))
+            base = None
+            if m.group('base') is not None:
+                if m.group('base') in impls:
+                    base = impls[m.group('base')]
+                else:
+                    base = imported[m.group('base')]
+            q = QIImpl(m.group('classname'), members, unfound=unfound, base=base)
+            impls[m.group('classname')] = q
+            continue
+
+        raise Exception("%s: unexpected input line" % f.loc())
+
+    return impls, deps
+
+def main():
+    from optparse import OptionParser
+
+    o = OptionParser()
+    o.add_option("-I", action="append", dest="include_dirs", default=[],
+                 help="Directory to search for included files.")
+    o.add_option("-D", dest="deps_file",
+                 help="Write dependencies to a file")
+    o.add_option("-o", dest="out_file",
+                 help="Write output to file. Required")
+
+    (options, files) = o.parse_args()
+
+    if options.out_file is None:
+        o.print_help()
+        sys.exit(1)
+
+    outfd = open(options.out_file, 'w')
+
+    deps = sets.Set()
+
+    for file in files:
+        impls, newdeps = parsefile(file, outfd, options.include_dirs)
+        for q in impls.itervalues():
+            q.output(outfd)
+        deps |= newdeps
+
+        if options.deps_file is not None:
+            depsfd = open(options.deps_file, 'w')
+            print >>depsfd, "%s: %s" % (options.out_file,
+                                        " \\\n   ".join(deps))
+
+if __name__ == '__main__':
+    main()
+
--- a/xpcom/components/Makefile.in
+++ b/xpcom/components/Makefile.in
@@ -54,16 +54,20 @@ REQUIRES	= string \
 CPPSRCS		= \
 		nsCategoryManager.cpp \
 		nsComponentManager.cpp \
 		nsNativeComponentLoader.cpp \
 		nsStaticComponentLoader.cpp \
 		nsServiceManagerObsolete.cpp \
 		$(NULL)
 
+GQI_SRCS = \
+  xpcomcomponents.gqi \
+  $(NULL)
+
 EXPORTS		= \
 		nsCategoryManagerUtils.h \
 		nsIServiceManagerObsolete.h \
 		nsModule.h \
 		nsObsoleteModuleLoading.h \
 		$(NULL)
 
 XPIDLSRCS	= \
--- a/xpcom/components/nsCategoryManager.cpp
+++ b/xpcom/components/nsCategoryManager.cpp
@@ -75,58 +75,16 @@ class nsIComponentLoaderManager;
   going to change much ;)
 */
 
 #define NS_CATEGORYMANAGER_ARENA_SIZE (1024 * 8)
 
 // pulled in from nsComponentManager.cpp
 char* ArenaStrdup(const char* s, PLArenaPool* aArena);
 
-//
-// BaseStringEnumerator is subclassed by EntryEnumerator and
-// CategoryEnumerator
-//
-class BaseStringEnumerator
-  : public nsISimpleEnumerator,
-           nsIUTF8StringEnumerator
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSISIMPLEENUMERATOR
-  NS_DECL_NSIUTF8STRINGENUMERATOR
-
-protected:
-  // Callback function for NS_QuickSort to sort mArray
-  static int SortCallback(const void *, const void *, void *);
-
-  BaseStringEnumerator()
-    : mArray(nsnull),
-      mCount(0),
-      mSimpleCurItem(0),
-      mStringCurItem(0) { }
-
-  // A virtual destructor is needed here because subclasses of
-  // BaseStringEnumerator do not implement their own Release() method.
-
-  virtual ~BaseStringEnumerator()
-  {
-    if (mArray)
-      delete[] mArray;
-  }
-
-  void Sort();
-
-  const char** mArray;
-  PRUint32 mCount;
-  PRUint32 mSimpleCurItem;
-  PRUint32 mStringCurItem;
-};
-
-NS_IMPL_ISUPPORTS2(BaseStringEnumerator, nsISimpleEnumerator, nsIUTF8StringEnumerator)
-
 NS_IMETHODIMP
 BaseStringEnumerator::HasMoreElements(PRBool *_retval)
 {
   *_retval = (mSimpleCurItem < mCount);
 
   return NS_OK;
 }
 
@@ -478,18 +436,16 @@ CategoryEnumerator::enumfunc_createenume
   return PL_DHASH_NEXT;
 }
 
 
 //
 // nsCategoryManager implementations
 //
 
-NS_IMPL_THREADSAFE_ISUPPORTS1(nsCategoryManager, nsICategoryManager)
-
 nsCategoryManager*
 nsCategoryManager::Create()
 {
   nsCategoryManager* manager = new nsCategoryManager();
   
   if (!manager)
     return nsnull;
 
@@ -781,27 +737,16 @@ nsCategoryManager::WriteCategoryManagerT
 
 NS_METHOD
 nsCategoryManager::SuppressNotifications(PRBool aSuppress)
 {
   mSuppressNotifications = aSuppress;
   return NS_OK;
 }
 
-class nsCategoryManagerFactory : public nsIFactory
-   {
-     public:
-       nsCategoryManagerFactory() { }
-
-       NS_DECL_ISUPPORTS
-       NS_DECL_NSIFACTORY
-   };
-
-NS_IMPL_ISUPPORTS1(nsCategoryManagerFactory, nsIFactory)
-
 NS_IMETHODIMP
 nsCategoryManagerFactory::CreateInstance( nsISupports* aOuter, const nsIID& aIID, void** aResult )
   {
     NS_ENSURE_ARG_POINTER(aResult);
 
     *aResult = 0;
 
     nsresult status = NS_OK;
--- a/xpcom/components/nsCategoryManager.h
+++ b/xpcom/components/nsCategoryManager.h
@@ -39,16 +39,19 @@
 #ifndef NSCATEGORYMANAGER_H
 #define NSCATEGORYMANAGER_H
 
 #include "prio.h"
 #include "prlock.h"
 #include "plarena.h"
 #include "nsClassHashtable.h"
 #include "nsICategoryManager.h"
+#include "nsIFactory.h"
+#include "nsISimpleEnumerator.h"
+#include "nsIStringEnumerator.h"
 
 #define NS_CATEGORYMANAGER_CLASSNAME     "Category Manager"
 
 /* 16d222a6-1dd2-11b2-b693-f38b02c021b2 */
 #define NS_CATEGORYMANAGER_CID \
 { 0x16d222a6, 0x1dd2, 0x11b2, \
   {0xb6, 0x93, 0xf3, 0x8b, 0x02, 0xc0, 0x21, 0xb2} }
 
@@ -163,9 +166,58 @@ private:
                        const char* aEntryName);
 
   PLArenaPool mArena;
   nsClassHashtable<nsDepCharHashKey, CategoryNode> mTable;
   PRLock* mLock;
   PRBool mSuppressNotifications;
 };
 
+class nsCategoryManagerFactory : public nsIFactory
+   {
+     public:
+       nsCategoryManagerFactory() { }
+
+       NS_DECL_ISUPPORTS
+       NS_DECL_NSIFACTORY
+   };
+
+//
+// BaseStringEnumerator is subclassed by EntryEnumerator and
+// CategoryEnumerator
+//
+class BaseStringEnumerator
+  : public nsISimpleEnumerator,
+           nsIUTF8StringEnumerator
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSISIMPLEENUMERATOR
+  NS_DECL_NSIUTF8STRINGENUMERATOR
+
+protected:
+  // Callback function for NS_QuickSort to sort mArray
+  static int SortCallback(const void *, const void *, void *);
+
+  BaseStringEnumerator()
+    : mArray(nsnull),
+      mCount(0),
+      mSimpleCurItem(0),
+      mStringCurItem(0) { }
+
+  // A virtual destructor is needed here because subclasses of
+  // BaseStringEnumerator do not implement their own Release() method.
+
+  virtual ~BaseStringEnumerator()
+  {
+    if (mArray)
+      delete[] mArray;
+  }
+
+  void Sort();
+
+  const char** mArray;
+  PRUint32 mCount;
+  PRUint32 mSimpleCurItem;
+  PRUint32 mStringCurItem;
+};
+
 #endif
--- a/xpcom/components/nsComponentManager.cpp
+++ b/xpcom/components/nsComponentManager.cpp
@@ -298,56 +298,16 @@ static const PLDHashTableOps contractID_
     PL_DHashMoveEntryStub,
     contractID_ClearEntry,
     PL_DHashFinalizeStub,
 };
 
 ////////////////////////////////////////////////////////////////////////////////
 // Hashtable Enumeration
 ////////////////////////////////////////////////////////////////////////////////
-typedef NS_CALLBACK(EnumeratorConverter)(PLDHashTable *table,
-                                         const PLDHashEntryHdr *hdr,
-                                         void *data,
-                                         nsISupports **retval);
-
-class PLDHashTableEnumeratorImpl : public nsIBidirectionalEnumerator,
-                                   public nsISimpleEnumerator
-{
-public:
-    NS_DECL_ISUPPORTS
-    NS_DECL_NSIENUMERATOR
-    NS_DECL_NSIBIDIRECTIONALENUMERATOR
-    NS_DECL_NSISIMPLEENUMERATOR
-
-    PLDHashTableEnumeratorImpl(PLDHashTable *table,
-                               EnumeratorConverter converter,
-                               void *converterData);
-    PRInt32 Count() { return mCount; }
-private:
-    PLDHashTableEnumeratorImpl(); /* no implementation */
-
-    ~PLDHashTableEnumeratorImpl();
-    void ReleaseElements();
-
-    nsVoidArray   mElements;
-    PRInt32       mCount, mCurrent;
-    PRMonitor*    mMonitor;
-
-    struct Closure {
-        PRBool                        succeeded;
-        EnumeratorConverter           converter;
-        void                          *data;
-        PLDHashTableEnumeratorImpl    *impl;
-    };
-
-    static PLDHashOperator PR_CALLBACK Enumerator(PLDHashTable *table,
-                                                  PLDHashEntryHdr *hdr,
-                                                  PRUint32 number,
-                                                  void *data);
-};
 
 // static
 PLDHashOperator PR_CALLBACK
 PLDHashTableEnumeratorImpl::Enumerator(PLDHashTable *table,
                                        PLDHashEntryHdr *hdr,
                                        PRUint32 number,
                                        void *data)
 {
@@ -376,21 +336,16 @@ PLDHashTableEnumeratorImpl::PLDHashTable
     Closure c = { PR_FALSE, converter, converterData, this };
     mCount = PL_DHashTableEnumerate(table, Enumerator, &c);
     if (!c.succeeded) {
         ReleaseElements();
         mCount = 0;
     }
 }
 
-NS_IMPL_ISUPPORTS3(PLDHashTableEnumeratorImpl,
-                   nsIBidirectionalEnumerator,
-                   nsIEnumerator,
-                   nsISimpleEnumerator)
-
 PLDHashTableEnumeratorImpl::~PLDHashTableEnumeratorImpl()
 {
     ReleaseElements();
 
     // Destroy the Lock
     if (mMonitor)
         nsAutoMonitor::DestroyMonitor(mMonitor);
 }
@@ -764,26 +719,16 @@ nsComponentManagerImpl::~nsComponentMana
         Shutdown();
 
     if (mMon) {
         nsAutoMonitor::DestroyMonitor(mMon);
     }
     PR_LOG(nsComponentManagerLog, PR_LOG_DEBUG, ("nsComponentManager: Destroyed."));
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS7(nsComponentManagerImpl,
-                              nsIComponentManager,
-                              nsIServiceManager,
-                              nsISupportsWeakReference,
-                              nsIInterfaceRequestor,
-                              nsIComponentRegistrar,
-                              nsIServiceManagerObsolete,
-                              nsIComponentManagerObsolete)
-
-
 nsresult
 nsComponentManagerImpl::GetInterface(const nsIID & uuid, void **result)
 {
     NS_WARNING("This isn't supported");
     // fall through to QI as anything QIable is a superset of what can be
     // got via the GetInterface()
     return  QueryInterface(uuid, result);
 }
--- a/xpcom/components/nsComponentManager.h
+++ b/xpcom/components/nsComponentManager.h
@@ -59,16 +59,17 @@
 #include "prmon.h"
 #include "nsCOMPtr.h"
 #include "nsWeakReference.h"
 #include "nsIFile.h"
 #include "plarena.h"
 #include "nsCOMArray.h"
 #include "nsDataHashtable.h"
 #include "nsTArray.h"
+#include "nsIEnumerator.h"
 
 struct nsFactoryEntry;
 class nsIServiceManager;
 
 #define NS_COMPONENTMANAGER_CID                      \
 { /* 91775d60-d5dc-11d2-92fb-00e09805570f */         \
     0x91775d60,                                      \
     0xd5dc,                                          \
@@ -329,10 +330,51 @@ struct nsFactoryTableEntry : public PLDH
 };
 
 struct nsContractIDTableEntry : public PLDHashEntryHdr {
     char           *mContractID;
     PRUint32        mContractIDLen;
     nsFactoryEntry *mFactoryEntry;    
 };
 
+typedef NS_CALLBACK(EnumeratorConverter)(PLDHashTable *table,
+                                         const PLDHashEntryHdr *hdr,
+                                         void *data,
+                                         nsISupports **retval);
+
+class PLDHashTableEnumeratorImpl : public nsIBidirectionalEnumerator,
+                                   public nsISimpleEnumerator
+{
+public:
+    NS_DECL_ISUPPORTS
+    NS_DECL_NSIENUMERATOR
+    NS_DECL_NSIBIDIRECTIONALENUMERATOR
+    NS_DECL_NSISIMPLEENUMERATOR
+
+    PLDHashTableEnumeratorImpl(PLDHashTable *table,
+                               EnumeratorConverter converter,
+                               void *converterData);
+    PRInt32 Count() { return mCount; }
+private:
+    PLDHashTableEnumeratorImpl(); /* no implementation */
+
+    ~PLDHashTableEnumeratorImpl();
+    void ReleaseElements();
+
+    nsVoidArray   mElements;
+    PRInt32       mCount, mCurrent;
+    PRMonitor*    mMonitor;
+
+    struct Closure {
+        PRBool                        succeeded;
+        EnumeratorConverter           converter;
+        void                          *data;
+        PLDHashTableEnumeratorImpl    *impl;
+    };
+
+    static PLDHashOperator PR_CALLBACK Enumerator(PLDHashTable *table,
+                                                  PLDHashEntryHdr *hdr,
+                                                  PRUint32 number,
+                                                  void *data);
+};
+
 #endif // nsComponentManager_h__
 
--- a/xpcom/components/nsNativeComponentLoader.cpp
+++ b/xpcom/components/nsNativeComponentLoader.cpp
@@ -82,19 +82,16 @@
 #define IMPLEMENT_BREAK_AFTER_LOAD
 #endif
 
 static PRLogModuleInfo *nsNativeModuleLoaderLog =
     PR_NewLogModule("nsNativeModuleLoader");
 
 #define LOG(level, args) PR_LOG(nsNativeModuleLoaderLog, level, args)
 
-NS_IMPL_QUERY_INTERFACE1(nsNativeModuleLoader, 
-                         nsIModuleLoader)
-
 NS_IMPL_ADDREF_USING_AGGREGATOR(nsNativeModuleLoader,
                                 nsComponentManagerImpl::gComponentManager)
 NS_IMPL_RELEASE_USING_AGGREGATOR(nsNativeModuleLoader,
                                  nsComponentManagerImpl::gComponentManager)
 
 nsresult
 nsNativeModuleLoader::Init()
 {
new file mode 100644
--- /dev/null
+++ b/xpcom/components/xpcomcomponents.gqi
@@ -0,0 +1,41 @@
+%import-idl "nsIEnumerator.idl"
+%import-idl "nsIComponentManager.idl"
+%import-idl "nsIServiceManager.idl"
+%import-idl "nsIWeakReference.idl"
+%import-idl "nsIInterfaceRequestor.idl"
+%import-idl "nsIComponentRegistrar.idl"
+%import-idl "nsIComponentManagerObsolete.idl"
+%import-idl "nsIStringEnumerator.idl"
+%import-idl "nsIModuleLoader.idl"
+%import-idl "nsICategoryManager.idl"
+
+%{C++
+#include "nsComponentManager.h"
+#include "nsCategoryManager.h"
+#include "nsNativeComponentLoader.h"
+%}
+
+%pseudo-iid nsIServiceManagerObsolete cf0df3b0-3401-11d2-8163-006008119d7a
+
+NS_IMPL_ISUPPORTS3(PLDHashTableEnumeratorImpl,
+                   nsIBidirectionalEnumerator,
+                   nsIEnumerator,
+                   nsISimpleEnumerator)
+
+NS_IMPL_THREADSAFE_ISUPPORTS7(nsComponentManagerImpl,
+                              nsIComponentManager,
+                              nsIServiceManager,
+                              nsISupportsWeakReference,
+                              nsIInterfaceRequestor,
+                              nsIComponentRegistrar,
+                              nsIServiceManagerObsolete,
+                              nsIComponentManagerObsolete)
+
+NS_IMPL_ISUPPORTS1(nsCategoryManagerFactory, nsIFactory)
+
+NS_IMPL_ISUPPORTS2(BaseStringEnumerator, nsISimpleEnumerator, nsIUTF8StringEnumerator)
+
+NS_IMPL_QUERY_INTERFACE1(nsNativeModuleLoader, 
+                         nsIModuleLoader)
+
+NS_IMPL_THREADSAFE_ISUPPORTS1(nsCategoryManager, nsICategoryManager)
--- a/xpcom/ds/Makefile.in
+++ b/xpcom/ds/Makefile.in
@@ -74,16 +74,20 @@ CPPSRCS		= \
 		nsSupportsPrimitives.cpp \
 		nsUnicharBuffer.cpp \
 		nsVariant.cpp \
 		nsTimelineService.cpp \
 		nsArray.cpp \
 		nsHashPropertyBag.cpp \
 		$(NULL)
 
+GQI_SRCS = \
+  xpcomds.gqi \
+  $(NULL)
+
 EXPORTS		= \
 		nsAtomService.h \
 		nsCheapSets.h \
 		nsCppSharedAllocator.h \
 		nsCRT.h \
 		nsDoubleHashtable.h \
 		nsExpirationTracker.h \
 		nsFixedSizeAllocator.h \
--- a/xpcom/ds/nsArray.cpp
+++ b/xpcom/ds/nsArray.cpp
@@ -45,19 +45,16 @@ struct findIndexOfClosure
 {
     nsISupports *targetElement;
     PRUint32 startIndex;
     PRUint32 resultIndex;
 };
 
 PR_STATIC_CALLBACK(PRBool) FindElementCallback(void* aElement, void* aClosure);
 
-
-NS_IMPL_ISUPPORTS2(nsArray, nsIArray, nsIMutableArray)
-
 nsArray::~nsArray()
 {
     Clear();
 }
     
 NS_IMETHODIMP
 nsArray::GetLength(PRUint32* aLength)
 {
--- a/xpcom/ds/nsAtomTable.cpp
+++ b/xpcom/ds/nsAtomTable.cpp
@@ -61,55 +61,16 @@ class nsStaticAtomWrapper;
  * If |gAtomTable.ops| is 0, then the table is uninitialized.
  */
 static PLDHashTable gAtomTable;
 
 // this is where we keep the nsStaticAtomWrapper objects
 
 static PLArenaPool* gStaticAtomArena = 0;
 
-class nsStaticAtomWrapper : public nsIAtom
-{
-public:
-  nsStaticAtomWrapper(const nsStaticAtom* aAtom, PRUint32 aLength) :
-    mStaticAtom(aAtom), mLength(aLength)
-  {
-    MOZ_COUNT_CTOR(nsStaticAtomWrapper);
-  }
-  ~nsStaticAtomWrapper() {   // no subclasses -> not virtual
-    // this is arena allocated and won't be called except in debug
-    // builds. If this function ever does anything non-debug, be sure
-    // to get rid of the ifdefs in AtomTableClearEntry!
-    MOZ_COUNT_DTOR(nsStaticAtomWrapper);
-  }
-
-  NS_IMETHOD QueryInterface(REFNSIID aIID,
-                            void** aInstancePtr);
-  NS_IMETHOD_(nsrefcnt) AddRef(void);
-  NS_IMETHOD_(nsrefcnt) Release(void);
-
-  NS_DECL_NSIATOM
-
-  const nsStaticAtom* GetStaticAtom() const {
-    return mStaticAtom;
-  }
-
-  PRUint32 getLength() const {
-    return mLength;
-  }
-
-private:
-  const nsStaticAtom* mStaticAtom;
-
-  // The length of the string in the static atom. The static atom
-  // (nsStaticAtom) doesn't hold a length, so we keep it here in the
-  // wrapper instead.
-  PRUint32 mLength;
-};
-
 // The |key| pointer in the various PLDHashTable callbacks we use is an
 // AtomTableClearEntry*.  These pointers can come from two places: either a
 // (probably stack-allocated) string key being passed to PL_DHashTableOperate,
 // or an actual entry in the atom table. PLDHashTable reseves the keyHash
 // values 0 and 1 for internal use, which means that the *PLDHashTable code*
 // will never pass an entry whose keyhash is 0 or 1 to our hooks. That means we
 // can use those values to tell whether an AtomTableEntry is a string key
 // created by a PLDHashTable code caller or an actual live AtomTableEntry used
@@ -439,18 +400,16 @@ AtomImpl::~AtomImpl()
     if (gAtomTable.entryCount == 0) {
       PL_DHashTableFinish(&gAtomTable);
       NS_ASSERTION(gAtomTable.entryCount == 0,
                    "PL_DHashTableFinish changed the entry count");
     }
   }
 }
 
-NS_IMPL_ISUPPORTS1(AtomImpl, nsIAtom)
-
 PermanentAtomImpl::PermanentAtomImpl()
   : AtomImpl()
 {
 }
 
 PermanentAtomImpl::~PermanentAtomImpl()
 {
   // So we can tell if we were permanent while running the base class dtor.
@@ -561,18 +520,16 @@ nsStaticAtomWrapper::AddRef()
 
 NS_IMETHODIMP_(nsrefcnt)
 nsStaticAtomWrapper::Release()
 {
   NS_ASSERTION(NS_IsMainThread(), "wrong thread");
   return 1;
 }
 
-NS_IMPL_QUERY_INTERFACE1(nsStaticAtomWrapper, nsIAtom)
-
 NS_IMETHODIMP
 nsStaticAtomWrapper::GetUTF8String(const char** aResult)
 {
   *aResult = mStaticAtom->mString;
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/xpcom/ds/nsByteBuffer.cpp
+++ b/xpcom/ds/nsByteBuffer.cpp
@@ -54,18 +54,16 @@ ByteBufferImpl::Init(PRUint32 aBufferSiz
     aBufferSize = MIN_BUFFER_SIZE;
   }
   mSpace = aBufferSize;
   mLength = 0;
   mBuffer = new char[aBufferSize];
   return mBuffer ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
-NS_IMPL_ISUPPORTS1(ByteBufferImpl,nsIByteBuffer)
-
 ByteBufferImpl::~ByteBufferImpl()
 {
   if (nsnull != mBuffer) {
     delete[] mBuffer;
     mBuffer = nsnull;
   }
   mLength = 0;
 }
--- a/xpcom/ds/nsHashPropertyBag.cpp
+++ b/xpcom/ds/nsHashPropertyBag.cpp
@@ -65,23 +65,16 @@ NS_NewHashPropertyBag(nsIWritablePropert
 }
 
 /*
  * nsHashPropertyBag impl
  */
 
 NS_IMPL_THREADSAFE_ADDREF(nsHashPropertyBag)
 NS_IMPL_THREADSAFE_RELEASE(nsHashPropertyBag)
-NS_INTERFACE_MAP_BEGIN(nsHashPropertyBag)
-  NS_INTERFACE_MAP_ENTRY(nsIWritablePropertyBag)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIPropertyBag, nsIWritablePropertyBag)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWritablePropertyBag)
-  NS_INTERFACE_MAP_ENTRY(nsIPropertyBag2)
-  NS_INTERFACE_MAP_ENTRY(nsIWritablePropertyBag2)
-NS_INTERFACE_MAP_END
 
 nsresult
 nsHashPropertyBag::Init()
 {
     // we can only assume that Init will fail only due to OOM.
     if (!mPropertyHash.Init())
         return NS_ERROR_OUT_OF_MEMORY;
     return NS_OK;
@@ -141,32 +134,16 @@ nsHashPropertyBag::DeleteProperty(const 
     return NS_OK;
 }
 
 
 //
 // nsSimpleProperty class and impl; used for GetEnumerator
 //
 
-class nsSimpleProperty : public nsIProperty {
-public:
-    nsSimpleProperty(const nsAString& aName, nsIVariant* aValue)
-        : mName(aName), mValue(aValue)
-    {
-    }
-
-    NS_DECL_ISUPPORTS
-    NS_DECL_NSIPROPERTY
-protected:
-    nsString mName;
-    nsCOMPtr<nsIVariant> mValue;
-};
-
-NS_IMPL_ISUPPORTS1(nsSimpleProperty, nsIProperty)
-
 NS_IMETHODIMP
 nsSimpleProperty::GetName(nsAString& aName)
 {
     aName.Assign(mName);
     return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/xpcom/ds/nsHashPropertyBag.h
+++ b/xpcom/ds/nsHashPropertyBag.h
@@ -43,16 +43,17 @@
 #include "nsCOMPtr.h"
 #include "nsCOMArray.h"
 #include "nsVoidArray.h"
 
 #include "nsIVariant.h"
 #include "nsIWritablePropertyBag.h"
 #include "nsIWritablePropertyBag2.h"
 #include "nsInterfaceHashtable.h"
+#include "nsIProperty.h"
 
 // Set IMETHOD_VISIBILITY to empty so that the class-level NS_COM declaration
 // controls member method visibility.
 #undef  IMETHOD_VISIBILITY
 #define IMETHOD_VISIBILITY
 
 class NS_COM nsHashPropertyBag : public nsIWritablePropertyBag
                                , public nsIWritablePropertyBag2
@@ -81,9 +82,23 @@ protected:
 #undef  IMETHOD_VISIBILITY
 #define IMETHOD_VISIBILITY NS_VISIBILITY_HIDDEN
 
 // Note: NS_NewHashPropertyBag returns a HPB that
 // uses a non-thread-safe internal hash
 extern "C" NS_COM nsresult
 NS_NewHashPropertyBag(nsIWritablePropertyBag* *_retval);
 
+class nsSimpleProperty : public nsIProperty {
+public:
+    nsSimpleProperty(const nsAString& aName, nsIVariant* aValue)
+        : mName(aName), mValue(aValue)
+    {
+    }
+
+    NS_DECL_ISUPPORTS
+    NS_DECL_NSIPROPERTY
+protected:
+    nsString mName;
+    nsCOMPtr<nsIVariant> mValue;
+};
+
 #endif /* nsHashPropertyBag_h___ */
--- a/xpcom/ds/nsIByteBuffer.h
+++ b/xpcom/ds/nsIByteBuffer.h
@@ -38,19 +38,16 @@
 #ifndef nsIByteBuffer_h___
 #define nsIByteBuffer_h___
 
 #include "nscore.h"
 #include "nsISupports.h"
 
 class nsIInputStream;
 
-#define NS_IBYTE_BUFFER_IID    \
-{ 0xe4a6e4b0, 0x93b4, 0x11d1, \
-  {0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
 #define NS_IBYTEBUFFER_IID    \
 { 0xe4a6e4b0, 0x93b4, 0x11d1, \
   {0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
 #define NS_BYTEBUFFER_CONTRACTID "@mozilla.org/byte-buffer;1"
 #define NS_BYTEBUFFER_CLASSNAME "Byte Buffer"
 
 /** Interface to a buffer that holds bytes */
 class nsIByteBuffer : public nsISupports {
--- a/xpcom/ds/nsINIParserImpl.cpp
+++ b/xpcom/ds/nsINIParserImpl.cpp
@@ -38,35 +38,16 @@
 #include "nsINIParserImpl.h"
 
 #include "nsILocalFile.h"
 
 #include "nsINIParser.h"
 #include "nsStringEnumerator.h"
 #include "nsVoidArray.h"
 
-class nsINIParserImpl :
-  public nsIINIParser
-{
-public:
-  NS_DECL_ISUPPORTS
-  NS_DECL_NSIINIPARSER
-
-  nsresult Init(nsILocalFile* aINIFile) {
-    return mParser.Init(aINIFile);
-  }
-
-private:
-  nsINIParser mParser;
-};
-
-NS_IMPL_ISUPPORTS2(nsINIParserFactory,
-                   nsIINIParserFactory,
-                   nsIFactory)
-
 NS_IMETHODIMP
 nsINIParserFactory::CreateINIParser(nsILocalFile* aINIFile,
                                     nsIINIParser* *aResult)
 {
   *aResult = nsnull;
 
   nsCOMPtr<nsINIParserImpl> p(new nsINIParserImpl());
   if (!p)
@@ -92,19 +73,16 @@ nsINIParserFactory::CreateInstance(nsISu
 }
 
 NS_IMETHODIMP
 nsINIParserFactory::LockFactory(PRBool aLock)
 {
   return NS_OK;
 }
 
-NS_IMPL_ISUPPORTS1(nsINIParserImpl,
-                   nsIINIParser)
-
 static PRBool
 SectionCB(const char* aSection, void *aClosure)
 {
   nsCStringArray *strings = static_cast<nsCStringArray*>(aClosure);
 
   strings->AppendCString(nsDependentCString(aSection));
   return PR_TRUE;
 }
--- a/xpcom/ds/nsINIParserImpl.h
+++ b/xpcom/ds/nsINIParserImpl.h
@@ -34,16 +34,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsINIParserImpl_h__
 #define nsINIParserImpl_h__
 
 #include "nsIINIParser.h"
+#include "nsINIParser.h"
 #include "nsIFactory.h"
 
 #define NS_INIPARSERFACTORY_CID \
 { 0xdfac10a9, 0xdd24, 0x43cf, \
   { 0xa0, 0x95, 0x6f, 0xfa, 0x2e, 0x4b, 0x6a, 0x6c } }
 
 #define NS_INIPARSERFACTORY_CONTRACTID \
   "@mozilla.org/xpcom/ini-parser-factory;1"
@@ -53,9 +54,24 @@ class nsINIParserFactory :
   public nsIFactory
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIINIPARSERFACTORY
   NS_DECL_NSIFACTORY
 };
 
+class nsINIParserImpl :
+  public nsIINIParser
+{
+public:
+  NS_DECL_ISUPPORTS
+  NS_DECL_NSIINIPARSER
+
+  nsresult Init(nsILocalFile* aINIFile) {
+    return mParser.Init(aINIFile);
+  }
+
+private:
+  nsINIParser mParser;
+};
+
 #endif // nsINIParserImpl_h__
--- a/xpcom/ds/nsIUnicharBuffer.h
+++ b/xpcom/ds/nsIUnicharBuffer.h
@@ -34,16 +34,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #ifndef nsIUnicharBuffer_h___
 #define nsIUnicharBuffer_h___
 
 #include "nscore.h"
 #include "nsISupports.h"
+#include "prlog.h"
 
 #define NS_IUNICHARBUFFER_IID \
 { 0x14cf6970, 0x93b5, 0x11d1, \
   {0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
 
 /// Interface to a buffer that holds unicode characters
 class nsIUnicharBuffer : public nsISupports {
 public:
--- a/xpcom/ds/nsObserverList.cpp
+++ b/xpcom/ds/nsObserverList.cpp
@@ -124,18 +124,16 @@ nsObserverList::NotifyObservers(nsISuppo
     nsCOMArray<nsIObserver> observers;
     FillObserverArray(observers);
 
     for (PRInt32 i = 0; i < observers.Count(); ++i) {
         observers[i]->Observe(aSubject, aTopic, someData);
     }
 }
 
-NS_IMPL_ISUPPORTS1(nsObserverEnumerator, nsISimpleEnumerator)
-
 nsObserverEnumerator::nsObserverEnumerator(nsObserverList* aObserverList)
     : mIndex(0)
 {
     aObserverList->FillObserverArray(mObservers);
 }
 
 NS_IMETHODIMP
 nsObserverEnumerator::HasMoreElements(PRBool *aResult)
--- a/xpcom/ds/nsPersistentProperties.cpp
+++ b/xpcom/ds/nsPersistentProperties.cpp
@@ -136,18 +136,16 @@ nsPersistentProperties::Create(nsISuppor
   nsresult rv = props->Init();
   if (NS_SUCCEEDED(rv))
     rv = props->QueryInterface(aIID, aResult);
 
   NS_RELEASE(props);
   return rv;
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(nsPersistentProperties, nsIPersistentProperties, nsIProperties)
-
 NS_IMETHODIMP
 nsPersistentProperties::Load(nsIInputStream *aIn)
 {
   PRInt32  c;
   nsresult ret = nsSimpleUnicharStreamFactory::GetInstance()->
     CreateInstanceFromUTF8Stream(aIn, &mIn);
 
   if (ret != NS_OK) {
@@ -473,18 +471,16 @@ nsPropertyElement::Create(nsISupports *a
   if (propElem == nsnull)
     return NS_ERROR_OUT_OF_MEMORY;
   NS_ADDREF(propElem);
   nsresult rv = propElem->QueryInterface(aIID, aResult);
   NS_RELEASE(propElem);
   return rv;
 }
 
-NS_IMPL_ISUPPORTS1(nsPropertyElement, nsIPropertyElement)
-
 NS_IMETHODIMP
 nsPropertyElement::GetKey(nsACString& aReturnKey)
 {
   aReturnKey = mKey;
   return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/xpcom/ds/nsStaticAtom.h
+++ b/xpcom/ds/nsStaticAtom.h
@@ -51,15 +51,53 @@
 // mAtom:   a convienience pointer - if you want to store the value of
 //          the atom created by this structure somewhere, put its
 //          address here
 struct nsStaticAtom {
     const char* mString;
     nsIAtom ** mAtom;
 };
 
+class nsStaticAtomWrapper : public nsIAtom
+{
+public:
+  nsStaticAtomWrapper(const nsStaticAtom* aAtom, PRUint32 aLength) :
+    mStaticAtom(aAtom), mLength(aLength)
+  {
+    MOZ_COUNT_CTOR(nsStaticAtomWrapper);
+  }
+  ~nsStaticAtomWrapper() {   // no subclasses -> not virtual
+    // this is arena allocated and won't be called except in debug
+    // builds. If this function ever does anything non-debug, be sure
+    // to get rid of the ifdefs in AtomTableClearEntry!
+    MOZ_COUNT_DTOR(nsStaticAtomWrapper);
+  }
+
+  NS_IMETHOD QueryInterface(REFNSIID aIID,
+                            void** aInstancePtr);
+  NS_IMETHOD_(nsrefcnt) AddRef(void);
+  NS_IMETHOD_(nsrefcnt) Release(void);
+
+  NS_DECL_NSIATOM
+
+  const nsStaticAtom* GetStaticAtom() const {
+    return mStaticAtom;
+  }
+
+  PRUint32 getLength() const {
+    return mLength;
+  }
+
+private:
+  const nsStaticAtom* mStaticAtom;
+
+  // The length of the string in the static atom. The static atom
+  // (nsStaticAtom) doesn't hold a length, so we keep it here in the
+  // wrapper instead.
+  PRUint32 mLength;
+};
 
 // register your lookup function with the atom table. Your function
 // will be called when at atom is not found in the main atom table.
 NS_COM nsresult
 NS_RegisterStaticAtoms(const nsStaticAtom*, PRUint32 aAtomCount);
 
 #endif
--- a/xpcom/ds/nsStringEnumerator.cpp
+++ b/xpcom/ds/nsStringEnumerator.cpp
@@ -44,83 +44,16 @@
 #include "nsReadableUtils.h"
 #include "nsISimpleEnumerator.h"
 #include "nsSupportsPrimitives.h"
 
 //
 // nsStringEnumerator
 //
 
-class nsStringEnumerator : public nsIStringEnumerator,
-                           public nsIUTF8StringEnumerator,
-                           public nsISimpleEnumerator
-{
-public:
-    nsStringEnumerator(const nsStringArray* aArray, PRBool aOwnsArray) :
-        mArray(aArray), mIndex(0), mOwnsArray(aOwnsArray), mIsUnicode(PR_TRUE)
-    {}
-    
-    nsStringEnumerator(const nsCStringArray* aArray, PRBool aOwnsArray) :
-        mCArray(aArray), mIndex(0), mOwnsArray(aOwnsArray), mIsUnicode(PR_FALSE)
-    {}
-
-    nsStringEnumerator(const nsStringArray* aArray, nsISupports* aOwner) :
-        mArray(aArray), mIndex(0), mOwner(aOwner), mOwnsArray(PR_FALSE), mIsUnicode(PR_TRUE)
-    {}
-    
-    nsStringEnumerator(const nsCStringArray* aArray, nsISupports* aOwner) :
-        mCArray(aArray), mIndex(0), mOwner(aOwner), mOwnsArray(PR_FALSE), mIsUnicode(PR_FALSE)
-    {}
-
-    NS_DECL_ISUPPORTS
-    NS_DECL_NSIUTF8STRINGENUMERATOR
-
-    // have to declare nsIStringEnumerator manually, because of
-    // overlapping method names
-    NS_IMETHOD GetNext(nsAString& aResult);
-    NS_DECL_NSISIMPLEENUMERATOR
-
-private:
-    ~nsStringEnumerator() {
-        if (mOwnsArray) {
-            // const-casting is safe here, because the NS_New*
-            // constructors make sure mOwnsArray is consistent with
-            // the constness of the objects
-            if (mIsUnicode)
-                delete const_cast<nsStringArray*>(mArray);
-            else
-                delete const_cast<nsCStringArray*>(mCArray);
-        }
-    }
-
-    union {
-        const nsStringArray* mArray;
-        const nsCStringArray* mCArray;
-    };
-
-    inline PRUint32 Count() {
-        return mIsUnicode ? mArray->Count() : mCArray->Count();
-    }
-    
-    PRUint32 mIndex;
-
-    // the owner allows us to hold a strong reference to the object
-    // that owns the array. Having a non-null value in mOwner implies
-    // that mOwnsArray is PR_FALSE, because we rely on the real owner
-    // to release the array
-    nsCOMPtr<nsISupports> mOwner;
-    PRPackedBool mOwnsArray;
-    PRPackedBool mIsUnicode;
-};
-
-NS_IMPL_ISUPPORTS3(nsStringEnumerator,
-                   nsIStringEnumerator,
-                   nsIUTF8StringEnumerator,
-                   nsISimpleEnumerator)
-
 NS_IMETHODIMP
 nsStringEnumerator::HasMore(PRBool* aResult)
 {
     NS_ENSURE_ARG_POINTER(aResult);
     *aResult = mIndex < Count();
     return NS_OK;
 }
 
--- a/xpcom/ds/nsStringEnumerator.h
+++ b/xpcom/ds/nsStringEnumerator.h
@@ -33,16 +33,18 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsIStringEnumerator.h"
 #include "nsVoidArray.h"
+#include "nsISimpleEnumerator.h"
+#include "nsCOMPtr.h"
 
 // nsIStringEnumerator/nsIUTF8StringEnumerator implementations
 //
 // Currently all implementations support both interfaces. The
 // constructors below provide the most common interface for the given
 // type (i.e. nsIStringEnumerator for PRUnichar* strings, and so
 // forth) but any resulting enumerators can be queried to the other
 // type. Internally, the enumerators will hold onto the type that was
@@ -115,8 +117,70 @@ NS_NewAdoptingUTF8StringEnumerator(nsIUT
 NS_COM nsresult
 NS_NewStringEnumerator(nsIStringEnumerator** aResult,
                        const nsStringArray* aArray,
                        nsISupports* aOwner);
 NS_COM nsresult
 NS_NewUTF8StringEnumerator(nsIUTF8StringEnumerator** aResult,
                            const nsCStringArray* aArray,
                            nsISupports* aOwner);
+
+class nsStringEnumerator : public nsIStringEnumerator,
+                           public nsIUTF8StringEnumerator,
+                           public nsISimpleEnumerator
+{
+public:
+    nsStringEnumerator(const nsStringArray* aArray, PRBool aOwnsArray) :
+        mArray(aArray), mIndex(0), mOwnsArray(aOwnsArray), mIsUnicode(PR_TRUE)
+    {}
+    
+    nsStringEnumerator(const nsCStringArray* aArray, PRBool aOwnsArray) :
+        mCArray(aArray), mIndex(0), mOwnsArray(aOwnsArray), mIsUnicode(PR_FALSE)
+    {}
+
+    nsStringEnumerator(const nsStringArray* aArray, nsISupports* aOwner) :
+        mArray(aArray), mIndex(0), mOwner(aOwner), mOwnsArray(PR_FALSE), mIsUnicode(PR_TRUE)
+    {}
+    
+    nsStringEnumerator(const nsCStringArray* aArray, nsISupports* aOwner) :
+        mCArray(aArray), mIndex(0), mOwner(aOwner), mOwnsArray(PR_FALSE), mIsUnicode(PR_FALSE)
+    {}
+
+    NS_DECL_ISUPPORTS
+    NS_DECL_NSIUTF8STRINGENUMERATOR
+
+    // have to declare nsIStringEnumerator manually, because of
+    // overlapping method names
+    NS_IMETHOD GetNext(nsAString& aResult);
+    NS_DECL_NSISIMPLEENUMERATOR
+
+private:
+    ~nsStringEnumerator() {
+        if (mOwnsArray) {
+            // const-casting is safe here, because the NS_New*
+            // constructors make sure mOwnsArray is consistent with
+            // the constness of the objects
+            if (mIsUnicode)
+                delete const_cast<nsStringArray*>(mArray);
+            else
+                delete const_cast<nsCStringArray*>(mCArray);
+        }
+    }
+
+    union {
+        const nsStringArray* mArray;
+        const nsCStringArray* mCArray;
+    };
+
+    inline PRUint32 Count() {
+        return mIsUnicode ? mArray->Count() : mCArray->Count();
+    }
+    
+    PRUint32 mIndex;
+
+    // the owner allows us to hold a strong reference to the object
+    // that owns the array. Having a non-null value in mOwner implies
+    // that mOwnsArray is PR_FALSE, because we rely on the real owner
+    // to release the array
+    nsCOMPtr<nsISupports> mOwner;
+    PRPackedBool mOwnsArray;
+    PRPackedBool mIsUnicode;
+};
--- a/xpcom/ds/nsSupportsArray.cpp
+++ b/xpcom/ds/nsSupportsArray.cpp
@@ -211,18 +211,16 @@ nsSupportsArray::Create(nsISupports *aOu
 
   nsCOMPtr<nsISupportsArray> it = new nsSupportsArray();
   if (!it)
     return NS_ERROR_OUT_OF_MEMORY;
 
   return it->QueryInterface(aIID, aResult);
 }
 
-NS_IMPL_THREADSAFE_ISUPPORTS3(nsSupportsArray, nsISupportsArray, nsICollection, nsISerializable)
-
 NS_IMETHODIMP
 nsSupportsArray::Read(nsIObjectInputStream *aStream)
 {
   nsresult rv;
 
   PRUint32 newArraySize;
   rv = aStream->Read32(&newArraySize);
 
@@ -677,51 +675,28 @@ NS_COM nsresult
 NS_NewISupportsArray(nsISupportsArray** aInstancePtrResult)
 {
   nsresult rv;
   rv = nsSupportsArray::Create(NULL, NS_GET_IID(nsISupportsArray),
                                (void**)aInstancePtrResult);
   return rv;
 }
 
-class nsArrayEnumerator : public nsISimpleEnumerator
-{
-public:
-    // nsISupports interface
-    NS_DECL_ISUPPORTS
-
-    // nsISimpleEnumerator interface
-    NS_IMETHOD HasMoreElements(PRBool* aResult);
-    NS_IMETHOD GetNext(nsISupports** aResult);
-
-    // nsArrayEnumerator methods
-    nsArrayEnumerator(nsISupportsArray* aValueArray);
-
-private:
-    ~nsArrayEnumerator(void);
-
-protected:
-    nsISupportsArray* mValueArray;
-    PRInt32 mIndex;
-};
-
 nsArrayEnumerator::nsArrayEnumerator(nsISupportsArray* aValueArray)
     : mValueArray(aValueArray),
       mIndex(0)
 {
     NS_IF_ADDREF(mValueArray);
 }
 
 nsArrayEnumerator::~nsArrayEnumerator(void)
 {
     NS_IF_RELEASE(mValueArray);
 }
 
-NS_IMPL_ISUPPORTS1(nsArrayEnumerator, nsISimpleEnumerator)
-
 NS_IMETHODIMP
 nsArrayEnumerator::HasMoreElements(PRBool* aResult)
 {
     NS_PRECONDITION(aResult != 0, "null ptr");
     if (! aResult)
         return NS_ERROR_NULL_POINTER;
 
     if (!mValueArray) {
--- a/xpcom/ds/nsSupportsArray.h
+++ b/xpcom/ds/nsSupportsArray.h
@@ -163,9 +163,30 @@ protected:
   PRUint32 mMaxSize;
 #endif
 
 private:
   // Copy constructors are not allowed
   nsSupportsArray(const nsISupportsArray& other);
 };
 
+class nsArrayEnumerator : public nsISimpleEnumerator
+{
+public:
+    // nsISupports interface
+    NS_DECL_ISUPPORTS
+
+    // nsISimpleEnumerator interface
+    NS_IMETHOD HasMoreElements(PRBool* aResult);
+    NS_IMETHOD GetNext(nsISupports** aResult);
+
+    // nsArrayEnumerator methods
+    nsArrayEnumerator(nsISupportsArray* aValueArray);
+
+private:
+    ~nsArrayEnumerator(void);
+
+protected:
+    nsISupportsArray* mValueArray;
+    PRInt32 mIndex;
+};
+
 #endif // nsSupportsArray_h__
--- a/xpcom/ds/nsSupportsArrayEnumerator.cpp
+++ b/xpcom/ds/nsSupportsArrayEnumerator.cpp
@@ -45,18 +45,16 @@ nsSupportsArrayEnumerator::nsSupportsArr
   NS_ADDREF(mArray);
 }
 
 nsSupportsArrayEnumerator::~nsSupportsArrayEnumerator()
 {
   NS_RELEASE(mArray);
 }
 
-NS_IMPL_ISUPPORTS2(nsSupportsArrayEnumerator, nsIBidirectionalEnumerator, nsIEnumerator)
-
 NS_IMETHODIMP
 nsSupportsArrayEnumerator::First()
 {
   mCursor = 0;
   PRUint32 cnt;
   nsresult rv = mArray->Count(&cnt);
   if (NS_FAILED(rv)) return rv;
   PRInt32 end = (PRInt32)cnt;
--- a/xpcom/ds/nsSupportsPrimitives.cpp
+++ b/xpcom/ds/nsSupportsPrimitives.cpp
@@ -42,18 +42,16 @@
 #include "prprf.h"
 #include "nsIInterfaceInfoManager.h"
 #include "nsDependentString.h"
 #include "nsReadableUtils.h"
 #include "nsPromiseFlatString.h"
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsIDImpl, nsISupportsID, nsISupportsPrimitive)
-
 nsSupportsIDImpl::nsSupportsIDImpl()
     : mData(nsnull)
 {
 }
 
 NS_IMETHODIMP nsSupportsIDImpl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -102,19 +100,16 @@ NS_IMETHODIMP nsSupportsIDImpl::ToString
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /*****************************************************************************
  * nsSupportsCStringImpl
  *****************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsCStringImpl, nsISupportsCString,
-                   nsISupportsPrimitive)
-
 NS_IMETHODIMP nsSupportsCStringImpl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
 
     *aType = TYPE_CSTRING;
     return NS_OK;
 }
 
@@ -139,19 +134,16 @@ NS_IMETHODIMP nsSupportsCStringImpl::Set
     mData = aData;
     return NS_OK;
 }
 
 /*****************************************************************************
  * nsSupportsStringImpl
  *****************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsStringImpl, nsISupportsString,
-                   nsISupportsPrimitive)
-
 NS_IMETHODIMP nsSupportsStringImpl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
 
     *aType = TYPE_STRING;
     return NS_OK;
 }
 
@@ -174,19 +166,16 @@ NS_IMETHODIMP nsSupportsStringImpl::ToSt
 NS_IMETHODIMP nsSupportsStringImpl::SetData(const nsAString& aData)
 {
     mData = aData;
     return NS_OK;
 }
 
 /***************************************************************************/
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsPRBoolImpl, nsISupportsPRBool,
-                              nsISupportsPrimitive)
-
 nsSupportsPRBoolImpl::nsSupportsPRBoolImpl()
     : mData(PR_FALSE)
 {
 }
 
 NS_IMETHODIMP nsSupportsPRBoolImpl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -215,19 +204,16 @@ NS_IMETHODIMP nsSupportsPRBoolImpl::ToSt
     char* result = (char*) nsMemory::Clone(str,
                                 (strlen(str)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsPRUint8Impl, nsISupportsPRUint8,
-                   nsISupportsPrimitive)
-
 nsSupportsPRUint8Impl::nsSupportsPRUint8Impl()
     : mData(0)
 {
 }
 
 NS_IMETHODIMP nsSupportsPRUint8Impl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -260,19 +246,16 @@ NS_IMETHODIMP nsSupportsPRUint8Impl::ToS
     char* result = (char*) nsMemory::Clone(buf,
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsPRUint16Impl, nsISupportsPRUint16,
-                   nsISupportsPrimitive)
-
 nsSupportsPRUint16Impl::nsSupportsPRUint16Impl()
     : mData(0)
 {
 }
 
 NS_IMETHODIMP nsSupportsPRUint16Impl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -305,19 +288,16 @@ NS_IMETHODIMP nsSupportsPRUint16Impl::To
     char* result = (char*) nsMemory::Clone(buf,
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsPRUint32Impl, nsISupportsPRUint32,
-                   nsISupportsPrimitive)
-
 nsSupportsPRUint32Impl::nsSupportsPRUint32Impl()
     : mData(0)
 {
 }
 
 NS_IMETHODIMP nsSupportsPRUint32Impl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -350,19 +330,16 @@ NS_IMETHODIMP nsSupportsPRUint32Impl::To
     char* result = (char*) nsMemory::Clone(buf,
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsPRUint64Impl, nsISupportsPRUint64,
-                   nsISupportsPrimitive)
-
 nsSupportsPRUint64Impl::nsSupportsPRUint64Impl()
     : mData(LL_ZERO)
 {
 }
 
 NS_IMETHODIMP nsSupportsPRUint64Impl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -395,19 +372,16 @@ NS_IMETHODIMP nsSupportsPRUint64Impl::To
     char* result = (char*) nsMemory::Clone(buf,
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsPRTimeImpl, nsISupportsPRTime,
-                   nsISupportsPrimitive)
-
 nsSupportsPRTimeImpl::nsSupportsPRTimeImpl()
     : mData(LL_ZERO)
 {
 }
 
 NS_IMETHODIMP nsSupportsPRTimeImpl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -440,19 +414,16 @@ NS_IMETHODIMP nsSupportsPRTimeImpl::ToSt
     char* result = (char*) nsMemory::Clone(buf,
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsCharImpl, nsISupportsChar,
-                   nsISupportsPrimitive)
-
 nsSupportsCharImpl::nsSupportsCharImpl()
     : mData(0)
 {
 }
 
 NS_IMETHODIMP nsSupportsCharImpl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -485,19 +456,16 @@ NS_IMETHODIMP nsSupportsCharImpl::ToStri
         result[1] = '\0';
     }
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsPRInt16Impl, nsISupportsPRInt16,
-                   nsISupportsPrimitive)
-
 nsSupportsPRInt16Impl::nsSupportsPRInt16Impl()
     : mData(0)
 {
 }
 
 NS_IMETHODIMP nsSupportsPRInt16Impl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -530,19 +498,16 @@ NS_IMETHODIMP nsSupportsPRInt16Impl::ToS
     char* result = (char*) nsMemory::Clone(buf,
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsPRInt32Impl, nsISupportsPRInt32,
-                   nsISupportsPrimitive)
-
 nsSupportsPRInt32Impl::nsSupportsPRInt32Impl()
     : mData(0)
 {
 }
 
 NS_IMETHODIMP nsSupportsPRInt32Impl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -575,19 +540,16 @@ NS_IMETHODIMP nsSupportsPRInt32Impl::ToS
     char* result = (char*) nsMemory::Clone(buf,
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsPRInt64Impl, nsISupportsPRInt64,
-                   nsISupportsPrimitive)
-
 nsSupportsPRInt64Impl::nsSupportsPRInt64Impl()
     : mData(LL_ZERO)
 {
 }
 
 NS_IMETHODIMP nsSupportsPRInt64Impl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -620,19 +582,16 @@ NS_IMETHODIMP nsSupportsPRInt64Impl::ToS
     char* result = (char*) nsMemory::Clone(buf,
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsFloatImpl, nsISupportsFloat,
-                   nsISupportsPrimitive)
-
 nsSupportsFloatImpl::nsSupportsFloatImpl()
     : mData(float(0.0))
 {
 }
 
 NS_IMETHODIMP nsSupportsFloatImpl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -665,19 +624,16 @@ NS_IMETHODIMP nsSupportsFloatImpl::ToStr
     char* result = (char*) nsMemory::Clone(buf,
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsDoubleImpl, nsISupportsDouble,
-                   nsISupportsPrimitive)
-
 nsSupportsDoubleImpl::nsSupportsDoubleImpl()
     : mData(double(0.0))
 {
 }
 
 NS_IMETHODIMP nsSupportsDoubleImpl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -711,19 +667,16 @@ NS_IMETHODIMP nsSupportsDoubleImpl::ToSt
                                 (strlen(buf)+1)*sizeof(char));
     *_retval = result;
     return  result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsVoidImpl, nsISupportsVoid,
-                              nsISupportsPrimitive)
-
 nsSupportsVoidImpl::nsSupportsVoidImpl()
     : mData(nsnull)
 {
 }
 
 NS_IMETHODIMP nsSupportsVoidImpl::GetType(PRUint16 *aType)
 {
     NS_ASSERTION(aType, "Bad pointer");
@@ -753,20 +706,16 @@ NS_IMETHODIMP nsSupportsVoidImpl::ToStri
     char* result = (char*) nsMemory::Clone(str, sizeof(str));
     *_retval = result;
     return  result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }  
 
 /***************************************************************************/
 
 
-NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsInterfacePointerImpl,
-                              nsISupportsInterfacePointer,
-                              nsISupportsPrimitive)
-
 nsSupportsInterfacePointerImpl::nsSupportsInterfacePointerImpl()
     : mIID(nsnull)
 {
 }
 
 nsSupportsInterfacePointerImpl::~nsSupportsInterfacePointerImpl()
 {
     if (mIID) {
@@ -834,18 +783,16 @@ NS_IMETHODIMP nsSupportsInterfacePointer
     // the interface has a known human-readable name
     char* result = (char*) nsMemory::Clone(str, sizeof(str));
     *_retval = result;
     return  result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
 /***************************************************************************/
 
-NS_IMPL_ISUPPORTS2(nsSupportsDependentCString,nsISupportsCString,nsISupportsPrimitive)
-
 nsSupportsDependentCString::nsSupportsDependentCString(const char* aStr)
     : mData(aStr)
 { }
 
 NS_IMETHODIMP
 nsSupportsDependentCString::GetType(PRUint16 *aType)
 {
     NS_ENSURE_ARG_POINTER(aType);
--- a/xpcom/ds/nsUnicharBuffer.cpp
+++ b/xpcom/ds/nsUnicharBuffer.cpp
@@ -69,18 +69,16 @@ UnicharBufferImpl::Init(PRUint32 aBuffer
     aBufferSize = MIN_BUFFER_SIZE;
   }
   mSpace = aBufferSize;
   mLength = 0;
   mBuffer = new PRUnichar[aBufferSize];
   return mBuffer ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 }
 
-NS_IMPL_ISUPPORTS1(UnicharBufferImpl, nsIUnicharBuffer)
-
 UnicharBufferImpl::~UnicharBufferImpl()
 {
   if (nsnull != mBuffer) {
     delete[] mBuffer;
     mBuffer = nsnull;
   }
   mLength = 0;
 }
--- a/xpcom/ds/nsVariant.cpp
+++ b/xpcom/ds/nsVariant.cpp
@@ -1684,18 +1684,16 @@ nsVariant::Traverse(const nsDiscriminate
             break;
     }
 }
 
 /***************************************************************************/
 /***************************************************************************/
 // members...
 
-NS_IMPL_ISUPPORTS2(nsVariant, nsIVariant, nsIWritableVariant)
-
 nsVariant::nsVariant()
     : mWritable(PR_TRUE)
 {
     nsVariant::Initialize(&mData);
 
 #ifdef DEBUG
     {
         // Assert that the nsIDataType consts match the values #defined in
new file mode 100644
--- /dev/null
+++ b/xpcom/ds/xpcomds.gqi
@@ -0,0 +1,135 @@
+%import-idl "nsIMutableArray.idl"
+%import-idl "nsIProperty.idl"
+%import-idl "nsIINIParser.idl"
+%import-idl "nsIFactory.idl"
+%import-idl "nsIVariant.idl"
+%import-idl "nsIPersistentProperties2.idl"
+%import-idl "nsISimpleEnumerator.idl"
+%import-idl "nsIStringEnumerator.idl"
+%import-idl "nsISupportsArray.idl"
+%import-idl "nsISerializable.idl"
+%import-idl "nsIAtom.idl"
+%import-idl "nsISupportsPrimitives.idl"
+%import-idl "nsIWritablePropertyBag.idl"
+%import-idl "nsIWritablePropertyBag2.idl"
+
+%{C++
+#include "nsArray.h"
+#include "nsIByteBuffer.h"
+#include "nsHashPropertyBag.h"
+#include "nsINIParserImpl.h"
+#include "nsVariant.h"
+#include "nsByteBuffer.h"
+#include "nsPersistentProperties.h"
+#include "nsUnicharBuffer.h"
+#include "nsObserverList.h"
+#include "nsStringEnumerator.h"
+#include "nsSupportsArray.h"
+#include "nsAtomTable.h"
+#include "nsStaticAtom.h"
+#include "nsSupportsArrayEnumerator.h"
+#include "nsSupportsPrimitives.h"
+%}
+
+%pseudo-iid nsIByteBuffer e4a6e4b0-93b4-11d1-895b-006008911b81
+%pseudo-iid nsIUnicharBuffer 14cf6970-93b5-11d1-895b-006008911b81
+
+NS_IMPL_ISUPPORTS2(nsArray, nsIArray, nsIMutableArray)
+
+NS_IMPL_ISUPPORTS1(nsSimpleProperty, nsIProperty)
+
+NS_IMPL_ISUPPORTS2(nsINIParserFactory,
+                   nsIINIParserFactory,
+                   nsIFactory)
+
+NS_IMPL_ISUPPORTS1(nsINIParserImpl,
+                   nsIINIParser)
+
+NS_IMPL_ISUPPORTS2(nsVariant, nsIVariant, nsIWritableVariant)
+
+NS_IMPL_ISUPPORTS1(ByteBufferImpl,nsIByteBuffer)
+
+NS_IMPL_THREADSAFE_ISUPPORTS2(nsPersistentProperties, nsIPersistentProperties, nsIProperties)
+
+NS_INTERFACE_MAP_BEGIN(nsHashPropertyBag)
+  NS_INTERFACE_MAP_ENTRY(nsIWritablePropertyBag)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsIPropertyBag, nsIWritablePropertyBag)
+  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWritablePropertyBag)
+  NS_INTERFACE_MAP_ENTRY(nsIPropertyBag2)
+  NS_INTERFACE_MAP_ENTRY(nsIWritablePropertyBag2)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_ISUPPORTS1(nsPropertyElement, nsIPropertyElement)
+
+NS_IMPL_ISUPPORTS1(UnicharBufferImpl, nsIUnicharBuffer)
+
+NS_IMPL_ISUPPORTS1(nsObserverEnumerator, nsISimpleEnumerator)
+
+NS_IMPL_ISUPPORTS3(nsStringEnumerator,
+                   nsIStringEnumerator,
+                   nsIUTF8StringEnumerator,
+                   nsISimpleEnumerator)
+
+NS_IMPL_THREADSAFE_ISUPPORTS3(nsSupportsArray, nsISupportsArray, nsICollection, nsISerializable)
+
+NS_IMPL_ISUPPORTS1(nsArrayEnumerator, nsISimpleEnumerator)
+
+NS_IMPL_ISUPPORTS1(AtomImpl, nsIAtom)
+
+NS_IMPL_QUERY_INTERFACE1(nsStaticAtomWrapper, nsIAtom)
+
+NS_IMPL_ISUPPORTS2(nsSupportsArrayEnumerator, nsIBidirectionalEnumerator, nsIEnumerator)
+
+NS_IMPL_ISUPPORTS2(nsSupportsIDImpl, nsISupportsID, nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsCStringImpl, nsISupportsCString,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsStringImpl, nsISupportsString,
+                   nsISupportsPrimitive)
+
+NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsPRBoolImpl, nsISupportsPRBool,
+                              nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsPRUint8Impl, nsISupportsPRUint8,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsPRUint16Impl, nsISupportsPRUint16,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsPRUint32Impl, nsISupportsPRUint32,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsPRUint64Impl, nsISupportsPRUint64,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsPRTimeImpl, nsISupportsPRTime,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsCharImpl, nsISupportsChar,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsPRInt16Impl, nsISupportsPRInt16,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsPRInt32Impl, nsISupportsPRInt32,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsPRInt64Impl, nsISupportsPRInt64,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsFloatImpl, nsISupportsFloat,
+                   nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsDoubleImpl, nsISupportsDouble,
+                   nsISupportsPrimitive)
+
+NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsVoidImpl, nsISupportsVoid,
+                              nsISupportsPrimitive)
+
+NS_IMPL_THREADSAFE_ISUPPORTS2(nsSupportsInterfacePointerImpl,
+                              nsISupportsInterfacePointer,
+                              nsISupportsPrimitive)
+
+NS_IMPL_ISUPPORTS2(nsSupportsDependentCString,nsISupportsCString,nsISupportsPrimitive)
+