mPresContext->Init(aDeviceContext);
rv = mPresContext->Init(aDeviceContext); if (NS_FAILED(rv)) { mPresContext = nsnull; return rv; }
DocumentViewerImpl::InitInternal(nsIWidget* aParentWidget,                                 nsIDeviceContext* aDeviceContext,                                 const nsRect& aBounds,                                 PRBool aDoCreation,                                 PRBool aInPrintPreview){  mParentWidget = aParentWidget; // not ref counted  nsresult rv = NS_OK;  NS_ENSURE_TRUE(mDocument, NS_ERROR_NULL_POINTER);  mDeviceContext = aDeviceContext;#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)  // Clear PrintPreview Alternate Device  if (mDeviceContext) {    mDeviceContext->SetAltDevice(nsnull);    mDeviceContext->SetCanonicalPixelScale(1.0);  }#endif  PRBool makeCX = PR_FALSE;  if (aDoCreation) {    if (aParentWidget && !mPresContext) {      // Create presentation context      if (GetIsCreatingPrintPreview()) {        mPresContext = do_CreateInstance(kPrintPreviewContextCID, &rv);      } else {        mPresContext = do_CreateInstance(kGalleyContextCID, &rv);      }      if (NS_FAILED(rv))        return rv;      mPresContext->Init(aDeviceContext); #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)      makeCX = !GetIsPrintPreview(); // needs to be true except when we are already in PP#else      makeCX = PR_TRUE;#endif    }  }  if (aDoCreation && mPresContext) {    // Create the ViewManager and Root View...    // We must do this before we tell the script global object about    // this new document since doing that will cause us to re-enter    // into nsSubDocumentFrame code through reflows caused by    // FlushPendingNotifications() calls down the road...    rv = MakeWindow(aParentWidget, aBounds);    NS_ENSURE_SUCCESS(rv, rv);    Hide();  }  nsCOMPtr<nsIInterfaceRequestor> requestor(do_QueryInterface(mContainer));  if (requestor) {    if (mPresContext) {      nsCOMPtr<nsILinkHandler> linkHandler;      requestor->GetInterface(NS_GET_IID(nsILinkHandler),                              getter_AddRefs(linkHandler));      mPresContext->SetContainer(mContainer);      mPresContext->SetLinkHandler(linkHandler);    }    if (!aInPrintPreview) {      // Set script-context-owner in the document      nsCOMPtr<nsIScriptGlobalObject> global;      requestor->GetInterface(NS_GET_IID(nsIScriptGlobalObject),                              getter_AddRefs(global));      if (global) {        mDocument->SetScriptGlobalObject(global);        nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument));        if (domdoc) {          global->SetNewDocument(domdoc, PR_TRUE, PR_TRUE);        }      }    }  }  if (aDoCreation && mPresContext) {    // The ViewManager and Root View was created above (in    // MakeWindow())...    rv = InitPresentationStuff(!makeCX);  }  return rv;}