Bug 1270447 Part 1: Use the RemotePrintJob's print settings in the parent when available. draft
authorBob Owen <bobowencode@gmail.com>
Sun, 29 May 2016 19:53:24 +0100
changeset 372643 a11d50bf872f6c9ba73de900ee700decf0daa0f8
parent 372484 2c7440e46d8786b2c82a1d2004e2b6d9d13f4046
child 372644 d17ff5c8223563855895cdc2e58e24b685a24ba9
push id19549
push userbobowencode@gmail.com
push dateSun, 29 May 2016 18:54:12 +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,23 @@ 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);