Bug 795930 - Hide ArchiveReader feature behind a pref (disabled by default), r=mounir
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 08 Nov 2012 15:57:17 +0000
changeset 112695 77378c09bbb526d7091d8f98c6c2f6a8901ecde5
parent 112694 d7ad671341278d6084b1ffd736e56063b553fac5
child 112696 fdcb6474f4b439026e87cc597e6ad84119f30c77
push id23835
push userryanvm@gmail.com
push dateFri, 09 Nov 2012 00:52:02 +0000
treeherdermozilla-central@27ae6c86237f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmounir
bugs795930
milestone19.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 795930 - Hide ArchiveReader feature behind a pref (disabled by default), r=mounir
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
@@ -6672,16 +6672,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 == 1 || aArgc == 2, NS_ERROR_INVALID_ARG);
 
+  if (!PrefEnabled()) {
+    return NS_ERROR_UNEXPECTED;
+  }
+
   // We expect to get a Blob object
   if (!aArgv[0].isObject()) {
     return NS_ERROR_INVALID_ARG; // We're not interested
   }
 
   JSObject* obj = &aArgv[0].toObject();
 
   nsCOMPtr<nsIDOMBlob> blob;
--- a/dom/file/ArchiveReader.h
+++ b/dom/file/ArchiveReader.h
@@ -43,16 +43,18 @@ public:
                         JSContext* aCx,
                         JSObject* aObj,
                         uint32_t aArgc,
                         JS::Value* 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 == 6;
   }
 
   function testSteps()
   {
@@ -246,16 +240,22 @@
       is(this.result[1].type, "text/plain", "ArchiveReader.getFile('test/a.txt') the type MUST be 'text/plain'");
 
       markTestDone();
     }
     handle5.onerror = function() {
       ok(false, "ArchiveReader.getFiles() 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
@@ -202,18 +202,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
@@ -1676,16 +1676,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);