nsCOMPtr<nsIContent> doc_root; mDocument->GetRootContent(getter_AddRefs(doc_root));
nsIContent *doc_root = mDocument->GetRootContent();
HTMLContentSink::Init(nsIDocument* aDoc,                      nsIURI* aURL,                      nsISupports* aContainer,                      nsIChannel* aChannel){  NS_ENSURE_TRUE(aContainer, NS_ERROR_NULL_POINTER);  MOZ_TIMER_DEBUGLOG(("Reset and start: nsHTMLContentSink::Init(), this=%p\n",                      this));  MOZ_TIMER_RESET(mWatch);  MOZ_TIMER_START(mWatch);  nsresult rv = nsContentSink::Init(aDoc, aURL, aContainer, aChannel);  if NS_FAILED(rv) {    MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));    MOZ_TIMER_STOP(mWatch);    return rv;  }  aDoc->AddObserver(this);  CallQueryInterface(aDoc, &mHTMLDocument);  mObservers = nsnull;  nsIParserService* service = nsContentUtils::GetParserServiceWeakRef();  if (!service) {    return NS_ERROR_OUT_OF_MEMORY;  }  service->GetTopicObservers(NS_LITERAL_STRING("text/html"),                             getter_AddRefs(mObservers));  NS_WARN_IF_FALSE(mDocShell, "oops no docshell!");  // Find out if subframes are enabled  if (mDocShell) {    PRBool subFramesEnabled = PR_TRUE;    mDocShell->GetAllowSubframes(&subFramesEnabled);    if (subFramesEnabled) {      mFlags |= NS_SINK_FLAG_FRAMES_ENABLED;    }  }  // Find out if scripts are enabled, if not, show <noscript> content  if (IsScriptEnabled(aDoc, mDocShell)) {    mFlags |= NS_SINK_FLAG_SCRIPT_ENABLED;  }  nsCOMPtr<nsIPrefBranch> prefBranch(do_GetService(NS_PREFSERVICE_CONTRACTID));  PRBool notifyPref = PR_TRUE;  if (prefBranch) {    prefBranch->GetBoolPref("content.notify.ontimer", &notifyPref);  }  mNotifyOnTimer = notifyPref;  mBackoffCount = -1; // never  if (prefBranch) {    prefBranch->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 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 = 120000;  if (prefBranch) {    prefBranch->GetIntPref("content.notify.interval", &mNotificationInterval);  }  // The mMaxTokenProcessingTime controls how long we stay away from  // the event loop when processing token. A lower value makes the app  // more responsive, but may increase page load time.  The content  // sink mNotificationInterval gates how frequently the content is  // processed so it will also affect how interactive the app is  // during page load also. The mNotification prevents contents  // flushes from happening too frequently. while  // mMaxTokenProcessingTime prevents flushes from happening too  // infrequently.  // The current ratio of 3 to 1 was determined to be the lowest  // mMaxTokenProcessingTime which does not impact page load  // performance.  See bugzilla bug 76722 for details.  mMaxTokenProcessingTime = mNotificationInterval * 3;  PRBool enableInterruptParsing = PR_TRUE;  // 3/4 second default for switching  mDynamicIntervalSwitchThreshold = 750000;  if (prefBranch) {    prefBranch->GetBoolPref("content.interrupt.parsing",                            &enableInterruptParsing);    prefBranch->GetIntPref("content.max.tokenizing.time",                           &mMaxTokenProcessingTime);    prefBranch->GetIntPref("content.switch.threshold",                           &mDynamicIntervalSwitchThreshold);  }  if (enableInterruptParsing) {    mFlags |= NS_SINK_FLAG_CAN_INTERRUPT_PARSER;  }  // Changed from 8192 to greatly improve page loading performance on  // large pages.  See bugzilla bug 77540.  mMaxTextRun = 8191;  if (prefBranch) {    prefBranch->GetIntPref("content.maxtextrun", &mMaxTextRun);  }  nsCOMPtr<nsINodeInfo> nodeInfo;  rv = mNodeInfoManager->GetNodeInfo(nsHTMLAtoms::html, nsnull,                                     kNameSpaceID_None,                                     getter_AddRefs(nodeInfo));  NS_ENSURE_SUCCESS(rv, rv);  // Make root part  nsCOMPtr<nsIContent> doc_root;  mDocument->GetRootContent(getter_AddRefs(doc_root));  if (doc_root) {    // If the document already has a root we'll use it. This will    // happen when we do document.open()/.write()/.close()...    CallQueryInterface(doc_root, &mRoot);  } else {    rv = NS_NewHTMLHtmlElement(&mRoot, nodeInfo);    if (NS_FAILED(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_LITERAL_STRING("head"),                                     nsnull, kNameSpaceID_None,                                     getter_AddRefs(nodeInfo));  NS_ENSURE_SUCCESS(rv, rv);  rv = NS_NewHTMLHeadElement(&mHead, nodeInfo);  if (NS_FAILED(rv)) {    MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));    MOZ_TIMER_STOP(mWatch);    return rv;  }  mRoot->AppendChildTo(mHead, PR_FALSE, PR_FALSE);  mCurrentContext = new SinkContext(this);  NS_ENSURE_TRUE(mCurrentContext, NS_ERROR_OUT_OF_MEMORY);  mCurrentContext->Begin(eHTMLTag_html, mRoot, 0, -1);  mContextStack.AppendElement(mCurrentContext);#ifdef NS_DEBUG  nsCAutoString spec;  (void)aURL->GetSpec(spec);  SINK_TRACE(SINK_TRACE_CALLS,             ("HTMLContentSink::Init: this=%p url='%s'",              this, spec.get()));#endif  MOZ_TIMER_DEBUGLOG(("Stop: nsHTMLContentSink::Init()\n"));  MOZ_TIMER_STOP(mWatch);  return NS_OK;}