Bug 1270447 Part 1: Use the RemotePrintJob's print settings in the parent when available. draft
authorBob Owen <bobowencode@gmail.com>
Tue, 24 May 2016 13:33:12 +0100
changeset 370279 60c21e58bbb8ee440063fb0b75d8f69e08026466
parent 370278 f6e1ee9ac46c73705320caa6a208e6a017f3bdd8
child 370280 13795aadc30a8090ee548fbe1add6c71c1f540fe
push id19026
push userbobowencode@gmail.com
push dateTue, 24 May 2016 12:34:53 +0000
bugs1270447
milestone49.0a1
Bug 1270447 Part 1: Use the RemotePrintJob's print settings in the parent when available. MozReview-Commit-ID: 4PnVf4pzHWr
embedding/components/printingui/ipc/PrintingParent.cpp
layout/printing/ipc/RemotePrintJobParent.cpp
layout/printing/ipc/RemotePrintJobParent.h
--- a/embedding/components/printingui/ipc/PrintingParent.cpp
+++ b/embedding/components/printingui/ipc/PrintingParent.cpp
@@ -93,30 +93,35 @@ PrintingParent::ShowPrintDialog(PBrowser
     return NS_ERROR_FAILURE;
   }
 
   // The initSettings we got can be wrapped using
   // PrintDataUtils' MockWebBrowserPrint, which implements enough of
   // nsIWebBrowserPrint to keep the dialogs happy.
   nsCOMPtr<nsIWebBrowserPrint> wbp = new MockWebBrowserPrint(aData);
 
+  // Use the existing RemotePrintJob and its settings, if we have one, to make
+  // sure they stay current.
+  RemotePrintJobParent* remotePrintJob =
+    static_cast<RemotePrintJobParent*>(aData.remotePrintJobParent());
   nsCOMPtr<nsIPrintSettings> settings;
-  nsresult rv = mPrintSettingsSvc->GetNewPrintSettings(getter_AddRefs(settings));
-  NS_ENSURE_SUCCESS(rv, rv);
+  nsresult rv;
+  if (remotePrintJob) {
+    settings = remotePrintJob->GetPrintSettings();
+  } else {
+    rv = mPrintSettingsSvc->GetNewPrintSettings(getter_AddRefs(settings));
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
 
   rv = mPrintSettingsSvc->DeserializeToPrintSettings(aData, settings);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = pps->ShowPrintDialog(parentWin, wbp, settings);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  // Serialize back to aResult. Use the existing RemotePrintJob if we have one
-  // otherwise SerializeAndEnsureRemotePrintJob() will create a new one.
-  RemotePrintJobParent* remotePrintJob =
-    static_cast<RemotePrintJobParent*>(aData.remotePrintJobParent());
   rv = SerializeAndEnsureRemotePrintJob(settings, nullptr, remotePrintJob,
                                         aResult);
 
   return rv;
 }
 
 bool
 PrintingParent::RecvShowPrintDialog(PPrintSettingsDialogParent* aDialog,
--- a/layout/printing/ipc/RemotePrintJobParent.cpp
+++ b/layout/printing/ipc/RemotePrintJobParent.cpp
@@ -195,16 +195,22 @@ RemotePrintJobParent::RecvStatusChange(c
 void
 RemotePrintJobParent::RegisterListener(nsIWebProgressListener* aListener)
 {
   MOZ_ASSERT(aListener);
 
   mPrintProgressListeners.AppendElement(aListener);
 }
 
+already_AddRefed<nsIPrintSettings> RemotePrintJobParent::GetPrintSettings()
+{
+  nsCOMPtr<nsIPrintSettings> printSettings = mPrintSettings;
+  return printSettings.forget();
+}
+
 RemotePrintJobParent::~RemotePrintJobParent()
 {
   MOZ_COUNT_DTOR(RemotePrintJobParent);
 }
 
 void
 RemotePrintJobParent::ActorDestroy(ActorDestroyReason aWhy)
 {
--- a/layout/printing/ipc/RemotePrintJobParent.h
+++ b/layout/printing/ipc/RemotePrintJobParent.h
@@ -52,16 +52,21 @@ public:
 
   /**
     * Register a progress listener to receive print progress updates.
     *
     * @param aListener the progress listener to register. Must not be null.
     */
   void RegisterListener(nsIWebProgressListener* aListener);
 
+  /**
+    * @return the print settings for this remote print job.
+    */
+  already_AddRefed<nsIPrintSettings> GetPrintSettings();
+
 private:
   ~RemotePrintJobParent() final;
 
   nsresult InitializePrintDevice(const nsString& aDocumentTitle,
                                  const nsString& aPrintToFile,
                                  const int32_t& aStartPage,
                                  const int32_t& aEndPage);