Bug 649170, use the same nsIWeakReference in DocumentViewer and nsPrintEngine, r=roc

This commit is contained in:
Olli Pettay 2011-05-10 15:55:26 +03:00
parent f7ac6dd55e
commit 3b50630ddb
3 changed files with 19 additions and 20 deletions

View File

@ -3634,7 +3634,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
}
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
NS_ASSERTION(docShell, "This has to be a docshell");
NS_ENSURE_STATE(docShell);
// Check to see if this document is still busy
// If it is busy and we aren't already "queued" up to print then
@ -3682,7 +3682,7 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
mPrintEngine = new nsPrintEngine();
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
rv = mPrintEngine->Initialize(this, docShell, mDocument,
rv = mPrintEngine->Initialize(this, mContainer, mDocument,
float(mDeviceContext->AppUnitsPerCSSInch()) /
float(mDeviceContext->AppUnitsPerDevPixel()) /
mPageZoom,
@ -3734,7 +3734,6 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
#endif
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
NS_ASSERTION(docShell, "This has to be a docshell");
if (!docShell || !mDeviceContext) {
PR_PL(("Can't Print Preview without device context and docshell"));
return NS_ERROR_FAILURE;
@ -3749,7 +3748,7 @@ DocumentViewerImpl::PrintPreview(nsIPrintSettings* aPrintSettings,
mPrintEngine = new nsPrintEngine();
NS_ENSURE_TRUE(mPrintEngine, NS_ERROR_OUT_OF_MEMORY);
rv = mPrintEngine->Initialize(this, docShell, doc,
rv = mPrintEngine->Initialize(this, mContainer, doc,
float(mDeviceContext->AppUnitsPerCSSInch()) /
float(mDeviceContext->AppUnitsPerDevPixel()) /
mPageZoom,

View File

@ -261,7 +261,6 @@ nsPrintEngine::nsPrintEngine() :
mIsDoingPrinting(PR_FALSE),
mIsDoingPrintPreview(PR_FALSE),
mProgressDialogIsShown(PR_FALSE),
mContainer(nsnull),
mScreenDPI(115.0f),
mPrt(nsnull),
mPagePrintTimer(nsnull),
@ -317,7 +316,7 @@ void nsPrintEngine::DestroyPrintingData()
//--------------------------------------------------------
nsresult nsPrintEngine::Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
nsISupports* aContainer,
nsIWeakReference* aContainer,
nsIDocument* aDocument,
float aScreenDPI,
FILE* aDebugFile)
@ -327,7 +326,7 @@ nsresult nsPrintEngine::Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
NS_ENSURE_ARG_POINTER(aDocument);
mDocViewerPrint = aDocViewerPrint;
mContainer = aContainer; // weak reference
mContainer = aContainer;
mDocument = aDocument;
mScreenDPI = aScreenDPI;
@ -366,11 +365,11 @@ void
nsPrintEngine::InstallPrintPreviewListener()
{
if (!mPrt->mPPEventListeners) {
nsCOMPtr<nsPIDOMWindow> win(do_GetInterface(mContainer));
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(win->GetFrameElementInternal()));
mPrt->mPPEventListeners = new nsPrintPreviewListener(target);
if (mPrt->mPPEventListeners) {
nsCOMPtr<nsIDocShell> docShell = do_QueryReferent(mContainer);
nsCOMPtr<nsPIDOMWindow> win(do_GetInterface(docShell));
if (win) {
nsCOMPtr<nsIDOMEventTarget> target(do_QueryInterface(win->GetFrameElementInternal()));
mPrt->mPPEventListeners = new nsPrintPreviewListener(target);
mPrt->mPPEventListeners->AddListeners();
}
}
@ -536,7 +535,7 @@ nsPrintEngine::DoCommonPrint(PRBool aIsPrintPreview,
PRBool isSelection = IsThereARangeSelection(mPrt->mCurrentFocusWin);
// Get the docshell for this documentviewer
nsCOMPtr<nsIDocShell> webContainer(do_QueryInterface(mContainer, &rv));
nsCOMPtr<nsIDocShell> webContainer(do_QueryReferent(mContainer, &rv));
NS_ENSURE_SUCCESS(rv, rv);
mPrt->mPrintObject = new nsPrintObject();
@ -767,8 +766,8 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings,
{
// Get the DocShell and see if it is busy
// (We can't Print Preview this document if it is still busy)
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(mContainer));
NS_ASSERTION(docShell, "This has to be a docshell");
nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mContainer));
NS_ENSURE_STATE(docShell);
PRUint32 busyFlags = nsIDocShell::BUSY_FLAGS_NONE;
if (NS_FAILED(docShell->GetBusyFlags(&busyFlags)) ||
@ -792,7 +791,7 @@ nsPrintEngine::PrintPreview(nsIPrintSettings* aPrintSettings,
NS_IMETHODIMP
nsPrintEngine::GetIsFramesetDocument(PRBool *aIsFramesetDocument)
{
nsCOMPtr<nsIDocShell> webContainer(do_QueryInterface(mContainer));
nsCOMPtr<nsIDocShell> webContainer(do_QueryReferent(mContainer));
*aIsFramesetDocument = IsParentAFrameSet(webContainer);
return NS_OK;
}
@ -805,7 +804,7 @@ nsPrintEngine::GetIsIFrameSelected(PRBool *aIsIFrameSelected)
*aIsIFrameSelected = PR_FALSE;
// Get the docshell for this documentviewer
nsCOMPtr<nsIDocShell> webContainer(do_QueryInterface(mContainer));
nsCOMPtr<nsIDocShell> webContainer(do_QueryReferent(mContainer));
// Get the currently focused window
nsCOMPtr<nsIDOMWindow> currentFocusWin = FindFocusedDOMWindow();
if (currentFocusWin && webContainer) {
@ -2849,7 +2848,7 @@ nsPrintEngine::IsWindowsInOurSubTree(nsPIDOMWindow * window)
if (docShellAsItem) {
// get this DocViewer docshell
nsCOMPtr<nsIDocShell> thisDVDocShell(do_QueryInterface(mContainer));
nsCOMPtr<nsIDocShell> thisDVDocShell(do_QueryReferent(mContainer));
while (!found) {
nsCOMPtr<nsIDocShell> parentDocshell(do_QueryInterface(docShellAsItem));
if (parentDocshell) {

View File

@ -55,6 +55,7 @@ class nsIDocumentViewerPrint;
class nsPrintObject;
class nsIDocShell;
class nsIPageSequenceFrame;
class nsIWeakReference;
//------------------------------------------------------------------------
// nsPrintEngine Class
@ -102,7 +103,7 @@ public:
void DestroyPrintingData();
nsresult Initialize(nsIDocumentViewerPrint* aDocViewerPrint,
nsISupports* aContainer,
nsIWeakReference* aContainer,
nsIDocument* aDocument,
float aScreenDPI,
FILE* aDebugFile);
@ -280,7 +281,7 @@ protected:
PRPackedBool mProgressDialogIsShown;
nsCOMPtr<nsIDocumentViewerPrint> mDocViewerPrint;
nsISupports* mContainer; // [WEAK] it owns me!
nsWeakPtr mContainer;
float mScreenDPI;
nsPrintData* mPrt;