DocumentViewerImpl::Print(nsIPrintSettings*       aPrintSettings, nsIWebProgressListener* aWebProgressListener)
DocumentViewerImpl::Print(PRBool            aSilent, FILE *            aDebugFile, nsIPrintSettings* aPrintSettings)
DocumentViewerImpl::Print(nsIPrintSettings*       aPrintSettings,                          nsIWebProgressListener* aWebProgressListener){#ifdef NS_PRINTING  INIT_RUNTIME_ERROR_CHECKING();#ifdef MOZ_XUL  // Temporary code for Bug 136185 / Bug 240490  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_QueryInterface(mContainer));  NS_ASSERTION(docShell, "This has to be a docshell");  // Check to see if this document is still busy  // If it is busy and we aren't already "queued" up to print then  // Indicate there is a print pending and cache the args for later  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) {    // A frame that's not displayed can't be printed!    PR_PL(("Printing Stopped - PreShell was NULL!"));    return NS_OK;  }  nsresult rv = NS_ERROR_FAILURE;  // if we are printing another URL, then exit  // the reason we check here is because this method can be called while  // another is still in here (the printing dialog is a good example).  // the only time we can print more than one job at a time is the regression tests  if (GetIsPrinting()) {    // Let the user know we are not ready to print.    rv = NS_ERROR_NOT_AVAILABLE;    nsPrintEngine::ShowPrintErrorDialog(rv);    return rv;  }  // If we are hosting a full-page plugin, tell it to print  // first. It shows its own native print UI.  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);#ifdef NS_DEBUG    mPrintEngine->Initialize(this, this, mContainer, mDocument,                              mDeviceContext, mPresContext, mWindow, mParentWidget, mDebugFile);#else    mPrintEngine->Initialize(this, this, mContainer, mDocument,                              mDeviceContext, mPresContext, mWindow, mParentWidget, nsnull);#endif  }  rv = mPrintEngine->Print(aPrintSettings, aWebProgressListener);  if (NS_FAILED(rv)) {    OnDonePrinting();  }  return rv;#else  PR_PL(("NS_PRINTING not defined - printing not implemented in this build!"));  return NS_ERROR_GFX_PRINTING_NOT_IMPLEMENTED;#endif /* NS_PRINTING */}