Prevent suppressing executable warnings using the "don't ask me this again" checkbox.

A hidden preference matching the behavior of "browser.download.manager.alertOnEXEOpen" is kept, but is renamed in order to recover cases where the checkbox was used accidentally.
While there, simplify the `confirmLaunchExecutable` function by converting from promises to async function.
Since Basilisk moved this prompting to toolkit, we also clean up some unused duplicate strings from application/basilisk while we're there.

This resolves #581
This commit is contained in:
wolfbeast 2018-07-02 19:05:56 +02:00 • committed by Roy Tam
commit ad2c18b0f2
6 changed files with 25 additions and 53 deletions

View file

@ -86,8 +86,7 @@ const kDownloadsStringsRequiringFormatting = {
shortTimeLeftHours: true, shortTimeLeftHours: true,
shortTimeLeftDays: true, shortTimeLeftDays: true,
statusSeparator: true, statusSeparator: true,
statusSeparatorBeforeNumber: true, statusSeparatorBeforeNumber: true
fileExecutableSecurityWarning: true
}; };
const kDownloadsStringsRequiringPluralForm = { const kDownloadsStringsRequiringPluralForm = {

View file

@ -96,10 +96,6 @@ shortTimeLeftDays=%1$Sd
statusSeparator=%1$S \u2014 %2$S statusSeparator=%1$S \u2014 %2$S
statusSeparatorBeforeNumber=%1$S \u2014 %2$S statusSeparatorBeforeNumber=%1$S \u2014 %2$S
fileExecutableSecurityWarning=“%S” is an executable file. Executable files may contain viruses or other malicious code that could harm your computer. Use caution when opening this file. Are you sure you want to launch “%S”?
fileExecutableSecurityWarningTitle=Open Executable File?
fileExecutableSecurityWarningDontAsk=Don’t ask me this again
# LOCALIZATION NOTE (otherDownloads2): # LOCALIZATION NOTE (otherDownloads2):
# This is displayed in an item at the bottom of the Downloads Panel when # This is displayed in an item at the bottom of the Downloads Panel when
# there are more downloads than can fit in the list in the panel. Use a # there are more downloads than can fit in the list in the panel. Use a

View file

@ -77,7 +77,7 @@ const nsIDM = Ci.nsIDownloadManager;
const kDownloadsStringBundleUrl = const kDownloadsStringBundleUrl =
"chrome://browser/locale/downloads/downloads.properties"; "chrome://browser/locale/downloads/downloads.properties";
const kPrefBdmAlertOnExeOpen = "browser.download.manager.alertOnEXEOpen"; const kPrefConfirmOpenExe = "browser.download.confirmOpenExecutable";
const kDownloadsStringsRequiringFormatting = { const kDownloadsStringsRequiringFormatting = {
sizeWithUnits: true, sizeWithUnits: true,
@ -530,8 +530,10 @@ this.DownloadsCommon = {
if (aFile.isExecutable() && !isWindowsExe) { if (aFile.isExecutable() && !isWindowsExe) {
let showAlert = true; let showAlert = true;
try { try {
showAlert = Services.prefs.getBoolPref(kPrefBdmAlertOnExeOpen); showAlert = Services.prefs.getBoolPref(kPrefConfirmOpenExe);
} catch (ex) { } } catch (ex) {
// If the preference does not exist, continue with the prompt.
}
if (showAlert) { if (showAlert) {
let name = aFile.leafName; let name = aFile.leafName;
@ -539,18 +541,11 @@ this.DownloadsCommon = {
DownloadsCommon.strings.fileExecutableSecurityWarning(name, name); DownloadsCommon.strings.fileExecutableSecurityWarning(name, name);
let title = let title =
DownloadsCommon.strings.fileExecutableSecurityWarningTitle; DownloadsCommon.strings.fileExecutableSecurityWarningTitle;
let dontAsk =
DownloadsCommon.strings.fileExecutableSecurityWarningDontAsk;
let checkbox = { value: false }; let open = Services.prompt.confirm(aOwnerWindow, title, message);
let open = Services.prompt.confirmCheck(aOwnerWindow, title, message,
dontAsk, checkbox);
if (!open) { if (!open) {
return; return;
} }
Services.prefs.setBoolPref(kPrefBdmAlertOnExeOpen,
!checkbox.value);
} }
} }

View file

@ -124,52 +124,35 @@ this.DownloadPrompter.prototype = {
/** /**
* Displays a warning message box that informs that the specified file is * Displays a warning message box that informs that the specified file is
* executable, and asks whether the user wants to launch it. The user is * executable, and asks whether the user wants to launch it.
* given the option of disabling future instances of this warning.
* *
* @param aPath * @param aPath
* String containing the full path to the file to be opened. * String containing the full path to the file to be opened.
* *
* @return {Promise}
* @resolves Boolean indicating whether the launch operation can continue. * @resolves Boolean indicating whether the launch operation can continue.
* @rejects JavaScript exception.
*/ */
confirmLaunchExecutable: function (aPath) async confirmLaunchExecutable: function (aPath)
{ {
const kPrefAlertOnEXEOpen = "browser.download.manager.alertOnEXEOpen"; const kPrefConfirmOpenExe = "browser.download.confirmOpenExecutable";
// Always launch in case we have no prompter implementation.
if (!this._prompter) {
return true;
}
try { try {
// Always launch in case we have no prompter implementation. if (!Services.prefs.getBoolPref(kPrefConfirmOpenExe)) {
if (!this._prompter) { return true;
return Promise.resolve(true);
} }
try {
if (!Services.prefs.getBoolPref(kPrefAlertOnEXEOpen)) {
return Promise.resolve(true);
}
} catch (ex) {
// If the preference does not exist, continue with the prompt.
}
let leafName = OS.Path.basename(aPath);
let s = DownloadUIHelper.strings;
let checkState = { value: false };
let shouldLaunch = this._prompter.confirmCheck(
s.fileExecutableSecurityWarningTitle,
s.fileExecutableSecurityWarning(leafName, leafName),
s.fileExecutableSecurityWarningDontAsk,
checkState);
if (shouldLaunch) {
Services.prefs.setBoolPref(kPrefAlertOnEXEOpen, !checkState.value);
}
return Promise.resolve(shouldLaunch);
} catch (ex) { } catch (ex) {
return Promise.reject(ex); // If the preference does not exist, continue with the prompt.
} }
let leafName = OS.Path.basename(aPath);
let s = DownloadUIHelper.strings;
return this._prompter.confirm(s.fileExecutableSecurityWarningTitle,
s.fileExecutableSecurityWarning(leafName, leafName));
}, },
/** /**

View file

@ -134,7 +134,6 @@ downloadsTitlePercent=#2% of #1 file - Downloads;#2% of #1 files - Downloads
fileExecutableSecurityWarning=“%S” is an executable file. Executable files may contain viruses or other malicious code that could harm your computer. Use caution when opening this file. Are you sure you want to launch “%S”? fileExecutableSecurityWarning=“%S” is an executable file. Executable files may contain viruses or other malicious code that could harm your computer. Use caution when opening this file. Are you sure you want to launch “%S”?
fileExecutableSecurityWarningTitle=Open Executable File? fileExecutableSecurityWarningTitle=Open Executable File?
fileExecutableSecurityWarningDontAsk=Don’t ask me this again
displayNameDesktop=Desktop displayNameDesktop=Desktop

View file

@ -20,12 +20,12 @@ const PREFS_WHITELIST = [
"apz.", "apz.",
"browser.cache.", "browser.cache.",
"browser.display.", "browser.display.",
"browser.download.confirmOpenExecutable",
"browser.download.folderList", "browser.download.folderList",
"browser.download.hide_plugins_without_extensions", "browser.download.hide_plugins_without_extensions",
"browser.download.importedFromSqlite", "browser.download.importedFromSqlite",
"browser.download.lastDir.savePerSite", "browser.download.lastDir.savePerSite",
"browser.download.manager.addToRecentDocs", "browser.download.manager.addToRecentDocs",
"browser.download.manager.alertOnEXEOpen",
"browser.download.manager.closeWhenDone", "browser.download.manager.closeWhenDone",
"browser.download.manager.displayedHistoryDays", "browser.download.manager.displayedHistoryDays",
"browser.download.manager.quitBehavior", "browser.download.manager.quitBehavior",