Bug 785744 - Async file picker cleanup. r=neil

This commit is contained in:
Brian R. Bondy 2012-08-29 14:37:43 -04:00
parent e2dc01a32c
commit e5dea77d70
3 changed files with 19 additions and 17 deletions

View File

@ -137,19 +137,18 @@ MockFilePickerInstance.prototype = {
},
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);
}
};

View File

@ -187,11 +187,13 @@ nsFilePicker.prototype = {
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();
aFilePickerShownCallback.done(result);
result = this.show();
} catch(ex) {
aFilePickerShownCallback.done(this.returnCancel);
}
if (aFilePickerShownCallback) {
aFilePickerShownCallback.done(result);
}
}.bind(this), Components.interfaces.nsIThread.DISPATCH_NORMAL);
},

View File

@ -51,15 +51,16 @@ public:
// 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: