Bug 785744 - Async file picker cleanup. r=neil
authorBrian R. Bondy <netzen@gmail.com>
Wed, 29 Aug 2012 14:37:43 -0400
changeset 103896 ca7e9d87a4f1cc94d0c66f86fef2fbf1b07fda32
parent 103895 e874ca7eba4a5dd81c7d1b63c8eaa925e5d8e357
child 103897 11c590f9b058313e52ee4b70e8df18d60969ab91
push id14226
push userbbondy@mozilla.com
push dateThu, 30 Aug 2012 17:28:35 +0000
treeherdermozilla-inbound@ca7e9d87a4f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersneil
bugs785744
milestone18.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 785744 - Async file picker cleanup. r=neil
testing/mochitest/MockFilePicker.jsm
toolkit/components/filepicker/nsFilePicker.js
widget/xpwidgets/nsBaseFilePicker.cpp
--- a/testing/mochitest/MockFilePicker.jsm
+++ b/testing/mochitest/MockFilePicker.jsm
@@ -132,29 +132,28 @@ MockFilePickerInstance.prototype = {
       var returnValue = MockFilePicker.showCallback(this);
       if (typeof returnValue != "undefined")
         return returnValue;
     }
     return MockFilePicker.returnValue;
   },
   open: function(aFilePickerShownCallback) {
     MockFilePicker.showing = true;
-    var self = this;
     var tm = Components.classes["@mozilla.org/thread-manager;1"]
                        .getService(Components.interfaces.nsIThreadManager);
-    tm.mainThread.dispatch({
-      run: function() {
-        try {
-          let result = self.show();
-          aFilePickerShownCallback.done(result);
-        } catch(ex) {
-          aFilePickerShownCallback.done(self.returnCancel);
-        }
+    tm.mainThread.dispatch(function() {
+      let result = Components.interfaces.nsIFilePicker.returnCancel;
+      try {
+        result = this.show();
+      } catch(ex) {
       }
-    }, Components.interfaces.nsIThread.DISPATCH_NORMAL);
+      if (aFilePickerShownCallback) {
+        aFilePickerShownCallback.done(result);
+      }
+    }.bind(this), Components.interfaces.nsIThread.DISPATCH_NORMAL);
   }
 };
 
 // Expose everything to content. We call reset() here so that all of the relevant
 // lazy expandos get added.
 MockFilePicker.reset();
 function exposeAll(obj) {
   var props = {};
--- a/toolkit/components/filepicker/nsFilePicker.js
+++ b/toolkit/components/filepicker/nsFilePicker.js
@@ -182,21 +182,23 @@ nsFilePicker.prototype = {
     this.mFilterTitles.push(title);
     this.mFilters.push(extensions);
   },
 
   open: function(aFilePickerShownCallback) {
     var tm = Components.classes["@mozilla.org/thread-manager;1"]
                        .getService(Components.interfaces.nsIThreadManager);
     tm.mainThread.dispatch(function() {
+      let result = Components.interfaces.nsIFilePicker.returnCancel;
       try {
-        let result = this.show();
+        result = this.show();
+      } catch(ex) {
+      }
+      if (aFilePickerShownCallback) {
         aFilePickerShownCallback.done(result);
-      } catch(ex) {
-        aFilePickerShownCallback.done(this.returnCancel);
       }
     }.bind(this), Components.interfaces.nsIThread.DISPATCH_NORMAL);
   },
 
   show: function() {
     var o = new Object();
     o.title = this.mTitle;
     o.mode = this.mMode;
--- a/widget/xpwidgets/nsBaseFilePicker.cpp
+++ b/widget/xpwidgets/nsBaseFilePicker.cpp
@@ -46,25 +46,26 @@ public:
   NS_IMETHOD Run()
   {
     NS_ASSERTION(NS_IsMainThread(),
                  "AsyncShowFilePicker should be on the main thread!");
 
     // It's possible that some widget implementations require GUI operations
     // to be on the main thread, so that's why we're not dispatching to another
     // thread and calling back to the main after it's done.
-    int16_t result;
+    int16_t result = nsIFilePicker::returnCancel;
     nsresult rv = mFilePicker->Show(&result);
     if (NS_FAILED(rv)) {
       NS_ERROR("FilePicker's Show() implementation failed!");
-      mCallback->Done(nsIFilePicker::returnCancel);
-      return NS_OK;
     }
 
-    return mCallback->Done(result);
+    if (mCallback) {
+      mCallback->Done(result);
+    }
+    return NS_OK;
   }
 
 private:
   nsRefPtr<nsIFilePicker> mFilePicker;
   nsRefPtr<nsIFilePickerShownCallback> mCallback;
 };
 
 nsBaseFilePicker::nsBaseFilePicker() :