nsCOMPtr<nsILayoutHistoryState> historyState = do_QueryReferent(mHistoryState);
nsCOMPtr<nsISupports> container; mPresContext->GetContainer(getter_AddRefs(container)); if (!container) return NS_ERROR_FAILURE;  nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(container)); if (!docShell) return NS_ERROR_FAILURE;  nsCOMPtr<nsILayoutHistoryState> historyState; docShell->GetLayoutHistoryState(getter_AddRefs(historyState));
PresShell::EndLoad(nsIDocument *aDocument){  // Restore frame state for the root scroll frame  nsIFrame* rootFrame = nsnull;  GetRootFrame(&rootFrame);  nsCOMPtr<nsILayoutHistoryState> historyState = do_QueryReferent(mHistoryState);  if (rootFrame && historyState) {    nsIFrame* scrollFrame = nsnull;    GetRootScrollFrame(mPresContext, rootFrame, &scrollFrame);    if (scrollFrame) {      mFrameManager->RestoreFrameStateFor(mPresContext, scrollFrame, historyState, nsIStatefulFrame::eDocumentScrollState);    }  }#ifdef MOZ_PERF_METRICS  // Dump reflow, style resolution and frame construction times here.  MOZ_TIMER_DEBUGLOG(("Stop: Reflow: PresShell::EndLoad(), this=%p\n", this));  MOZ_TIMER_STOP(mReflowWatch);  MOZ_TIMER_LOG(("Reflow time (this=%p): ", this));  MOZ_TIMER_PRINT(mReflowWatch);    MOZ_TIMER_DEBUGLOG(("Stop: Frame Creation: PresShell::EndLoad(), this=%p\n", this));  MOZ_TIMER_STOP(mFrameCreationWatch);  MOZ_TIMER_LOG(("Frame construction plus style resolution time (this=%p): ", this));  MOZ_TIMER_PRINT(mFrameCreationWatch);  // Print style resolution stopwatch maintained by style set  MOZ_TIMER_DEBUGLOG(("Stop: Style Resolution: PresShell::EndLoad(), this=%p\n", this));  CtlStyleWatch(kStyleWatchStop|kStyleWatchDisable, mStyleSet);  MOZ_TIMER_LOG(("Style resolution time (this=%p): ", this));  CtlStyleWatch(kStyleWatchPrint, mStyleSet);#endif    mDocumentLoading = PR_FALSE;  return NS_OK;}