PRBool updateHistory = (mSHEntry != nsnull);  if (mSHEntry) { if (mPresShell) mPresShell->Freeze();   mSHEntry->SetSticky(mIsSticky); mIsSticky = PR_TRUE;  mSHEntry->SetContentViewer(this);   if (mPresShell) { nsIViewManager *vm = mPresShell->GetViewManager(); if (vm) { nsIView *rootView = nsnull; vm->GetRootView(rootView);  if (rootView) { nsIView *rootViewParent = rootView->GetParent(); if (rootViewParent) { nsIViewManager *parentVM = rootViewParent->GetViewManager(); if (parentVM) { parentVM->RemoveChild(rootView); } } } } }  Hide();   if (mDocument) { nsresult rv = mDocument->Sanitize(); if (NS_FAILED(rv)) {  mSHEntry->SetContentViewer(nsnull); mSHEntry->SyncPresentationState(); } }   mSHEntry = nsnull;      nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(mContainer); if (webNav) { nsCOMPtr<nsISHistory> history; webNav->GetSessionHistory(getter_AddRefs(history)); nsCOMPtr<nsISHistoryInternal> historyInt = do_QueryInterface(history); if (historyInt) { historyInt->EvictContentViewers(); } }       if (mDocument) mDocument->SetContainer(nsnull); if (mPresContext) mPresContext->SetLinkHandler(nsnull);  return NS_OK; }  mDocument->Destroy(); mDocument = nsnull;
DocumentViewerImpl::Destroy(){#ifdef NS_PRINTING  // Here is where we check to see if the docment was still being prepared   // for printing when it was asked to be destroy from someone externally  // This usually happens if the document is unloaded while the user is in the Print Dialog  //  // So we flip the bool to remember that the document is going away  // and we can clean up and abort later after returning from the Print Dialog  if (mPrintEngine) {    if (mPrintEngine->CheckBeforeDestroy()) {      return NS_OK;    }  }#endif  // Don't let the document get unloaded while we are printing  // this could happen if we hit the back button during printing  if (mDestroyRefCount != 0) {    --mDestroyRefCount;    return NS_OK;  }  // All callers are supposed to call destroy to break circular  // references.  If we do this stuff in the destructor, the  // destructor might never be called (especially if we're being  // used from JS.#ifdef NS_PRINTING  if (mPrintEngine) {    mPrintEngine->Destroy();    NS_RELEASE(mPrintEngine);  }#endif  // Avoid leaking the old viewer.  if (mPreviousViewer) {    mPreviousViewer->Destroy();    mPreviousViewer = nsnull;  }  if (mDeviceContext) {    mDeviceContext->FlushFontCache();    mDeviceContext = nsnull;  }  if (mPresShell) {    // Break circular reference (or something)    mPresShell->EndObservingDocument();    nsCOMPtr<nsISelection> selection;    GetDocumentSelection(getter_AddRefs(selection));    nsCOMPtr<nsISelectionPrivate> selPrivate(do_QueryInterface(selection));    if (selPrivate && mSelectionListener)      selPrivate->RemoveSelectionListener(mSelectionListener);    mPresShell->Destroy();    mPresShell = nsnull;  }  if (mPresContext) {    mPresContext->SetContainer(nsnull);    mPresContext->SetLinkHandler(nsnull);    mPresContext = nsnull;  }  mContainer = nsnull;  return NS_OK;}