Bug 1354443 part.1-1 Make nsPrintData refcountable r=dholbert

MozReview-Commit-ID: 78azPbH9S9x
This commit is contained in:
Masayuki Nakano 2017-05-09 17:08:20 +09:00
parent 9a2799794a
commit 3fd5206e5b
4 changed files with 27 additions and 23 deletions

View File

@ -34,7 +34,6 @@ nsPrintData::nsPrintData(ePrintDataType aType) :
mShrinkRatio(1.0), mOrigDCScale(1.0), mPPEventListeners(nullptr),
mBrandName(nullptr)
{
MOZ_COUNT_CTOR(nsPrintData);
nsCOMPtr<nsIStringBundle> brandBundle;
nsCOMPtr<nsIStringBundleService> svc =
mozilla::services::GetStringBundleService();
@ -53,7 +52,6 @@ nsPrintData::nsPrintData(ePrintDataType aType) :
nsPrintData::~nsPrintData()
{
MOZ_COUNT_DTOR(nsPrintData);
// remove the event listeners
if (mPPEventListeners) {
mPPEventListeners->RemoveListeners();

View File

@ -13,6 +13,7 @@
#include "nsDeviceContext.h"
#include "nsIPrintProgressParams.h"
#include "nsIPrintSettings.h"
#include "nsISupportsImpl.h"
#include "nsTArray.h"
#include "nsCOMArray.h"
@ -37,11 +38,11 @@ class nsIWebProgressListener;
//------------------------------------------------------------------------
class nsPrintData {
public:
typedef enum {eIsPrinting, eIsPrintPreview } ePrintDataType;
explicit nsPrintData(ePrintDataType aType);
~nsPrintData(); // non-virtual
NS_INLINE_DECL_REFCOUNTING(nsPrintData)
// Listener Helper Methods
void OnEndPrinting();
@ -93,6 +94,7 @@ private:
nsPrintData() = delete;
nsPrintData& operator=(const nsPrintData& aOther) = delete;
~nsPrintData(); // non-virtual
};
#endif /* nsPrintData_h___ */

View File

@ -210,18 +210,18 @@ NS_IMPL_ISUPPORTS(nsPrintEngine, nsIWebProgressListener,
//---------------------------------------------------
//-- nsPrintEngine Class Impl
//---------------------------------------------------
nsPrintEngine::nsPrintEngine() :
mIsCreatingPrintPreview(false),
mIsDoingPrinting(false),
mIsDoingPrintPreview(false),
mProgressDialogIsShown(false),
mScreenDPI(115.0f),
mPagePrintTimer(nullptr),
mDebugFile(nullptr),
mLoadCounter(0),
mDidLoadDataForPrinting(false),
mIsDestroying(false),
mDisallowSelectionPrint(false)
nsPrintEngine::nsPrintEngine()
: mIsCreatingPrintPreview(false)
, mIsDoingPrinting(false)
, mIsDoingPrintPreview(false)
, mProgressDialogIsShown(false)
, mScreenDPI(115.0f)
, mPagePrintTimer(nullptr)
, mDebugFile(nullptr)
, mLoadCounter(0)
, mDidLoadDataForPrinting(false)
, mIsDestroying(false)
, mDisallowSelectionPrint(false)
{
}
@ -431,10 +431,8 @@ nsPrintEngine::DoCommonPrint(bool aIsPrintPreview,
mProgressDialogIsShown = false;
}
mPrt = mozilla::MakeUnique<nsPrintData>(aIsPrintPreview
? nsPrintData::eIsPrintPreview
: nsPrintData::eIsPrinting);
NS_ENSURE_TRUE(mPrt, NS_ERROR_OUT_OF_MEMORY);
mPrt = new nsPrintData(aIsPrintPreview ? nsPrintData::eIsPrintPreview :
nsPrintData::eIsPrinting);
// if they don't pass in a PrintSettings, then get the Global PS
mPrt->mPrintSettings = aPrintSettings;

View File

@ -265,13 +265,19 @@ protected:
nsWeakPtr mContainer;
float mScreenDPI;
mozilla::UniquePtr<nsPrintData> mPrt;
// We are the primary owner of our nsPrintData member vars. These vars
// are refcounted so that functions (e.g. nsPrintData methods) can create
// temporary owning references when they need to fire a callback that
// could conceivably destroy this nsPrintEngine owner object and all its
// member-data.
RefPtr<nsPrintData> mPrt;
nsPagePrintTimer* mPagePrintTimer;
WeakFrame mPageSeqFrame;
// Print Preview
mozilla::UniquePtr<nsPrintData> mPrtPreview;
mozilla::UniquePtr<nsPrintData> mOldPrtPreview;
RefPtr<nsPrintData> mPrtPreview;
RefPtr<nsPrintData> mOldPrtPreview;
nsCOMPtr<nsIDocument> mDocument;