Bug 164250 Instrument the PrintEngine for print testing

r=dcone sr=kin
This commit is contained in:
rods%netscape.com 2002-09-03 23:21:15 +00:00
Родитель b710f902ac
Коммит 24609f73f8
9 изменённых файлов: 299 добавлений и 13 удалений

Просмотреть файл

@ -56,6 +56,7 @@ REQUIRES = xpcom \
gfx2 \
uriloader \
webbrwsr \
debug \
$(NULL)
CPPSRCS = \

Просмотреть файл

@ -3038,6 +3038,8 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
nsIWebProgressListener* aWebProgressListener)
{
#ifdef NS_PRINTING
INIT_RUNTIME_ERROR_CHECKING();
// Temporary code for Bug 136185
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
if (xulDoc) {

Просмотреть файл

@ -278,6 +278,10 @@ nsPrintEngine::nsPrintEngine() :
//-------------------------------------------------------
nsPrintEngine::~nsPrintEngine()
{
#ifdef MOZ_LAYOUTDEBUG
nsPrintEngine::mLayoutDebugObj = nsnull;
#endif
Destroy(); // for insurance
}
@ -592,6 +596,8 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
NS_ASSERTION(mPrt->mPrintSettings, "You can't Print without a PrintSettings!");
rv = NS_ERROR_FAILURE;
}
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_CHECKFORPRINTERS, rv, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE);
if (NS_FAILED(rv)) {
PR_PL(("NS_ERROR_FAILURE - CheckForPrinters for Printers failed"));
return CleanupOnFailure(rv, PR_FALSE);
@ -604,6 +610,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
// The print settings hold an nsWeakPtr to the session so it does not
// need to be cleared from the settings at the end of the job.
mPrt->mPrintSession = do_CreateInstance("@mozilla.org/gfx/printsession;1", &rv);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_CREATEPRTSESSION, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
PR_PL(("NS_ERROR_FAILURE - do_CreateInstance for printsession failed"));
return CleanupOnFailure(rv, PR_TRUE);
@ -648,9 +655,12 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
// Add Root Doc to Tree and List
mPrt->mPrintObject = new nsPrintObject();
if (NS_FAILED(mPrt->mPrintObject->Init(webContainer))) {
rv = mPrt->mPrintObject->Init(webContainer);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_INITPRTOBJ, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
PR_PL(("NS_ERROR_FAILURE - Failed on Init of PrintObject"));
return NS_ERROR_FAILURE;
ShowPrintErrorDialog(NS_ERROR_FAILURE);
return rv;
}
mPrt->mPrintDocList->AppendElement(mPrt->mPrintObject);
@ -709,6 +719,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
nsCOMPtr<nsIDeviceContextSpecFactory> factory =
do_CreateInstance(kDeviceContextSpecFactoryCID, &rv);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_CREATESPECFACTORY, rv, NS_ERROR_FAILURE);
if (NS_SUCCEEDED(rv)) {
#ifdef DEBUG_dcone
printf("PRINT JOB STARTING\n");
@ -769,6 +780,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
}
}
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NOPROMPTSERVICE, rv, NS_ERROR_GFX_NO_PRINTROMPTSERVICE);
if (NS_FAILED(rv)) {
PR_PL(("**** Printing Stopped before CreateDeviceContextSpec"));
return CleanupOnFailure(rv, PR_TRUE);
@ -792,6 +804,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
return NS_ERROR_ABORT;
}
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NODEVSPEC, rv, NS_ERROR_FAILURE);
if (NS_SUCCEEDED(rv)) {
rv = mPresContext->GetDeviceContext(getter_AddRefs(dx));
if (NS_SUCCEEDED(rv)) {
@ -902,7 +915,37 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType);
}
// Get the Needed info for Calling PrepareDocument
#ifdef MOZ_LAYOUTDEBUG
{
// This is a special debugging regression tool section
PRUnichar* tempFileName = nsnull;
if (nsPrintEngine::IsDoingRuntimeTesting()) {
// Here we check for a special filename (the destination for the print job)
// and sets into the print settings if there is a name then we want to
// print to a file. if not, let it print normally.
if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintFileName(&tempFileName)) && tempFileName) {
if (*tempFileName) {
mPrt->mPrintSettings->SetPrintToFile(PR_TRUE);
mPrt->mPrintSettings->SetToFileName(tempFileName);
}
nsMemory::Free(tempFileName);
}
// Here we check to see how we should print a frameset (if there is one)
PRBool asIs = PR_FALSE;
if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintAsIs(&asIs))) {
PRInt16 howToEnableFrameUI;
mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI);
if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) {
mPrt->mPrintFrameType = asIs?nsIPrintSettings::kFramesAsIs:nsIPrintSettings::kEachFrameSep;
mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType);
}
}
}
}
#endif
// Get the Needed info for Calling PrepareDocument
PRUnichar* fileName = nsnull;
// check to see if we are printing to a file
PRBool isPrintToFile = PR_FALSE;
@ -924,7 +967,11 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
if (docTitleStr) nsMemory::Free(docTitleStr);
if (docURLStr) nsMemory::Free(docURLStr);
NS_ENSURE_SUCCESS(rv, rv);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_PREPAREDOC, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
return CleanupOnFailure(rv, PR_TRUE);
}
PRBool doNotify;
ShowPrintProgress(PR_TRUE, doNotify);
@ -2347,7 +2394,9 @@ nsPrintEngine::SetupToPrintContent(nsIWebShell* aParent,
}
// Here we reflow all the PrintObjects
if (NS_FAILED(ReflowDocList(mPrt->mPrintObject, doSetPixelScale, mPrt->mShrinkToFit))) {
nsresult rv = ReflowDocList(mPrt->mPrintObject, doSetPixelScale, mPrt->mShrinkToFit);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_REFLOWDOCLIST, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
@ -2479,7 +2528,7 @@ nsPrintEngine::SetupToPrintContent(nsIWebShell* aParent,
}
}
nsresult rv = NS_OK;
rv = NS_OK;
// BeginDocument may pass back a FAILURE code
// i.e. On Windows, if you are printing to a file and hit "Cancel"
// to the "File Name" dialog, this comes back as an error
@ -2493,6 +2542,7 @@ nsPrintEngine::SetupToPrintContent(nsIWebShell* aParent,
if (docTitleStr) nsMemory::Free(docTitleStr);
if (docURLStr) nsMemory::Free(docURLStr);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_BEGINDOC, rv, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(rv, rv);
// This will print the webshell document
@ -3596,6 +3646,7 @@ nsPrintEngine::PrintPage(nsIPresContext* aPresContext,
// When rv == NS_ERROR_ABORT, it means we want out of the
// print job without displaying any error messages
nsresult rv = mPageSeqFrame->PrintNextPage(aPresContext);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NEXTPAGE, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
if (rv != NS_ERROR_ABORT) {
ShowPrintErrorDialog(rv);
@ -5115,12 +5166,58 @@ static void DumpPrintObjectsListStart(char * aStr, nsVoidArray * aDocList)
#define DUMP_DOC_LIST(_title) DumpPrintObjectsListStart((_title), mPrt->mPrintDocList);
#define DUMP_DOC_TREE DumpPrintObjectsTree(mPrt->mPrintObject);
#define DUMP_DOC_TREELAYOUT DumpPrintObjectsTreeLayout(mPrt->mPrintObject, mPrt->mPrintDC);
#else
#define DUMP_DOC_LIST(_title)
#define DUMP_DOC_TREE
#define DUMP_DOC_TREELAYOUT
#endif
#ifdef MOZ_LAYOUTDEBUG
nsCOMPtr<nsIDebugObject> nsPrintEngine::mLayoutDebugObj;
PRBool nsPrintEngine::mIsDoingRuntimeTesting = PR_FALSE;
void
nsPrintEngine::InitializeTestRuntimeError()
{
nsCOMPtr<nsIPref> prefs (do_GetService(NS_PREF_CONTRACTID));
if (prefs) {
mIsDoingRuntimeTesting = PR_FALSE;
prefs->GetBoolPref("print.doing_runtime_error_checking", &mIsDoingRuntimeTesting);
}
mLayoutDebugObj = do_GetService("@mozilla.org/debug/debugobject;1");
}
PRBool
nsPrintEngine::IsDoingRuntimeTesting()
{
PRBool isDoingTests = PR_FALSE;
if (mLayoutDebugObj) {
mLayoutDebugObj->GetDoRuntimeTests(&isDoingTests);
}
return isDoingTests;
}
nsresult
nsPrintEngine::TestRuntimeErrorCondition(PRInt16 aRuntimeID,
nsresult aCurrentErrorCode,
nsresult aNewErrorCode)
{
PRInt16 id;
if (mLayoutDebugObj) {
if (NS_SUCCEEDED(mLayoutDebugObj->GetTestId(&id))) {
if (id == aRuntimeID) {
return aNewErrorCode;
}
}
}
return aCurrentErrorCode;
}
#endif
//---------------------------------------------------------------
//---------------------------------------------------------------
//-- End of debug helper routines

Просмотреть файл

@ -66,6 +66,10 @@ class nsPagePrintTimer;
#include "nsIDocumentViewer.h"
#include "nsIDocumentViewerPrint.h"
#ifdef MOZ_LAYOUTDEBUG
#include "nsIDebugObject.h"
#endif
//------------------------------------------------------------------------
// nsPrintEngine Class
//
@ -270,6 +274,19 @@ public:
void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) { mIsCreatingPrintPreview = aIsCreatingPrintPreview; }
PRBool GetIsCreatingPrintPreview() { return mIsCreatingPrintPreview; }
#ifdef MOZ_LAYOUTDEBUG
static nsresult TestRuntimeErrorCondition(PRInt16 aRuntimeID,
nsresult aCurrentErrorCode,
nsresult aNewErrorCode);
static PRBool IsDoingRuntimeTesting();
static void InitializeTestRuntimeError();
protected:
static PRBool mIsDoingRuntimeTesting;
static nsCOMPtr<nsIDebugObject> mLayoutDebugObj; // always de-referenced with the destructor
#endif
protected:
static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell);
void FirePrintCompletionEvent();
@ -329,5 +346,16 @@ private:
};
#ifdef MOZ_LAYOUTDEBUG
#define INIT_RUNTIME_ERROR_CHECKING() nsPrintEngine::InitializeTestRuntimeError();
#define CHECK_RUNTIME_ERROR_CONDITION(_name, _currerr, _newerr) \
if (nsPrintEngine::IsDoingRuntimeTesting()) { \
_currerr = nsPrintEngine::TestRuntimeErrorCondition(_name, _currerr, _newerr); \
}
#else
#define CHECK_RUNTIME_ERROR_CONDITION
#define INIT_RUNTIME_ERROR_CHECKING
#endif
#endif /* nsPrintEngine_h___ */

Просмотреть файл

@ -44,6 +44,7 @@ REQUIRES = xpcom \
necko \
content \
layout \
debug \
$(NULL)
CPPSRCS = \

Просмотреть файл

@ -49,6 +49,10 @@
#include "nsString.h"
#if defined(DEBUG_rods) && defined(MOZ_LAYOUTDEBUG)
#include "nsIDebugObject.h"
#endif
#define DOC_TITLE_LENGTH 64
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
@ -789,8 +793,28 @@ NS_IMETHODIMP nsDeviceContextWin :: BeginDocument(PRUnichar * aTitle, PRUnichar*
docinfo.cbSize = sizeof(docinfo);
docinfo.lpszDocName = title != nsnull?title:"Mozilla Document";
#ifdef DEBUG_rods
#if defined(DEBUG_rods) && defined(MOZ_LAYOUTDEBUG)
docinfo.lpszOutput = "\\p.ps";
// This is for overriding the above when doing the runtime checking
char * tempFileName = nsnull;
nsCOMPtr<nsIDebugObject>debugObj = do_GetService("@mozilla.org/debug/debugobject;1");
if (debugObj) {
PRBool isDoingTests;
if (NS_SUCCEEDED(debugObj->GetDoRuntimeTests(&isDoingTests)) && isDoingTests) {
PRUnichar * name;
debugObj->GetPrintFileName(&name);
if (name) {
if (*name) {
nsCString cStrName;
cStrName.AssignWithConversion(name);
tempFileName = ToNewCString(cStrName);
}
nsMemory::Free(name);
}
docinfo.lpszOutput = tempFileName;
}
}
#else
docinfo.lpszOutput = docName;
#endif
@ -808,6 +832,12 @@ NS_IMETHODIMP nsDeviceContextWin :: BeginDocument(PRUnichar * aTitle, PRUnichar*
if (title != nsnull) delete [] title;
if (docName != nsnull) nsMemory::Free(docName);
#if defined(DEBUG_rods) && defined(MOZ_LAYOUTDEBUG)
if (tempFileName) {
nsMemory::Free(tempFileName);
}
#endif
}
return rv;

Просмотреть файл

@ -3038,6 +3038,8 @@ DocumentViewerImpl::Print(nsIPrintSettings* aPrintSettings,
nsIWebProgressListener* aWebProgressListener)
{
#ifdef NS_PRINTING
INIT_RUNTIME_ERROR_CHECKING();
// Temporary code for Bug 136185
nsCOMPtr<nsIXULDocument> xulDoc(do_QueryInterface(mDocument));
if (xulDoc) {

Просмотреть файл

@ -278,6 +278,10 @@ nsPrintEngine::nsPrintEngine() :
//-------------------------------------------------------
nsPrintEngine::~nsPrintEngine()
{
#ifdef MOZ_LAYOUTDEBUG
nsPrintEngine::mLayoutDebugObj = nsnull;
#endif
Destroy(); // for insurance
}
@ -592,6 +596,8 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
NS_ASSERTION(mPrt->mPrintSettings, "You can't Print without a PrintSettings!");
rv = NS_ERROR_FAILURE;
}
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_CHECKFORPRINTERS, rv, NS_ERROR_GFX_PRINTER_NO_PRINTER_AVAILABLE);
if (NS_FAILED(rv)) {
PR_PL(("NS_ERROR_FAILURE - CheckForPrinters for Printers failed"));
return CleanupOnFailure(rv, PR_FALSE);
@ -604,6 +610,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
// The print settings hold an nsWeakPtr to the session so it does not
// need to be cleared from the settings at the end of the job.
mPrt->mPrintSession = do_CreateInstance("@mozilla.org/gfx/printsession;1", &rv);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_CREATEPRTSESSION, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
PR_PL(("NS_ERROR_FAILURE - do_CreateInstance for printsession failed"));
return CleanupOnFailure(rv, PR_TRUE);
@ -648,9 +655,12 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
// Add Root Doc to Tree and List
mPrt->mPrintObject = new nsPrintObject();
if (NS_FAILED(mPrt->mPrintObject->Init(webContainer))) {
rv = mPrt->mPrintObject->Init(webContainer);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_INITPRTOBJ, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
PR_PL(("NS_ERROR_FAILURE - Failed on Init of PrintObject"));
return NS_ERROR_FAILURE;
ShowPrintErrorDialog(NS_ERROR_FAILURE);
return rv;
}
mPrt->mPrintDocList->AppendElement(mPrt->mPrintObject);
@ -709,6 +719,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
nsCOMPtr<nsIDeviceContextSpecFactory> factory =
do_CreateInstance(kDeviceContextSpecFactoryCID, &rv);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_CREATESPECFACTORY, rv, NS_ERROR_FAILURE);
if (NS_SUCCEEDED(rv)) {
#ifdef DEBUG_dcone
printf("PRINT JOB STARTING\n");
@ -769,6 +780,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
}
}
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NOPROMPTSERVICE, rv, NS_ERROR_GFX_NO_PRINTROMPTSERVICE);
if (NS_FAILED(rv)) {
PR_PL(("**** Printing Stopped before CreateDeviceContextSpec"));
return CleanupOnFailure(rv, PR_TRUE);
@ -792,6 +804,7 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
return NS_ERROR_ABORT;
}
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NODEVSPEC, rv, NS_ERROR_FAILURE);
if (NS_SUCCEEDED(rv)) {
rv = mPresContext->GetDeviceContext(getter_AddRefs(dx));
if (NS_SUCCEEDED(rv)) {
@ -902,7 +915,37 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
mPrt->mPrintSettings->GetPrintFrameType(&mPrt->mPrintFrameType);
}
// Get the Needed info for Calling PrepareDocument
#ifdef MOZ_LAYOUTDEBUG
{
// This is a special debugging regression tool section
PRUnichar* tempFileName = nsnull;
if (nsPrintEngine::IsDoingRuntimeTesting()) {
// Here we check for a special filename (the destination for the print job)
// and sets into the print settings if there is a name then we want to
// print to a file. if not, let it print normally.
if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintFileName(&tempFileName)) && tempFileName) {
if (*tempFileName) {
mPrt->mPrintSettings->SetPrintToFile(PR_TRUE);
mPrt->mPrintSettings->SetToFileName(tempFileName);
}
nsMemory::Free(tempFileName);
}
// Here we check to see how we should print a frameset (if there is one)
PRBool asIs = PR_FALSE;
if (NS_SUCCEEDED(mLayoutDebugObj->GetPrintAsIs(&asIs))) {
PRInt16 howToEnableFrameUI;
mPrt->mPrintSettings->GetHowToEnableFrameUI(&howToEnableFrameUI);
if (howToEnableFrameUI != nsIPrintSettings::kFrameEnableNone) {
mPrt->mPrintFrameType = asIs?nsIPrintSettings::kFramesAsIs:nsIPrintSettings::kEachFrameSep;
mPrt->mPrintSettings->SetPrintFrameType(mPrt->mPrintFrameType);
}
}
}
}
#endif
// Get the Needed info for Calling PrepareDocument
PRUnichar* fileName = nsnull;
// check to see if we are printing to a file
PRBool isPrintToFile = PR_FALSE;
@ -924,7 +967,11 @@ nsPrintEngine::Print(nsIPrintSettings* aPrintSettings,
if (docTitleStr) nsMemory::Free(docTitleStr);
if (docURLStr) nsMemory::Free(docURLStr);
NS_ENSURE_SUCCESS(rv, rv);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_PREPAREDOC, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
return CleanupOnFailure(rv, PR_TRUE);
}
PRBool doNotify;
ShowPrintProgress(PR_TRUE, doNotify);
@ -2347,7 +2394,9 @@ nsPrintEngine::SetupToPrintContent(nsIWebShell* aParent,
}
// Here we reflow all the PrintObjects
if (NS_FAILED(ReflowDocList(mPrt->mPrintObject, doSetPixelScale, mPrt->mShrinkToFit))) {
nsresult rv = ReflowDocList(mPrt->mPrintObject, doSetPixelScale, mPrt->mShrinkToFit);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_REFLOWDOCLIST, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
@ -2479,7 +2528,7 @@ nsPrintEngine::SetupToPrintContent(nsIWebShell* aParent,
}
}
nsresult rv = NS_OK;
rv = NS_OK;
// BeginDocument may pass back a FAILURE code
// i.e. On Windows, if you are printing to a file and hit "Cancel"
// to the "File Name" dialog, this comes back as an error
@ -2493,6 +2542,7 @@ nsPrintEngine::SetupToPrintContent(nsIWebShell* aParent,
if (docTitleStr) nsMemory::Free(docTitleStr);
if (docURLStr) nsMemory::Free(docURLStr);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_BEGINDOC, rv, NS_ERROR_FAILURE);
NS_ENSURE_SUCCESS(rv, rv);
// This will print the webshell document
@ -3596,6 +3646,7 @@ nsPrintEngine::PrintPage(nsIPresContext* aPresContext,
// When rv == NS_ERROR_ABORT, it means we want out of the
// print job without displaying any error messages
nsresult rv = mPageSeqFrame->PrintNextPage(aPresContext);
CHECK_RUNTIME_ERROR_CONDITION(nsIDebugObject::PRT_RUNTIME_NEXTPAGE, rv, NS_ERROR_FAILURE);
if (NS_FAILED(rv)) {
if (rv != NS_ERROR_ABORT) {
ShowPrintErrorDialog(rv);
@ -5115,12 +5166,58 @@ static void DumpPrintObjectsListStart(char * aStr, nsVoidArray * aDocList)
#define DUMP_DOC_LIST(_title) DumpPrintObjectsListStart((_title), mPrt->mPrintDocList);
#define DUMP_DOC_TREE DumpPrintObjectsTree(mPrt->mPrintObject);
#define DUMP_DOC_TREELAYOUT DumpPrintObjectsTreeLayout(mPrt->mPrintObject, mPrt->mPrintDC);
#else
#define DUMP_DOC_LIST(_title)
#define DUMP_DOC_TREE
#define DUMP_DOC_TREELAYOUT
#endif
#ifdef MOZ_LAYOUTDEBUG
nsCOMPtr<nsIDebugObject> nsPrintEngine::mLayoutDebugObj;
PRBool nsPrintEngine::mIsDoingRuntimeTesting = PR_FALSE;
void
nsPrintEngine::InitializeTestRuntimeError()
{
nsCOMPtr<nsIPref> prefs (do_GetService(NS_PREF_CONTRACTID));
if (prefs) {
mIsDoingRuntimeTesting = PR_FALSE;
prefs->GetBoolPref("print.doing_runtime_error_checking", &mIsDoingRuntimeTesting);
}
mLayoutDebugObj = do_GetService("@mozilla.org/debug/debugobject;1");
}
PRBool
nsPrintEngine::IsDoingRuntimeTesting()
{
PRBool isDoingTests = PR_FALSE;
if (mLayoutDebugObj) {
mLayoutDebugObj->GetDoRuntimeTests(&isDoingTests);
}
return isDoingTests;
}
nsresult
nsPrintEngine::TestRuntimeErrorCondition(PRInt16 aRuntimeID,
nsresult aCurrentErrorCode,
nsresult aNewErrorCode)
{
PRInt16 id;
if (mLayoutDebugObj) {
if (NS_SUCCEEDED(mLayoutDebugObj->GetTestId(&id))) {
if (id == aRuntimeID) {
return aNewErrorCode;
}
}
}
return aCurrentErrorCode;
}
#endif
//---------------------------------------------------------------
//---------------------------------------------------------------
//-- End of debug helper routines

Просмотреть файл

@ -66,6 +66,10 @@ class nsPagePrintTimer;
#include "nsIDocumentViewer.h"
#include "nsIDocumentViewerPrint.h"
#ifdef MOZ_LAYOUTDEBUG
#include "nsIDebugObject.h"
#endif
//------------------------------------------------------------------------
// nsPrintEngine Class
//
@ -270,6 +274,19 @@ public:
void SetIsCreatingPrintPreview(PRBool aIsCreatingPrintPreview) { mIsCreatingPrintPreview = aIsCreatingPrintPreview; }
PRBool GetIsCreatingPrintPreview() { return mIsCreatingPrintPreview; }
#ifdef MOZ_LAYOUTDEBUG
static nsresult TestRuntimeErrorCondition(PRInt16 aRuntimeID,
nsresult aCurrentErrorCode,
nsresult aNewErrorCode);
static PRBool IsDoingRuntimeTesting();
static void InitializeTestRuntimeError();
protected:
static PRBool mIsDoingRuntimeTesting;
static nsCOMPtr<nsIDebugObject> mLayoutDebugObj; // always de-referenced with the destructor
#endif
protected:
static nsIPresShell* GetPresShellFor(nsIDocShell* aDocShell);
void FirePrintCompletionEvent();
@ -329,5 +346,16 @@ private:
};
#ifdef MOZ_LAYOUTDEBUG
#define INIT_RUNTIME_ERROR_CHECKING() nsPrintEngine::InitializeTestRuntimeError();
#define CHECK_RUNTIME_ERROR_CONDITION(_name, _currerr, _newerr) \
if (nsPrintEngine::IsDoingRuntimeTesting()) { \
_currerr = nsPrintEngine::TestRuntimeErrorCondition(_name, _currerr, _newerr); \
}
#else
#define CHECK_RUNTIME_ERROR_CONDITION
#define INIT_RUNTIME_ERROR_CHECKING
#endif
#endif /* nsPrintEngine_h___ */