nsLayoutFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult) {
nsresult nsLayoutFactory::CreateInstance(nsISupports *aOuter, const nsIID &aIID, void **aResult) {
nsLayoutFactory::CreateInstance(nsISupports *aOuter,                                const nsIID &aIID,                                void **aResult){  nsresult res;  PRBool refCounted = PR_TRUE; // XXX What is it with this? It is always PR_TRUE???  if (aResult == NULL) {    return NS_ERROR_NULL_POINTER;  }  *aResult = NULL;  nsISupports *inst = nsnull;  // XXX ClassID check happens here  if (mClassID.Equals(kHTMLDocumentCID)) {    res = NS_NewHTMLDocument((nsIDocument **)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewHTMLDocument", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kXMLDocumentCID)) {    res = NS_NewXMLDocument((nsIDocument **)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewXMLDocument", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kImageDocumentCID)) {    res = NS_NewImageDocument((nsIDocument **)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewImageDocument", res);      return res;    }    refCounted = PR_TRUE;  }#if 1// XXX replace these with nsIHTMLElementFactory calls  else if (mClassID.Equals(kHTMLImageElementCID)) {    res = NS_NewHTMLImageElement((nsIHTMLContent**)&inst, nsHTMLAtoms::img);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewHTMLImageElement", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kHTMLOptionElementCID)) {    res = NS_NewHTMLOptionElement((nsIHTMLContent**)&inst, nsHTMLAtoms::option);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewHTMLOptionElement", res);      return res;    }    refCounted = PR_TRUE;  }// XXX why the heck is this exported???? bad bad bad bad  else if (mClassID.Equals(kPresShellCID)) {    res = NS_NewPresShell((nsIPresShell**) &inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewPresShell", res);      return res;    }    refCounted = PR_TRUE;  }#endif  else if (mClassID.Equals(kFrameSelectionCID)) {    res = NS_NewRangeList((nsIFrameSelection**)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewRangeList", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kRangeCID)) {    res = NS_NewRange((nsIDOMRange **)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewRange", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kContentIteratorCID)) {    res = NS_NewContentIterator((nsIContentIterator **)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewContentIterator", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kSubtreeIteratorCID)) {    res = NS_NewContentSubtreeIterator((nsIContentIterator **)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewContentSubtreeIterator", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kCSSParserCID)) {    res = NS_NewCSSParser((nsICSSParser**)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewCSSParser", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kHTMLStyleSheetCID)) {    res = NS_NewHTMLStyleSheet((nsIHTMLStyleSheet**)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewHTMLStyleSheet", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kHTMLCSSStyleSheetCID)) {    res = NS_NewHTMLCSSStyleSheet((nsIHTMLCSSStyleSheet**)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewHTMLCSSStyleSheet", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kCSSLoaderCID)) {    res = NS_NewCSSLoader((nsICSSLoader**)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewCSSLoader", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kTextNodeCID)) {    res = NS_NewTextNode((nsIContent**) &inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewTextNode", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kNameSpaceManagerCID)) {    res = NS_NewNameSpaceManager((nsINameSpaceManager**)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewNameSpaceManager", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kFrameUtilCID)) {    res = NS_NewFrameUtil((nsIFrameUtil**) &inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewFrameUtil", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kEventListenerManagerCID)) {    res = NS_NewEventListenerManager((nsIEventListenerManager**) &inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewEventListenerManager", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kPrintPreviewContextCID)) {    res = NS_NewPrintPreviewContext((nsIPresContext**) &inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewPrintPreviewContext", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kLayoutDocumentLoaderFactoryCID)) {    res = NS_NewLayoutDocumentLoaderFactory((nsIDocumentLoaderFactory**)&inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewLayoutDocumentLoaderFactory", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kLayoutDebuggerCID)) {    res = NS_NewLayoutDebugger((nsILayoutDebugger**) &inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewLayoutDebugger", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kHTMLElementFactoryCID)) {    res = NS_NewHTMLElementFactory((nsIHTMLElementFactory**) &inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewHTMLElementFactory", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kXMLElementFactoryCID)) {    res = NS_NewXMLElementFactory((nsIXMLElementFactory**) &inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewXMLElementFactory", res);      return res;    }    refCounted = PR_TRUE;  }  else if (mClassID.Equals(kTextEncoderCID)) {    res = NS_NewTextEncoder((nsIDocumentEncoder**) &inst);    if (NS_FAILED(res)) {      LOG_NEW_FAILURE("NS_NewTextEncoder", res);      return res;    }    refCounted = PR_TRUE;  }  else {    return NS_NOINTERFACE;  }  if (inst == NULL) {    return NS_ERROR_OUT_OF_MEMORY;  }  if (!refCounted) {    NS_ADDREF(inst);  }  res = inst->QueryInterface(aIID, aResult);  NS_RELEASE(inst);  if (res != NS_OK) {    // We didn't get the right interface, so clean up    LOG_NEW_FAILURE("final QueryInterface", res);  }  return res;}