Bug 1426087 - Decrement nsDocumentViewer::mDestroyRefCount in a separate function. r=jwatt, a=ritu
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -1660,17 +1660,16 @@ nsDocumentViewer::Destroy()
mAutoBeforeAndAfterPrint = nullptr;
#endif
// Don't let the document get unloaded while we are printing.
// this could happen if we hit the back button during printing.
// We also keep the viewer from being cached in session history, since
// we require all documents there to be sanitized.
if (mDestroyRefCount != 0) {
- --mDestroyRefCount;
return NS_OK;
}
// If we were told to put ourselves into session history instead of destroy
// the presentation, do that now.
if (mSHEntry) {
if (mPresShell)
mPresShell->Freeze();
@@ -4466,16 +4465,22 @@ nsDocumentViewer::SetIsPrintPreview(bool
//------------------------------------------------------------
void
nsDocumentViewer::IncrementDestroyRefCount()
{
++mDestroyRefCount;
}
+void
+nsDocumentViewer::DecrementDestroyRefCount()
+{
+ --mDestroyRefCount;
+}
+
//------------------------------------------------------------
#if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
//------------------------------------------------------------
// Reset ESM focus for all descendent doc shells.
static void
ResetFocusState(nsIDocShell* aDocShell)
{
--- a/layout/base/nsIDocumentViewerPrint.h
+++ b/layout/base/nsIDocumentViewerPrint.h
@@ -37,16 +37,17 @@ public:
virtual bool GetIsPrintPreview() = 0;
// The style set returned by CreateStyleSet is in the middle of an
// update batch so that the caller can add sheets to it if needed.
// Callers should call EndUpdate() on it when ready to use.
virtual mozilla::StyleSetHandle CreateStyleSet(nsIDocument* aDocument) = 0;
virtual void IncrementDestroyRefCount() = 0;
+ virtual void DecrementDestroyRefCount() = 0;
virtual void ReturnToGalleyPresentation() = 0;
virtual void OnDonePrinting() = 0;
/**
* Returns true is InitializeForPrintPreview() has been called.
*/
@@ -71,16 +72,17 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsIDocumen
/* Use this macro when declaring classes that implement this interface. */
#define NS_DECL_NSIDOCUMENTVIEWERPRINT \
void SetIsPrinting(bool aIsPrinting) override; \
bool GetIsPrinting() override; \
void SetIsPrintPreview(bool aIsPrintPreview) override; \
bool GetIsPrintPreview() override; \
mozilla::StyleSetHandle CreateStyleSet(nsIDocument* aDocument) override; \
void IncrementDestroyRefCount() override; \
+ void DecrementDestroyRefCount() override; \
void ReturnToGalleyPresentation() override; \
void OnDonePrinting() override; \
bool IsInitializedForPrintPreview() override; \
void InitializeForPrintPreview() override; \
void SetPrintPreviewPresentation(nsViewManager* aViewManager, \
nsPresContext* aPresContext, \
nsIPresShell* aPresShell) override;
--- a/layout/printing/nsPagePrintTimer.cpp
+++ b/layout/printing/nsPagePrintTimer.cpp
@@ -12,24 +12,18 @@
#include "nsPrintEngine.h"
using namespace mozilla;
NS_IMPL_ISUPPORTS_INHERITED(nsPagePrintTimer, mozilla::Runnable, nsITimerCallback)
nsPagePrintTimer::~nsPagePrintTimer()
{
- // "Destroy" the document viewer; this normally doesn't actually
- // destroy it because of the IncrementDestroyRefCount call below
- // XXX This is messy; the document viewer should use a single approach
- // to keep itself alive during printing
- nsCOMPtr<nsIContentViewer> cv(do_QueryInterface(mDocViewerPrint));
- if (cv) {
- cv->Destroy();
- }
+ // This matches the IncrementDestroyRefCount call in the constructor.
+ mDocViewerPrint->DecrementDestroyRefCount();
}
nsresult
nsPagePrintTimer::StartTimer(bool aUseDelay)
{
uint32_t delay = 0;
if (aUseDelay) {
if (mFiringCount < 10) {