Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 3 - DOM Caches enabled, r=asuth
☠☠ backed out by ccd7b237c433 ☠ ☠
authorAndrea Marchesini <amarchesini@mozilla.com>
Wed, 13 Dec 2017 14:02:44 -0600
changeset 396268 000c8d5fbc03d656b87b088dfabb57e5d8cd8d0b
parent 396267 2e263a2519c50359bd6b9663b94d462e5e30249e
child 396269 19b14deed8fefc08d567cb01feb9151fb47812c7
push id33087
push userdluca@mozilla.com
push dateThu, 14 Dec 2017 09:54:55 +0000
treeherdermozilla-central@8062887ff0d9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1419771
milestone59.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 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 3 - DOM Caches enabled, r=asuth
dom/base/DOMPreferences.cpp
dom/base/DOMPreferences.h
dom/base/nsGlobalWindowInner.h
dom/cache/Cache.cpp
dom/cache/Cache.h
dom/cache/CacheStorage.cpp
dom/cache/CacheStorage.h
dom/webidl/Cache.webidl
dom/webidl/CacheStorage.webidl
dom/webidl/WindowOrWorkerGlobalScope.webidl
dom/workers/WorkerPrefs.h
--- a/dom/base/DOMPreferences.cpp
+++ b/dom/base/DOMPreferences.cpp
@@ -31,24 +31,26 @@ PREF(DumpEnabled, "browser.dom.window.du
 /* static */ bool
 DOMPreferences::DumpEnabled()
 {
   return true;
 }
 #endif
 
 PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled")
+PREF(DOMCachesEnabled, "dom.caches.enabled")
 
 #undef PREF
 
 #define PREF_WEBIDL(name)                              \
   /* static */ bool                                    \
   DOMPreferences::name(JSContext* aCx, JSObject* aObj) \
   {                                                    \
     return DOMPreferences::name();                     \
   }
 
 PREF_WEBIDL(ImageBitmapExtensionsEnabled)
+PREF_WEBIDL(DOMCachesEnabled)
 
 #undef PREF_WEBIDL
 
 } // dom namespace
 } // mozilla namespace
--- a/dom/base/DOMPreferences.h
+++ b/dom/base/DOMPreferences.h
@@ -14,14 +14,18 @@ class DOMPreferences final
 {
 public:
   // Returns true if the browser.dom.window.dump.enabled pref is set.
   static bool DumpEnabled();
 
   // Returns true if the canvas.imagebitmap_extensions.enabled pref is set.
   static bool ImageBitmapExtensionsEnabled();
   static bool ImageBitmapExtensionsEnabled(JSContext* aCx, JSObject* aObj);
+
+  // Returns true if the dom.caches.enabled pref is set.
+  static bool DOMCachesEnabled();
+  static bool DOMCachesEnabled(JSContext* aCx, JSObject* aObj);
 };
 
 } // dom namespace
 } // mozilla namespace
 
 #endif // mozilla_dom_DOMPreferences_h
--- a/dom/base/nsGlobalWindowInner.h
+++ b/dom/base/nsGlobalWindowInner.h
@@ -32,16 +32,17 @@
 #include "nsIScriptObjectPrincipal.h"
 #include "nsITimer.h"
 #include "nsIDOMModalContentWindow.h"
 #include "mozilla/EventListenerManager.h"
 #include "nsIPrincipal.h"
 #include "nsSize.h"
 #include "mozilla/FlushType.h"
 #include "prclist.h"
+#include "mozilla/dom/DOMPreferences.h"
 #include "mozilla/dom/BindingDeclarations.h"
 #include "mozilla/dom/StorageEvent.h"
 #include "mozilla/dom/StorageEventBinding.h"
 #include "mozilla/dom/UnionTypes.h"
 #include "mozilla/ErrorResult.h"
 #include "nsFrameMessageManager.h"
 #include "mozilla/Attributes.h"
 #include "mozilla/GuardObjects.h"
--- a/dom/cache/Cache.cpp
+++ b/dom/cache/Cache.cpp
@@ -12,16 +12,17 @@
 #include "mozilla/dom/PromiseNativeHandler.h"
 #include "mozilla/dom/Response.h"
 #include "mozilla/dom/WorkerPrivate.h"
 #include "mozilla/dom/CacheBinding.h"
 #include "mozilla/dom/cache/AutoUtils.h"
 #include "mozilla/dom/cache/CacheChild.h"
 #include "mozilla/dom/cache/CacheWorkerHolder.h"
 #include "mozilla/dom/cache/ReadStream.h"
+#include "mozilla/dom/DOMPreferences.h"
 #include "mozilla/ErrorResult.h"
 #include "mozilla/Preferences.h"
 #include "mozilla/Unused.h"
 #include "nsIGlobalObject.h"
 
 namespace mozilla {
 namespace dom {
 namespace cache {
@@ -512,39 +513,16 @@ Cache::Keys(JSContext* aCx, const Option
     if (NS_WARN_IF(aRv.Failed())) {
       return nullptr;
     }
   }
 
   return ExecuteOp(args, aRv);
 }
 
-// static
-bool
-Cache::PrefEnabled(JSContext* aCx, JSObject* aObj)
-{
-  using mozilla::dom::workers::WorkerPrivate;
-  using mozilla::dom::workers::GetWorkerPrivateFromContext;
-
-  // If we're on the main thread, then check the pref directly.
-  if (NS_IsMainThread()) {
-    bool enabled = false;
-    Preferences::GetBool("dom.caches.enabled", &enabled);
-    return enabled;
-  }
-
-  // Otherwise check the pref via the work private helper
-  WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
-  if (!workerPrivate) {
-    return false;
-  }
-
-  return workerPrivate->DOMCachesEnabled();
-}
-
 nsISupports*
 Cache::GetParentObject() const
 {
   return mGlobal;
 }
 
 JSObject*
 Cache::WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto)
--- a/dom/cache/Cache.h
+++ b/dom/cache/Cache.h
@@ -63,18 +63,16 @@ public:
   already_AddRefed<Promise>
   Delete(JSContext* aCx, const RequestOrUSVString& aRequest,
          const CacheQueryOptions& aOptions, ErrorResult& aRv);
   already_AddRefed<Promise>
   Keys(JSContext* aCx, const Optional<RequestOrUSVString>& aRequest,
        const CacheQueryOptions& aParams, ErrorResult& aRv);
 
   // binding methods
-  static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
-
   nsISupports* GetParentObject() const;
   virtual JSObject* WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto) override;
 
   // Called when CacheChild actor is being destroyed
   void DestroyInternal(CacheChild* aActor);
 
   // TypeUtils methods
   virtual nsIGlobalObject*
--- a/dom/cache/CacheStorage.cpp
+++ b/dom/cache/CacheStorage.cpp
@@ -440,23 +440,16 @@ CacheStorage::Keys(ErrorResult& aRv)
   entry->mArgs = StorageKeysArgs();
 
   RunRequest(Move(entry));
 
   return promise.forget();
 }
 
 // static
-bool
-CacheStorage::PrefEnabled(JSContext* aCx, JSObject* aObj)
-{
-  return Cache::PrefEnabled(aCx, aObj);
-}
-
-// static
 already_AddRefed<CacheStorage>
 CacheStorage::Constructor(const GlobalObject& aGlobal,
                           CacheStorageNamespace aNamespace,
                           nsIPrincipal* aPrincipal, ErrorResult& aRv)
 {
   if (NS_WARN_IF(!NS_IsMainThread())) {
     aRv.Throw(NS_ERROR_FAILURE);
     return nullptr;
--- a/dom/cache/CacheStorage.h
+++ b/dom/cache/CacheStorage.h
@@ -68,18 +68,16 @@ public:
   already_AddRefed<Promise> Keys(ErrorResult& aRv);
 
   // chrome-only webidl interface methods
   static already_AddRefed<CacheStorage>
   Constructor(const GlobalObject& aGlobal, CacheStorageNamespace aNamespace,
               nsIPrincipal* aPrincipal, ErrorResult& aRv);
 
   // binding methods
-  static bool PrefEnabled(JSContext* aCx, JSObject* aObj);
-
   nsISupports* GetParentObject() const;
   virtual JSObject* WrapObject(JSContext* aContext, JS::Handle<JSObject*> aGivenProto) override;
 
   // Called when CacheStorageChild actor is being destroyed
   void DestroyInternal(CacheStorageChild* aActor);
 
   // TypeUtils methods
   virtual nsIGlobalObject* GetGlobalObject() const override;
--- a/dom/webidl/Cache.webidl
+++ b/dom/webidl/Cache.webidl
@@ -6,17 +6,17 @@
  * The origin of this IDL file is
  * http://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html
  *
  */
 
 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#cache
 
 [Exposed=(Window,Worker),
- Func="mozilla::dom::cache::Cache::PrefEnabled"]
+ Func="mozilla::dom::DOMPreferences::DOMCachesEnabled"]
 interface Cache {
   [NewObject]
   Promise<Response> match(RequestInfo request, optional CacheQueryOptions options);
   [NewObject]
   Promise<sequence<Response>> matchAll(optional RequestInfo request, optional CacheQueryOptions options);
   [NewObject, NeedsCallerType]
   Promise<void> add(RequestInfo request);
   [NewObject, NeedsCallerType]
--- a/dom/webidl/CacheStorage.webidl
+++ b/dom/webidl/CacheStorage.webidl
@@ -9,17 +9,17 @@
  */
 
 // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#cache-storage
 
 interface Principal;
 
 [Exposed=(Window,Worker),
  ChromeConstructor(CacheStorageNamespace namespace, Principal principal),
- Func="mozilla::dom::cache::CacheStorage::PrefEnabled"]
+ Func="mozilla::dom::DOMPreferences::DOMCachesEnabled"]
 interface CacheStorage {
   [NewObject]
   Promise<Response> match(RequestInfo request, optional CacheQueryOptions options);
   [NewObject]
   Promise<boolean> has(DOMString cacheName);
   [NewObject]
   Promise<Cache> open(DOMString cacheName);
   [NewObject]
--- a/dom/webidl/WindowOrWorkerGlobalScope.webidl
+++ b/dom/webidl/WindowOrWorkerGlobalScope.webidl
@@ -57,17 +57,17 @@ partial interface WindowOrWorkerGlobalSc
 partial interface WindowOrWorkerGlobalScope {
    // readonly attribute IDBFactory indexedDB;
    [Throws]
    readonly attribute IDBFactory? indexedDB;
 };
 
 // https://w3c.github.io/ServiceWorker/#self-caches
 partial interface WindowOrWorkerGlobalScope {
-  [Throws, Func="mozilla::dom::cache::CacheStorage::PrefEnabled", SameObject]
+  [Throws, Func="mozilla::dom::DOMPreferences::DOMCachesEnabled", SameObject]
   readonly attribute CacheStorage caches;
 };
 
 // Mozilla extensions
 partial interface WindowOrWorkerGlobalScope {
   // Extensions to ImageBitmap bits.
   // Bug 1141979 - [FoxEye] Extend ImageBitmap with interfaces to access its
   // underlying image data
--- a/dom/workers/WorkerPrefs.h
+++ b/dom/workers/WorkerPrefs.h
@@ -16,17 +16,16 @@
 //     macro in Workers.h.
 //   * The name of the function that updates the new value of a pref.
 //
 //   WORKER_PREF("foo.bar", UpdaterFunction)
 //
 //   * First argument is the name of the pref.
 //   * The name of the function that updates the new value of a pref.
 
-WORKER_SIMPLE_PREF("dom.caches.enabled", DOMCachesEnabled, DOM_CACHES)
 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.storageManager.enabled", StorageManagerEnabled, STORAGEMANAGER_ENABLED)