diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index 23cd43a96056..493ba14e46e1 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -710,6 +710,10 @@ Notification::PrefEnabled(JSContext* aCx, JSObject* aObj) return false; } + if (workerPrivate->IsServiceWorker()) { + return workerPrivate->DOMServiceWorkerNotificationEnabled(); + } + return workerPrivate->DOMWorkerNotificationEnabled(); } diff --git a/dom/webidl/Notification.webidl b/dom/webidl/Notification.webidl index 2f7cd5f62b22..4bca9812cec5 100644 --- a/dom/webidl/Notification.webidl +++ b/dom/webidl/Notification.webidl @@ -94,8 +94,8 @@ enum NotificationDirection { }; partial interface ServiceWorkerRegistration { - [Throws] + [Throws, Func="mozilla::dom::ServiceWorkerNotificationAPIVisible"] Promise showNotification(DOMString title, optional NotificationOptions options); - [Throws] + [Throws, Func="mozilla::dom::ServiceWorkerNotificationAPIVisible"] Promise> getNotifications(optional GetNotificationOptions filter); }; diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index c74dbceb0eee..f9200fec2987 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -161,6 +161,7 @@ static_assert(MAX_WORKERS_PER_DOMAIN >= 1, #define PREF_DOM_CACHES_TESTING_ENABLED "dom.caches.testing.enabled" #define PREF_WORKERS_PERFORMANCE_LOGGING_ENABLED "dom.performance.enable_user_timing_logging" #define PREF_DOM_WORKERNOTIFICATION_ENABLED "dom.webnotifications.enabled" +#define PREF_DOM_SERVICEWORKERNOTIFICATION_ENABLED "dom.webnotifications.serviceworker.enabled" #define PREF_WORKERS_LATEST_JS_VERSION "dom.workers.latestJSVersion" #define PREF_INTL_ACCEPT_LANGUAGES "intl.accept_languages" #define PREF_SERVICEWORKERS_ENABLED "dom.serviceWorkers.enabled" @@ -1937,6 +1938,10 @@ RuntimeService::Init() WorkerPrefChanged, PREF_DOM_WORKERNOTIFICATION_ENABLED, reinterpret_cast(WORKERPREF_DOM_WORKERNOTIFICATION))) || + NS_FAILED(Preferences::RegisterCallbackAndCall( + WorkerPrefChanged, + PREF_DOM_SERVICEWORKERNOTIFICATION_ENABLED, + reinterpret_cast(WORKERPREF_DOM_SERVICEWORKERNOTIFICATION))) || NS_FAILED(Preferences::RegisterCallbackAndCall( WorkerPrefChanged, PREF_SERVICEWORKERS_ENABLED, @@ -2196,6 +2201,10 @@ RuntimeService::Cleanup() WorkerPrefChanged, PREF_DOM_WORKERNOTIFICATION_ENABLED, reinterpret_cast(WORKERPREF_DOM_WORKERNOTIFICATION))) || + NS_FAILED(Preferences::UnregisterCallback( + WorkerPrefChanged, + PREF_DOM_SERVICEWORKERNOTIFICATION_ENABLED, + reinterpret_cast(WORKERPREF_DOM_SERVICEWORKERNOTIFICATION))) || NS_FAILED(Preferences::UnregisterCallback( WorkerPrefChanged, PREF_PUSH_ENABLED, @@ -2754,6 +2763,7 @@ RuntimeService::WorkerPrefChanged(const char* aPrefName, void* aClosure) case WORKERPREF_DOM_CACHES: case WORKERPREF_DOM_CACHES_TESTING: case WORKERPREF_DOM_WORKERNOTIFICATION: + case WORKERPREF_DOM_SERVICEWORKERNOTIFICATION: case WORKERPREF_PERFORMANCE_LOGGING_ENABLED: #ifdef DUMP_CONTROLLED_BY_PREF case WORKERPREF_DUMP: diff --git a/dom/workers/ServiceWorkerRegistration.cpp b/dom/workers/ServiceWorkerRegistration.cpp index 87f7b28d6c0a..5e7d573b37d9 100644 --- a/dom/workers/ServiceWorkerRegistration.cpp +++ b/dom/workers/ServiceWorkerRegistration.cpp @@ -53,6 +53,22 @@ ServiceWorkerRegistrationVisible(JSContext* aCx, JSObject* aObj) return workerPrivate->ServiceWorkersEnabled(); } +bool +ServiceWorkerNotificationAPIVisible(JSContext* aCx, JSObject* aObj) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.webnotifications.serviceworker.enabled", false); + } + + // Otherwise check the pref via the work private helper + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return false; + } + + return workerPrivate->DOMServiceWorkerNotificationEnabled(); +} + NS_IMPL_ADDREF_INHERITED(ServiceWorkerRegistrationBase, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(ServiceWorkerRegistrationBase, DOMEventTargetHelper) diff --git a/dom/workers/ServiceWorkerRegistration.h b/dom/workers/ServiceWorkerRegistration.h index a986ca58de26..f20686a36c2a 100644 --- a/dom/workers/ServiceWorkerRegistration.h +++ b/dom/workers/ServiceWorkerRegistration.h @@ -33,6 +33,9 @@ class WorkerPrivate; bool ServiceWorkerRegistrationVisible(JSContext* aCx, JSObject* aObj); +bool +ServiceWorkerNotificationAPIVisible(JSContext* aCx, JSObject* aObj); + // This class exists solely so that we can satisfy some WebIDL Func= attribute // constraints. Func= converts the function name to a header file to include, in // this case "ServiceWorkerRegistration.h". diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index c54ad9127508..39bab26ee3bd 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -1277,6 +1277,13 @@ public: return mPreferences[WORKERPREF_DOM_WORKERNOTIFICATION]; } + bool + DOMServiceWorkerNotificationEnabled() const + { + AssertIsOnWorkerThread(); + return mPreferences[WORKERPREF_DOM_SERVICEWORKERNOTIFICATION]; + } + bool DOMCachesTestingEnabled() const { diff --git a/dom/workers/Workers.h b/dom/workers/Workers.h index 45d8324d4735..7ac053c3a258 100644 --- a/dom/workers/Workers.h +++ b/dom/workers/Workers.h @@ -202,6 +202,7 @@ enum WorkerPreference WORKERPREF_SERVICEWORKERS, // dom.serviceWorkers.enabled WORKERPREF_INTERCEPTION_ENABLED, // dom.serviceWorkers.interception.enabled WORKERPREF_DOM_WORKERNOTIFICATION, // dom.webnotifications.workers.enabled + WORKERPREF_DOM_SERVICEWORKERNOTIFICATION, // dom.webnotifications.serviceworker.enabled WORKERPREF_DOM_CACHES_TESTING, // dom.caches.testing.enabled WORKERPREF_SERVICEWORKERS_TESTING, // dom.serviceWorkers.testing.enabled WORKERPREF_INTERCEPTION_OPAQUE_ENABLED, // dom.serviceWorkers.interception.opaque.enabled diff --git a/dom/workers/test/serviceworkers/test_notification_get.html b/dom/workers/test/serviceworkers/test_notification_get.html index 00a1cfd5d42d..0a45240cff84 100644 --- a/dom/workers/test/serviceworkers/test_notification_get.html +++ b/dom/workers/test/serviceworkers/test_notification_get.html @@ -147,6 +147,7 @@ ["dom.serviceWorkers.enabled", true], ["dom.serviceWorkers.testing.enabled", true], ["dom.webnotifications.workers.enabled", true], + ["dom.webnotifications.serviceworker.enabled", true], ["notification.prompt.testing", true], ]}, function() { registerSW() diff --git a/dom/workers/test/serviceworkers/test_notificationclick.html b/dom/workers/test/serviceworkers/test_notificationclick.html index cb4322c05bfc..b55cec2b7dc5 100644 --- a/dom/workers/test/serviceworkers/test_notificationclick.html +++ b/dom/workers/test/serviceworkers/test_notificationclick.html @@ -49,6 +49,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=916893 ["dom.serviceWorkers.enabled", true], ["dom.serviceWorkers.testing.enabled", true], ["dom.webnotifications.workers.enabled", true], + ["dom.webnotifications.serviceworker.enabled", true], ['dom.serviceWorkers.interception.enabled', true], ["notification.prompt.testing", true], ]}, runTest); diff --git a/dom/workers/test/serviceworkers/test_notificationclick_focus.html b/dom/workers/test/serviceworkers/test_notificationclick_focus.html index 4460ae5da107..ed0d273a4aea 100644 --- a/dom/workers/test/serviceworkers/test_notificationclick_focus.html +++ b/dom/workers/test/serviceworkers/test_notificationclick_focus.html @@ -49,6 +49,7 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=916893 ["dom.serviceWorkers.enabled", true], ["dom.serviceWorkers.testing.enabled", true], ["dom.webnotifications.workers.enabled", true], + ["dom.webnotifications.serviceworker.enabled", true], ["notification.prompt.testing", true], ["dom.disable_open_click_delay", 1000], ]}, runTest); diff --git a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js index f9d7082b71fb..c0dbe9e299d8 100644 --- a/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js +++ b/dom/workers/test/serviceworkers/test_serviceworker_interfaces.js @@ -160,9 +160,9 @@ var interfaceNamesInGlobalScope = // IMPORTANT: Do not change this list without review from a DOM peer! "MessagePort", // IMPORTANT: Do not change this list without review from a DOM peer! - "Notification", + { name: "Notification", release: false }, // IMPORTANT: Do not change this list without review from a DOM peer! - "NotificationEvent", + { name: "NotificationEvent", release: false }, // IMPORTANT: Do not change this list without review from a DOM peer! "Performance", // IMPORTANT: Do not change this list without review from a DOM peer! diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 5ec1cbb088a4..764f8417db1b 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4380,6 +4380,9 @@ pref("notification.feature.enabled", false); // Web Notification pref("dom.webnotifications.enabled", true); +#if !defined(RELEASE_BUILD) +pref("dom.webnotifications.serviceworker.enabled", true); +#endif // Alert animation effect, name is disableSlidingEffect for backwards-compat. pref("alerts.disableSlidingEffect", false);