зеркало из https://github.com/mozilla/gecko-dev.git
Bug 908244 - When a download is launched automatically, the target file should be deleted when the browser is closed. r=paolo
This commit is contained in:
Родитель
20b0503b1d
Коммит
e607a271ee
|
@ -352,6 +352,10 @@ pref("browser.download.panel.shown", false);
|
|||
// enabled has been completed already.
|
||||
pref("browser.download.panel.firstSessionCompleted", false);
|
||||
|
||||
#ifndef XP_MACOSX
|
||||
pref("browser.helperApps.deleteTempFileOnExit", true);
|
||||
#endif
|
||||
|
||||
// search engines URL
|
||||
pref("browser.search.searchEnginesURL", "https://addons.mozilla.org/%LOCALE%/firefox/search-engines/");
|
||||
|
||||
|
|
|
@ -151,6 +151,7 @@ pref("browser.display.focus_ring_style", 1);
|
|||
pref("browser.helperApps.alwaysAsk.force", false);
|
||||
pref("browser.helperApps.neverAsk.saveToDisk", "");
|
||||
pref("browser.helperApps.neverAsk.openFile", "");
|
||||
pref("browser.helperApps.deleteTempFileOnExit", false);
|
||||
|
||||
#ifdef XP_WIN
|
||||
// By default, security zone information is stored in the Alternate Data Stream
|
||||
|
|
|
@ -64,12 +64,17 @@ XPCOMUtils.defineLazyModuleGetter(this, "OS",
|
|||
"resource://gre/modules/osfile.jsm")
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Promise",
|
||||
"resource://gre/modules/commonjs/sdk/core/promise.js");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Services",
|
||||
"resource://gre/modules/Services.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Task",
|
||||
"resource://gre/modules/Task.jsm");
|
||||
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "gDownloadHistory",
|
||||
"@mozilla.org/browser/download-history;1",
|
||||
Ci.nsIDownloadHistory);
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "gExternalAppLauncher",
|
||||
"@mozilla.org/uriloader/external-helper-app-service;1",
|
||||
Ci.nsPIExternalAppLauncher);
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "gExternalHelperAppService",
|
||||
"@mozilla.org/uriloader/external-helper-app-service;1",
|
||||
Ci.nsIExternalHelperAppService);
|
||||
|
@ -421,6 +426,17 @@ Download.prototype = {
|
|||
|
||||
if (this.launchWhenSucceeded) {
|
||||
this.launch().then(null, Cu.reportError);
|
||||
|
||||
// Always schedule files to be deleted at the end of the private browsing
|
||||
// mode, regardless of the value of the pref.
|
||||
if (this.source.isPrivate) {
|
||||
gExternalAppLauncher.deleteTemporaryPrivateFileWhenPossible(
|
||||
new FileUtils.File(this.target.path));
|
||||
} else if (Services.prefs.getBoolPref(
|
||||
"browser.helperApps.deleteTempFileOnExit")) {
|
||||
gExternalAppLauncher.deleteTemporaryFileOnExit(
|
||||
new FileUtils.File(this.target.path));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1728,3 +1728,60 @@ add_task(function test_history_tryToKeepPartialData()
|
|||
continueResponses();
|
||||
yield promiseDownloadStopped(download);
|
||||
});
|
||||
|
||||
/**
|
||||
* Tests that the temp download files are removed on exit and exiting private
|
||||
* mode after they have been launched.
|
||||
*/
|
||||
add_task(function test_launchWhenSucceeded_deleteTempFileOnExit() {
|
||||
const kDeleteTempFileOnExit = "browser.helperApps.deleteTempFileOnExit";
|
||||
|
||||
let customLauncherPath = getTempFile("app-launcher").path;
|
||||
let autoDeleteTargetPathOne = getTempFile(TEST_TARGET_FILE_NAME).path;
|
||||
let autoDeleteTargetPathTwo = getTempFile(TEST_TARGET_FILE_NAME).path;
|
||||
let noAutoDeleteTargetPath = getTempFile(TEST_TARGET_FILE_NAME).path;
|
||||
|
||||
let autoDeleteDownloadOne = yield Downloads.createDownload({
|
||||
source: { url: httpUrl("source.txt"), isPrivate: true },
|
||||
target: autoDeleteTargetPathOne,
|
||||
launchWhenSucceeded: true,
|
||||
launcherPath: customLauncherPath,
|
||||
});
|
||||
yield autoDeleteDownloadOne.start();
|
||||
|
||||
Services.prefs.setBoolPref(kDeleteTempFileOnExit, true);
|
||||
let autoDeleteDownloadTwo = yield Downloads.createDownload({
|
||||
source: httpUrl("source.txt"),
|
||||
target: autoDeleteTargetPathTwo,
|
||||
launchWhenSucceeded: true,
|
||||
launcherPath: customLauncherPath,
|
||||
});
|
||||
yield autoDeleteDownloadTwo.start();
|
||||
|
||||
Services.prefs.setBoolPref(kDeleteTempFileOnExit, false);
|
||||
let noAutoDeleteDownload = yield Downloads.createDownload({
|
||||
source: httpUrl("source.txt"),
|
||||
target: noAutoDeleteTargetPath,
|
||||
launchWhenSucceeded: true,
|
||||
launcherPath: customLauncherPath,
|
||||
});
|
||||
yield noAutoDeleteDownload.start();
|
||||
|
||||
Services.prefs.clearUserPref(kDeleteTempFileOnExit);
|
||||
|
||||
do_check_true(yield OS.File.exists(autoDeleteTargetPathOne));
|
||||
do_check_true(yield OS.File.exists(autoDeleteTargetPathTwo));
|
||||
do_check_true(yield OS.File.exists(noAutoDeleteTargetPath));
|
||||
|
||||
// Simulate leaving private browsing mode
|
||||
Services.obs.notifyObservers(null, "last-pb-context-exited", null);
|
||||
do_check_false(yield OS.File.exists(autoDeleteTargetPathOne));
|
||||
|
||||
// Simulate browser shutdown
|
||||
let expire = Cc["@mozilla.org/uriloader/external-helper-app-service;1"]
|
||||
.getService(Ci.nsIObserver);
|
||||
expire.observe(null, "profile-before-change", null);
|
||||
do_check_false(yield OS.File.exists(autoDeleteTargetPathTwo));
|
||||
do_check_true(yield OS.File.exists(noAutoDeleteTargetPath));
|
||||
});
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче