Bug 361909 - Work around race condition in download helper app dialog box. Patch by Joshua McKenty <joshua@flock.com>, r=gavin

This commit is contained in:
mattwillis@gmail.com 2007-08-22 07:49:25 -07:00
parent 0b758ec54e
commit 2fe2643902

View File

@ -87,26 +87,37 @@ nsUnknownContentTypeDialog.prototype = {
show: function(aLauncher, aContext, aReason) {
this.mLauncher = aLauncher;
this.mContext = aContext;
// Display the dialog using the Window Watcher interface.
var ir = aContext.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var dwi = ir.getInterface(Components.interfaces.nsIDOMWindowInternal);
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
this.mDialog = ww.openWindow(dwi,
"chrome://mozapps/content/downloads/unknownContentType.xul",
null,
"chrome,centerscreen,titlebar,dialog=yes,dependent",
null);
// Hook this object to the dialog.
this.mDialog.dialog = this;
// Hook up utility functions.
this.getSpecialFolderKey = this.mDialog.getSpecialFolderKey;
// Watch for error notifications.
this.progressListener.helperAppDlg = this;
this.mLauncher.setWebProgressListener(this.progressListener);
const nsITimer = Components.interfaces.nsITimer;
this._timer = Components.classes["@mozilla.org/timer;1"]
.createInstance(nsITimer);
this._timer.initWithCallback(this, 0, nsITimer.TYPE_ONE_SHOT);
},
// When opening from new tab, if tab closes while dialog is opening,
// (which is a race condition on the XUL file being cached and the timer
// in nsExternalHelperAppService), the dialog gets a blur and doesn't
// activate the OK button. So we wait a bit before doing opening it.
reallyShow: function() {
var ir = this.mContext.QueryInterface(Components.interfaces.nsIInterfaceRequestor);
var dwi = ir.getInterface(Components.interfaces.nsIDOMWindowInternal);
var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
.getService(Components.interfaces.nsIWindowWatcher);
this.mDialog = ww.openWindow(dwi,
"chrome://mozapps/content/downloads/unknownContentType.xul",
null,
"chrome,centerscreen,titlebar,dialog=yes,dependent",
null);
// Hook this object to the dialog.
this.mDialog.dialog = this;
// Hook up utility functions.
this.getSpecialFolderKey = this.mDialog.getSpecialFolderKey;
// Watch for error notifications.
this.progressListener.helperAppDlg = this;
this.mLauncher.setWebProgressListener(this.progressListener);
},
// promptForSaveToFile: Display file picker dialog and return selected file.
@ -454,17 +465,24 @@ nsUnknownContentTypeDialog.prototype = {
.createInstance(nsITimer);
this._timer.initWithCallback(this, 250, nsITimer.TYPE_ONE_SHOT);
},
_timer: null,
notify: function (aTimer) {
try { // The user may have already canceled the dialog.
if (!this._blurred)
this.mDialog.document.documentElement.getButton('accept').disabled = false;
} catch (ex) {}
this._delayExpired = true;
this._timer = null; // the timer won't release us, so we have to release it
if (!this.mDialog) {
this.reallyShow();
} else {
// The user may have already canceled the dialog.
try {
if (!this._blurred) {
this.mDialog.document.documentElement.getButton("accept").disabled = false;
}
} catch (ex) {}
this._delayExpired = true;
}
// The timer won't release us, so we have to release it.
this._timer = null;
},
postShowCallback: function () {
this.mDialog.sizeToContent();