Bug 1349538 - JSONView should not open more than 1 filePicker at the same time, r=honza
authorAndrea Marchesini <amarchesini@mozilla.com>
Tue, 28 Mar 2017 13:30:34 +0200
changeset 350112 2aa13dbce320123fb307e5c6c555762f743fb85d
parent 350111 490b80ca23d23f750fdf5517651d6c1759b8afbc
child 350113 9238bcffd4383fbb82b32d4f21f704ace2a89499
push id31568
push userkwierso@gmail.com
push dateTue, 28 Mar 2017 20:31:07 +0000
treeherdermozilla-central@272ce6c25721 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewershonza
bugs1349538
milestone55.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 1349538 - JSONView should not open more than 1 filePicker at the same time, r=honza
devtools/client/jsonview/main.js
devtools/client/jsonview/utils.js
--- a/devtools/client/jsonview/main.js
+++ b/devtools/client/jsonview/main.js
@@ -46,17 +46,15 @@ var JsonView = {
   // Message handlers for events from child processes
 
   /**
    * Save JSON to a file needs to be implemented here
    * in the parent process.
    */
   onSave: function (message) {
     JsonViewUtils.getTargetFile().then(file => {
-      if (file) {
-        JsonViewUtils.saveToFile(file, message.data);
-      }
-    });
+      JsonViewUtils.saveToFile(file, message.data);
+    }, () => {});
   }
 };
 
 // Exports from this module
 module.exports.JsonView = JsonView;
--- a/devtools/client/jsonview/utils.js
+++ b/devtools/client/jsonview/utils.js
@@ -14,35 +14,46 @@ const OPEN_FLAGS = {
   RDONLY: parseInt("0x01", 16),
   WRONLY: parseInt("0x02", 16),
   CREATE_FILE: parseInt("0x08", 16),
   APPEND: parseInt("0x10", 16),
   TRUNCATE: parseInt("0x20", 16),
   EXCL: parseInt("0x80", 16)
 };
 
+let filePickerShown = false;
+
 /**
  * Open File Save As dialog and let the user to pick proper file location.
  */
 exports.getTargetFile = function () {
-  return new Promise(resolve => {
+  return new Promise((resolve, reject) => {
+    if (filePickerShown) {
+      reject(null);
+      return;
+    }
+
+    filePickerShown = true;
+
     let fp = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
 
     let win = getMostRecentBrowserWindow();
     fp.init(win, null, Ci.nsIFilePicker.modeSave);
     fp.appendFilter("JSON Files", "*.json; *.jsonp;");
     fp.appendFilters(Ci.nsIFilePicker.filterText);
     fp.appendFilters(Ci.nsIFilePicker.filterAll);
     fp.filterIndex = 0;
 
     fp.open(rv => {
+      filePickerShown = false;
+
       if (rv == Ci.nsIFilePicker.returnOK || rv == Ci.nsIFilePicker.returnReplace) {
         resolve(fp.file);
       } else {
-        resolve(null);
+        reject(null);
       }
     });
   });
 };
 
 /**
  * Save JSON to a file
  */