Bug 1189846 Part 1: Move PrintSettings serialization into nsIPrintSettingsService. r=jimm
authorBob Owen <bobowencode@gmail.com>
Mon, 16 May 2016 10:40:53 +0100
changeset 336507 01f780f3be075944a158d55b7fa1cb3b414859a2
parent 336506 0041bc955a8d3f68c99c0de24e91f93d004022d4
child 336508 ece4ab0326116579d7b9097cb3c80cbf2501ad9b
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1189846
milestone49.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 1189846 Part 1: Move PrintSettings serialization into nsIPrintSettingsService. r=jimm MozReview-Commit-ID: 1sI6VXUHETZ
embedding/components/printingui/ipc/PrintingParent.cpp
embedding/components/printingui/ipc/nsPrintingProxy.cpp
widget/nsIPrintOptions.idl
widget/nsIPrintSettingsService.idl
--- a/embedding/components/printingui/ipc/PrintingParent.cpp
+++ b/embedding/components/printingui/ipc/PrintingParent.cpp
@@ -1,24 +1,26 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/TabParent.h"
+#include "mozilla/unused.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIDOMWindow.h"
 #include "nsIPrintingPromptService.h"
 #include "nsIPrintOptions.h"
 #include "nsIPrintProgressParams.h"
 #include "nsIPrintSettingsService.h"
 #include "nsIServiceManager.h"
+#include "nsServiceManagerUtils.h"
 #include "nsIWebProgressListener.h"
 #include "PrintingParent.h"
 #include "PrintDataUtils.h"
 #include "PrintProgressDialogParent.h"
 #include "PrintSettingsDialogParent.h"
 #include "mozilla/layout/RemotePrintJobParent.h"
 
 using namespace mozilla;
@@ -84,31 +86,32 @@ PrintingParent::ShowPrintDialog(PBrowser
   }
 
   // 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);
 
   nsresult rv;
-  nsCOMPtr<nsIPrintOptions> po = do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv);
+  nsCOMPtr<nsIPrintSettingsService> printSettingsSvc =
+    do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIPrintSettings> settings;
-  rv = po->CreatePrintSettings(getter_AddRefs(settings));
+  rv = printSettingsSvc->GetNewPrintSettings(getter_AddRefs(settings));
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = po->DeserializeToPrintSettings(aData, settings);
+  rv = printSettingsSvc->DeserializeToPrintSettings(aData, settings);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = pps->ShowPrintDialog(parentWin, wbp, settings);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // And send it back.
-  rv = po->SerializeToPrintData(settings, nullptr, aResult);
+  rv = printSettingsSvc->SerializeToPrintData(settings, nullptr, aResult);
 
   PRemotePrintJobParent* remotePrintJob = new RemotePrintJobParent(settings);
   aResult->remotePrintJobParent() = SendPRemotePrintJobConstructor(remotePrintJob);
 
   return rv;
 }
 
 bool
@@ -132,31 +135,30 @@ PrintingParent::RecvShowPrintDialog(PPri
 }
 
 bool
 PrintingParent::RecvSavePrintSettings(const PrintData& aData,
                                       const bool& aUsePrinterNamePrefix,
                                       const uint32_t& aFlags,
                                       nsresult* aResult)
 {
-  nsCOMPtr<nsIPrintSettingsService> pss =
+  nsCOMPtr<nsIPrintSettingsService> printSettingsSvc =
     do_GetService("@mozilla.org/gfx/printsettings-service;1", aResult);
   NS_ENSURE_SUCCESS(*aResult, true);
 
-  nsCOMPtr<nsIPrintOptions> po = do_QueryInterface(pss, aResult);
-  NS_ENSURE_SUCCESS(*aResult, true);
-
   nsCOMPtr<nsIPrintSettings> settings;
-  *aResult = po->CreatePrintSettings(getter_AddRefs(settings));
+  *aResult = printSettingsSvc->GetNewPrintSettings(getter_AddRefs(settings));
   NS_ENSURE_SUCCESS(*aResult, true);
 
-  *aResult = po->DeserializeToPrintSettings(aData, settings);
+  *aResult = printSettingsSvc->DeserializeToPrintSettings(aData, settings);
   NS_ENSURE_SUCCESS(*aResult, true);
 
-  *aResult = pss->SavePrintSettingsToPrefs(settings, aUsePrinterNamePrefix, aFlags);
+  *aResult = printSettingsSvc->SavePrintSettingsToPrefs(settings,
+                                                        aUsePrinterNamePrefix,
+                                                        aFlags);
 
   return true;
 }
 
 PPrintProgressDialogParent*
 PrintingParent::AllocPPrintProgressDialogParent()
 {
   PrintProgressDialogParent* actor = new PrintProgressDialogParent();
--- a/embedding/components/printingui/ipc/nsPrintingProxy.cpp
+++ b/embedding/components/printingui/ipc/nsPrintingProxy.cpp
@@ -11,18 +11,20 @@
 #include "mozilla/dom/TabChild.h"
 #include "mozilla/layout/RemotePrintJobChild.h"
 #include "mozilla/unused.h"
 #include "nsIDocShell.h"
 #include "nsIDocShellTreeOwner.h"
 #include "nsIPrintingPromptService.h"
 #include "nsPIDOMWindow.h"
 #include "nsPrintOptionsImpl.h"
+#include "nsServiceManagerUtils.h"
 #include "PrintDataUtils.h"
 #include "PrintProgressDialogChild.h"
+#include "PrintSettingsDialogChild.h"
 
 using namespace mozilla;
 using namespace mozilla::dom;
 using namespace mozilla::embedding;
 using namespace mozilla::layout;
 
 static StaticRefPtr<nsPrintingProxy> sPrintingProxyInstance;
 
@@ -82,22 +84,23 @@ nsPrintingProxy::ShowPrintDialog(mozIDOM
 
   nsCOMPtr<nsITabChild> tabchild = docShell->GetTabChild();
   NS_ENSURE_STATE(tabchild);
 
   TabChild* pBrowser = static_cast<TabChild*>(tabchild.get());
 
   // Next, serialize the nsIWebBrowserPrint and nsIPrintSettings we were given.
   nsresult rv = NS_OK;
-  nsCOMPtr<nsIPrintOptions> po =
+  nsCOMPtr<nsIPrintSettingsService> printSettingsSvc =
     do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PrintData inSettings;
-  rv = po->SerializeToPrintData(printSettings, webBrowserPrint, &inSettings);
+  rv = printSettingsSvc->SerializeToPrintData(printSettings, webBrowserPrint,
+                                              &inSettings);
   NS_ENSURE_SUCCESS(rv, rv);
 
   // Now, the waiting game. The parent process should be showing
   // the printing dialog soon. In the meantime, we need to spin a
   // nested event loop while we wait for the results of the dialog
   // to be returned to us.
 
   RefPtr<PrintSettingsDialogChild> dialog = new PrintSettingsDialogChild();
@@ -107,17 +110,18 @@ nsPrintingProxy::ShowPrintDialog(mozIDOM
 
   while(!dialog->returned()) {
     NS_ProcessNextEvent(nullptr, true);
   }
 
   rv = dialog->result();
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = po->DeserializeToPrintSettings(dialog->data(), printSettings);
+  rv = printSettingsSvc->DeserializeToPrintSettings(dialog->data(),
+                                                    printSettings);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsPrintingProxy::ShowProgress(mozIDOMWindowProxy*      parent,
                               nsIWebBrowserPrint*      webBrowserPrint,    // ok to be null
                               nsIPrintSettings*        printSettings,      // ok to be null
                               nsIObserver*             openDialogObserver, // ok to be null
@@ -175,22 +179,22 @@ nsPrintingProxy::ShowPrinterProperties(m
 }
 
 nsresult
 nsPrintingProxy::SavePrintSettings(nsIPrintSettings* aPS,
                                    bool aUsePrinterNamePrefix,
                                    uint32_t aFlags)
 {
   nsresult rv;
-  nsCOMPtr<nsIPrintOptions> po =
+  nsCOMPtr<nsIPrintSettingsService> printSettingsSvc =
     do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv);
   NS_ENSURE_SUCCESS(rv, rv);
 
   PrintData settings;
-  rv = po->SerializeToPrintData(aPS, nullptr, &settings);
+  rv = printSettingsSvc->SerializeToPrintData(aPS, nullptr, &settings);
   NS_ENSURE_SUCCESS(rv, rv);
 
   Unused << SendSavePrintSettings(settings, aUsePrinterNamePrefix, aFlags,
                                   &rv);
   return rv;
 }
 
 PPrintProgressDialogChild*
--- a/widget/nsIPrintOptions.idl
+++ b/widget/nsIPrintOptions.idl
@@ -1,35 +1,17 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsISupports.idl"
 #include "nsIPrintSettings.idl"
 
-%{ C++
-struct nsFont;
-
-namespace mozilla {
-namespace embedding {
-  class PrintData;
-}
-}
-%}
-
 interface nsIStringEnumerator;
-interface nsIWebBrowserPrint;
-
-/**
- * Native types
- */
-[ref] native nsNativeFontRef(nsFont);
-[ref] native PrintDataRef(const mozilla::embedding::PrintData);
-[ptr] native PrintDataPtr(mozilla::embedding::PrintData);
 
 /**
  * Print options interface
  *
  * Do not attempt to freeze this API - it still needs lots of work. Consult
  * John Keiser <jkeiser@netscape.com> and Roland Mainz
  * <roland.mainz@informatik.med.uni-giessen.de> for futher details.
  */
@@ -61,49 +43,16 @@ interface nsIPrintOptions : nsISupports
                              aPrintSettings, out boolean aDisplayed);
 
   /**
    * Native data constants
    */
   const short kNativeDataPrintRecord        = 0;
 
   [noscript] voidPtr GetNativeData(in short aDataType);
-
-  /**
-   * Given some nsIPrintSettings and (optionally) an nsIWebBrowserPrint, populates
-   * a PrintData representing them which can be sent over IPC. Values are only
-   * ever read from aSettings and aWBP.
-   *
-   * @param aSettings
-   *        An nsIPrintSettings for a print job.
-   * @param aWBP (optional)
-   *        The nsIWebBrowserPrint for the print job.
-   * @param data
-   *        Pointer to a pre-existing PrintData to populate.
-   *
-   * @return nsresult
-   */
-  [noscript] void SerializeToPrintData(in nsIPrintSettings aPrintSettings,
-                                       in nsIWebBrowserPrint aWebBrowserPrint,
-                                       in PrintDataPtr data);
-
-  /**
-   * This function is the opposite of SerializeToPrintData, in that it takes
-   * a PrintData, and populates a pre-existing nsIPrintSettings with the data
-   * from PrintData.
-   *
-   * @param PrintData
-   *        Printing information sent through IPC.
-   * @param settings
-   *        A pre-existing nsIPrintSettings to populate with the PrintData.
-   *
-   * @return nsresult
-   */
-  [noscript] void DeserializeToPrintSettings(in PrintDataRef data,
-                                             in nsIPrintSettings aPrintSettings);
 };
 
 [scriptable, uuid(5e738fff-404c-4c94-9189-e8f2cce93e94)]
 
 interface nsIPrinterEnumerator : nsISupports
 {
   /**
    * The name of the system default printer. This name should also be
--- a/widget/nsIPrintSettingsService.idl
+++ b/widget/nsIPrintSettingsService.idl
@@ -5,16 +5,31 @@
 
 /* Interface to the Service for gwetting the Global PrintSettings object
    or a unique PrintSettings object
 */
 
 #include "nsISupports.idl"
 
 interface nsIPrintSettings;
+interface nsIWebBrowserPrint;
+
+%{ C++
+namespace mozilla {
+namespace embedding {
+  class PrintData;
+}
+}
+%}
+
+/**
+ * Native types
+ */
+[ref] native PrintDataRef(const mozilla::embedding::PrintData);
+[ptr] native PrintDataPtr(mozilla::embedding::PrintData);
 
 [scriptable, uuid(841387C8-72E6-484b-9296-BF6EEA80D58A)]
 interface nsIPrintSettingsService : nsISupports
 {
   /**
    * Returns a "global" PrintSettings object 
    * Creates a new the first time, if one doesn't exist.
    *
@@ -92,15 +107,50 @@ interface nsIPrintSettingsService : nsIS
    * Items not written:
    *   startPageRange, endPageRange, scaling, printRange, title
    *   docURL, howToEnableFrameUI, isCancelled, printFrameTypeUsage
    *   printFrameType, printSilent, shrinkToFit, numCopies
    *
    */
   void savePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
 
+  /**
+   * Given some nsIPrintSettings and (optionally) an nsIWebBrowserPrint,
+   * populates a PrintData representing them which can be sent over IPC. Values
+   * are only ever read from aSettings and aWBP.
+   *
+   * @param aSettings
+   *        An nsIPrintSettings for a print job.
+   * @param aWBP (optional)
+   *        The nsIWebBrowserPrint for the print job.
+   * @param data
+   *        Pointer to a pre-existing PrintData to populate.
+   *
+   * @return nsresult
+   */
+  [noscript]
+  void SerializeToPrintData(in nsIPrintSettings aPrintSettings,
+                            in nsIWebBrowserPrint aWebBrowserPrint,
+                            in PrintDataPtr data);
+
+  /**
+   * This function is the opposite of SerializeToPrintData, in that it takes
+   * a PrintData, and populates a pre-existing nsIPrintSettings with the data
+   * from PrintData.
+   *
+   * @param PrintData
+   *        Printing information sent through IPC.
+   * @param settings
+   *        A pre-existing nsIPrintSettings to populate with the PrintData.
+   *
+   * @return nsresult
+   */
+  [noscript]
+  void DeserializeToPrintSettings(in PrintDataRef data,
+                                  in nsIPrintSettings aPrintSettings);
+
 };
 
 %{C++
 // {841387C8-72E6-484b-9296-BF6EEA80D58A}
 #define NS_PRINTSETTINGSSERVICE_IID \
  {0x841387c8, 0x72e6, 0x484b, { 0x92, 0x96, 0xbf, 0x6e, 0xea, 0x80, 0xd5, 0x8a}}
 %}