--- a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
+++ b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
@@ -75,16 +75,17 @@ XPCOMUtils.defineLazyServiceGetter(this,
Ci.nsIApplicationReputationService);
XPCOMUtils.defineLazyServiceGetter(this, "volumeService",
"@mozilla.org/telephony/volume-service;1",
"nsIVolumeService");
// We have to use the gCombinedDownloadIntegration identifier because, in this
// module only, the DownloadIntegration identifier refers to the base version.
+/* global gCombinedDownloadIntegration:false */
Integration.downloads.defineModuleGetter(this, "gCombinedDownloadIntegration",
"resource://gre/modules/DownloadIntegration.jsm",
"DownloadIntegration");
const Timer = Components.Constructor("@mozilla.org/timer;1", "nsITimer",
"initWithCallback");
/**
@@ -271,17 +272,17 @@ this.DownloadIntegration = {
this._downloadsDirectory = gEnvironment.get("DOWNLOADS_DIRECTORY");
if (!this._downloadsDirectory) {
throw new Components.Exception("DOWNLOADS_DIRECTORY is not set.",
Cr.NS_ERROR_FILE_UNRECOGNIZED_PATH);
}
} else {
try {
this._downloadsDirectory = this._getDirectory("DfltDwnld");
- } catch(e) {
+ } catch (e) {
this._downloadsDirectory = await this._createDownloadsDirectory("Home");
}
}
return this._downloadsDirectory;
},
_downloadsDirectory: null,
@@ -290,38 +291,38 @@ this.DownloadIntegration = {
*
* @return {Promise}
* @resolves The downloads directory string path.
*/
async getPreferredDownloadsDirectory() {
let directoryPath = null;
let prefValue = Services.prefs.getIntPref("browser.download.folderList", 1);
- switch(prefValue) {
+ switch (prefValue) {
case 0: // Desktop
directoryPath = this._getDirectory("Desk");
break;
case 1: // Downloads
directoryPath = await this.getSystemDownloadsDirectory();
break;
case 2: // Custom
try {
let directory = Services.prefs.getComplexValue("browser.download.dir",
Ci.nsIFile);
directoryPath = directory.path;
await OS.File.makeDir(directoryPath, { ignoreExisting: true });
- } catch(ex) {
+ } catch (ex) {
// Either the preference isn't set or the directory cannot be created.
directoryPath = await this.getSystemDownloadsDirectory();
}
break;
case 3: // Cloud Storage
try {
directoryPath = await CloudStorage.getDownloadFolder();
- } catch(ex) {}
+ } catch (ex) {}
if (!directoryPath) {
directoryPath = await this.getSystemDownloadsDirectory();
}
break;
default:
directoryPath = await this.getSystemDownloadsDirectory();
}
return directoryPath;
@@ -672,17 +673,17 @@ this.DownloadIntegration = {
* Asks for confirmation for launching the specified executable file. This
* can be overridden by regression tests to avoid the interactive prompt.
*/
async confirmLaunchExecutable(path) {
// We don't anchor the prompt to a specific window intentionally, not
// only because this is the same behavior as the system-level prompt,
// but also because the most recently active window is the right choice
// in basically all cases.
- return await DownloadUIHelper.getPrompter().confirmLaunchExecutable(path);
+ return DownloadUIHelper.getPrompter().confirmLaunchExecutable(path);
},
/**
* Launches the specified file, unless overridden by regression tests.
*/
launchFile(file, mimeInfo) {
if (mimeInfo) {
mimeInfo.launchWithFile(file);
@@ -957,20 +958,18 @@ this.DownloadObserver = {
}
for (let download of this._privateInProgressDownloads) {
download.cancel();
this._canceledOfflineDownloads.add(download);
}
break;
case "wake_notification":
case "resume_process_notification":
- let wakeDelay = 10000;
- try {
- wakeDelay = Services.prefs.getIntPref("browser.download.manager.resumeOnWakeDelay");
- } catch(e) {}
+ let wakeDelay =
+ Services.prefs.getIntPref("browser.download.manager.resumeOnWakeDelay", 10000);
if (wakeDelay >= 0) {
this._wakeTimer = new Timer(this._resumeOfflineDownloads.bind(this), wakeDelay,
Ci.nsITimer.TYPE_ONE_SHOT);
}
break;
case "network:offline-status-changed":
if (aData == "online") {
@@ -999,18 +998,17 @@ this.DownloadObserver = {
* reflected on the provided list of downloads.
*
* You do not need to keep a reference to this object in order to keep it alive,
* because the history service already keeps a strong reference to it.
*
* @param aList
* DownloadList object linked to this observer.
*/
-this.DownloadHistoryObserver = function (aList)
-{
+this.DownloadHistoryObserver = function(aList) {
this._list = aList;
PlacesUtils.history.addObserver(this);
}
this.DownloadHistoryObserver.prototype = {
/**
* DownloadList object linked to this observer.
*/
@@ -1024,40 +1022,39 @@ this.DownloadHistoryObserver.prototype =
download.source.url)));
},
// nsINavHistoryObserver
onClearHistory: function DL_onClearHistory() {
this._list.removeFinished();
},
- onTitleChanged: function () {},
- onBeginUpdateBatch: function () {},
- onEndUpdateBatch: function () {},
- onVisit: function () {},
- onPageChanged: function () {},
- onDeleteVisits: function () {},
+ onTitleChanged() {},
+ onBeginUpdateBatch() {},
+ onEndUpdateBatch() {},
+ onVisit() {},
+ onPageChanged() {},
+ onDeleteVisits() {},
};
/**
* This view can be added to a DownloadList object to trigger a save operation
* in the given DownloadStore object when a relevant change occurs. You should
* call the "initialize" method in order to register the view and load the
* current state from disk.
*
* You do not need to keep a reference to this object in order to keep it alive,
* because the DownloadList object already keeps a strong reference to it.
*
* @param aList
* The DownloadList object on which the view should be registered.
* @param aStore
* The DownloadStore object used for saving.
*/
-this.DownloadAutoSaveView = function (aList, aStore)
-{
+this.DownloadAutoSaveView = function(aList, aStore) {
this._list = aList;
this._store = aStore;
this._downloadsMap = new Map();
this._writer = new DeferredTask(() => this._store.save(), kSaveDelayMs);
AsyncShutdown.profileBeforeChange.addBlocker("DownloadAutoSaveView: writing data",
() => this._writer.finalize());
}
@@ -1079,18 +1076,17 @@ this.DownloadAutoSaveView.prototype = {
/**
* Registers the view and loads the current state from disk.
*
* @return {Promise}
* @resolves When the view has been registered.
* @rejects JavaScript exception.
*/
- initialize: function ()
- {
+ initialize() {
// We set _initialized to true after adding the view, so that
// onDownloadAdded doesn't cause a save to occur.
return this._list.addView(this).then(() => this._initialized = true);
},
/**
* This map contains only Download objects that should be saved to disk, and
* associates them with the result of their getSerializationHash function, for
@@ -1102,51 +1098,47 @@ this.DownloadAutoSaveView.prototype = {
* DeferredTask for the save operation.
*/
_writer: null,
/**
* Called when the list of downloads changed, this triggers the asynchronous
* serialization of the list of downloads.
*/
- saveSoon: function ()
- {
+ saveSoon() {
this._writer.arm();
},
// DownloadList callback
- onDownloadAdded: function (aDownload)
- {
+ onDownloadAdded(aDownload) {
if (gCombinedDownloadIntegration.shouldPersistDownload(aDownload)) {
this._downloadsMap.set(aDownload, aDownload.getSerializationHash());
if (this._initialized) {
this.saveSoon();
}
}
},
// DownloadList callback
- onDownloadChanged: function (aDownload)
- {
+ onDownloadChanged(aDownload) {
if (!gCombinedDownloadIntegration.shouldPersistDownload(aDownload)) {
if (this._downloadsMap.has(aDownload)) {
this._downloadsMap.delete(aDownload);
this.saveSoon();
}
return;
}
let hash = aDownload.getSerializationHash();
if (this._downloadsMap.get(aDownload) != hash) {
this._downloadsMap.set(aDownload, hash);
this.saveSoon();
}
},
// DownloadList callback
- onDownloadRemoved: function (aDownload)
- {
+ onDownloadRemoved(aDownload) {
if (this._downloadsMap.has(aDownload)) {
this._downloadsMap.delete(aDownload);
this.saveSoon();
}
},
};