Bug 1386805 - changes to saveAsPDF() and printPreview(); r=mixedpuppy
authordw-dev <dw-dev@gmx.com>
Fri, 11 Aug 2017 18:24:57 +0100
changeset 374321 5279a1edf8aeb09f641090ce7bf03b9f0fc16626
parent 374320 dcbf487465debe6e418677b2c9d984f57b2df394
child 374322 222deac54a16a604dbbbb06408872dc8a833a3b5
push id32320
push userarchaeopteryx@coole-files.de
push dateSat, 12 Aug 2017 21:35:10 +0000
treeherdermozilla-central@6062341662fc [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmixedpuppy
bugs1386805
milestone57.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 1386805 - changes to saveAsPDF() and printPreview(); r=mixedpuppy saveAsPDF() - changed to return error message in lastError if called on Mac OS X. saveAsPDF() - changed returned status values to lower case with underscores instead of spaces. printPreview() - changed to return error message in lastError if print preview fails. MozReview-Commit-ID: KxWJ3ClqaHy
browser/components/extensions/ext-tabs.js
browser/components/extensions/schemas/tabs.json
--- a/browser/components/extensions/ext-tabs.js
+++ b/browser/components/extensions/ext-tabs.js
@@ -762,57 +762,61 @@ this.tabs = class extends ExtensionAPI {
 
         printPreview() {
           let activeTab = getTabOrActive(null);
           let {
             PrintUtils,
             PrintPreviewListener,
           } = activeTab.ownerGlobal;
 
-          return new Promise(resolve => {
+          return new Promise((resolve, reject) => {
             let ppBrowser = PrintUtils._shouldSimplify ?
               PrintPreviewListener.getSimplifiedPrintPreviewBrowser() :
               PrintPreviewListener.getPrintPreviewBrowser();
 
             let mm = ppBrowser.messageManager;
 
             let onEntered = (message) => {
               mm.removeMessageListener("Printing:Preview:Entered", onEntered);
               if (message.data.failed) {
-                throw new ExtensionError("Print preview failed");
+                reject({message: "Print preview failed"});
               }
               resolve();
             };
 
             mm.addMessageListener("Printing:Preview:Entered", onEntered);
 
             PrintUtils.printPreview(PrintPreviewListener);
           });
         },
 
         saveAsPDF(pageSettings) {
           let activeTab = getTabOrActive(null);
           let picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
           let title = strBundle.GetStringFromName("saveaspdf.saveasdialog.title");
 
+          if (AppConstants.platform === "macosx") {
+            return Promise.reject({message: "Not supported on Mac OS X"});
+          }
+
           picker.init(activeTab.ownerGlobal, title, Ci.nsIFilePicker.modeSave);
           picker.appendFilter("PDF", "*.pdf");
           picker.defaultExtension = "pdf";
           picker.defaultString = activeTab.linkedBrowser.contentTitle + ".pdf";
 
           return new Promise(resolve => {
             picker.open(function(retval) {
               if (retval == 0 || retval == 2) {
                 // OK clicked (retval == 0) or replace confirmed (retval == 2)
                 try {
                   let fstream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
                   fstream.init(picker.file, 0x2A, 0x1B6, 0);  // write|create|truncate, file permissions rw-rw-rw- = 0666 = 0x1B6
                   fstream.close();  // unlock file
                 } catch (e) {
-                  resolve(retval == 0 ? "Not saved" : "Not replaced");
+                  resolve(retval == 0 ? "not_saved" : "not_replaced");
                   return;
                 }
 
                 let psService = Cc["@mozilla.org/gfx/printsettings-service;1"].getService(Ci.nsIPrintSettingsService);
                 let printSettings = psService.newPrintSettings;
 
                 printSettings.printToFile = true;
                 printSettings.toFileName = picker.file.path;
@@ -875,20 +879,20 @@ this.tabs = class extends ExtensionAPI {
                   printSettings.marginTop = pageSettings.marginTop;
                 }
                 if (pageSettings.marginBottom !== null) {
                   printSettings.marginBottom = pageSettings.marginBottom;
                 }
 
                 activeTab.linkedBrowser.print(activeTab.linkedBrowser.outerWindowID, printSettings, null);
 
-                resolve(retval == 0 ? "Saved" : "Replaced");
+                resolve(retval == 0 ? "saved" : "replaced");
               } else {
                 // Cancel clicked (retval == 1)
-                resolve("Cancelled");
+                resolve("canceled");
               }
             });
           });
         },
       },
     };
     return self;
   }
--- a/browser/components/extensions/schemas/tabs.json
+++ b/browser/components/extensions/schemas/tabs.json
@@ -1150,17 +1150,17 @@
             "type": "function",
             "name": "callback",
             "optional": true,
             "description": "Called after save as dialog closed.",
             "parameters": [
               {
                 "type": "string",
                 "name": "status",
-                "description": "Save status: Saved, Replaced, Cancelled, Not Saved, Not Replaced."
+                "description": "Save status: saved, replaced, canceled, not_saved, not_replaced."
               }
             ]
           }
         ]
       }
     ],
     "events": [
       {