Bug 795930 - Hide ArchiveReader feature behind a pref (disabled by default). r=mounir, a=lsblakk
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 08 Nov 2012 15:57:17 +0000
changeset 109793 593cf8318f49baf68f090b0d788eaa74b5acda26
parent 109790 25b230afe8216153c6ba80a48fd6752bb7d1e2d0
child 109794 0c946992bf3dd4850f25b40fb58d78c66417b0e1
push id1676
push userryanvm@gmail.com
push dateFri, 09 Nov 2012 01:30:13 +0000
treeherdermozilla-beta@593cf8318f49 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir, lsblakk
bugs795930
milestone17.0
Bug 795930 - Hide ArchiveReader feature behind a pref (disabled by default). r=mounir, a=lsblakk
dom/base/nsDOMClassInfo.cpp
dom/file/ArchiveReader.cpp
dom/file/ArchiveReader.h
dom/file/test/helpers.js
dom/indexedDB/test/helpers.js
dom/tests/mochitest/general/test_interfaces.html
modules/libpref/src/init/all.js
--- a/dom/base/nsDOMClassInfo.cpp
+++ b/dom/base/nsDOMClassInfo.cpp
@@ -6701,16 +6701,24 @@ ConstructorEnabled(const nsGlobalNameStr
 
   // Don't expose CSSSupportsRule unless @supports processing is enabled.
   if (aStruct->mDOMClassInfoID == eDOMClassInfo_CSSSupportsRule_id) {
     if (!CSSSupportsRule::PrefEnabled()) {
       return false;
     }
   }
 
+  // Don't expose ArchiveReader unless user has explicitly enabled it
+  if (aStruct->mDOMClassInfoID == eDOMClassInfo_ArchiveReader_id ||
+      aStruct->mDOMClassInfoID == eDOMClassInfo_ArchiveRequest_id) {
+    if (!dom::file::ArchiveReader::PrefEnabled()) {
+      return false;
+    }
+  }
+
   return true;
 }
 
 // static
 nsresult
 nsWindowSH::GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
                           JSObject *obj, jsid id, bool *did_resolve)
 {
--- a/dom/file/ArchiveReader.cpp
+++ b/dom/file/ArchiveReader.cpp
@@ -11,16 +11,18 @@
 
 #include "nsContentUtils.h"
 #include "nsLayoutStatics.h"
 #include "nsDOMClassInfoID.h"
 
 #include "nsIURI.h"
 #include "nsNetUtil.h"
 
+#include "mozilla/Preferences.h"
+
 USING_FILE_NAMESPACE
 
 ArchiveReader::ArchiveReader()
 : mBlob(nullptr),
   mWindow(nullptr),
   mStatus(NOT_STARTED)
 {
   MOZ_COUNT_CTOR(ArchiveReader);
@@ -28,25 +30,35 @@ ArchiveReader::ArchiveReader()
 }
 
 ArchiveReader::~ArchiveReader()
 {
   MOZ_COUNT_DTOR(ArchiveReader);
   nsLayoutStatics::Release();
 }
 
+bool
+ArchiveReader::PrefEnabled()
+{
+  return Preferences::GetBool("dom.archivereader.enabled", true);
+}
+
 NS_IMETHODIMP
 ArchiveReader::Initialize(nsISupports* aOwner,
                           JSContext* aCx,
                           JSObject* aObj,
                           uint32_t aArgc,
                           JS::Value* aArgv)
 {
   NS_ENSURE_TRUE(aArgc > 0, NS_ERROR_UNEXPECTED);
 
+  if (!PrefEnabled()) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
   // We expect to get a Blob object
   if (!aArgv[0].isObject()) {
     return NS_ERROR_UNEXPECTED; // We're not interested
   }
 
   JSObject* obj = &aArgv[0].toObject();
 
   nsCOMPtr<nsIDOMBlob> blob;
--- a/dom/file/ArchiveReader.h
+++ b/dom/file/ArchiveReader.h
@@ -39,16 +39,18 @@ public:
                         JSContext* aCx,
                         JSObject* aObj,
                         uint32_t aArgc,
                         jsval* aArgv);
 
   nsresult GetInputStream(nsIInputStream** aInputStream);
   nsresult GetSize(uint64_t* aSize);
 
+  static bool PrefEnabled();
+
 public: // for the ArchiveRequest:
   nsresult RegisterRequest(ArchiveRequest* aRequest);
 
 public: // For events:
   void Ready(nsTArray<nsCOMPtr<nsIDOMFile> >& aFileList,
              nsresult aStatus);
 
 private:
--- a/dom/file/test/helpers.js
+++ b/dom/file/test/helpers.js
@@ -8,29 +8,33 @@ const DeviceStorageKey = "DS";
 
 var fileStorages = [
   { key: IndexedDatabaseKey }
 //  { key: DeviceStorageKey }
 ];
 
 var utils = SpecialPowers.getDOMWindowUtils(window);
 
+var archiveReaderEnabled = false;
+
 var testGenerator = testSteps();
 
 function runTest()
 {
   allowUnlimitedQuota();
+  enableArchiveReader();
 
   SimpleTest.waitForExplicitFinish();
   testGenerator.next();
 }
 
 function finishTest()
 {
   resetUnlimitedQuota();
+  resetArchiveReader();
 
   SimpleTest.executeSoon(function() {
     testGenerator.close();
     SimpleTest.finish();
   });
 }
 
 function grabEventAndContinueHandler(event)
@@ -93,16 +97,27 @@ function allowUnlimitedQuota(url)
   addPermission("indexedDB-unlimited", true, url);
 }
 
 function resetUnlimitedQuota(url)
 {
   removePermission("indexedDB-unlimited", url);
 }
 
+function enableArchiveReader()
+{
+  archiveReaderEnabled = SpecialPowers.getBoolPref("dom.archivereader.enabled");
+  SpecialPowers.setBoolPref("dom.archivereader.enabled", true);
+}
+
+function resetArchiveReader()
+{
+  SpecialPowers.setBoolPref("dom.archivereader.enabled", archiveReaderEnabled);
+}
+
 function getFileHandle(fileStorageKey, name)
 {
   var requestService = SpecialPowers.getDOMRequestService();
   var request = requestService.createRequest(window);
 
   switch (fileStorageKey) {
     case IndexedDatabaseKey:
       var dbname = window.location.pathname;
--- a/dom/indexedDB/test/helpers.js
+++ b/dom/indexedDB/test/helpers.js
@@ -1,14 +1,15 @@
 /**
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 var testGenerator = testSteps();
+var archiveReaderEnabled = false;
 
 function executeSoon(aFun)
 {
   let comp = SpecialPowers.wrap(Components);
 
   let thread = comp.classes["@mozilla.org/thread-manager;1"]
                    .getService(comp.interfaces.nsIThreadManager)
                    .mainThread;
@@ -55,23 +56,26 @@ if (!window.runTest) {
 
     if (limitedQuota) {
       denyUnlimitedQuota();
     }
     else {
       allowUnlimitedQuota();
     }
 
+    enableArchiveReader();
+
     clearAllDatabases(function () { testGenerator.next(); });
   }
 }
 
 function finishTest()
 {
   resetUnlimitedQuota();
+  resetArchiveReader();
 
   SimpleTest.executeSoon(function() {
     testGenerator.close();
     //clearAllDatabases(function() { SimpleTest.finish(); });
     SimpleTest.finish();
   });
 }
 
@@ -150,22 +154,22 @@ function compareKeys(k1, k2) {
     return (k2 instanceof Date) &&
       k1.getTime() === k2.getTime();
   }
 
   if (k1 instanceof Array) {
     if (!(k2 instanceof Array) ||
         k1.length != k2.length)
       return false;
-    
+
     for (let i = 0; i < k1.length; ++i) {
       if (!compareKeys(k1[i], k2[i]))
         return false;
     }
-    
+
     return true;
   }
 
   return false;
 }
 
 function addPermission(type, allow, url)
 {
@@ -198,13 +202,24 @@ function denyUnlimitedQuota(url)
   addPermission("indexedDB-unlimited", false, url);
 }
 
 function resetUnlimitedQuota(url)
 {
   removePermission("indexedDB-unlimited", url);
 }
 
+function enableArchiveReader()
+{
+  archiveReaderEnabled = SpecialPowers.getBoolPref("dom.archivereader.enabled");
+  SpecialPowers.setBoolPref("dom.archivereader.enabled", true);
+}
+
+function resetArchiveReader()
+{
+  SpecialPowers.setBoolPref("dom.archivereader.enabled", archiveReaderEnabled);
+}
+
 function gc()
 {
   SpecialPowers.forceGC();
   SpecialPowers.forceCC();
 }
--- a/dom/tests/mochitest/general/test_interfaces.html
+++ b/dom/tests/mochitest/general/test_interfaces.html
@@ -207,18 +207,16 @@ var interfaceNamesInGlobalScope =
     "SVGFEMorphologyElement",
     "SVGFETurbulenceElement",
     "XULTextBoxElement",
     "SVGDocument",
     "CSSStyleDeclaration",
     "SVGAltGlyphElement",
     "Screen",
     "FileReader",
-    "ArchiveReader",
-    "ArchiveRequest",
     "SVGSwitchElement",
     "SVGPolylineElement",
     "SVGPathSegLinetoAbs",
     "NavigatorDeviceStorage",
     "HTMLOptionsCollection",
     "IDBKeyRange",
     "Parser",
     "HTMLDivElement",
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -1642,16 +1642,19 @@ pref("gestures.enable_single_finger_inpu
 //pref("editor.encode_entity",                 "html");
 
 pref("editor.resizing.preserve_ratio",       true);
 pref("editor.positioning.offset",            0);
 
 pref("dom.max_chrome_script_run_time", 20);
 pref("dom.max_script_run_time", 10);
 
+// If true, ArchiveReader will be enabled
+pref("dom.archivereader.enabled", false);
+
 // Hang monitor timeout after which we kill the browser, in seconds
 // (0 is disabled)
 // Disabled on all platforms per bug 705748 until the found issues are
 // resolved.
 pref("hangmonitor.timeout", 0);
 
 // If true, plugins will be click to play
 pref("plugins.click_to_play", false);