nsCOMPtr<nsIPrintSettings> printSettings;
INIT_RUNTIME_ERROR_CHECKING();  #ifdef MOZ_XUL  nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument)); if (xulDoc) { nsPrintEngine::ShowPrintErrorDialog(NS_ERROR_GFX_PRINTER_NO_XUL); return NS_ERROR_FAILURE; } #endif  nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer)); NS_ASSERTION(docShell, "This has to be a docshell");     PRUint32 busyFlags = nsIDocShell::BUSY_FLAGS_NONE; if ((NS_FAILED(docShell->GetBusyFlags(&busyFlags)) || (busyFlags != nsIDocShell::BUSY_FLAGS_NONE && busyFlags & nsIDocShell::BUSY_FLAGS_PAGE_LOADING)) && !mPrintDocIsFullyLoaded) { if (!mPrintIsPending) { mCachedPrintSettings           = aPrintSettings; mCachedPrintWebProgressListner = aWebProgressListener; mPrintIsPending                = PR_TRUE; } PR_PL(("Printing Stopped - document is still busy!")); return NS_ERROR_GFX_PRINTER_DOC_IS_BUSY; }  nsCOMPtr<nsIPresShell> presShell; docShell->GetPresShell(getter_AddRefs(presShell));  if (!presShell) {  PR_PL(("Printing Stopped - PreShell was NULL!")); return NS_OK; }  nsresult rv = NS_ERROR_FAILURE;      if (GetIsPrinting()) {  rv = NS_ERROR_NOT_AVAILABLE; nsPrintEngine::ShowPrintErrorDialog(rv); return rv; }    nsCOMPtr<nsIPluginDocument> pDoc(do_QueryInterface(mDocument)); if (pDoc) return pDoc->Print();  if (!mPrintEngine) { mPrintEngine = new nsPrintEngine(); NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY); NS_ADDREF(mPrintEngine);
DocumentViewerImpl::Print(PRBool            aSilent,                          FILE *            aDebugFile,                          nsIPrintSettings* aPrintSettings){#ifdef NS_PRINTING  nsCOMPtr<nsIPrintSettings> printSettings;#ifdef NS_DEBUG  nsresult rv = NS_ERROR_FAILURE;  mDebugFile = aDebugFile;  // if they don't pass in a PrintSettings, then make one  // it will have all the default values  printSettings = aPrintSettings;  nsCOMPtr<nsIPrintOptions> printOptions = do_GetService(sPrintOptionsContractID, &rv);  if (NS_SUCCEEDED(rv)) {    // if they don't pass in a PrintSettings, then make one    if (printSettings == nsnull) {      printOptions->CreatePrintSettings(getter_AddRefs(printSettings));    }    NS_ASSERTION(printSettings, "You can't PrintPreview without a PrintSettings!");  }  if (printSettings) printSettings->SetPrintSilent(aSilent);  if (printSettings) printSettings->SetShowPrintProgress(PR_FALSE);#endif  return Print(printSettings, nsnull);#else  return NS_ERROR_FAILURE;#endif}