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 114057 83b3764cce455cc1ffd99fe7abb24c7f4c235139
parent 114056 4dbb66879cf5db998180834bd6ee040b3dd0669e
child 114058 c8a8a30e99d1f3b382f0aeaf6f2ef221ea6f20dc
push id2623
push userryanvm@gmail.com
push dateFri, 09 Nov 2012 01:24:05 +0000
treeherdermozilla-aurora@c8a8a30e99d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir, lsblakk
bugs795930
milestone18.0a2
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/file/test/test_archivereader.html
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
@@ -6665,16 +6665,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/file/test/test_archivereader.html
+++ b/dom/file/test/test_archivereader.html
@@ -3,24 +3,18 @@
   http://creativecommons.org/publicdomain/zero/1.0/
 -->
 <html>
 <head>
   <title>Archive Reader Test</title>
 
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
-</head>
 
-<body>
-<p id="display">
-  <input id="fileList" type="file"></input>
-</p>
-
-<script type="text/javascript;version=1.7">
+  <script type="text/javascript;version=1.7">
   function createZipFileWithData(fileData) {
     var Cc = SpecialPowers.Cc;
     var Ci = SpecialPowers.Ci;
 
     var dirSvc = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
     var testFile = dirSvc.get("ProfD", Ci.nsIFile);
     testFile.append("fileArchiveReader.zip");
     var outStream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(Ci.nsIFileOutputStream);
@@ -53,17 +47,17 @@
 
     return fileList.files[0];
   }
 
   handleFinished = 0;
   function markTestDone() {
     ++handleFinished;
     if (isFinished()) {
-      SimpleTest.finish();
+      finishTest();
     }
   }
   function isFinished() {
     return handleFinished == 5;
   }
 
   function testSteps()
   {
@@ -227,16 +221,22 @@
           is(p[i], "hello world", "ArchiveReader + FileReader are working with a compress data");
         markTestDone();
       }
     }
     handle4.onerror = function() {
       ok(false, "ArchiveReader.getFile('test/a.txt') should not return an 'error'");
       markTestDone();
     }
+    yield;
   }
 
-  SimpleTest.waitForExplicitFinish();
-  testSteps();
   </script>
+  <script type="text/javascript;version=1.7" src="helpers.js"></script>
+</head>
+
+<body onload="runTest();">
+<p id="display">
+  <input id="fileList" type="file"></input>
+</p>
 </body>
 
 </html>
--- 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;
 
 // The test js is shared between xpcshell (which has no SpecialPowers object)
 // and content mochitests (where the |Components| object is accessible only as
 // SpecialPowers.Components). Expose Components if necessary here to make things
 // work everywhere.
 if (typeof Components === 'undefined')
   Components = SpecialPowers.Components;
 
@@ -63,23 +64,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();
   });
 }
 
@@ -158,22 +162,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)
 {
@@ -206,13 +210,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
@@ -206,18 +206,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
@@ -1675,16 +1675,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);