Bug 1430686 - Rename the document viewer "DestroyRefCount" member and methods. r=bobowen
authorJonathan Watt <jwatt@jwatt.org>
Mon, 08 Jan 2018 16:59:31 +0000
changeset 399465 f3d24c21360d9a34b14a6f5401de130fdb94bfb8
parent 399464 001402b879ceb6eb765166b05e99414ffcf55dd5
child 399466 1359c950dc758d408238074ef84363fb3a8051f4
push id98967
push userjwatt@jwatt.org
push dateTue, 16 Jan 2018 21:11:14 +0000
treeherdermozilla-inbound@76ce0d94b9b7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbobowen
bugs1430686
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1430686 - Rename the document viewer "DestroyRefCount" member and methods. r=bobowen MozReview-Commit-ID: KGUJXOKEQjV
layout/base/nsDocumentViewer.cpp
layout/base/nsIDocumentViewerPrint.h
layout/printing/nsPagePrintTimer.cpp
layout/printing/nsPagePrintTimer.h
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -353,17 +353,17 @@ protected:
   // mTextZoom/mPageZoom record the textzoom/pagezoom of the first (galley)
   // presshell only.
   float mTextZoom;      // Text zoom, defaults to 1.0
   float mPageZoom;
   float mOverrideDPPX;  // DPPX overrided, defaults to 0.0
   int mMinFontSize;
 
   int16_t mNumURLStarts;
-  int16_t mDestroyRefCount;    // a second "refcount" for the document viewer's "destroy"
+  int16_t mDestroyBlockedCount;
 
   unsigned      mStopped : 1;
   unsigned      mLoaded : 1;
   unsigned      mDeferredWindowClose : 1;
   // document management data
   //   these items are specific to markup documents (html and xml)
   //   may consider splitting these out into a subclass
   unsigned      mIsSticky : 1;
@@ -499,17 +499,17 @@ void nsDocumentViewer::PrepareToStartLoa
 nsDocumentViewer::nsDocumentViewer()
   : mParentWidget(nullptr),
     mAttachedToParent(false),
     mTextZoom(1.0),
     mPageZoom(1.0),
     mOverrideDPPX(0.0),
     mMinFontSize(0),
     mNumURLStarts(0),
-    mDestroyRefCount(0),
+    mDestroyBlockedCount(0),
     mStopped(false),
     mLoaded(false),
     mDeferredWindowClose(false),
     mIsSticky(true),
     mInPermitUnload(false),
     mInPermitUnloadPrompt(false),
 #ifdef NS_PRINTING
     mClosingWhilePrinting(false),
@@ -551,17 +551,17 @@ nsDocumentViewer::~nsDocumentViewer()
     mDocument->Destroy();
   }
 
   if (mPrintJob) {
     mPrintJob->Destroy();
     mPrintJob = nullptr;
   }
 
-  MOZ_RELEASE_ASSERT(mDestroyRefCount == 0);
+  MOZ_RELEASE_ASSERT(mDestroyBlockedCount == 0);
   NS_ASSERTION(!mPresShell && !mPresContext,
                "User did not call nsIContentViewer::Destroy");
   if (mPresShell || mPresContext) {
     // Make sure we don't hand out a reference to the content viewer to
     // the SHEntry!
     mSHEntry = nullptr;
 
     Destroy();
@@ -1671,17 +1671,17 @@ nsDocumentViewer::Destroy()
   // Dispatch the 'afterprint' event now, if pending:
   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) {
+  if (mDestroyBlockedCount != 0) {
     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();
@@ -4463,25 +4463,25 @@ nsDocumentViewer::SetIsPrintPreview(bool
 }
 
 //----------------------------------------------------------------------------------
 // nsIDocumentViewerPrint IFace
 //----------------------------------------------------------------------------------
 
 //------------------------------------------------------------
 void
-nsDocumentViewer::IncrementDestroyRefCount()
+nsDocumentViewer::IncrementDestroyBlockedCount()
 {
-  ++mDestroyRefCount;
+  ++mDestroyBlockedCount;
 }
 
 void
-nsDocumentViewer::DecrementDestroyRefCount()
+nsDocumentViewer::DecrementDestroyBlockedCount()
 {
-  --mDestroyRefCount;
+  --mDestroyBlockedCount;
 }
 
 //------------------------------------------------------------
 
 #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
 //------------------------------------------------------------
 // Reset ESM focus for all descendent doc shells.
 static void
--- a/layout/base/nsIDocumentViewerPrint.h
+++ b/layout/base/nsIDocumentViewerPrint.h
@@ -36,18 +36,23 @@ public:
   virtual void SetIsPrintPreview(bool aIsPrintPreview) = 0;
   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;
+  /**
+   * This is used by nsPagePrintTimer to make nsDocumentViewer::Destroy()
+   * a no-op until printing is finished.  That prevents the nsDocumentViewer
+   * and its document, presshell and prescontext from going away.
+   */
+  virtual void IncrementDestroyBlockedCount() = 0;
+  virtual void DecrementDestroyBlockedCount() = 0;
 
   virtual void OnDonePrinting() = 0;
 
   /**
    * Returns true is InitializeForPrintPreview() has been called.
    */
   virtual bool IsInitializedForPrintPreview() = 0;
 
@@ -69,18 +74,18 @@ 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 IncrementDestroyBlockedCount() override; \
+  void DecrementDestroyBlockedCount() override; \
   void OnDonePrinting() override; \
   bool IsInitializedForPrintPreview() override; \
   void InitializeForPrintPreview() override; \
   void SetPrintPreviewPresentation(nsViewManager* aViewManager, \
                                    nsPresContext* aPresContext, \
                                    nsIPresShell* aPresShell) override;
 
 #endif /* nsIDocumentViewerPrint_h___ */
--- a/layout/printing/nsPagePrintTimer.cpp
+++ b/layout/printing/nsPagePrintTimer.cpp
@@ -12,18 +12,18 @@
 #include "nsPrintJob.h"
 
 using namespace mozilla;
 
 NS_IMPL_ISUPPORTS_INHERITED(nsPagePrintTimer, mozilla::Runnable, nsITimerCallback)
 
 nsPagePrintTimer::~nsPagePrintTimer()
 {
-  // This matches the IncrementDestroyRefCount call in the constructor.
-  mDocViewerPrint->DecrementDestroyRefCount();
+  // This matches the IncrementDestroyBlockedCount call in the constructor.
+  mDocViewerPrint->DecrementDestroyBlockedCount();
 }
 
 nsresult
 nsPagePrintTimer::StartTimer(bool aUseDelay)
 {
   uint32_t delay = 0;
   if (aUseDelay) {
     if (mFiringCount < 10) {
--- a/layout/printing/nsPagePrintTimer.h
+++ b/layout/printing/nsPagePrintTimer.h
@@ -37,17 +37,17 @@ public:
     , mDocument(aDocument)
     , mDelay(aDelay)
     , mFiringCount(0)
     , mPrintObj(nullptr)
     , mWatchDogCount(0)
     , mDone(false)
   {
     MOZ_ASSERT(aDocument);
-    mDocViewerPrint->IncrementDestroyRefCount();
+    mDocViewerPrint->IncrementDestroyBlockedCount();
   }
 
   NS_DECL_NSITIMERCALLBACK
 
   nsresult Start(nsPrintObject* aPO);
 
   NS_IMETHOD Run() override;