Skip to content

Commit

Permalink
[embedlite-components] Replace notifyObserver with sendAcyncMessage f…
Browse files Browse the repository at this point in the history
…or downloadpicker. Contributes to JB#53798

WebView requires handling downloadpicker. It would be easier to control using the active window than globally.
Also need to take care of the missing PREF_BD_USEDOWNLOADDIR.
  • Loading branch information
atatarov committed Apr 8, 2021
1 parent a7465da commit 5da39a4
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions jscomps/HelperAppDialog.js
Expand Up @@ -80,23 +80,31 @@ HelperAppLauncherDialog.prototype = {
aSuggestedFileExtension,
aForcePrompt) {
this.mLauncher = aLauncher;
Services.obs.addObserver(this, "embedui:downloadpicker", false);

let downloadDir = Services.prefs.getStringPref(PREF_BD_DOWNLOADDIR);
var result = {
defaultFileName: aDefaultFileName,
suggestedFileExtension: aSuggestedFileExtension,
downloadDirectory: downloadDir
suggestedFileExtension: aSuggestedFileExtension
}
if (!aForcePrompt) {
let autodownload = Services.prefs.getBoolPref(PREF_BD_USEDOWNLOADDIR);
let autodownload = Services.prefs.getBoolPref(PREF_BD_USEDOWNLOADDIR, false);

if (autodownload) {
try {
result.downloadDirectory = Services.prefs.getStringPref(PREF_BD_DOWNLOADDIR);
} catch (e) {
Logger.warn("HelperAppDialog: browser.download.dir isn't enabled, will use prefferedDir", e)
}
this.saveAndDownload(result);
return;
}
}
Services.obs.addObserver(this, "embedui:downloadpicker", false);
Services.obs.notifyObservers(null, "embed:downloadpicker", JSON.stringify(result));
try {
let winId = Services.embedlite.getIDByWindow(Services.ww.activeWindow);
Services.embedlite.sendAsyncMessage(winId, "embed:downloadpicker", JSON.stringify(result));
} catch (e) {
Logger.warn("HelperAppDialog: sending async message failed", e)
}
},

promptForSaveToFile: function hald_promptForSaveToFile(aLauncher, aContext, aDefaultFile, aSuggestedFileExt, aForcePrompt) {
Expand Down

0 comments on commit 5da39a4

Please sign in to comment.