diff --git a/dom/base/DOMPreferences.cpp b/dom/base/DOMPreferences.cpp index 0e9b0bc2e5ff..17857e3b1a39 100644 --- a/dom/base/DOMPreferences.cpp +++ b/dom/base/DOMPreferences.cpp @@ -47,6 +47,7 @@ PREF(ServiceWorkersTestingEnabled, "dom.serviceWorkers.testing.enabled") PREF(OpenWindowEnabled, "dom.serviceWorkers.openWindow.enabled") PREF(StorageManagerEnabled, "dom.storageManager.enabled") PREF(PromiseRejectionEventsEnabled, "dom.promise_rejection_events.enabled") +PREF(PushEnabled, "dom.push.enabled") #undef PREF @@ -65,6 +66,7 @@ PREF_WEBIDL(ServiceWorkersEnabled) PREF_WEBIDL(OpenWindowEnabled) PREF_WEBIDL(StorageManagerEnabled) PREF_WEBIDL(PromiseRejectionEventsEnabled) +PREF_WEBIDL(PushEnabled) #undef PREF_WEBIDL diff --git a/dom/base/DOMPreferences.h b/dom/base/DOMPreferences.h index 6650220cb9ab..c4da11be9127 100644 --- a/dom/base/DOMPreferences.h +++ b/dom/base/DOMPreferences.h @@ -63,6 +63,10 @@ public: // Returns true if the dom.promise_rejection_events.enabled pref is set. static bool PromiseRejectionEventsEnabled(); static bool PromiseRejectionEventsEnabled(JSContext* aCx, JSObject* aObj); + + // Returns true if the dom.push.enabled pref is set. + static bool PushEnabled(); + static bool PushEnabled(JSContext* aCx, JSObject* aObj); }; } // dom namespace diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 3de36467f7b9..65a5679726b8 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -8912,25 +8912,6 @@ nsContentUtils::GetReferrerPolicyFromHeader(const nsAString& aHeader) return referrerPolicy; } -// static -bool -nsContentUtils::PushEnabled(JSContext* aCx, JSObject* aObj) -{ - if (NS_IsMainThread()) { - return Preferences::GetBool("dom.push.enabled", false); - } - - using namespace workers; - - // Otherwise, check the pref via the WorkerPrivate - WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); - if (!workerPrivate) { - return false; - } - - return workerPrivate->PushEnabled(); -} - // static bool nsContentUtils::StreamsEnabled(JSContext* aCx, JSObject* aObj) diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 3e3ecc0a0888..a3da7d7db5cf 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -2918,8 +2918,6 @@ public: */ static mozilla::net::ReferrerPolicy GetReferrerPolicyFromHeader(const nsAString& aHeader); - static bool PushEnabled(JSContext* aCx, JSObject* aObj); - static bool StreamsEnabled(JSContext* aCx, JSObject* aObj); static bool IsNonSubresourceRequest(nsIChannel* aChannel); diff --git a/dom/push/PushManager.h b/dom/push/PushManager.h index caafaf76a68e..fc608e7880e5 100644 --- a/dom/push/PushManager.h +++ b/dom/push/PushManager.h @@ -32,9 +32,9 @@ #include "mozilla/ErrorResult.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/TypedArray.h" +#include "mozilla/dom/DOMPreferences.h" #include "nsCOMPtr.h" -#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled #include "mozilla/RefPtr.h" class nsIGlobalObject; diff --git a/dom/push/PushSubscription.h b/dom/push/PushSubscription.h index 1a2b8081c69c..b68d042fc525 100644 --- a/dom/push/PushSubscription.h +++ b/dom/push/PushSubscription.h @@ -10,13 +10,13 @@ #include "jsapi.h" #include "nsCOMPtr.h" #include "nsWrapperCache.h" -#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled #include "mozilla/AlreadyAddRefed.h" #include "mozilla/ErrorResult.h" #include "mozilla/RefPtr.h" #include "mozilla/dom/BindingDeclarations.h" +#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/PushSubscriptionBinding.h" #include "mozilla/dom/PushSubscriptionOptionsBinding.h" #include "mozilla/dom/TypedArray.h" diff --git a/dom/push/PushSubscriptionOptions.h b/dom/push/PushSubscriptionOptions.h index 8b513b81e27b..3df566f6b3a7 100644 --- a/dom/push/PushSubscriptionOptions.h +++ b/dom/push/PushSubscriptionOptions.h @@ -8,9 +8,9 @@ #define mozilla_dom_PushSubscriptionOptions_h #include "nsCycleCollectionParticipant.h" -#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled #include "nsTArray.h" #include "nsWrapperCache.h" +#include "mozilla/dom/DOMPreferences.h" class nsIGlobalObject; diff --git a/dom/webidl/PushEvent.webidl b/dom/webidl/PushEvent.webidl index a4624e4512e9..b7925857cfbb 100644 --- a/dom/webidl/PushEvent.webidl +++ b/dom/webidl/PushEvent.webidl @@ -8,7 +8,7 @@ */ [Constructor(DOMString type, optional PushEventInit eventInitDict), - Func="nsContentUtils::PushEnabled", + Func="mozilla::dom::DOMPreferences::PushEnabled", Exposed=ServiceWorker] interface PushEvent : ExtendableEvent { readonly attribute PushMessageData? data; diff --git a/dom/webidl/PushManager.webidl b/dom/webidl/PushManager.webidl index 1c69c402e0ad..732ac250871b 100644 --- a/dom/webidl/PushManager.webidl +++ b/dom/webidl/PushManager.webidl @@ -22,7 +22,7 @@ interface PushManagerImpl { Promise permissionState(optional PushSubscriptionOptionsInit options); }; -[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled", +[Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled", ChromeConstructor(DOMString scope)] interface PushManager { [Throws, UseCounter] diff --git a/dom/webidl/PushMessageData.webidl b/dom/webidl/PushMessageData.webidl index 32da84f377ee..14c019498c48 100644 --- a/dom/webidl/PushMessageData.webidl +++ b/dom/webidl/PushMessageData.webidl @@ -7,7 +7,7 @@ * https://w3c.github.io/push-api/ */ -[Func="nsContentUtils::PushEnabled", +[Func="mozilla::dom::DOMPreferences::PushEnabled", Exposed=ServiceWorker] interface PushMessageData { diff --git a/dom/webidl/PushSubscription.webidl b/dom/webidl/PushSubscription.webidl index eab576d3cec4..22c2b811f459 100644 --- a/dom/webidl/PushSubscription.webidl +++ b/dom/webidl/PushSubscription.webidl @@ -36,7 +36,7 @@ dictionary PushSubscriptionInit BufferSource? appServerKey; }; -[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled", +[Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled", ChromeConstructor(PushSubscriptionInit initDict)] interface PushSubscription { diff --git a/dom/webidl/PushSubscriptionOptions.webidl b/dom/webidl/PushSubscriptionOptions.webidl index 569a1ddae361..f5a10a7a60db 100644 --- a/dom/webidl/PushSubscriptionOptions.webidl +++ b/dom/webidl/PushSubscriptionOptions.webidl @@ -7,7 +7,7 @@ * https://w3c.github.io/push-api/ */ -[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled"] +[Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled"] interface PushSubscriptionOptions { [SameObject, Throws] diff --git a/dom/webidl/ServiceWorkerRegistration.webidl b/dom/webidl/ServiceWorkerRegistration.webidl index 8bfecb0b2c48..932ee5dc9509 100644 --- a/dom/webidl/ServiceWorkerRegistration.webidl +++ b/dom/webidl/ServiceWorkerRegistration.webidl @@ -38,7 +38,7 @@ enum ServiceWorkerUpdateViaCache { // https://w3c.github.io/push-api/ partial interface ServiceWorkerRegistration { - [Throws, Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled"] + [Throws, Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled"] readonly attribute PushManager pushManager; }; diff --git a/dom/workers/ServiceWorkerRegistration.h b/dom/workers/ServiceWorkerRegistration.h index 20dfd8b771f1..955b9b72c7d4 100644 --- a/dom/workers/ServiceWorkerRegistration.h +++ b/dom/workers/ServiceWorkerRegistration.h @@ -8,11 +8,11 @@ #define mozilla_dom_ServiceWorkerRegistration_h #include "mozilla/DOMEventTargetHelper.h" +#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/ServiceWorkerBinding.h" #include "mozilla/dom/ServiceWorkerCommon.h" #include "mozilla/dom/ServiceWorkerRegistrationBinding.h" #include "mozilla/dom/workers/bindings/WorkerHolder.h" -#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled // Support for Notification API extension. #include "mozilla/dom/NotificationBinding.h" diff --git a/dom/workers/WorkerPrefs.h b/dom/workers/WorkerPrefs.h index 7b87e157b556..be9bcc173ff7 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.push.enabled", PushEnabled, PUSH_ENABLED) WORKER_SIMPLE_PREF("dom.streams.enabled", StreamsEnabled, STREAMS_ENABLED) WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED) WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)