mPresContext->Init(mDeviceContext);
rv = mPresContext->Init(mDeviceContext); if (NS_FAILED(rv)) { mPresContext = nsnull; return rv; }
DocumentViewerImpl::Show(void){  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);  // We don't need the previous viewer anymore since we're not  // displaying it.  if (mPreviousViewer) {    // This little dance *may* only be to keep    // PresShell::EndObservingDocument happy, but I'm not sure.    nsCOMPtr<nsIContentViewer> prevViewer(mPreviousViewer);    mPreviousViewer = nsnull;    prevViewer->Destroy();  }  if (mWindow) {    mWindow->Show(PR_TRUE);  }  if (mDocument && !mPresShell && !mWindow) {    nsresult rv;    nsCOMPtr<nsIBaseWindow> base_win(do_QueryInterface(mContainer));    NS_ENSURE_TRUE(base_win, NS_ERROR_UNEXPECTED);    base_win->GetParentWidget(&mParentWidget);    NS_ENSURE_TRUE(mParentWidget, NS_ERROR_UNEXPECTED);    mDeviceContext = dont_AddRef(mParentWidget->GetDeviceContext());#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)    // Clear PrintPreview Alternate Device    if (mDeviceContext) {      mDeviceContext->SetAltDevice(nsnull);    }#endif    // Create presentation context    if (GetIsCreatingPrintPreview()) {      NS_ERROR("Whoa, we should not get here!");      return NS_ERROR_UNEXPECTED;    }    mPresContext = do_CreateInstance(kGalleyContextCID, &rv);    NS_ENSURE_SUCCESS(rv, rv);    mPresContext->Init(mDeviceContext);    nsRect tbounds;    mParentWidget->GetBounds(tbounds);    rv = MakeWindow(mParentWidget, tbounds);    if (NS_FAILED(rv))      return rv;    if (mPresContext && mContainer) {      nsCOMPtr<nsILinkHandler> linkHandler(do_GetInterface(mContainer));      if (linkHandler) {        mPresContext->SetLinkHandler(linkHandler);      }      mPresContext->SetContainer(mContainer);    }    if (mPresContext) {      Hide();      rv = InitPresentationStuff(PR_TRUE);    }    // If we get here the document load has already started and the    // window is shown because some JS on the page caused it to be    // shown...    mPresShell->UnsuppressPainting();  }  return NS_OK;}