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());  #ifdef NS_PRINT_PREVIEW  if (mDeviceContext) { mDeviceContext->SetAltDevice(nsnull); } #endif   if (mIsCreatingPrintPreview) { 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);  float p2t; mPresContext->GetPixelsToTwips(&p2t); tbounds *= p2t;   mViewManager = do_CreateInstance(kViewManagerCID); NS_ENSURE_TRUE(mViewManager, NS_ERROR_NOT_AVAILABLE);    rv = mViewManager->Init(mDeviceContext); if (NS_FAILED(rv)) return rv;  rv = mViewManager->SetWindowOffset(tbounds.x, tbounds.y); if (NS_FAILED(rv)) return rv;       tbounds.x = 0; tbounds.y = 0;     nsIView *view = nsnull; rv = CallCreateInstance(kViewCID, &view); if (NS_FAILED(rv)) return rv; rv = view->Init(mViewManager, tbounds, nsnull); if (NS_FAILED(rv)) return rv;  rv = view->CreateWidget(kWidgetCID, nsnull, mParentWidget->GetNativeData(NS_NATIVE_WIDGET), PR_TRUE, PR_FALSE);  if (NS_FAILED(rv)) return rv;   mViewManager->SetRootView(view);  view->GetWidget(*getter_AddRefs(mWindow));  if (mPresContext && mContainer) { nsCOMPtr<nsILinkHandler> linkHandler(do_GetInterface(mContainer));  if (linkHandler) { mPresContext->SetLinkHandler(linkHandler); }  mPresContext->SetContainer(mContainer); }  if (mPresContext) { Hide();  rv = InitPresentationStuff(PR_TRUE); }      mPresShell->UnsuppressPainting(); }
DocumentViewerImpl::Show(void){  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);  NS_PRECONDITION(mWindow, "null window");  // 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);  }  return NS_OK;}