Bug 1419771 - Introduce DOMPreferences, a thread-safe access to preferences for DOM - part 13 - Push enabled, r=asuth

This commit is contained in:
Andrea Marchesini 2017-11-30 18:16:45 +01:00
Родитель 02c4d1fc9d
Коммит dd319f861b
15 изменённых файлов: 16 добавлений и 32 удалений

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

@ -47,6 +47,7 @@ PREF(ServiceWorkersTestingEnabled, "dom.serviceWorkers.testing.enabled")
PREF(OpenWindowEnabled, "dom.serviceWorkers.openWindow.enabled")
PREF(StorageManagerEnabled, "dom.storageManager.enabled")
PREF(PromiseRejectionEventsEnabled, "dom.promise_rejection_events.enabled")
PREF(PushEnabled, "dom.push.enabled")
#undef PREF
@ -65,6 +66,7 @@ PREF_WEBIDL(ServiceWorkersEnabled)
PREF_WEBIDL(OpenWindowEnabled)
PREF_WEBIDL(StorageManagerEnabled)
PREF_WEBIDL(PromiseRejectionEventsEnabled)
PREF_WEBIDL(PushEnabled)
#undef PREF_WEBIDL

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

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

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

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

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

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

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

@ -32,9 +32,9 @@
#include "mozilla/ErrorResult.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/TypedArray.h"
#include "mozilla/dom/DOMPreferences.h"
#include "nsCOMPtr.h"
#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled
#include "mozilla/RefPtr.h"
class nsIGlobalObject;

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

@ -10,13 +10,13 @@
#include "jsapi.h"
#include "nsCOMPtr.h"
#include "nsWrapperCache.h"
#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled
#include "mozilla/AlreadyAddRefed.h"
#include "mozilla/ErrorResult.h"
#include "mozilla/RefPtr.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/dom/PushSubscriptionBinding.h"
#include "mozilla/dom/PushSubscriptionOptionsBinding.h"
#include "mozilla/dom/TypedArray.h"

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

@ -8,9 +8,9 @@
#define mozilla_dom_PushSubscriptionOptions_h
#include "nsCycleCollectionParticipant.h"
#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled
#include "nsTArray.h"
#include "nsWrapperCache.h"
#include "mozilla/dom/DOMPreferences.h"
class nsIGlobalObject;

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

@ -8,7 +8,7 @@
*/
[Constructor(DOMString type, optional PushEventInit eventInitDict),
Func="nsContentUtils::PushEnabled",
Func="mozilla::dom::DOMPreferences::PushEnabled",
Exposed=ServiceWorker]
interface PushEvent : ExtendableEvent {
readonly attribute PushMessageData? data;

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

@ -22,7 +22,7 @@ interface PushManagerImpl {
Promise<PushPermissionState> permissionState(optional PushSubscriptionOptionsInit options);
};
[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled",
[Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled",
ChromeConstructor(DOMString scope)]
interface PushManager {
[Throws, UseCounter]

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

@ -7,7 +7,7 @@
* https://w3c.github.io/push-api/
*/
[Func="nsContentUtils::PushEnabled",
[Func="mozilla::dom::DOMPreferences::PushEnabled",
Exposed=ServiceWorker]
interface PushMessageData
{

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

@ -36,7 +36,7 @@ dictionary PushSubscriptionInit
BufferSource? appServerKey;
};
[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled",
[Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled",
ChromeConstructor(PushSubscriptionInit initDict)]
interface PushSubscription
{

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

@ -7,7 +7,7 @@
* https://w3c.github.io/push-api/
*/
[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled"]
[Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled"]
interface PushSubscriptionOptions
{
[SameObject, Throws]

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

@ -38,7 +38,7 @@ enum ServiceWorkerUpdateViaCache {
// https://w3c.github.io/push-api/
partial interface ServiceWorkerRegistration {
[Throws, Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled"]
[Throws, Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled"]
readonly attribute PushManager pushManager;
};

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

@ -8,11 +8,11 @@
#define mozilla_dom_ServiceWorkerRegistration_h
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/dom/ServiceWorkerBinding.h"
#include "mozilla/dom/ServiceWorkerCommon.h"
#include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
#include "mozilla/dom/workers/bindings/WorkerHolder.h"
#include "nsContentUtils.h" // Required for nsContentUtils::PushEnabled
// Support for Notification API extension.
#include "mozilla/dom/NotificationBinding.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.push.enabled", PushEnabled, PUSH_ENABLED)
WORKER_SIMPLE_PREF("dom.streams.enabled", StreamsEnabled, STREAMS_ENABLED)
WORKER_SIMPLE_PREF("dom.requestcontext.enabled", RequestContextEnabled, REQUESTCONTEXT_ENABLED)
WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED)