mHistoryState = getter_AddRefs(NS_GetWeakReference(historyState));
docShell->SetLayoutHistoryState(historyState);
PresShell::CaptureHistoryState(nsILayoutHistoryState** aState, PRBool aLeavingPage){  nsresult rv = NS_OK;  NS_PRECONDITION(nsnull != aState, "null state pointer");  nsCOMPtr<nsILayoutHistoryState> historyState = do_QueryReferent(mHistoryState);  if (!historyState) {    // Create the document state object    rv = NS_NewLayoutHistoryState(getter_AddRefs(historyState));      if (NS_FAILED(rv)) {       *aState = nsnull;      return rv;    }        mHistoryState = getter_AddRefs(NS_GetWeakReference(historyState));  }  *aState = historyState;  NS_IF_ADDREF(*aState);    // Capture frame state for the entire frame hierarchy  nsIFrame* rootFrame = nsnull;  rv = GetRootFrame(&rootFrame);  if (NS_FAILED(rv) || nsnull == rootFrame) return rv;  // Capture frame state for the root scroll frame  // Don't capture state when first creating doc element heirarchy  // As the scroll position is 0 and this will cause us to loose  // our previously saved place!  if (aLeavingPage) {    nsIFrame* scrollFrame = nsnull;    rv = GetRootScrollFrame(mPresContext, rootFrame, &scrollFrame);    if (scrollFrame) {      rv = mFrameManager->CaptureFrameStateFor(mPresContext, scrollFrame, historyState, nsIStatefulFrame::eDocumentScrollState);    }  }  rv = mFrameManager->CaptureFrameState(mPresContext, rootFrame, historyState);     return rv;}