diff --git a/dom/base/DOMPreferences.cpp b/dom/base/DOMPreferences.cpp index e7f72e62d4b1..be91e9598c38 100644 --- a/dom/base/DOMPreferences.cpp +++ b/dom/base/DOMPreferences.cpp @@ -36,6 +36,7 @@ DOMPreferences::DumpEnabled() #endif PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled") +PREF(DOMCachesEnabled, "dom.caches.enabled") #undef PREF @@ -47,6 +48,7 @@ PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled") } PREF_WEBIDL(ImageBitmapExtensionsEnabled) +PREF_WEBIDL(DOMCachesEnabled) #undef PREF_WEBIDL diff --git a/dom/base/DOMPreferences.h b/dom/base/DOMPreferences.h index 3b82d66e78f7..dda727d9a281 100644 --- a/dom/base/DOMPreferences.h +++ b/dom/base/DOMPreferences.h @@ -19,6 +19,10 @@ public: // 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 diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index b70d2db2b810..4881d5ecfce3 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -37,6 +37,7 @@ #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" diff --git a/dom/cache/Cache.cpp b/dom/cache/Cache.cpp index d27a64cdd76d..8943af14c084 100644 --- a/dom/cache/Cache.cpp +++ b/dom/cache/Cache.cpp @@ -17,6 +17,7 @@ #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" @@ -517,29 +518,6 @@ Cache::Keys(JSContext* aCx, const Optional& aRequest, 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 { diff --git a/dom/cache/Cache.h b/dom/cache/Cache.h index 5148faacfc08..2af7a4c6794e 100644 --- a/dom/cache/Cache.h +++ b/dom/cache/Cache.h @@ -68,8 +68,6 @@ public: const CacheQueryOptions& aParams, ErrorResult& aRv); // binding methods - static bool PrefEnabled(JSContext* aCx, JSObject* aObj); - nsISupports* GetParentObject() const; virtual JSObject* WrapObject(JSContext* aContext, JS::Handle aGivenProto) override; diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp index b86a26cd7200..3cc1b64df609 100644 --- a/dom/cache/CacheStorage.cpp +++ b/dom/cache/CacheStorage.cpp @@ -444,13 +444,6 @@ CacheStorage::Keys(ErrorResult& aRv) return promise.forget(); } -// static -bool -CacheStorage::PrefEnabled(JSContext* aCx, JSObject* aObj) -{ - return Cache::PrefEnabled(aCx, aObj); -} - // static already_AddRefed CacheStorage::Constructor(const GlobalObject& aGlobal, diff --git a/dom/cache/CacheStorage.h b/dom/cache/CacheStorage.h index 2ba60dcd769a..ef7b4145dc6b 100644 --- a/dom/cache/CacheStorage.h +++ b/dom/cache/CacheStorage.h @@ -73,8 +73,6 @@ public: nsIPrincipal* aPrincipal, ErrorResult& aRv); // binding methods - static bool PrefEnabled(JSContext* aCx, JSObject* aObj); - nsISupports* GetParentObject() const; virtual JSObject* WrapObject(JSContext* aContext, JS::Handle aGivenProto) override; diff --git a/dom/webidl/Cache.webidl b/dom/webidl/Cache.webidl index ed2cb88739f2..fed193510758 100644 --- a/dom/webidl/Cache.webidl +++ b/dom/webidl/Cache.webidl @@ -11,7 +11,7 @@ // 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 match(RequestInfo request, optional CacheQueryOptions options); diff --git a/dom/webidl/CacheStorage.webidl b/dom/webidl/CacheStorage.webidl index cf5bad44b201..8c9afd493e25 100644 --- a/dom/webidl/CacheStorage.webidl +++ b/dom/webidl/CacheStorage.webidl @@ -14,7 +14,7 @@ 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 match(RequestInfo request, optional CacheQueryOptions options); diff --git a/dom/webidl/WindowOrWorkerGlobalScope.webidl b/dom/webidl/WindowOrWorkerGlobalScope.webidl index 1b6637b630bf..63c38c48c1ab 100644 --- a/dom/webidl/WindowOrWorkerGlobalScope.webidl +++ b/dom/webidl/WindowOrWorkerGlobalScope.webidl @@ -62,7 +62,7 @@ partial interface WindowOrWorkerGlobalScope { // 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; }; diff --git a/dom/workers/WorkerPrefs.h b/dom/workers/WorkerPrefs.h index c71ac059ef3d..34b8f1ce8ed4 100644 --- a/dom/workers/WorkerPrefs.h +++ b/dom/workers/WorkerPrefs.h @@ -21,7 +21,6 @@ // * 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)