Bug 952961 - Remove our own executable check and pref check, and added a regitry check when downloading a file. r=paolo
authorMasatoshi Kimura <VYV03354@nifty.ne.jp>
Sun, 12 Jan 2014 17:05:28 +0900
changeset 163028 d5d5fb7cb4696d186349ba834e00dcb3ecd06bc0
parent 163027 1979dd1a55d3d4a8b79bd16cdb837564de4de20b
child 163029 0c63a95e2dd8157e8d7f0c3911b67dbc0d6a4a8f
push id38371
push userVYV03354@nifty.ne.jp
push dateSun, 12 Jan 2014 08:09:58 +0000
treeherdermozilla-inbound@d5d5fb7cb469 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspaolo
bugs952961
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 952961 - Remove our own executable check and pref check, and added a regitry check when downloading a file. r=paolo
modules/libpref/src/init/all.js
toolkit/components/jsdownloads/src/DownloadIntegration.jsm
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -156,23 +156,16 @@ pref("browser.display.focus_ring_on_anyt
 // 0 = solid border, 1 = dotted border
 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
-// of downloaded executable files on Windows.  This preference allows disabling
-// this feature, and thus the associated system-level execution prompts.
-pref("browser.download.saveZoneInformation", true);
-#endif
-
 // xxxbsmedberg: where should prefs for the toolkit go?
 pref("browser.chrome.toolbar_tips",         true);
 // 0 = Pictures Only, 1 = Text Only, 2 = Pictures and Text
 pref("browser.chrome.toolbar_style",        2);
 // max image size for which it is placed in the tab icon for tabbrowser.
 // if 0, no images are used for tab icons for image documents.
 pref("browser.chrome.image_icons.max_size", 1024);
 
--- a/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
+++ b/toolkit/components/jsdownloads/src/DownloadIntegration.jsm
@@ -508,56 +508,80 @@ this.DownloadIntegration = {
       fileSize: aDownload.currentBytes,
       sha256Hash: hash },
       function onComplete(aShouldBlock, aRv) {
         deferred.resolve(aShouldBlock);
       });
     return deferred.promise;
   },
 
+#ifdef XP_WIN
+  /**
+   * Checks whether downloaded files should be marked as coming from
+   * Internet Zone.
+   *
+   * @return true if files should be marked
+   */
+  _shouldSaveZoneInformation: function() {
+    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;
+    }
+  },
+#endif
+
   /**
    * Performs platform-specific operations when a download is done.
    *
    * aParam aDownload
    *        The Download object.
    *
    * @return {Promise}
    * @resolves When all the operations completed successfully.
    * @rejects JavaScript exception if any of the operations failed.
    */
   downloadDone: function(aDownload) {
     return Task.spawn(function () {
 #ifdef XP_WIN
-      // On Windows, we mark any executable file saved to the NTFS file system
-      // as coming from the Internet security zone.  We do this by writing to
-      // the "Zone.Identifier" Alternate Data Stream directly, because the Save
-      // method of the IAttachmentExecute interface would trigger operations
-      // that may cause the application to hang, or other performance issues.
+      // On Windows, we mark any file saved to the NTFS file system as coming
+      // from the Internet security zone unless Group Policy disables the
+      // feature.  We do this by writing to the "Zone.Identifier" Alternate
+      // Data Stream directly, because the Save method of the
+      // IAttachmentExecute interface would trigger operations that may cause
+      // the application to hang, or other performance issues.
       // The stream created in this way is forward-compatible with all the
       // current and future versions of Windows.
-      if (Services.prefs.getBoolPref("browser.download.saveZoneInformation")) {
-        let file = new FileUtils.File(aDownload.target.path);
-        if (file.isExecutable()) {
+      if (this._shouldSaveZoneInformation()) {
+        try {
+          let streamPath = aDownload.target.path + ":Zone.Identifier";
+          let stream = yield OS.File.open(streamPath, { create: true });
           try {
-            let streamPath = aDownload.target.path + ":Zone.Identifier";
-            let stream = yield OS.File.open(streamPath, { create: true });
-            try {
-              yield stream.write(gInternetZoneIdentifier);
-            } finally {
-              yield stream.close();
-            }
-          } catch (ex) {
-            // If writing to the stream fails, we ignore the error and continue.
-            // The Windows API error 123 (ERROR_INVALID_NAME) is expected to
-            // occur when working on a file system that does not support
-            // Alternate Data Streams, like FAT32, thus we don't report this
-            // specific error.
-            if (!(ex instanceof OS.File.Error) || ex.winLastError != 123) {
-              Cu.reportError(ex);
-            }
+            yield stream.write(gInternetZoneIdentifier);
+          } finally {
+            yield stream.close();
+          }
+        } catch (ex) {
+          // If writing to the stream fails, we ignore the error and continue.
+          // The Windows API error 123 (ERROR_INVALID_NAME) is expected to
+          // occur when working on a file system that does not support
+          // Alternate Data Streams, like FAT32, thus we don't report this
+          // specific error.
+          if (!(ex instanceof OS.File.Error) || ex.winLastError != 123) {
+            Cu.reportError(ex);
           }
         }
       }
 #endif
 
       gDownloadPlatform.downloadDone(NetUtil.newURI(aDownload.source.url),
                                      new FileUtils.File(aDownload.target.path),
                                      aDownload.contentType,