Bug 1509972 part 4: Use UniquePtr (not nsAutoPtr) to store nsDocumentViewer member mAutoBeforeAndAfterPrint. r=TYLin
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 26 Nov 2018 22:34:20 +0000
changeset 504638 ffbdfd28202f40c0bc360758504cb98cc4ad9264
parent 504637 025e1c8e3cf86a8ec5779fa057d48bec7c984c13
child 504639 102cab25b07a8040ea31835f47ac7ab1f669e20a
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersTYLin
bugs1509972
milestone65.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 1509972 part 4: Use UniquePtr (not nsAutoPtr) to store nsDocumentViewer member mAutoBeforeAndAfterPrint. r=TYLin Depends on D12995 Differential Revision: https://phabricator.services.mozilla.com/D12996
layout/base/nsDocumentViewer.cpp
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -4,17 +4,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* container for a document and its presentation */
 
 #include "gfxContext.h"
 #include "mozilla/RestyleManager.h"
 #include "mozilla/ServoStyleSet.h"
-#include "nsAutoPtr.h"
 #include "nscore.h"
 #include "nsCOMPtr.h"
 #include "nsCRT.h"
 #include "nsString.h"
 #include "nsReadableUtils.h"
 #include "nsIContent.h"
 #include "nsIContentViewer.h"
 #include "nsIDocumentViewerPrint.h"
@@ -479,17 +478,17 @@ protected:
   unsigned                         mPrintIsPending : 1;
   unsigned                         mPrintDocIsFullyLoaded : 1;
   nsCOMPtr<nsIPrintSettings>       mCachedPrintSettings;
   nsCOMPtr<nsIWebProgressListener> mCachedPrintWebProgressListner;
 
   RefPtr<nsPrintJob>               mPrintJob;
   float                            mOriginalPrintPreviewScale;
   float                            mPrintPreviewZoom;
-  nsAutoPtr<AutoPrintEventDispatcher> mAutoBeforeAndAfterPrint;
+  UniquePtr<AutoPrintEventDispatcher> mAutoBeforeAndAfterPrint;
 #endif // NS_PRINT_PREVIEW
 
 #endif // NS_PRINTING
 
   /* character set member data */
   int32_t mHintCharsetSource;
   const Encoding* mHintCharset;
   const Encoding* mForceCharacterSet;
@@ -3864,18 +3863,18 @@ nsDocumentViewer::Print(nsIPrintSettings
     }
 
     return rv;
   }
 
   // Dispatch 'beforeprint' event and ensure 'afterprint' will be dispatched:
   MOZ_ASSERT(!mAutoBeforeAndAfterPrint,
              "We don't want to dispatch nested beforeprint/afterprint");
-  nsAutoPtr<AutoPrintEventDispatcher> autoBeforeAndAfterPrint(
-    new AutoPrintEventDispatcher(mDocument));
+  auto autoBeforeAndAfterPrint =
+    MakeUnique<AutoPrintEventDispatcher>(mDocument);
   NS_ENSURE_STATE(!GetIsPrinting());
   // 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();
 
   // Our call to nsPrintJob::Print() may cause mPrintJob to be
@@ -3894,17 +3893,17 @@ nsDocumentViewer::Print(nsIPrintSettings
       printJob->Destroy();
       return rv;
     }
     mPrintJob = printJob;
   }
   if (printJob->HasPrintCallbackCanvas()) {
     // Postpone the 'afterprint' event until after the mozPrintCallback
     // callbacks have been called:
-    mAutoBeforeAndAfterPrint = autoBeforeAndAfterPrint;
+    mAutoBeforeAndAfterPrint = std::move(autoBeforeAndAfterPrint);
   }
   dom::Element* root = mDocument->GetRootElement();
   if (root && root->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdisallowselectionprint)) {
     printJob->SetDisallowSelectionPrint(true);
   }
   rv = printJob->Print(aPrintSettings, aWebProgressListener);
   if (NS_FAILED(rv)) {
     OnDonePrinting();
@@ -3949,19 +3948,19 @@ nsDocumentViewer::PrintPreview(nsIPrintS
   // Dispatch 'beforeprint' event and ensure 'afterprint' will be dispatched:
   // XXX Currently[1] when the user switches between portrait and landscape
   // mode in print preview, we re-enter this function before
   // mAutoBeforeAndAfterPrint (if set) is cleared to dispatch the 'afterprint'
   // event.  To avoid sending multiple 'beforeprint'/'afterprint' events we
   // must avoid creating a new AutoPrintEventDispatcher object here if we
   // already have one saved in mAutoBeforeAndAfterPrint.
   // [1] Until PDF.js is removed (though, maybe after that as well).
-  nsAutoPtr<AutoPrintEventDispatcher> autoBeforeAndAfterPrint;
+  UniquePtr<AutoPrintEventDispatcher> autoBeforeAndAfterPrint;
   if (!mAutoBeforeAndAfterPrint) {
-    autoBeforeAndAfterPrint = new AutoPrintEventDispatcher(doc);
+    autoBeforeAndAfterPrint = MakeUnique<AutoPrintEventDispatcher>(doc);
   }
   NS_ENSURE_STATE(!GetIsPrinting());
   // beforeprint event may have caused ContentViewer to be shutdown.
   NS_ENSURE_STATE(mContainer);
   NS_ENSURE_STATE(mDeviceContext);
 
   // Our call to nsPrintJob::PrintPreview() may cause mPrintJob to be
   // Release()'d in Destroy().  Therefore, we need to grab the instance with
@@ -3979,17 +3978,17 @@ nsDocumentViewer::PrintPreview(nsIPrintS
       return rv;
     }
     mPrintJob = printJob;
   }
   if (autoBeforeAndAfterPrint &&
       printJob->HasPrintCallbackCanvas()) {
     // Postpone the 'afterprint' event until after the mozPrintCallback
     // callbacks have been called:
-    mAutoBeforeAndAfterPrint = autoBeforeAndAfterPrint;
+    mAutoBeforeAndAfterPrint = std::move(autoBeforeAndAfterPrint);
   }
   dom::Element* root = doc->GetRootElement();
   if (root && root->HasAttr(kNameSpaceID_None, nsGkAtoms::mozdisallowselectionprint)) {
     PR_PL(("PrintPreview: found mozdisallowselectionprint"));
     printJob->SetDisallowSelectionPrint(true);
   }
   rv = printJob->PrintPreview(aPrintSettings, aChildDOMWin,
                               aWebProgressListener);