diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index 77770413b05f..d57a03340f9a 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -928,6 +928,21 @@ NotificationTask::Run() return NS_OK; } +bool +Notification::RequireInteractionEnabled(JSContext* aCx, JSObject* aOjb) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.webnotifications.requireinteraction.enabled", false); + } + + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return false; + } + + return workerPrivate->DOMWorkerNotificationRIEnabled(); +} + // static bool Notification::PrefEnabled(JSContext* aCx, JSObject* aObj) @@ -1821,6 +1836,11 @@ Notification::ShowInternal() uniqueCookie.AppendInt(sCount++); bool inPrivateBrowsing = IsInPrivateBrowsing(); + bool requireInteraction = mRequireInteraction; + if (!Preferences::GetBool("dom.webnotifications.requireinteraction.enabled", false)) { + requireInteraction = false; + } + nsAutoString alertName; GetAlertName(alertName); nsCOMPtr alert = @@ -1835,7 +1855,7 @@ Notification::ShowInternal() mDataAsBase64, GetPrincipal(), inPrivateBrowsing, - mRequireInteraction); + requireInteraction); NS_ENSURE_SUCCESS_VOID(rv); if (isPersistent) { @@ -2702,7 +2722,7 @@ Notification::ShowPersistentNotification(JSContext* aCx, // which leads to uglier code. NotificationPermission permission = GetPermission(aGlobal, aRv); - // "If permission for notification’s origin is not "granted", reject promise with a TypeError exception, and terminate these substeps." + // "If permission for notification's origin is not "granted", reject promise with a TypeError exception, and terminate these substeps." if (NS_WARN_IF(aRv.Failed()) || permission == NotificationPermission::Denied) { ErrorResult result; result.ThrowTypeError(); diff --git a/dom/notification/Notification.h b/dom/notification/Notification.h index 604cf8dd3461..a2c4b5c6828b 100644 --- a/dom/notification/Notification.h +++ b/dom/notification/Notification.h @@ -155,6 +155,7 @@ public: NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(Notification, DOMEventTargetHelper) NS_DECL_NSIOBSERVER + static bool RequireInteractionEnabled(JSContext* aCx, JSObject* aObj); static bool PrefEnabled(JSContext* aCx, JSObject* aObj); // Returns if Notification.get() is allowed for the current global. static bool IsGetEnabled(JSContext* aCx, JSObject* aObj); diff --git a/dom/webidl/Notification.webidl b/dom/webidl/Notification.webidl index 9a203b1de2f3..7a55a52ae9f3 100644 --- a/dom/webidl/Notification.webidl +++ b/dom/webidl/Notification.webidl @@ -51,7 +51,7 @@ interface Notification : EventTarget { [Pure] readonly attribute DOMString? icon; - [Constant] + [Constant, Func="mozilla::dom::Notification::RequireInteractionEnabled"] readonly attribute boolean requireInteraction; [Constant] diff --git a/dom/workers/WorkerPrefs.h b/dom/workers/WorkerPrefs.h index 9dab06d90e50..05717c3b7118 100644 --- a/dom/workers/WorkerPrefs.h +++ b/dom/workers/WorkerPrefs.h @@ -30,6 +30,7 @@ WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CA 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.serviceWorkers.openWindow.enabled", OpenWindowEnabled, OPEN_WINDOW_ENABLED) diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index e4a2791f41da..84193d7e3351 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4690,6 +4690,11 @@ pref("notification.feature.enabled", false); // Web Notification pref("dom.webnotifications.enabled", true); pref("dom.webnotifications.serviceworker.enabled", true); +#ifdef NIGHTLY_BUILD +pref("dom.webnotifications.requireinteraction.enabled", true); +#else +pref("dom.webnotifications.requireinteraction.enabled", false); +#endif // Alert animation effect, name is disableSlidingEffect for backwards-compat. pref("alerts.disableSlidingEffect", false);