else { *aState = mHistoryState; NS_IF_ADDREF(mHistoryState); }
*aState = historyState; NS_IF_ADDREF(*aState);
PresShell::CaptureHistoryState(nsILayoutHistoryState** aState, PRBool aLeavingPage){  nsresult rv = NS_OK;  NS_PRECONDITION(nsnull != aState, "null state pointer");  if (!mHistoryState) {    // Create the document state object    rv = NS_NewLayoutHistoryState(aState); // This addrefs      if (NS_FAILED(rv)) {       *aState = nsnull;      return rv;    }        mHistoryState = *aState;  }  else {    *aState = mHistoryState;    NS_IF_ADDREF(mHistoryState);  }    // 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, mHistoryState, nsIStatefulFrame::eDocumentScrollState);    }  }  rv = mFrameManager->CaptureFrameState(mPresContext, rootFrame, mHistoryState);     return rv;}