rv = mPrt->mFilePointer ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr);
rv = mPrt->mDebugFilePtr ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr);
DocumentViewerImpl::SetupToPrintContent(nsIWebShell*          aParent,                                        nsIDeviceContext*     aDContext,                                        nsIDOMWindowInternal* aCurrentFocusedDOMWin){  NS_ENSURE_ARG_POINTER(aParent);  NS_ENSURE_ARG_POINTER(aDContext);  // NOTE: aCurrentFocusedDOMWin may be null (which is OK)  mPrt->mPrintDocDC = aDContext;  // In this step we figure out which documents should be printed  // i.e. if we are printing the selection then only enable that PrintObject  // for printing  if (NS_FAILED(EnablePOsForPrinting())) {    return NS_ERROR_FAILURE;  }  DUMP_DOC_LIST("\nAfter Enable------------------------------------------");  // Here we reflow all the PrintObjects  if (NS_FAILED(ReflowDocList(mPrt->mPrintObject))) {    return NS_ERROR_FAILURE;  }  DUMP_DOC_LIST("\nAfter Reflow------------------------------------------");  PRINT_DEBUG_MSG1("\n-------------------------------------------------------\n\n");  // Set up the clipping rectangle for all documents  // When frames are being printed as part of a frame set and also IFrames,   // they are reflowed with a very large page height. We need to setup the  // clipping so they do not rpint over top of anything else  PRINT_DEBUG_MSG1("SetClipRect-------------------------------------------------------\n");  nsRect clipRect(-1,-1,-1, -1);  SetClipRect(mPrt->mPrintObject, clipRect, 0, 0, PR_FALSE);  CalcNumPrintableDocsAndPages(mPrt->mNumPrintableDocs, mPrt->mNumPrintablePages);  PRINT_DEBUG_MSG3("--- Printing %d docs and %d pages\n", mPrt->mNumPrintableDocs, mPrt->mNumPrintablePages);  DUMP_DOC_TREELAYOUT;  PRINT_DEBUG_FLUSH;#ifdef DEBUG_PRINTING_X#if defined(XP_PC)  for (PRInt32 i=0;i<mPrt->mPrintDocList->Count();i++) {    PrintObject* po = (PrintObject*)mPrt->mPrintDocList->ElementAt(i);    NS_ASSERTION(po, "PrintObject can't be null!");    if (po->mPresShell) {      nsIPageSequenceFrame* pageSequence;      po->mPresShell->GetPageSequenceFrame(&pageSequence);      if (pageSequence != nsnull) {        // install the debugging file pointer        nsSimplePageSequenceFrame * sf = NS_STATIC_CAST(nsSimplePageSequenceFrame*, pageSequence);        sf->SetDebugFD(mPrt->mDebugFD);      }    }  }#endif#endif  mPrt->mPrintDocDC = aDContext;  mPrt->mPrintDocDW = aCurrentFocusedDOMWin;  // This will print the webshell document  // when it completes asynchronously in the DonePrintingPages method  // it will check to see if there are more webshells to be printed and   // then PrintDocContent will be called again.  nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));  PRUnichar * docTitleStr;  PRUnichar * docURLStr;  GetWebShellTitleAndURL(webContainer, &docTitleStr, &docURLStr);   if (!docTitleStr) {    if (docURLStr) {      docTitleStr = docURLStr;      docURLStr   = nsnull;    } else {      docTitleStr = ToNewUnicode(NS_LITERAL_STRING("Document"));    }  }  nsresult rv = NS_OK;  if (mIsDoingPrinting) {    // BeginDocument may pass back a FAILURE code    // i.e. On Windows, if you are printing to a file and hit "Cancel"     //      to the "File Name" dialog, this comes back as an error    // Don't start printing when regression test are executed      rv = mPrt->mFilePointer ? NS_OK: mPrt->mPrintDC->BeginDocument(docTitleStr);    PRINT_DEBUG_MSG1("****************** Begin Document ************************\n");    if (docTitleStr != nsnull) {      nsMemory::Free(docTitleStr);    }    if (docURLStr != nsnull) {      nsMemory::Free(docURLStr);    }    if (NS_FAILED(rv)) {      return rv;    }    PrintDocContent(mPrt->mPrintObject, rv); // ignore return value  }  return rv;}