mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 1419771 - Introduce DOMPrefs, a thread-safe access to preferences for DOM - part 8 - ServiceWorkers enabled, r=asuth
This commit is contained in:
parent
19b6228ddd
commit
a45ddd5050
@ -41,6 +41,7 @@ PREF(PerformanceLoggingEnabled, "dom.performance.enable_user_timing_logging")
|
||||
PREF(NotificationEnabled, "dom.webnotifications.enabled")
|
||||
PREF(NotificationEnabledInServiceWorkers, "dom.webnotifications.serviceworker.enabled")
|
||||
PREF(NotificationRIEnabled, "dom.webnotifications.requireinteraction.enabled")
|
||||
PREF(ServiceWorkersEnabled, "dom.serviceWorkers.enabled")
|
||||
|
||||
#undef PREF
|
||||
|
||||
@ -55,6 +56,7 @@ PREF_WEBIDL(ImageBitmapExtensionsEnabled)
|
||||
PREF_WEBIDL(DOMCachesEnabled)
|
||||
PREF_WEBIDL(NotificationEnabledInServiceWorkers)
|
||||
PREF_WEBIDL(NotificationRIEnabled)
|
||||
PREF_WEBIDL(ServiceWorkersEnabled)
|
||||
|
||||
#undef PREF_WEBIDL
|
||||
|
||||
|
@ -44,6 +44,10 @@ public:
|
||||
// set.
|
||||
static bool NotificationRIEnabled();
|
||||
static bool NotificationRIEnabled(JSContext* aCx, JSObject* aObj);
|
||||
|
||||
// Returns true if the dom.serviceWorkers.enabled pref is set.
|
||||
static bool ServiceWorkersEnabled();
|
||||
static bool ServiceWorkersEnabled(JSContext* aCx, JSObject* aObj);
|
||||
};
|
||||
|
||||
} // dom namespace
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "mozilla/dom/PTabContext.h"
|
||||
#include "mozilla/dom/TabParent.h"
|
||||
#include "mozilla/dom/TabChild.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
@ -246,7 +247,7 @@ MaybeInvalidTabContext::MaybeInvalidTabContext(const IPCTabContext& aParams)
|
||||
// It is meant as a temporary solution until service workers can
|
||||
// provide a TabChild equivalent. Don't allow this on b2g since
|
||||
// it might be used to escalate privileges.
|
||||
if (!Preferences::GetBool("dom.serviceWorkers.enabled", false)) {
|
||||
if (!DOMPrefs::ServiceWorkersEnabled()) {
|
||||
mInvalidReason = "ServiceWorkers should be enabled.";
|
||||
return;
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
* https://notifications.spec.whatwg.org/
|
||||
*/
|
||||
|
||||
[Func="mozilla::dom::ServiceWorkerRegistration::Visible",
|
||||
[Func="mozilla::dom::DOMPrefs::ServiceWorkersEnabled",
|
||||
Exposed=(Window,Worker)]
|
||||
interface ServiceWorkerRegistration : EventTarget {
|
||||
[Unforgeable] readonly attribute ServiceWorker? installing;
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "ServiceWorkerPrivate.h"
|
||||
#include "WorkerPrivate.h"
|
||||
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/ClientIPCTypes.h"
|
||||
#include "mozilla/dom/ClientState.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
@ -33,7 +33,7 @@ bool
|
||||
ServiceWorkerVisible(JSContext* aCx, JSObject* aObj)
|
||||
{
|
||||
if (NS_IsMainThread()) {
|
||||
return Preferences::GetBool("dom.serviceWorkers.enabled", false);
|
||||
return DOMPrefs::ServiceWorkersEnabled();
|
||||
}
|
||||
|
||||
return IS_INSTANCE_OF(ServiceWorkerGlobalScope, aObj);
|
||||
|
@ -12,12 +12,12 @@
|
||||
#include "nsIURL.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Services.h"
|
||||
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/Navigator.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/ServiceWorkerContainerBinding.h"
|
||||
@ -53,7 +53,7 @@ ServiceWorkerContainer::IsEnabled(JSContext* aCx, JSObject* aGlobal)
|
||||
return false;
|
||||
}
|
||||
|
||||
return Preferences::GetBool("dom.serviceWorkers.enabled", false);
|
||||
return DOMPrefs::ServiceWorkersEnabled();
|
||||
}
|
||||
|
||||
ServiceWorkerContainer::ServiceWorkerContainer(nsPIDOMWindowInner* aWindow)
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include "ServiceWorkerRegistration.h"
|
||||
|
||||
#include "ipc/ErrorIPCUtils.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/Notification.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/PromiseWindowProxy.h"
|
||||
@ -14,7 +15,6 @@
|
||||
#include "mozilla/dom/PushManagerBinding.h"
|
||||
#include "mozilla/dom/PushManager.h"
|
||||
#include "mozilla/dom/ServiceWorkerRegistrationBinding.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/Unused.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
@ -38,22 +38,6 @@ using namespace mozilla::dom::workers;
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
/* static */ bool
|
||||
ServiceWorkerRegistration::Visible(JSContext* aCx, JSObject* aObj)
|
||||
{
|
||||
if (NS_IsMainThread()) {
|
||||
return Preferences::GetBool("dom.serviceWorkers.enabled", false);
|
||||
}
|
||||
|
||||
// Otherwise check the pref via the work private helper
|
||||
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||
if (!workerPrivate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return workerPrivate->ServiceWorkersEnabled();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////
|
||||
// Main Thread implementation
|
||||
|
||||
|
@ -61,9 +61,6 @@ public:
|
||||
|
||||
IMPL_EVENT_HANDLER(updatefound)
|
||||
|
||||
static bool
|
||||
Visible(JSContext* aCx, JSObject* aObj);
|
||||
|
||||
static already_AddRefed<ServiceWorkerRegistration>
|
||||
CreateForMainThread(nsPIDOMWindowInner* aWindow,
|
||||
const nsAString& aScope);
|
||||
|
@ -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.serviceWorkers.enabled", ServiceWorkersEnabled, SERVICEWORKERS_ENABLED)
|
||||
WORKER_SIMPLE_PREF("dom.serviceWorkers.testing.enabled", ServiceWorkersTestingEnabled, SERVICEWORKERS_TESTING_ENABLED)
|
||||
WORKER_SIMPLE_PREF("dom.storageManager.enabled", StorageManagerEnabled, STORAGEMANAGER_ENABLED)
|
||||
WORKER_SIMPLE_PREF("dom.promise_rejection_events.enabled", PromiseRejectionEventsEnabled, PROMISE_REJECTION_EVENTS_ENABLED)
|
||||
|
Loading…
Reference in New Issue
Block a user