printSettings = aPrintSettings; nsCOMPtr<nsIPrintOptions> printOptions = do_GetService(kPrintOptionsCID, &rv);
mPrt->mPrintSettings = aPrintSettings; mPrt->mPrintOptions  = do_GetService(kPrintOptionsCID, &rv); if (NS_SUCCEEDED(rv) && mPrt->mPrintOptions) {  if (mPrt->mPrintSettings == nsnull) { mPrt->mPrintOptions->CreatePrintSettings(getter_AddRefs(mPrt->mPrintSettings)); } NS_ASSERTION(mPrt->mPrintSettings, "You can't PrintPreview without a PrintSettings!");   if (NS_FAILED(CheckForPrinters(mPrt->mPrintOptions, mPrt->mPrintSettings, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE, PR_TRUE))) { delete mPrt; mPrt = nsnull; return NS_ERROR_FAILURE; } } mPrt->mPrintSettings->SetIsCancelled(PR_FALSE); mPrt->mPrintSettings->GetShrinkToFit(&mPrt->mShrinkToFit);   mIsDoingPrinting = PR_TRUE;     mPrt->mPreparingForPrint = PR_TRUE;  if (aWebProgressListener != nsnull) { mPrt->mPrintProgressListeners.AppendElement((void*)aWebProgressListener); NS_ADDREF(aWebProgressListener); }     mPrt->mCurrentFocusWin = getter_AddRefs(FindFocusedDOMWindowInternal());   PRBool isSelection = IsThereARangeSelection(mPrt->mCurrentFocusWin);   if (mPrt->mPrintDocList == nsnull) { mPrt->mPrintDocList = new nsVoidArray(); if (mPrt->mPrintDocList == nsnull) { mIsDoingPrinting = PR_FALSE; delete mPrt; mPrt = nsnull; return NS_ERROR_FAILURE; } } else { mPrt->mPrintDocList->Clear(); }   nsCOMPtr<nsIWebShell> webContainer(do_QueryInterface(mContainer));   mPrt->mPrintObject             = new PrintObject; mPrt->mPrintObject->mWebShell  = webContainer; mPrt->mPrintDocList->AppendElement(mPrt->mPrintObject);  mPrt->mIsParentAFrameSet = IsParentAFrameSet(webContainer); mPrt->mPrintObject->mFrameType = mPrt->mIsParentAFrameSet?eFrameSet:eDoc;   nsCOMPtr<nsIDocShellTreeNode>  parentAsNode(do_QueryInterface(webContainer)); BuildDocTree(parentAsNode, mPrt->mPrintDocList, mPrt->mPrintObject);    MapContentToWebShells(mPrt->mPrintObject, mPrt->mPrintObject);      mPrt->mIsIFrameSelected = IsThereAnIFrameSelected(webContainer, mPrt->mCurrentFocusWin, mPrt->mIsParentAFrameSet);  DUMP_DOC_LIST("\nAfter Mapping------------------------------------------");  rv = NS_ERROR_FAILURE;  if (mPrt->mIsParentAFrameSet) { if (mPrt->mCurrentFocusWin) { mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAll); } else { mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableAsIsAndEach); } } else { mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone); }  mPrt->mPrintSettings->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB, isSelection || mPrt->mIsIFrameSelected);  #ifdef DEBUG_PRINTING if (mPrt->mPrintSettings) { PRInt16 printHowEnable = nsIPrintSettings::kFrameEnableNone; mPrt->mPrintSettings->GetHowToEnableFrameUI(&printHowEnable); PRBool val; mPrt->mPrintSettings->GetPrintOptions(nsIPrintSettings::kEnableSelectionRB, &val);  PRINT_DEBUG_MSG1("********* DocumentViewerImpl::Print *********\n"); PRINT_DEBUG_MSG2("IsParentAFrameSet:   %s \n", PRT_YESNO(mPrt->mIsParentAFrameSet)); PRINT_DEBUG_MSG2("IsIFrameSelected:    %s \n", PRT_YESNO(mPrt->mIsIFrameSelected)); PRINT_DEBUG_MSG2("Main Doc Frame Type: %s \n", gFrameTypesStr[mPrt->mPrintObject->mFrameType]); PRINT_DEBUG_MSG2("HowToEnableFrameUI:  %s \n", gFrameHowToEnableStr[printHowEnable]); PRINT_DEBUG_MSG2("EnableSelectionRB:   %s \n", PRT_YESNO(val)); PRINT_DEBUG_MSG1("*********************************************\n"); PRINT_DEBUG_FLUSH } #endif   nsCOMPtr<nsIDeviceContextSpecFactory> factory = do_CreateInstance(kDeviceContextSpecFactoryCID, &rv);
DocumentViewerImpl::Print(PRBool            aSilent,                          FILE *            aDebugFile,                           nsIPrintSettings* aPrintSettings){  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(kPrintOptionsCID, &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);#endif  return Print(printSettings, nsnull);  }