Bug 1399787 - Part 12. Delay dispatching FinalizePrint message until the last page was processed. r=jwatt
☠☠ backed out by 2e0485d0998d ☠ ☠
authorcku <cku@mozilla.com>
Mon, 06 Nov 2017 16:28:51 +0800
changeset 395702 a7d70f7f33354a433a986dec8f983e7ead3e463b
parent 395701 2800f9d20d96e8b891b8b34e4364c47a7978e7f6
child 395703 d7fef200e8b9f3003210945bc56dfb978e143888
push id33054
push userrgurzau@mozilla.com
push dateFri, 08 Dec 2017 21:57:23 +0000
treeherdermozilla-central@6e2181b6137c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwatt
bugs1399787
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 1399787 - Part 12. Delay dispatching FinalizePrint message until the last page was processed. r=jwatt For the last page, here is the final three messages sent between the content process, RemotePrintJobChild, and the chrome process, RemotePrintJobParent, for printing: 1. The content process sends *ProcessPage* to the chrome process via SendProcessPrint to request the chrome process print the last page. 2. The content process sends *FinalizePrint* to the chrome process via SendFinalizePrint to notify the chrome that there are no more outstanding print requests, and that the chrome process can release interal resource now. 3. The content process receive PageProcessed message from the chrome process. This calling sequence is fine for sync style PrintTarget (even though the FinalizePrint message is sent out a bit ealy). Since a sync PrintTarget completes its print task right after receiving *ProcessPage* message in #1, sending FinalizePrint before getting PageProcessed response is harmless. But this message dispatching sequence does cause a problem for async style PrintTargetEMF. After getting a message sent in #2, PrintTargetEMF release all resources before getting a EMF conversion response from the PDFium process. So the last page can not be printed correctly. This patch reorder the #2 and #3 message, that is to send FinalizePrint after the content process received PageProcessed message of the last page. MozReview-Commit-ID: 9ZVSrFnuHBU
layout/printing/nsPagePrintTimer.cpp
layout/printing/nsPrintEngine.cpp
--- a/layout/printing/nsPagePrintTimer.cpp
+++ b/layout/printing/nsPagePrintTimer.cpp
@@ -75,22 +75,19 @@ nsPagePrintTimer::Run()
   // Check to see if we are done
   // inRange will be true if a page is actually printed
   bool inRange;
   bool donePrinting;
 
   // donePrinting will be true if it completed successfully or
   // if the printing was cancelled
   donePrinting = !mPrintEngine || mPrintEngine->PrintPage(mPrintObj, inRange);
-  if (donePrinting) {
-    // now clean up print or print the next webshell
-    if (!mPrintEngine || mPrintEngine->DonePrintingPages(mPrintObj, NS_OK)) {
-      initNewTimer = false;
-      mDone = true;
-    }
+  if (mPrintEngine && donePrinting) {
+    initNewTimer = false;
+    mDone = true;
   }
 
   // Note that the Stop() destroys this after the print job finishes
   // (The PrintEngine stops holding a reference when DonePrintingPages
   // returns true.)
   Stop();
   if (initNewTimer) {
     ++mFiringCount;
@@ -176,16 +173,21 @@ nsPagePrintTimer::WaitForRemotePrint()
 
 void
 nsPagePrintTimer::RemotePrintFinished()
 {
   if (!mWaitingForRemotePrint) {
     return;
   }
 
+  // now clean up print or print the next webshell
+  if (mDone && mPrintEngine) {
+    mPrintEngine->DonePrintingPages(mPrintObj, NS_OK);
+  }
+
   mWaitingForRemotePrint->SetTarget(
     mDocument->EventTargetFor(mozilla::TaskCategory::Other));
   mozilla::Unused <<
     mWaitingForRemotePrint->InitWithCallback(this, 0, nsITimer::TYPE_ONE_SHOT);
 }
 
 nsresult
 nsPagePrintTimer::Start(nsPrintObject* aPO)
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -2789,16 +2789,17 @@ nsPrintEngine::PrintPage(nsPrintObject* 
 
   PR_PL(("-----------------------------------\n"));
   PR_PL(("------ In DV::PrintPage PO: %p (%s)\n", aPO, gFrameTypesStr[aPO->mFrameType]));
 
   // Check setting to see if someone request it be cancelled
   bool isCancelled = false;
   printData->mPrintSettings->GetIsCancelled(&isCancelled);
   if (isCancelled || printData->mIsAborted) {
+    DonePrintingPages(aPO, NS_OK);
     return true;
   }
 
   int32_t pageNum, numPages, endPage;
   nsIPageSequenceFrame* pageSeqFrame = do_QueryFrame(mPageSeqFrame.GetFrame());
   pageSeqFrame->GetCurrentPageNum(&pageNum);
   pageSeqFrame->GetNumPages(&numPages);