diff --git a/dom/base/DOMPrefs.cpp b/dom/base/DOMPrefs.cpp index fcedc5790c61..fb590fa482e8 100644 --- a/dom/base/DOMPrefs.cpp +++ b/dom/base/DOMPrefs.cpp @@ -41,6 +41,7 @@ PREF(PerformanceLoggingEnabled, "dom.performance.enable_user_timing_logging") PREF(NotificationEnabled, "dom.webnotifications.enabled") PREF(NotificationEnabledInServiceWorkers, "dom.webnotifications.serviceworker.enabled") PREF(NotificationRIEnabled, "dom.webnotifications.requireinteraction.enabled") +PREF(ServiceWorkersEnabled, "dom.serviceWorkers.enabled") #undef PREF @@ -55,6 +56,7 @@ PREF_WEBIDL(ImageBitmapExtensionsEnabled) PREF_WEBIDL(DOMCachesEnabled) PREF_WEBIDL(NotificationEnabledInServiceWorkers) PREF_WEBIDL(NotificationRIEnabled) +PREF_WEBIDL(ServiceWorkersEnabled) #undef PREF_WEBIDL diff --git a/dom/base/DOMPrefs.h b/dom/base/DOMPrefs.h index 2ea348c4edbc..406da722a5d4 100644 --- a/dom/base/DOMPrefs.h +++ b/dom/base/DOMPrefs.h @@ -44,6 +44,10 @@ public: // set. static bool NotificationRIEnabled(); static bool NotificationRIEnabled(JSContext* aCx, JSObject* aObj); + + // Returns true if the dom.serviceWorkers.enabled pref is set. + static bool ServiceWorkersEnabled(); + static bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aObj); }; } // dom namespace diff --git a/dom/ipc/TabContext.cpp b/dom/ipc/TabContext.cpp index 8a6d462ab6ea..43724baa1b65 100644 --- a/dom/ipc/TabContext.cpp +++ b/dom/ipc/TabContext.cpp @@ -8,6 +8,7 @@ #include "mozilla/dom/PTabContext.h" #include "mozilla/dom/TabParent.h" #include "mozilla/dom/TabChild.h" +#include "mozilla/dom/DOMPrefs.h" #include "nsIScriptSecurityManager.h" #include "nsServiceManagerUtils.h" @@ -246,7 +247,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams) // It is meant as a temporary solution until service workers can // provide a TabChild equivalent. Don't allow this on b2g since // it might be used to escalate privileges. - if (!Preferences::GetBool("dom.serviceWorkers.enabled", false)) { + if (!DOMPrefs::ServiceWorkersEnabled()) { mInvalidReason = "ServiceWorkers should be enabled."; return; } diff --git a/dom/webidl/ServiceWorkerRegistration.webidl b/dom/webidl/ServiceWorkerRegistration.webidl index c5bfcf28d166..6794e2da8401 100644 --- a/dom/webidl/ServiceWorkerRegistration.webidl +++ b/dom/webidl/ServiceWorkerRegistration.webidl @@ -9,7 +9,7 @@ * https://notifications.spec.whatwg.org/ */ -[Func="mozilla::dom::ServiceWorkerRegistration::Visible", +[Func="mozilla::dom::DOMPrefs::ServiceWorkersEnabled", Exposed=(Window,Worker)] interface ServiceWorkerRegistration : EventTarget { [Unforgeable] readonly attribute ServiceWorker? installing; diff --git a/dom/workers/ServiceWorker.cpp b/dom/workers/ServiceWorker.cpp index 793de9cf8362..8ebbb614d0c3 100644 --- a/dom/workers/ServiceWorker.cpp +++ b/dom/workers/ServiceWorker.cpp @@ -12,7 +12,7 @@ #include "ServiceWorkerPrivate.h" #include "WorkerPrivate.h" -#include "mozilla/Preferences.h" +#include "mozilla/dom/DOMPrefs.h" #include "mozilla/dom/ClientIPCTypes.h" #include "mozilla/dom/ClientState.h" #include "mozilla/dom/Promise.h" @@ -33,7 +33,7 @@ bool ServiceWorkerVisible(JSContext* aCx, JSObject* aObj) { if (NS_IsMainThread()) { - return Preferences::GetBool("dom.serviceWorkers.enabled", false); + return DOMPrefs::ServiceWorkersEnabled(); } return IS_INSTANCE_OF(ServiceWorkerGlobalScope, aObj); diff --git a/dom/workers/ServiceWorkerContainer.cpp b/dom/workers/ServiceWorkerContainer.cpp index 82b6623d2a9d..eaac4691ddf3 100644 --- a/dom/workers/ServiceWorkerContainer.cpp +++ b/dom/workers/ServiceWorkerContainer.cpp @@ -12,12 +12,12 @@ #include "nsIURL.h" #include "nsNetUtil.h" #include "nsPIDOMWindow.h" -#include "mozilla/Preferences.h" #include "mozilla/Services.h" #include "nsCycleCollectionParticipant.h" #include "nsServiceManagerUtils.h" +#include "mozilla/dom/DOMPrefs.h" #include "mozilla/dom/Navigator.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/ServiceWorkerContainerBinding.h" @@ -53,7 +53,7 @@ ServiceWorkerContainer::IsEnabled(JSContext* aCx, JSObject* aGlobal) return false; } - return Preferences::GetBool("dom.serviceWorkers.enabled", false); + return DOMPrefs::ServiceWorkersEnabled(); } ServiceWorkerContainer::ServiceWorkerContainer(nsPIDOMWindowInner* aWindow) diff --git a/dom/workers/ServiceWorkerRegistration.cpp b/dom/workers/ServiceWorkerRegistration.cpp index 2905f262c1bc..26848eb76093 100644 --- a/dom/workers/ServiceWorkerRegistration.cpp +++ b/dom/workers/ServiceWorkerRegistration.cpp @@ -7,6 +7,7 @@ #include "ServiceWorkerRegistration.h" #include "ipc/ErrorIPCUtils.h" +#include "mozilla/dom/DOMPrefs.h" #include "mozilla/dom/Notification.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseWindowProxy.h" @@ -14,7 +15,6 @@ #include "mozilla/dom/PushManagerBinding.h" #include "mozilla/dom/PushManager.h" #include "mozilla/dom/ServiceWorkerRegistrationBinding.h" -#include "mozilla/Preferences.h" #include "mozilla/Services.h" #include "mozilla/Unused.h" #include "nsCycleCollectionParticipant.h" @@ -38,22 +38,6 @@ using namespace mozilla::dom::workers; namespace mozilla { namespace dom { -/* static */ bool -ServiceWorkerRegistration::Visible(JSContext* aCx, JSObject* aObj) -{ - if (NS_IsMainThread()) { - return Preferences::GetBool("dom.serviceWorkers.enabled", false); - } - - // Otherwise check the pref via the work private helper - WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); - if (!workerPrivate) { - return false; - } - - return workerPrivate->ServiceWorkersEnabled(); -} - //////////////////////////////////////////////////// // Main Thread implementation diff --git a/dom/workers/ServiceWorkerRegistration.h b/dom/workers/ServiceWorkerRegistration.h index 3728fdfe9657..20dfd8b771f1 100644 --- a/dom/workers/ServiceWorkerRegistration.h +++ b/dom/workers/ServiceWorkerRegistration.h @@ -61,9 +61,6 @@ public: IMPL_EVENT_HANDLER(updatefound) - static bool - Visible(JSContext* aCx, JSObject* aObj); - static already_AddRefed CreateForMainThread(nsPIDOMWindowInner* aWindow, const nsAString& aScope); diff --git a/dom/workers/WorkerPrefs.h b/dom/workers/WorkerPrefs.h index 4c35a20445e5..f25c94d22d6f 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.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) WORKER_SIMPLE_PREF("dom.promise_rejection_events.enabled", PromiseRejectionEventsEnabled, PROMISE_REJECTION_EVENTS_ENABLED)