mRoot->AppendChildTo(mHead, PR_FALSE);
mRoot->AppendChildTo(mHead, PR_FALSE, PR_FALSE);
HTMLContentSink::Init(nsIDocument* aDoc,                      nsIURI* aURL,                      nsIWebShell* aContainer,                      nsIChannel* aChannel){    MOZ_TIMER_DEBUGLOG(("Reset and start: nsHTMLContentSink::Init(), this=%p\n", this));  MOZ_TIMER_RESET(mWatch);  MOZ_TIMER_START(mWatch);  NS_PRECONDITION(nsnull != aDoc, "null ptr");  NS_PRECONDITION(nsnull != aURL, "null ptr");  NS_PRECONDITION(nsnull != aContainer, "null ptr");  if ((nsnull == aDoc) || (nsnull == aURL) || (nsnull == aContainer)) {    MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));    MOZ_TIMER_STOP(mWatch);    return NS_ERROR_NULL_POINTER;  }  nsresult rv;  mDocument = aDoc;  NS_ADDREF(aDoc);  aDoc->AddObserver(this);  aDoc->QueryInterface(NS_GET_IID(nsIHTMLDocument), (void**)&mHTMLDocument);  rv = mDocument->GetNodeInfoManager(mNodeInfoManager);  NS_ENSURE_SUCCESS(rv, rv);  mDocumentURI = aURL;  NS_ADDREF(aURL);  mDocumentBaseURL = aURL;  NS_ADDREF(aURL);  mWebShell = aContainer;  NS_ADDREF(aContainer);  NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);  if (NS_FAILED(rv)) {    MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));    MOZ_TIMER_STOP(mWatch);    return rv;  }  mNotifyOnTimer = PR_TRUE;  prefs->GetBoolPref("content.notify.ontimer", &mNotifyOnTimer);  mBackoffCount = -1; // never  prefs->GetIntPref("content.notify.backoffcount", &mBackoffCount);  // The mNotificationInterval has a dramatic effect on how long it   // takes to initially display content for slow connections.  // The current value of 1/4 of second provides good   // incremental display of content without causing an increase  // in page load time. If this value is set below 1/10 of second  // it starts to impact page load performance.  // see bugzilla bug 72138 for more info.  mNotificationInterval = 250000;  prefs->GetIntPref("content.notify.interval", &mNotificationInterval);  mMaxTextRun = 8192;  prefs->GetIntPref("content.maxtextrun", &mMaxTextRun);  nsIHTMLContentContainer* htmlContainer = nsnull;  if (NS_SUCCEEDED(aDoc->QueryInterface(NS_GET_IID(nsIHTMLContentContainer), (void**)&htmlContainer))) {    htmlContainer->GetCSSLoader(mCSSLoader);    NS_RELEASE(htmlContainer);  }  // XXX this presumes HTTP header info is alread set in document  // XXX if it isn't we need to set it here...  ProcessHTTPHeaders(aChannel);  mDocument->GetHeaderData(nsHTMLAtoms::headerDefaultStyle, mPreferredStyle);  nsCOMPtr<nsINodeInfo> nodeInfo;  rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::html, nsnull,                                     kNameSpaceID_None,                                     *getter_AddRefs(nodeInfo));  NS_ENSURE_SUCCESS(rv, rv);  // Make root part  rv = NS_NewHTMLHtmlElement(&mRoot, nodeInfo);  if (NS_OK != rv) {    MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));    MOZ_TIMER_STOP(mWatch);    return rv;  }  mRoot->SetDocument(mDocument, PR_FALSE, PR_TRUE);  mDocument->SetRootContent(mRoot);  // Make head part  rv = mNodeInfoManager->GetNodeInfo(NS_ConvertASCIItoUCS2("head"),                                     nsnull, kNameSpaceID_None,                                     *getter_AddRefs(nodeInfo));  NS_ENSURE_SUCCESS(rv, rv);  rv = NS_NewHTMLHeadElement(&mHead, nodeInfo);  if (NS_OK != rv) {    MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));    MOZ_TIMER_STOP(mWatch);    return rv;  }  mRoot->AppendChildTo(mHead, PR_FALSE);  mCurrentContext = new SinkContext(this);  mCurrentContext->Begin(eHTMLTag_html, mRoot, 0, -1);  mContextStack.AppendElement(mCurrentContext);  char* spec;  (void)aURL->GetSpec(&spec);  SINK_TRACE(SINK_TRACE_CALLS,             ("HTMLContentSink::Init: this=%p url='%s'",              this, spec));  nsCRT::free(spec);  MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));  MOZ_TIMER_STOP(mWatch);  return NS_OK;}