Bug 1432651 part 4 - Stop using nsIPrintSession::GetRemotePrintJob in nsPrintJob. r=bobowen draft
authorJonathan Watt <jwatt@jwatt.org>
Tue, 23 Jan 2018 23:48:40 +0000
changeset 723867 f272d7d63367e3e5eda89a449ec2dfa93d0937aa
parent 723866 96259d00ef77f8606a5d84104bad78ec4055ebef
child 723868 1b8e1416625d874d8d59a2bf628c561184e3d6e6
push id96561
push userjwatt@jwatt.org
push dateTue, 23 Jan 2018 23:51:24 +0000
reviewersbobowen
bugs1432651
milestone60.0a1
Bug 1432651 part 4 - Stop using nsIPrintSession::GetRemotePrintJob in nsPrintJob. r=bobowen This makes nsPrintJob methods obtain the RemotePrintJobChild from its nsPrintData instead of from the nsIPrintSettings' nsIPrintSession. MozReview-Commit-ID: 4JAbGp4fQkE
layout/printing/nsPrintJob.cpp
--- a/layout/printing/nsPrintJob.cpp
+++ b/layout/printing/nsPrintJob.cpp
@@ -717,27 +717,24 @@ nsPrintJob::DoCommonPrint(bool          
   bool remotePrintJobListening = false;
   if (!aIsPrintPreview) {
     rv = printData->mPrintSettings->GetPrintSession(
                                       getter_AddRefs(printSession));
     if (NS_FAILED(rv) || !printSession) {
       printSession = do_CreateInstance("@mozilla.org/gfx/printsession;1", &rv);
       NS_ENSURE_SUCCESS(rv, rv);
       printData->mPrintSettings->SetPrintSession(printSession);
-    } else {
-      RefPtr<mozilla::layout::RemotePrintJobChild> remotePrintJob;
-      printSession->GetRemotePrintJob(getter_AddRefs(remotePrintJob));
-      if (NS_SUCCEEDED(rv) && remotePrintJob) {
-        // If we have a RemotePrintJob add it to the print progress listeners,
-        // so it can forward to the parent.
-        printData->mPrintProgressListeners.AppendElement(remotePrintJob);
-        remotePrintJobListening = true;
-      }
     }
 
+    if (printData->mRemotePrintJob) {
+      // If we have a RemotePrintJob add it to the print progress listeners,
+      // so it can forward to the parent.
+      printData->mPrintProgressListeners.AppendElement(printData->mRemotePrintJob);
+      remotePrintJobListening = true;
+    }
   }
 
   if (aWebProgressListener != nullptr) {
     printData->mPrintProgressListeners.AppendObject(aWebProgressListener);
   }
 
   // Get the currently focused window and cache it
   // because the Print Dialog will "steal" focus and later when you try
@@ -874,30 +871,28 @@ nsPrintJob::DoCommonPrint(bool          
           return NS_ERROR_FAILURE;
         }
 
         if (NS_SUCCEEDED(rv)) {
           // since we got the dialog and it worked then make sure we
           // are telling GFX we want to print silent
           printSilently = true;
 
-          if (printData->mPrintSettings && !aIsPrintPreview) {
-            // The user might have changed shrink-to-fit in the print dialog, so update our copy of its state
-            printData->mPrintSettings->GetShrinkToFit(&printData->mShrinkToFit);
-
-            // If we haven't already added the RemotePrintJob as a listener,
-            // add it now if there is one.
+          if (!aIsPrintPreview) {
+            if (printData->mPrintSettings) {
+              // The user might have changed shrink-to-fit in the print dialog, so update our copy of its state
+              printData->mPrintSettings->GetShrinkToFit(&printData->mShrinkToFit);
+            }
+
+            // The ShowPrintDialog() call above may have created a
+            // RemotePrintJobChild if we didn't already have one.  In that case
+            // we won't have added it as a listener, so we need to do that now.
             if (!remotePrintJobListening) {
-              RefPtr<mozilla::layout::RemotePrintJobChild> remotePrintJob;
-              printSession->GetRemotePrintJob(getter_AddRefs(remotePrintJob));
-              if (NS_SUCCEEDED(rv) && remotePrintJob) {
-                printData->mPrintProgressListeners.AppendElement(
-                                                     remotePrintJob);
-                remotePrintJobListening = true;
-              }
+              printData->mPrintProgressListeners.AppendElement(printData->mRemotePrintJob);
+              remotePrintJobListening = true;
             }
           }
         } else if (rv == NS_ERROR_NOT_IMPLEMENTED) {
           // This means the Dialog service was there,
           // but they choose not to implement this dialog and
           // are looking for default behavior from the toolkit
           rv = NS_OK;
         }
@@ -3507,25 +3502,19 @@ nsPrintJob::StartPagePrintTimer(const Un
     NS_ENSURE_TRUE(cv, NS_ERROR_FAILURE);
     nsCOMPtr<nsIDocument> doc = cv->GetDocument();
     NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
 
     RefPtr<nsPagePrintTimer> timer =
       new nsPagePrintTimer(this, mDocViewerPrint, doc, printPageDelay);
     timer.forget(&mPagePrintTimer);
 
-    nsCOMPtr<nsIPrintSession> printSession;
-    nsresult rv = mPrt->mPrintSettings->GetPrintSession(getter_AddRefs(printSession));
-    if (NS_SUCCEEDED(rv) && printSession) {
-      RefPtr<mozilla::layout::RemotePrintJobChild> remotePrintJob;
-      printSession->GetRemotePrintJob(getter_AddRefs(remotePrintJob));
-      if (NS_SUCCEEDED(rv) && remotePrintJob) {
-        remotePrintJob->SetPagePrintTimer(mPagePrintTimer);
-        remotePrintJob->SetPrintJob(this);
-      }
+    if (mPrt->mRemotePrintJob) {
+      mPrt->mRemotePrintJob->SetPagePrintTimer(mPagePrintTimer);
+      mPrt->mRemotePrintJob->SetPrintJob(this);
     }
   }
 
   return mPagePrintTimer->Start(aPO.get());
 }
 
 /*=============== nsIObserver Interface ======================*/
 NS_IMETHODIMP