Bug 720984 - contentAreaUtils.js: getTargetFile leaks gDownloadLastDir into the global scope. r=gavin
authorDão Gottwald <dao@mozilla.com>
Thu, 26 Jan 2012 13:09:45 +0100
changeset 86700 b0d7705cd271bfe9cf3506967eb4a5a9c0537224
parent 86699 572cfaeede5cb713f544ccdf45c6504b2d8ecc12
child 86701 eba8a5ac183f19d0acf435eacb9469186b8e684c
push id805
push userakeybl@mozilla.com
push dateWed, 01 Feb 2012 18:17:35 +0000
treeherdermozilla-aurora@6fb3bf232436 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs720984
milestone12.0a1
Bug 720984 - contentAreaUtils.js: getTargetFile leaks gDownloadLastDir into the global scope. r=gavin
toolkit/content/contentAreaUtils.js
toolkit/content/tests/unit/test_privatebrowsing_downloadLastDir_c.js
--- a/toolkit/content/contentAreaUtils.js
+++ b/toolkit/content/contentAreaUtils.js
@@ -558,18 +558,19 @@ function initFileInfo(aFI, aURL, aURLCha
  *        An nsIURI associated with the download. The last used
  *        directory of the picker is retrieved from/stored in the 
  *        Content Pref Service using this URI.
  * @return true if the user confirmed a filename in the picker or the picker
  *         was not displayed; false if they dismissed the picker.
  */
 function getTargetFile(aFpP, /* optional */ aSkipPrompt, /* optional */ aRelatedURI)
 {
-  if (typeof gDownloadLastDir != "object")
-    Components.utils.import("resource://gre/modules/DownloadLastDir.jsm");
+  if (!getTargetFile.gDownloadLastDir)
+    Components.utils.import("resource://gre/modules/DownloadLastDir.jsm", getTargetFile);
+  var gDownloadLastDir = getTargetFile.gDownloadLastDir;
 
   var prefs = getPrefsBrowserDownload("browser.download.");
   var useDownloadDir = prefs.getBoolPref("useDownloadDir");
   const nsILocalFile = Components.interfaces.nsILocalFile;
 
   if (!aSkipPrompt)
     useDownloadDir = false;
 
--- a/toolkit/content/tests/unit/test_privatebrowsing_downloadLastDir_c.js
+++ b/toolkit/content/tests/unit/test_privatebrowsing_downloadLastDir_c.js
@@ -38,16 +38,17 @@
 
 const Ci = Components.interfaces;
 const Cc = Components.classes;
 
 function loadUtilsScript() {
   let loader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                getService(Ci.mozIJSSubScriptLoader);
   loader.loadSubScript("chrome://global/content/contentAreaUtils.js");
+  Components.utils.import("resource://gre/modules/DownloadLastDir.jsm");
 }
 
 do_get_profile();
 
 let window = {};
 function run_test()
 {
   let pb;