Skip to content

Commit

Permalink
[embedlite-components] Remove message listener if filepicker was canc…
Browse files Browse the repository at this point in the history
…elled. Contributes to JB#53949

The FilePicker.js handle messages for filepickerresponse,
there is no cancelling if the aData is empty.
Should to remove message listener if data is empty and call returnCancell for nsIFilePicker.
  • Loading branch information
Aleksey Tatarov committed Jun 2, 2021
1 parent 82bd88a commit 677ba59
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions jscomps/FilePicker.js
Expand Up @@ -248,7 +248,14 @@ FilePicker.prototype = {

this._promptActive = false;

if (!this._filePath) {
if (!this._filePath || !accepted) {
try {
this._callback.done(Ci.nsIFilePicker.returnCancel);
Services.embedlite.removeMessageListener("filepickerresponse", this);
delete this._callback;
} catch (e) {
Logger.warn("FilePicker: cancelling filepicker failed", e)
}
return;
}

Expand All @@ -265,8 +272,7 @@ FilePicker.prototype = {
promise.then(domFile => {
this._domFiles.push(domFile);
if (this._callback && (this._domFiles.length === this._filePath.length)) {
this._callback.done(this._filePath && accepted ?
Ci.nsIFilePicker.returnOK : Ci.nsIFilePicker.returnCancel);
this._callback.done(Ci.nsIFilePicker.returnOK);
Services.embedlite.removeMessageListener("filepickerresponse", this);
delete this._callback;
}
Expand Down

0 comments on commit 677ba59

Please sign in to comment.