diff options
Diffstat (limited to 'toolkit/components/jsdownloads/src/DownloadIntegration.jsm')
-rw-r--r-- | toolkit/components/jsdownloads/src/DownloadIntegration.jsm | 71 |
1 files changed, 44 insertions, 27 deletions
diff --git a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm index 5fed9212a..7439d9d11 100644 --- a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm +++ b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm @@ -28,6 +28,8 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "AsyncShutdown", "resource://gre/modules/AsyncShutdown.jsm"); +XPCOMUtils.defineLazyModuleGetter(this, "AppConstants", + "resource://gre/modules/AppConstants.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "DeferredTask", "resource://gre/modules/DeferredTask.jsm"); XPCOMUtils.defineLazyModuleGetter(this, "Downloads", @@ -528,20 +530,34 @@ this.DownloadIntegration = { * @return true if files should be marked */ _shouldSaveZoneInformation() { - let key = Cc["@mozilla.org/windows-registry-key;1"] - .createInstance(Ci.nsIWindowsRegKey); + let zonePref = 2; try { - key.open(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, - "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Attachments", - Ci.nsIWindowsRegKey.ACCESS_QUERY_VALUE); - try { - return key.readIntValue("SaveZoneInformation") != 1; - } finally { - key.close(); - } - } catch (ex) { - // If the key is not present, files should be marked by default. - return true; + zonePref = Services.prefs.getIntPref("browser.download.saveZoneInformation"); + } catch (ex) {} + + switch (zonePref) { + case 0: // Never + return false; + case 1: // Always + return true; + case 2: // System-defined + let key = Cc["@mozilla.org/windows-registry-key;1"] + .createInstance(Ci.nsIWindowsRegKey); + try { + key.open(Ci.nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, + "Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Attachments", + Ci.nsIWindowsRegKey.ACCESS_QUERY_VALUE); + try { + return key.readIntValue("SaveZoneInformation") != 1; + } finally { + key.close(); + } + } catch (ex) { + // If the key is not present, files should be marked by default. + return true; + } + default: // Invalid pref value defaults marking files. + return true; } }, #endif @@ -675,20 +691,6 @@ this.DownloadIntegration = { launchDownload: Task.async(function* (aDownload) { let file = new FileUtils.File(aDownload.target.path); -#ifndef XP_WIN - // Ask for confirmation if the file is executable, except on Windows where - // the operating system will show the prompt based on the security zone. - // We do this here, instead of letting the caller handle the prompt - // separately in the user interface layer, for two reasons. The first is - // because of its security nature, so that add-ons cannot forget to do - // this check. The second is that the system-level security prompt would - // be displayed at launch time in any case. - if (file.isExecutable() && - !(yield this.confirmLaunchExecutable(file.path))) { - return; - } -#endif - // In case of a double extension, like ".tar.gz", we only // consider the last one, because the MIME service cannot // handle multiple extensions. @@ -698,6 +700,21 @@ this.DownloadIntegration = { fileExtension = match[1]; } + let isWindowsExe = AppConstants.platform == "win" && + fileExtension.toLowerCase() == "exe"; + + // Ask for confirmation if the file is executable, except for .exe on + // Windows where the operating system will show the prompt based on the + // security zone. We do this here, instead of letting the caller handle + // the prompt separately in the user interface layer, for two reasons. The + // first is because of its security nature, so that add-ons cannot forget + // to do this check. The second is that the system-level security prompt + // would be displayed at launch time in any case. + if (file.isExecutable() && !isWindowsExe && + !(yield this.confirmLaunchExecutable(file.path))) { + return; + } + try { // The MIME service might throw if contentType == "" and it can't find // a MIME type for the given extension, so we'll treat this case as |