Bug 1088070 - Move saving nsIPrintSettings after a print job to browser-content.js. r=Mossop.
☠☠ backed out by 8a16b7515de8 ☠ ☠
authorMike Conley <mconley@mozilla.com>
Fri, 27 Feb 2015 14:17:33 -0500
changeset 231967 d053fdf3b60984f3cbca960c49d5f28e9a14e82d
parent 231966 20a6d6e9c31a20ee380fde5771b9767ecf3671f4
child 231968 a1c1f919b5b83cf0e5e5b72fd75615ec7df3a5c1
push idunknown
push userunknown
push dateunknown
reviewersMossop
bugs1088070
milestone39.0a1
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
@@ -373,16 +373,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;
       }
@@ -469,19 +474,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,
     });
   },