Bug 1652322. Stop nsPrintJob::DoCommonPrint using its arguments after it creates the static clone. r=bobowen

I'm going to be splitting DoCommonPrint so that the parts that run after the
static clone is created happen after a roundtrip to the parent process.

Differential Revision: https://phabricator.services.mozilla.com/D83262
This commit is contained in:
Jonathan Watt 2020-07-12 16:36:27 +00:00
parent 0d3ea503ee
commit 7e3e095b25

View File

@ -592,8 +592,8 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
// Grab the new instance with local variable to guarantee that it won't be
// deleted during this method.
mPrt = new nsPrintData(aIsPrintPreview ? nsPrintData::eIsPrintPreview
: nsPrintData::eIsPrinting);
mPrt = new nsPrintData(mIsCreatingPrintPreview ? nsPrintData::eIsPrintPreview
: nsPrintData::eIsPrinting);
RefPtr<nsPrintData> printData = mPrt;
// if they don't pass in a PrintSettings, then get the Global PS
@ -609,7 +609,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
printData->mPrintSettings->SetIsCancelled(false);
printData->mPrintSettings->GetShrinkToFit(&printData->mShrinkToFit);
if (aIsPrintPreview) {
if (mIsCreatingPrintPreview) {
// Our new print preview nsPrintData is stored in mPtr until we move it
// to mPrtPreview once we've finish creating the print preview. We must
// clear mPtrPreview so that code will use mPtr until that happens.
@ -623,7 +623,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
// XXX What lifetime does the printSession need to have?
nsCOMPtr<nsIPrintSession> printSession;
bool remotePrintJobListening = false;
if (!aIsPrintPreview) {
if (!mIsCreatingPrintPreview) {
rv = printData->mPrintSettings->GetPrintSession(
getter_AddRefs(printSession));
if (NS_FAILED(rv) || !printSession) {
@ -667,7 +667,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
nsAutoScriptBlocker scriptBlocker;
printData->mPrintObject = MakeUnique<nsPrintObject>();
rv = printData->mPrintObject->InitAsRootObject(docShell, aSourceDoc,
aIsPrintPreview);
mIsCreatingPrintPreview);
NS_ENSURE_SUCCESS(rv, rv);
printData->mPrintDocList.AppendElement(printData->mPrintObject.get());
@ -688,7 +688,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
// cause our print/print-preview operation to finish. In this case, we
// should immediately return an error code so that the root caller knows
// it shouldn't continue to do anything with this instance.
if (mIsDestroying || (aIsPrintPreview && !mIsCreatingPrintPreview)) {
if (mIsDestroying || (mIsCreatingPrintPreview && !mIsCreatingPrintPreview)) {
return NS_ERROR_FAILURE;
}
@ -719,7 +719,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
// because we use that to retrieve the print settings from the printer.
// The dialog is not shown, but this means we don't need to access the printer
// driver from the child, which causes sandboxing issues.
if (!aIsPrintPreview || printingViaParent) {
if (!mIsCreatingPrintPreview || printingViaParent) {
scriptSuppressor.Suppress();
bool printSilently = false;
printData->mPrintSettings->GetPrintSilent(&printSilently);
@ -738,7 +738,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
if (printPromptService) {
nsPIDOMWindowOuter* domWin = nullptr;
// We leave domWin as nullptr to indicate a call for print preview.
if (!aIsPrintPreview) {
if (!mIsCreatingPrintPreview) {
domWin = mOriginalDoc->GetWindow();
NS_ENSURE_TRUE(domWin, NS_ERROR_FAILURE);
@ -765,7 +765,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
rv = printPromptService->ShowPrintDialog(domWin,
printData->mPrintSettings);
if (!aIsPrintPreview) {
if (!mIsCreatingPrintPreview) {
if (rv == NS_ERROR_ABORT) {
// When printing silently we can't get here since the user doesn't
// have the opportunity to cancel printing.
@ -795,7 +795,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
// are telling GFX we want to print silent
printSilently = true;
if (printData->mPrintSettings && !aIsPrintPreview) {
if (printData->mPrintSettings && !mIsCreatingPrintPreview) {
// The user might have changed shrink-to-fit in the print dialog, so
// update our copy of its state
printData->mPrintSettings->GetShrinkToFit(&printData->mShrinkToFit);
@ -831,7 +831,8 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
NS_ENSURE_SUCCESS(rv, rv);
}
rv = devspec->Init(nullptr, printData->mPrintSettings, aIsPrintPreview);
rv = devspec->Init(nullptr, printData->mPrintSettings,
mIsCreatingPrintPreview);
NS_ENSURE_SUCCESS(rv, rv);
printData->mPrintDC = new nsDeviceContext();
@ -844,7 +845,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
[self](nsresult aResult) { self->PageDone(aResult); });
}
if (aIsPrintPreview) {
if (mIsCreatingPrintPreview) {
// override any UI that wants to PrintPreview any selection or page range
// we want to view every page in PrintPreview each time
printData->mPrintSettings->SetPrintRange(nsIPrintSettings::kRangeAllPages);
@ -863,7 +864,7 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
mLoadCounter = 0;
mDidLoadDataForPrinting = false;
if (aIsPrintPreview) {
if (mIsCreatingPrintPreview) {
bool notifyOnInit = false;
ShowPrintProgress(false, notifyOnInit);