Bug 1088070 - Move saving nsIPrintSettings after a print job to browser-content.js. r=Mossop.
authorMike Conley <mconley@mozilla.com>
Thu, 05 Mar 2015 13:16:35 -0500
changeset 232182 1c9ad6279fa635fb239ca8885365a4c6f4668f73
parent 232181 e58f9c6913b7e1df3b3c9dfce47bd25f57dbfb96
child 232183 8893464d6b2d9f82aac735c6578a48bb34c28618
push id28372
push usercbook@mozilla.com
push dateFri, 06 Mar 2015 12:07:51 +0000
treeherdermozilla-central@7d85ac833cff [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMossop
bugs1088070
milestone39.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 1088070 - Move saving nsIPrintSettings after a print job to browser-content.js. r=Mossop.
toolkit/components/printing/content/printUtils.js
toolkit/content/browser-content.js
--- a/toolkit/components/printing/content/printUtils.js
+++ b/toolkit/components/printing/content/printUtils.js
@@ -163,38 +163,16 @@ var PrintUtils = {
 
     if (!aBrowser) {
       throw new Error("PrintUtils.print could not resolve content window " +
                       "to a browser.");
     }
 
     let mm = aBrowser.messageManager;
 
-    mm.addMessageListener("Printing:Print:Done", function onPrintingDone(msg) {
-      mm.removeMessageListener("Printing:Print:Done", onPrintingDone);
-      let rv = msg.data.rv;
-      let printSettings = msg.objects.printSettings;
-      if (rv != Components.results.NS_OK &&
-          rv != Components.results.NS_ERROR_ABORT) {
-        Cu.reportError(`In Printing:Print:Done handler, got unexpected rv
-                        ${rv}.`);
-      }
-
-      if (gPrintSettingsAreGlobal && gSavePrintSettings) {
-        let PSSVC =
-          Components.classes["@mozilla.org/gfx/printsettings-service;1"]
-                    .getService(Components.interfaces.nsIPrintSettingsService);
-
-        PSSVC.savePrintSettingsToPrefs(printSettings, true,
-                                       printSettings.kInitSaveAll);
-        PSSVC.savePrintSettingsToPrefs(printSettings, false,
-                                       printSettings.kInitSavePrinterName);
-      }
-    });
-
     mm.sendAsyncMessage("Printing:Print", null, {
       contentWindow: aWindow,
     });
   },
 
   /**
    * Initializes print preview.
    *
--- a/toolkit/content/browser-content.js
+++ b/toolkit/content/browser-content.js
@@ -374,16 +374,21 @@ let Printing = {
     "Printing:Preview:UpdatePageCount",
     "Printing:Print",
   ],
 
   init() {
     this.MESSAGES.forEach(msgName => addMessageListener(msgName, this));
   },
 
+  get shouldSavePrintSettings() {
+    return Services.prefs.getBoolPref("print.use_global_printsettings", false) &&
+           Services.prefs.getBoolPref("print.save_print_settings", false);
+  },
+
   receiveMessage(message) {
     let objects = message.objects;
     let data = message.data;
     switch(message.name) {
       case "Printing:Preview:Enter": {
         this.enterPrintPreview(objects.contentWindow);
         break;
       }
@@ -476,19 +481,31 @@ let Printing = {
     let rv = Cr.NS_OK;
     try {
       let print = contentWindow.QueryInterface(Ci.nsIInterfaceRequestor)
                                .getInterface(Ci.nsIWebBrowserPrint);
       print.print(printSettings, null);
     } catch(e) {
       // Pressing cancel is expressed as an NS_ERROR_ABORT return value,
       // causing an exception to be thrown which we catch here.
-      rv = e.result;
+      if (e.result != Cr.NS_ERROR_ABORT) {
+        Cu.reportError(`In Printing:Print:Done handler, got unexpected rv
+                        ${e.result}.`);
+      }
     }
-    sendAsyncMessage("Printing:Print:Done", { rv }, { printSettings });
+
+    if (this.shouldSavePrintSettings) {
+      let PSSVC = Cc["@mozilla.org/gfx/printsettings-service;1"]
+                    .getService(Ci.nsIPrintSettingsService);
+
+      PSSVC.savePrintSettingsToPrefs(printSettings, true,
+                                     printSettings.kInitSaveAll);
+      PSSVC.savePrintSettingsToPrefs(printSettings, false,
+                                     printSettings.kInitSavePrinterName);
+    }
   },
 
   updatePageCount() {
     let numPages = docShell.printPreview.printPreviewNumPages;
     sendAsyncMessage("Printing:Preview:UpdatePageCount", {
       numPages: numPages,
     });
   },