Bug 1203324 - disable notifications on serviceworkers. r=ehsan,wchen

Per the product discussion, the Notification API should be disabled in
ServiceWorker in release builds for 42 since the UX isn't great [1].

The aim is to release in 44.

Apologies for the code duplication for pref checking in Notification and
ServiceWorkerRegistration. There isn't a easy way to get
ServiceWorkerRegistration's generated binding to include Notification.h without
having an attribute/method that uses Notification.

[1]: https://mana.mozilla.org/wiki/x/TgAJAw

--HG--
extra : commitid : 5dtc2E63kuM
extra : rebase_source : 4265dcd154462aa4f3b915e9e898fe7b82bf9afc
This commit is contained in:
Nikhil Marathe 2015-09-15 12:58:32 -07:00
Родитель b48b5d99b8
Коммит 6d235278db
12 изменённых файлов: 51 добавлений и 4 удалений

Просмотреть файл

@ -710,6 +710,10 @@ Notification::PrefEnabled(JSContext* aCx, JSObject* aObj)
return false;
}
if (workerPrivate->IsServiceWorker()) {
return workerPrivate->DOMServiceWorkerNotificationEnabled();
}
return workerPrivate->DOMWorkerNotificationEnabled();
}

Просмотреть файл

@ -94,8 +94,8 @@ enum NotificationDirection {
};
partial interface ServiceWorkerRegistration {
[Throws]
[Throws, Func="mozilla::dom::ServiceWorkerNotificationAPIVisible"]
Promise<void> showNotification(DOMString title, optional NotificationOptions options);
[Throws]
[Throws, Func="mozilla::dom::ServiceWorkerNotificationAPIVisible"]
Promise<sequence<Notification>> getNotifications(optional GetNotificationOptions filter);
};

Просмотреть файл

@ -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<void *>(WORKERPREF_DOM_WORKERNOTIFICATION))) ||
NS_FAILED(Preferences::RegisterCallbackAndCall(
WorkerPrefChanged,
PREF_DOM_SERVICEWORKERNOTIFICATION_ENABLED,
reinterpret_cast<void *>(WORKERPREF_DOM_SERVICEWORKERNOTIFICATION))) ||
NS_FAILED(Preferences::RegisterCallbackAndCall(
WorkerPrefChanged,
PREF_SERVICEWORKERS_ENABLED,
@ -2196,6 +2201,10 @@ RuntimeService::Cleanup()
WorkerPrefChanged,
PREF_DOM_WORKERNOTIFICATION_ENABLED,
reinterpret_cast<void *>(WORKERPREF_DOM_WORKERNOTIFICATION))) ||
NS_FAILED(Preferences::UnregisterCallback(
WorkerPrefChanged,
PREF_DOM_SERVICEWORKERNOTIFICATION_ENABLED,
reinterpret_cast<void *>(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:

Просмотреть файл

@ -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)

Просмотреть файл

@ -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".

Просмотреть файл

@ -1277,6 +1277,13 @@ public:
return mPreferences[WORKERPREF_DOM_WORKERNOTIFICATION];
}
bool
DOMServiceWorkerNotificationEnabled() const
{
AssertIsOnWorkerThread();
return mPreferences[WORKERPREF_DOM_SERVICEWORKERNOTIFICATION];
}
bool
DOMCachesTestingEnabled() const
{

Просмотреть файл

@ -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

Просмотреть файл

@ -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()

Просмотреть файл

@ -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);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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!

Просмотреть файл

@ -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);