Bug 1304966 - Enable Storage API only for nightly bulid, r=baku
authorShawn Huang <shuang@mozilla.com>
Wed, 26 Oct 2016 21:38:08 +0800
changeset 319593 6817b7629eeafb0b66a9976f13f7d2ef892a7e47
parent 319592 3762c5ea3950b4eff887c41fbb3032820ff81e8e
child 319594 24e39ddd4314249f4660a2c34823a02630620db6
push id20745
push userphilringnalda@gmail.com
push dateThu, 27 Oct 2016 01:57:01 +0000
treeherderfx-team@3f4c3a3cabaf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbaku
bugs1304966
milestone52.0a1
Bug 1304966 - Enable Storage API only for nightly bulid, r=baku
dom/cache/test/mochitest/test_cache_orphaned_body.html
dom/indexedDB/test/test_storage_manager_estimate.html
dom/indexedDB/test/unit/test_storage_manager_estimate.js
dom/quota/StorageManager.cpp
dom/quota/StorageManager.h
dom/webidl/Navigator.webidl
dom/webidl/StorageManager.webidl
dom/workers/WorkerPrefs.h
modules/libpref/init/all.js
--- a/dom/cache/test/mochitest/test_cache_orphaned_body.html
+++ b/dom/cache/test/mochitest/test_cache_orphaned_body.html
@@ -83,17 +83,18 @@ function gc() {
     SpecialPowers.exactGC(resolve);
   });
 }
 
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPrefEnv({
   "set": [["dom.caches.enabled", true],
           ["dom.caches.testing.enabled", true],
-          ["dom.quotaManager.testing", true]],
+          ["dom.quotaManager.testing", true],
+          ["dom.storageManager.enabled", true]],
 }, function() {
   var name = 'orphanedBodyOwner';
   var cache = null;
   var response = null;
   var initialUsage = 0;
   var fullUsage = 0;
   var resetUsage = 0;
   var endUsage = 0;
--- a/dom/indexedDB/test/test_storage_manager_estimate.html
+++ b/dom/indexedDB/test/test_storage_manager_estimate.html
@@ -9,11 +9,11 @@
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
 
   <script type="text/javascript;version=1.7" src="unit/test_storage_manager_estimate.js"></script>
   <script type="text/javascript;version=1.7" src="helpers.js"></script>
 
 </head>
 
-<body onload="runTest();"></body>
+<body onload="setup();"></body>
 
 </html>
--- a/dom/indexedDB/test/unit/test_storage_manager_estimate.js
+++ b/dom/indexedDB/test/unit/test_storage_manager_estimate.js
@@ -49,8 +49,15 @@ function testSteps()
   });
   let usageAfterPut = yield undefined;
   ok(usageAfterPut > usageAfterCreate, 'estimated usage must increase after putting large object');
   db.close();
 
   finishTest();
   yield undefined;
 }
+
+function setup()
+{
+  SpecialPowers.pushPrefEnv({
+    "set": [["dom.storageManager.enabled", true]]
+  },  runTest);
+}
--- a/dom/quota/StorageManager.cpp
+++ b/dom/quota/StorageManager.cpp
@@ -327,16 +327,30 @@ StorageManager::Estimate(ErrorResult& aR
   runnnable->Dispatch(aRv);
   if (NS_WARN_IF(aRv.Failed())) {
     return nullptr;
   }
 
   return promise.forget();
 }
 
+// static
+bool
+StorageManager::PrefEnabled(JSContext* aCx, JSObject* aObj)
+{
+  if (NS_IsMainThread()) {
+    return Preferences::GetBool("dom.storageManager.enabled");
+  }
+
+  WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
+  MOZ_ASSERT(workerPrivate);
+
+  return workerPrivate->StorageManagerEnabled();
+}
+
 NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(StorageManager, mOwner)
 
 NS_IMPL_CYCLE_COLLECTING_ADDREF(StorageManager)
 NS_IMPL_CYCLE_COLLECTING_RELEASE(StorageManager)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(StorageManager)
   NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
   NS_INTERFACE_MAP_ENTRY(nsISupports)
--- a/dom/quota/StorageManager.h
+++ b/dom/quota/StorageManager.h
@@ -20,16 +20,20 @@ struct StorageEstimate;
 
 class StorageManager final
   : public nsISupports
   , public nsWrapperCache
 {
   nsCOMPtr<nsIGlobalObject> mOwner;
 
 public:
+  // Return dom.quota.storageManager.enabled on main/worker thread.
+  static bool
+  PrefEnabled(JSContext* aCx, JSObject* aObj);
+
   explicit
   StorageManager(nsIGlobalObject* aGlobal);
 
   nsIGlobalObject*
   GetParentObject() const
   {
     return mOwner;
   }
--- a/dom/webidl/Navigator.webidl
+++ b/dom/webidl/Navigator.webidl
@@ -83,16 +83,17 @@ interface NavigatorContentUtils {
   //DOMString isProtocolHandlerRegistered(DOMString scheme, DOMString url);
   //DOMString isContentHandlerRegistered(DOMString mimeType, DOMString url);
   //void unregisterProtocolHandler(DOMString scheme, DOMString url);
   //void unregisterContentHandler(DOMString mimeType, DOMString url);
 };
 
 [NoInterfaceObject, Exposed=(Window,Worker)]
 interface NavigatorStorage {
+  [Func="mozilla::dom::StorageManager::PrefEnabled"]
   readonly attribute StorageManager storage;
 };
 
 [NoInterfaceObject]
 interface NavigatorStorageUtils {
   // NOT IMPLEMENTED
   //void yieldForStorageUpdates();
 };
--- a/dom/webidl/StorageManager.webidl
+++ b/dom/webidl/StorageManager.webidl
@@ -3,17 +3,18 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is
  * https://storage.spec.whatwg.org/#storagemanager
  *
  */
 
-[Exposed=(Window,Worker)]
+[Exposed=(Window,Worker),
+ Func="mozilla::dom::StorageManager::PrefEnabled"]
 interface StorageManager {
   // [Throws]
   // Promise<boolean> persisted();
   // [Throws]
   // [Exposed=Window] Promise<boolean> persist();
   [Throws]
   Promise<StorageEstimate> estimate();
 };
--- a/dom/workers/WorkerPrefs.h
+++ b/dom/workers/WorkerPrefs.h
@@ -29,16 +29,17 @@ WORKER_SIMPLE_PREF("dom.caches.enabled",
 WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CACHES_TESTING)
 WORKER_SIMPLE_PREF("dom.performance.enable_user_timing_logging", PerformanceLoggingEnabled, PERFORMANCE_LOGGING_ENABLED)
 WORKER_SIMPLE_PREF("dom.webnotifications.enabled", DOMWorkerNotificationEnabled, DOM_WORKERNOTIFICATION)
 WORKER_SIMPLE_PREF("dom.webnotifications.serviceworker.enabled", DOMServiceWorkerNotificationEnabled, DOM_SERVICEWORKERNOTIFICATION)
 WORKER_SIMPLE_PREF("dom.webnotifications.requireinteraction.enabled", DOMWorkerNotificationRIEnabled, DOM_WORKERNOTIFICATIONRI)
 WORKER_SIMPLE_PREF("dom.serviceWorkers.enabled", ServiceWorkersEnabled, SERVICEWORKERS_ENABLED)
 WORKER_SIMPLE_PREF("dom.serviceWorkers.testing.enabled", ServiceWorkersTestingEnabled, SERVICEWORKERS_TESTING_ENABLED)
 WORKER_SIMPLE_PREF("dom.serviceWorkers.openWindow.enabled", OpenWindowEnabled, OPEN_WINDOW_ENABLED)
+WORKER_SIMPLE_PREF("dom.storageManager.enabled", StorageManagerEnabled, STORAGEMANAGER_ENABLED)
 WORKER_SIMPLE_PREF("dom.push.enabled", PushEnabled, PUSH_ENABLED)
 WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
 WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)
 WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK)
 WORKER_PREF("dom.workers.latestJSVersion", JSVersionChanged)
 WORKER_PREF("intl.accept_languages", PrefLanguagesChanged)
 WORKER_PREF("general.appname.override", AppNameOverrideChanged)
 WORKER_PREF("general.appversion.override", AppVersionOverrideChanged)
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5508,8 +5508,15 @@ pref("security.mixed_content.send_hsts_p
 // Don't change the order of evaluation of mixed-content and HSTS upgrades in
 // order to be most compatible with current standards
 pref("security.mixed_content.use_hsts", false);
 #else
 // Change the order of evaluation so HSTS upgrades happen before
 // mixed-content blocking
 pref("security.mixed_content.use_hsts", true);
 #endif
+
+// Disable Storage api in release builds.
+#ifdef NIGHTLY_BUILD
+pref("dom.storageManager.enabled", true);
+#else
+pref("dom.storageManager.enabled", false);
+#endif