Bug 1419771 - Introduce DOMPrefs, a thread-safe access to preferences for DOM - part 11 - Promise Rejection Event enabled, r=asuth

This commit is contained in:
Andrea Marchesini 2018-01-08 14:05:04 +01:00
parent 01fd1fc62e
commit c05772d855
6 changed files with 7 additions and 23 deletions

View File

@ -44,6 +44,7 @@ PREF(NotificationRIEnabled, "dom.webnotifications.requireinteraction.enabled")
PREF(ServiceWorkersEnabled, "dom.serviceWorkers.enabled")
PREF(ServiceWorkersTestingEnabled, "dom.serviceWorkers.testing.enabled")
PREF(StorageManagerEnabled, "dom.storageManager.enabled")
PREF(PromiseRejectionEventsEnabled, "dom.promise_rejection_events.enabled")
#undef PREF
@ -60,6 +61,7 @@ PREF_WEBIDL(NotificationEnabledInServiceWorkers)
PREF_WEBIDL(NotificationRIEnabled)
PREF_WEBIDL(ServiceWorkersEnabled)
PREF_WEBIDL(StorageManagerEnabled)
PREF_WEBIDL(PromiseRejectionEventsEnabled)
#undef PREF_WEBIDL

View File

@ -55,6 +55,10 @@ public:
// Returns true if the dom.storageManager.enabled pref is set.
static bool StorageManagerEnabled();
static bool StorageManagerEnabled(JSContext* aCx, JSObject* aObj);
// Returns true if the dom.promise_rejection_events.enabled pref is set.
static bool PromiseRejectionEventsEnabled();
static bool PromiseRejectionEventsEnabled(JSContext* aCx, JSObject* aObj);
};
} // dom namespace

View File

@ -8885,25 +8885,6 @@ nsContentUtils::GetReferrerPolicyFromHeader(const nsAString& aHeader)
return referrerPolicy;
}
// static
bool
nsContentUtils::PromiseRejectionEventsEnabled(JSContext* aCx, JSObject* aObj)
{
if (NS_IsMainThread()) {
return Preferences::GetBool("dom.promise_rejection_events.enabled", false);
}
using namespace workers;
// Otherwise, check the pref via the WorkerPrivate
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
if (!workerPrivate) {
return false;
}
return workerPrivate->PromiseRejectionEventsEnabled();
}
// static
bool
nsContentUtils::PushEnabled(JSContext* aCx, JSObject* aObj)

View File

@ -2911,8 +2911,6 @@ public:
*/
static mozilla::net::ReferrerPolicy GetReferrerPolicyFromHeader(const nsAString& aHeader);
static bool PromiseRejectionEventsEnabled(JSContext* aCx, JSObject* aObj);
static bool PushEnabled(JSContext* aCx, JSObject* aObj);
static bool StreamsEnabled(JSContext* aCx, JSObject* aObj);

View File

@ -6,7 +6,7 @@
[Constructor(DOMString type, PromiseRejectionEventInit eventInitDict),
Exposed=(Window,Worker),
Func="nsContentUtils::PromiseRejectionEventsEnabled"]
Func="mozilla::dom::DOMPrefs::PromiseRejectionEventsEnabled"]
interface PromiseRejectionEvent : Event
{
[BinaryName="rejectedPromise"]

View File

@ -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.promise_rejection_events.enabled", PromiseRejectionEventsEnabled, PROMISE_REJECTION_EVENTS_ENABLED)
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)