diff --git a/dom/base/DOMPreferences.cpp b/dom/base/DOMPreferences.cpp deleted file mode 100644 index 648631584373..000000000000 --- a/dom/base/DOMPreferences.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#include "DOMPreferences.h" -#include "mozilla/Atomics.h" -#include "mozilla/Preferences.h" - -namespace mozilla { -namespace dom { - -void -DOMPreferences::Initialize() -{ - MOZ_ASSERT(NS_IsMainThread()); - - // Let's cache all the values on the main-thread. -#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) - DOMPreferences::DumpEnabled(); -#endif - -#define PREF(name, pref) DOMPreferences::name(); -#include "DOMPreferencesInternal.h" -#undef PREF -} - -#define PREF(name, pref) \ - /* static */ bool \ - DOMPreferences::name() \ - { \ - static bool initialized = false; \ - static Atomic cachedValue; \ - if (!initialized) { \ - initialized = true; \ - Preferences::AddAtomicBoolVarCache(&cachedValue, \ - pref, false); \ - } \ - return cachedValue; \ - } - -#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) -PREF(DumpEnabled, "browser.dom.window.dump.enabled") -#else -/* static */ bool -DOMPreferences::DumpEnabled() -{ - return true; -} -#endif - -#include "DOMPreferencesInternal.h" -#undef PREF - -#define PREF_WEBIDL(name) \ - /* static */ bool \ - DOMPreferences::name(JSContext* aCx, JSObject* aObj) \ - { \ - return DOMPreferences::name(); \ - } - -PREF_WEBIDL(ImageBitmapExtensionsEnabled) -PREF_WEBIDL(DOMCachesEnabled) -PREF_WEBIDL(NotificationEnabledInServiceWorkers) -PREF_WEBIDL(NotificationRIEnabled) -PREF_WEBIDL(ServiceWorkersEnabled) -PREF_WEBIDL(StorageManagerEnabled) -PREF_WEBIDL(PromiseRejectionEventsEnabled) -PREF_WEBIDL(PushEnabled) -PREF_WEBIDL(StreamsEnabled) -PREF_WEBIDL(RequestContextEnabled) -PREF_WEBIDL(OffscreenCanvasEnabled) -PREF_WEBIDL(WebkitBlinkDirectoryPickerEnabled) -PREF_WEBIDL(NetworkInformationEnabled) -PREF_WEBIDL(FetchObserverEnabled) - -#undef PREF_WEBIDL - -} // dom namespace -} // mozilla namespace diff --git a/dom/base/DOMPreferences.h b/dom/base/DOMPreferences.h deleted file mode 100644 index 30989f0f2025..000000000000 --- a/dom/base/DOMPreferences.h +++ /dev/null @@ -1,104 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -#ifndef mozilla_dom_DOMPreferences_h -#define mozilla_dom_DOMPreferences_h - -namespace mozilla { -namespace dom { - -class DOMPreferences final -{ -public: - // This must be called on the main-thread. - static void Initialize(); - - // Returns true if the browser.dom.window.dump.enabled pref is set. - static bool DumpEnabled(); - - // Returns true if the canvas.imagebitmap_extensions.enabled pref is set. - static bool ImageBitmapExtensionsEnabled(); - static bool ImageBitmapExtensionsEnabled(JSContext* aCx, JSObject* aObj); - - // Returns true if the dom.caches.enabled pref is set. - static bool DOMCachesEnabled(); - static bool DOMCachesEnabled(JSContext* aCx, JSObject* aObj); - - // Returns true if the dom.caches.testing.enabled pref is set. - static bool DOMCachesTestingEnabled(); - - // Returns true if the dom.performance.enable_user_timing_logging pref is set. - static bool PerformanceLoggingEnabled(); - - // Returns true if the dom.webnotifications.enabled pref is set. - // Note that you should use NotificationEnabledInServiceWorkers if you need to - // enable Notification API for ServiceWorkers - static bool NotificationEnabled(); - - // Returns true if the dom.webnotifications.serviceworker.enabled pref is set. - static bool NotificationEnabledInServiceWorkers(); - static bool NotificationEnabledInServiceWorkers(JSContext* aCx, - JSObject* aObj); - - // Returns true if the dom.webnotifications.requireinteraction.enabled pref is - // 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); - - // Returns true if the dom.serviceWorkers.testing.enabled pref is set. - static bool ServiceWorkersTestingEnabled(); - - // 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); - - // Returns true if the dom.push.enabled pref is set. - static bool PushEnabled(); - static bool PushEnabled(JSContext* aCx, JSObject* aObj); - - // Returns true if the dom.streams.enabled pref is set. - static bool StreamsEnabled(); - static bool StreamsEnabled(JSContext* aCx, JSObject* aObj); - - // Returns true if the dom.requestcontext.enabled pref is set. - static bool RequestContextEnabled(); - static bool RequestContextEnabled(JSContext* aCx, JSObject* aObj); - - // Returns true if the gfx.offscreencanvas.enabled pref is set. - static bool OffscreenCanvasEnabled(); - static bool OffscreenCanvasEnabled(JSContext* aCx, JSObject* aObj); - - // Returns true if the dom.webkitBlink.dirPicker.enabled pref is set. - static bool WebkitBlinkDirectoryPickerEnabled(); - static bool WebkitBlinkDirectoryPickerEnabled(JSContext* aCx, JSObject* aObj); - - // Returns true if the dom.netinfo.enabled pref is set. - static bool NetworkInformationEnabled(); - static bool NetworkInformationEnabled(JSContext* aCx, JSObject* aObj); - - // Returns true if the dom.fetchObserver.enabled pref is set. - static bool FetchObserverEnabled(); - static bool FetchObserverEnabled(JSContext* aCx, JSObject* aObj); - - // Returns true if the privacy.resistFingerprinting pref is set. - static bool ResistFingerprintingEnabled(); - - // Returns true if the devtools.enabled pref is set. - static bool DevToolsEnabled(); -}; - -} // dom namespace -} // mozilla namespace - -#endif // mozilla_dom_DOMPreferences_h diff --git a/dom/base/DOMPreferencesInternal.h b/dom/base/DOMPreferencesInternal.h deleted file mode 100644 index 7adcf4a3c5c9..000000000000 --- a/dom/base/DOMPreferencesInternal.h +++ /dev/null @@ -1,26 +0,0 @@ -/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* vim: set ts=8 sts=2 et sw=2 tw=80: */ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ - -PREF(ImageBitmapExtensionsEnabled, "canvas.imagebitmap_extensions.enabled") -PREF(DOMCachesEnabled, "dom.caches.enabled") -PREF(DOMCachesTestingEnabled, "dom.caches.testing.enabled") -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") -PREF(ServiceWorkersTestingEnabled, "dom.serviceWorkers.testing.enabled") -PREF(StorageManagerEnabled, "dom.storageManager.enabled") -PREF(PromiseRejectionEventsEnabled, "dom.promise_rejection_events.enabled") -PREF(PushEnabled, "dom.push.enabled") -PREF(StreamsEnabled, "dom.streams.enabled") -PREF(RequestContextEnabled, "dom.requestcontext.enabled") -PREF(OffscreenCanvasEnabled, "gfx.offscreencanvas.enabled") -PREF(WebkitBlinkDirectoryPickerEnabled, "dom.webkitBlink.dirPicker.enabled") -PREF(NetworkInformationEnabled, "dom.netinfo.enabled") -PREF(FetchObserverEnabled, "dom.fetchObserver.enabled") -PREF(ResistFingerprintingEnabled, "privacy.resistFingerprinting") -PREF(DevToolsEnabled, "devtools.enabled") diff --git a/dom/base/FuzzingFunctions.h b/dom/base/FuzzingFunctions.h index 148793149e75..93aad43befb7 100644 --- a/dom/base/FuzzingFunctions.h +++ b/dom/base/FuzzingFunctions.h @@ -8,9 +8,6 @@ #define mozilla_dom_FuzzingFunctions namespace mozilla { - -class ErrorResult; - namespace dom { class GlobalObject; diff --git a/dom/base/IntlUtils.cpp b/dom/base/IntlUtils.cpp index eead340fb179..9fc21414fd58 100644 --- a/dom/base/IntlUtils.cpp +++ b/dom/base/IntlUtils.cpp @@ -10,10 +10,6 @@ #include "mozIMozIntl.h" #include "nsContentUtils.h" -#ifdef XP_WIN -#undef GetLocaleInfo -#endif - namespace mozilla { namespace dom { diff --git a/dom/base/IntlUtils.h b/dom/base/IntlUtils.h index 5fea7331573a..56408adf925e 100644 --- a/dom/base/IntlUtils.h +++ b/dom/base/IntlUtils.h @@ -10,10 +10,6 @@ #include "nsWrapperCache.h" #include "xpcprivate.h" -#ifdef XP_WIN -#undef GetLocaleInfo -#endif - class nsPIDOMWindowInner; namespace mozilla { diff --git a/dom/base/moz.build b/dom/base/moz.build index bb600592e95c..bb7feeacaade 100644 --- a/dom/base/moz.build +++ b/dom/base/moz.build @@ -171,7 +171,6 @@ EXPORTS.mozilla.dom += [ 'DOMMatrix.h', 'DOMParser.h', 'DOMPoint.h', - 'DOMPreferences.h', 'DOMQuad.h', 'DOMRect.h', 'DOMRequest.h', @@ -249,7 +248,6 @@ UNIFIED_SOURCES += [ 'DOMMatrix.cpp', 'DOMParser.cpp', 'DOMPoint.cpp', - 'DOMPreferences.cpp', 'DOMQuad.cpp', 'DOMRect.cpp', 'DOMRequest.cpp', diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp index 4226bf7fe0ae..c2a1a84aefc3 100644 --- a/dom/base/nsContentUtils.cpp +++ b/dom/base/nsContentUtils.cpp @@ -295,9 +295,11 @@ bool nsContentUtils::sIsFrameTimingPrefEnabled = false; bool nsContentUtils::sIsPerformanceTimingEnabled = false; bool nsContentUtils::sIsResourceTimingEnabled = false; bool nsContentUtils::sIsPerformanceNavigationTimingEnabled = false; +bool nsContentUtils::sIsUserTimingLoggingEnabled = false; bool nsContentUtils::sIsFormAutofillAutocompleteEnabled = false; bool nsContentUtils::sIsWebComponentsEnabled = false; bool nsContentUtils::sIsCustomElementsEnabled = false; +bool nsContentUtils::sDevToolsEnabled = false; bool nsContentUtils::sSendPerformanceTimingNotifications = false; bool nsContentUtils::sUseActivityCursor = false; bool nsContentUtils::sAnimationsAPICoreEnabled = false; @@ -335,6 +337,10 @@ nsIParser* nsContentUtils::sXMLFragmentParser = nullptr; nsIFragmentContentSink* nsContentUtils::sXMLFragmentSink = nullptr; bool nsContentUtils::sFragmentParsingActive = false; +#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) +bool nsContentUtils::sDOMWindowDumpEnabled; +#endif + bool nsContentUtils::sDoNotTrackEnabled = false; mozilla::LazyLogModule nsContentUtils::sDOMDumpLog("Dump"); @@ -652,6 +658,9 @@ nsContentUtils::Init() Preferences::AddBoolVarCache(&sIsPerformanceNavigationTimingEnabled, "dom.enable_performance_navigation_timing", true); + Preferences::AddBoolVarCache(&sIsUserTimingLoggingEnabled, + "dom.performance.enable_user_timing_logging", false); + Preferences::AddBoolVarCache(&sIsFrameTimingPrefEnabled, "dom.enable_frame_timing", false); @@ -664,6 +673,9 @@ nsContentUtils::Init() Preferences::AddBoolVarCache(&sIsCustomElementsEnabled, "dom.webcomponents.customelements.enabled", false); + Preferences::AddBoolVarCache(&sDevToolsEnabled, + "devtools.enabled"); + Preferences::AddIntVarCache(&sPrivacyMaxInnerWidth, "privacy.window.maxInnerWidth", 1000); @@ -687,6 +699,11 @@ nsContentUtils::Init() "network.cookie.cookieBehavior", nsICookieService::BEHAVIOR_ACCEPT); +#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) + Preferences::AddBoolVarCache(&sDOMWindowDumpEnabled, + "browser.dom.window.dump.enabled"); +#endif + Preferences::AddBoolVarCache(&sDoNotTrackEnabled, "privacy.donottrackheader.enabled", false); @@ -2374,7 +2391,17 @@ nsContentUtils::IsCallerChrome() bool nsContentUtils::ShouldResistFingerprinting() { - return DOMPreferences::ResistFingerprintingEnabled(); + if (NS_IsMainThread()) { + return nsRFPService::IsResistFingerprintingEnabled(); + } + + workers::WorkerPrivate* workerPrivate = workers::GetCurrentThreadWorkerPrivate(); + if (NS_WARN_IF(!workerPrivate)) { + return false; + } + workerPrivate->AssertIsOnWorkerThread(); + + return workerPrivate->ResistFingerprintingEnabled(); } bool @@ -7584,6 +7611,19 @@ nsContentUtils::IsAllowedNonCorsContentType(const nsACString& aHeaderValue) contentType.LowerCaseEqualsLiteral("multipart/form-data"); } +bool +nsContentUtils::DOMWindowDumpEnabled() +{ +#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) + // In optimized builds we check a pref that controls if we should + // enable output from dump() or not, in debug builds it's always + // enabled. + return nsContentUtils::sDOMWindowDumpEnabled; +#else + return true; +#endif +} + bool nsContentUtils::DoNotTrackEnabled() { @@ -8896,6 +8936,63 @@ 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) +{ + 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) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.streams.enabled", false); + } + + using namespace workers; + + // Otherwise, check the pref via the WorkerPrivate + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return false; + } + + return workerPrivate->StreamsEnabled(); +} + // static bool nsContentUtils::IsNonSubresourceRequest(nsIChannel* aChannel) @@ -11023,6 +11120,21 @@ nsContentUtils::ExtractErrorValues(JSContext* aCx, #undef EXTRACT_EXN_VALUES +/* static */ bool +nsContentUtils::DevToolsEnabled(JSContext* aCx) +{ + if (NS_IsMainThread()) { + return sDevToolsEnabled; + } + + workers::WorkerPrivate* workerPrivate = workers::GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return false; + } + + return workerPrivate->DevToolsEnabled(); +} + /* static */ bool nsContentUtils::ContentIsLink(nsIContent* aContent) { diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h index 44949624c0aa..f72cd3ffe0e8 100644 --- a/dom/base/nsContentUtils.h +++ b/dom/base/nsContentUtils.h @@ -2276,6 +2276,14 @@ public: return sIsPerformanceTimingEnabled; } + /* + * Returns true if user timing API should print to console. + */ + static bool IsUserTimingLoggingEnabled() + { + return sIsUserTimingLoggingEnabled; + } + /* * Returns true if the performance timing APIs are enabled. */ @@ -2682,6 +2690,11 @@ public: */ static mozilla::HTMLEditor* GetHTMLEditor(nsPresContext* aPresContext); + /** + * Returns true if the browser.dom.window.dump.enabled pref is set. + */ + static bool DOMWindowDumpEnabled(); + /** * Returns true if the privacy.donottrackheader.enabled pref is set. */ @@ -2918,6 +2931,12 @@ 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); + static bool IsNonSubresourceRequest(nsIChannel* aChannel); static uint32_t CookiesBehavior() @@ -3401,10 +3420,12 @@ private: static bool sIsPerformanceTimingEnabled; static bool sIsResourceTimingEnabled; static bool sIsPerformanceNavigationTimingEnabled; + static bool sIsUserTimingLoggingEnabled; static bool sIsFrameTimingPrefEnabled; static bool sIsFormAutofillAutocompleteEnabled; static bool sIsWebComponentsEnabled; static bool sIsCustomElementsEnabled; + static bool sDevToolsEnabled; static bool sSendPerformanceTimingNotifications; static bool sUseActivityCursor; static bool sAnimationsAPICoreEnabled; @@ -3453,6 +3474,9 @@ private: // bytecode out of the nsCacheInfoChannel. static nsCString* sJSBytecodeMimeType; +#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) + static bool sDOMWindowDumpEnabled; +#endif static bool sDoNotTrackEnabled; static mozilla::LazyLogModule sDOMDumpLog; diff --git a/dom/base/nsFrameMessageManager.cpp b/dom/base/nsFrameMessageManager.cpp index 671df79073a1..7b379ea5b655 100644 --- a/dom/base/nsFrameMessageManager.cpp +++ b/dom/base/nsFrameMessageManager.cpp @@ -36,7 +36,6 @@ #include "mozilla/Preferences.h" #include "mozilla/ScriptPreloader.h" #include "mozilla/Telemetry.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/File.h" #include "mozilla/dom/MessagePort.h" #include "mozilla/dom/ContentParent.h" @@ -806,7 +805,7 @@ nsFrameMessageManager::ReleaseCachedProcesses() NS_IMETHODIMP nsFrameMessageManager::Dump(const nsAString& aStr) { - if (!DOMPreferences::DumpEnabled()) { + if (!nsContentUtils::DOMWindowDumpEnabled()) { return NS_OK; } diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index ff26a34672eb..28a34798196b 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -17,7 +17,6 @@ #include "nsHistory.h" #include "nsDOMNavigationTiming.h" #include "nsIDOMStorageManager.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/LocalStorage.h" #include "mozilla/dom/Storage.h" #include "mozilla/dom/IdleRequest.h" @@ -3383,7 +3382,7 @@ nsGlobalWindowInner::GetFullScreen() void nsGlobalWindowInner::Dump(const nsAString& aStr) { - if (!DOMPreferences::DumpEnabled()) { + if (!nsContentUtils::DOMWindowDumpEnabled()) { return; } @@ -7586,7 +7585,7 @@ nsGlobalWindowInner::CreateImageBitmap(JSContext* aCx, const Sequence& aLayout, ErrorResult& aRv) { - if (!DOMPreferences::ImageBitmapExtensionsEnabled()) { + if (!ImageBitmap::ExtensionsEnabled(aCx)) { aRv.Throw(NS_ERROR_TYPE_ERR); return nullptr; } diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 78d96cedb25b..0b57f30582ea 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -37,7 +37,6 @@ #include "nsSize.h" #include "mozilla/FlushType.h" #include "prclist.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/StorageEvent.h" #include "mozilla/dom/StorageEventBinding.h" diff --git a/dom/cache/Cache.cpp b/dom/cache/Cache.cpp index 8943af14c084..d27a64cdd76d 100644 --- a/dom/cache/Cache.cpp +++ b/dom/cache/Cache.cpp @@ -17,7 +17,6 @@ #include "mozilla/dom/cache/CacheChild.h" #include "mozilla/dom/cache/CacheWorkerHolder.h" #include "mozilla/dom/cache/ReadStream.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/ErrorResult.h" #include "mozilla/Preferences.h" #include "mozilla/Unused.h" @@ -518,6 +517,29 @@ Cache::Keys(JSContext* aCx, const Optional& aRequest, return ExecuteOp(args, aRv); } +// static +bool +Cache::PrefEnabled(JSContext* aCx, JSObject* aObj) +{ + using mozilla::dom::workers::WorkerPrivate; + using mozilla::dom::workers::GetWorkerPrivateFromContext; + + // If we're on the main thread, then check the pref directly. + if (NS_IsMainThread()) { + bool enabled = false; + Preferences::GetBool("dom.caches.enabled", &enabled); + return enabled; + } + + // Otherwise check the pref via the work private helper + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return false; + } + + return workerPrivate->DOMCachesEnabled(); +} + nsISupports* Cache::GetParentObject() const { diff --git a/dom/cache/Cache.h b/dom/cache/Cache.h index 2af7a4c6794e..5148faacfc08 100644 --- a/dom/cache/Cache.h +++ b/dom/cache/Cache.h @@ -68,6 +68,8 @@ public: const CacheQueryOptions& aParams, ErrorResult& aRv); // binding methods + static bool PrefEnabled(JSContext* aCx, JSObject* aObj); + nsISupports* GetParentObject() const; virtual JSObject* WrapObject(JSContext* aContext, JS::Handle aGivenProto) override; diff --git a/dom/cache/CacheStorage.cpp b/dom/cache/CacheStorage.cpp index 2e5b9194d3f8..b86a26cd7200 100644 --- a/dom/cache/CacheStorage.cpp +++ b/dom/cache/CacheStorage.cpp @@ -9,7 +9,6 @@ #include "mozilla/Unused.h" #include "mozilla/dom/CacheBinding.h" #include "mozilla/dom/CacheStorageBinding.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/InternalRequest.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/Response.h" @@ -162,7 +161,7 @@ CacheStorage::CreateOnMainThread(Namespace aNamespace, nsIGlobalObject* aGlobal, bool testingEnabled = aForceTrustedOrigin || Preferences::GetBool("dom.caches.testing.enabled", false) || - DOMPreferences::ServiceWorkersTestingEnabled(); + Preferences::GetBool("dom.serviceWorkers.testing.enabled", false); if (!IsTrusted(principalInfo, testingEnabled)) { NS_WARNING("CacheStorage not supported on untrusted origins."); @@ -220,8 +219,8 @@ CacheStorage::CreateOnWorker(Namespace aNamespace, nsIGlobalObject* aGlobal, // origin checks. The ServiceWorker has its own trusted origin checks // that are better than ours. In addition, we don't have information // about the window any more, so we can't do our own checks. - bool testingEnabled = DOMPreferences::DOMCachesTestingEnabled() || - DOMPreferences::ServiceWorkersTestingEnabled() || + bool testingEnabled = aWorkerPrivate->DOMCachesTestingEnabled() || + aWorkerPrivate->ServiceWorkersTestingEnabled() || aWorkerPrivate->ServiceWorkersTestingInWindow() || aWorkerPrivate->IsServiceWorker(); @@ -445,6 +444,13 @@ CacheStorage::Keys(ErrorResult& aRv) return promise.forget(); } +// static +bool +CacheStorage::PrefEnabled(JSContext* aCx, JSObject* aObj) +{ + return Cache::PrefEnabled(aCx, aObj); +} + // static already_AddRefed CacheStorage::Constructor(const GlobalObject& aGlobal, diff --git a/dom/cache/CacheStorage.h b/dom/cache/CacheStorage.h index ef7b4145dc6b..2ba60dcd769a 100644 --- a/dom/cache/CacheStorage.h +++ b/dom/cache/CacheStorage.h @@ -73,6 +73,8 @@ public: nsIPrincipal* aPrincipal, ErrorResult& aRv); // binding methods + static bool PrefEnabled(JSContext* aCx, JSObject* aObj); + nsISupports* GetParentObject() const; virtual JSObject* WrapObject(JSContext* aContext, JS::Handle aGivenProto) override; diff --git a/dom/canvas/ImageBitmap.cpp b/dom/canvas/ImageBitmap.cpp index 9f6f41a2bf14..ddf59eec7c1a 100644 --- a/dom/canvas/ImageBitmap.cpp +++ b/dom/canvas/ImageBitmap.cpp @@ -6,7 +6,6 @@ #include "mozilla/dom/ImageBitmap.h" #include "mozilla/CheckedInt.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/ImageBitmapBinding.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/StructuredCloneTags.h" @@ -1435,6 +1434,18 @@ ImageBitmap::WriteStructuredClone(JSStructuredCloneWriter* aWriter, return true; } +/*static*/ bool +ImageBitmap::ExtensionsEnabled(JSContext* aCx, JSObject*) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("canvas.imagebitmap_extensions.enabled"); + } else { + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + MOZ_ASSERT(workerPrivate); + return workerPrivate->ImageBitmapExtensionsEnabled(); + } +} + // ImageBitmap extensions. ImageBitmapFormat ImageBitmap::FindOptimalFormat(const Optional>& aPossibleFormats, diff --git a/dom/canvas/ImageBitmap.h b/dom/canvas/ImageBitmap.h index 3862f040294b..fb04161919f1 100644 --- a/dom/canvas/ImageBitmap.h +++ b/dom/canvas/ImageBitmap.h @@ -152,6 +152,12 @@ public: nsTArray>& aClonedSurfaces, ImageBitmap* aImageBitmap); + // Mozilla Extensions + // aObj is an optional argument that isn't used by ExtensionsEnabled() and + // only exists because the bindings layer insists on passing it to us. All + // other consumers of this function should only call it passing one argument. + static bool ExtensionsEnabled(JSContext* aCx, JSObject* aObj = nullptr); + friend CreateImageBitmapFromBlob; friend CreateImageBitmapFromBlobTask; friend CreateImageBitmapFromBlobWorkerTask; diff --git a/dom/canvas/OffscreenCanvas.cpp b/dom/canvas/OffscreenCanvas.cpp index 6feabac01536..d17d6acae6e7 100644 --- a/dom/canvas/OffscreenCanvas.cpp +++ b/dom/canvas/OffscreenCanvas.cpp @@ -6,7 +6,6 @@ #include "OffscreenCanvas.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/OffscreenCanvasBinding.h" #include "mozilla/dom/WorkerPrivate.h" #include "mozilla/dom/WorkerScope.h" @@ -333,6 +332,18 @@ OffscreenCanvas::CreateFromCloneData(nsIGlobalObject* aGlobal, OffscreenCanvasCl return wc.forget(); } +/* static */ bool +OffscreenCanvas::PrefEnabled(JSContext* aCx, JSObject* aObj) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("gfx.offscreencanvas.enabled"); + } else { + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + MOZ_ASSERT(workerPrivate); + return workerPrivate->OffscreenCanvasEnabled(); + } +} + /* static */ bool OffscreenCanvas::PrefEnabledOnWorkerThread(JSContext* aCx, JSObject* aObj) { @@ -340,7 +351,7 @@ OffscreenCanvas::PrefEnabledOnWorkerThread(JSContext* aCx, JSObject* aObj) return true; } - return DOMPreferences::OffscreenCanvasEnabled(aCx, aObj); + return PrefEnabled(aCx, aObj); } NS_IMPL_CYCLE_COLLECTION_INHERITED(OffscreenCanvas, DOMEventTargetHelper, mCurrentContext) diff --git a/dom/canvas/OffscreenCanvas.h b/dom/canvas/OffscreenCanvas.h index c474ea4f1ebc..4de97b1bb2c8 100644 --- a/dom/canvas/OffscreenCanvas.h +++ b/dom/canvas/OffscreenCanvas.h @@ -9,7 +9,6 @@ #include "gfxTypes.h" #include "mozilla/DOMEventTargetHelper.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/layers/LayersTypes.h" #include "mozilla/RefPtr.h" #include "CanvasRenderingContextHelper.h" @@ -131,6 +130,8 @@ public: static already_AddRefed CreateFromCloneData(nsIGlobalObject* aGlobal, OffscreenCanvasCloneData* aData); + static bool PrefEnabled(JSContext* aCx, JSObject* aObj); + // Return true on main-thread, and return gfx.offscreencanvas.enabled // on worker thread. static bool PrefEnabledOnWorkerThread(JSContext* aCx, JSObject* aObj); diff --git a/dom/console/Console.cpp b/dom/console/Console.cpp index b60915380671..a9b93b11853f 100644 --- a/dom/console/Console.cpp +++ b/dom/console/Console.cpp @@ -8,7 +8,6 @@ #include "mozilla/dom/ConsoleBinding.h" #include "mozilla/dom/BlobBinding.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/Exceptions.h" #include "mozilla/dom/File.h" #include "mozilla/dom/FunctionBinding.h" @@ -1055,7 +1054,7 @@ Console::ProfileMethodInternal(JSContext* aCx, const nsAString& aAction, const Sequence& aData) { // Make all Console API no-op if DevTools aren't enabled. - if (!DOMPreferences::DevToolsEnabled()) { + if (!nsContentUtils::DevToolsEnabled(aCx)) { return; } @@ -1208,7 +1207,7 @@ Console::MethodInternal(JSContext* aCx, MethodName aMethodName, const Sequence& aData) { // Make all Console API no-op if DevTools aren't enabled. - if (!DOMPreferences::DevToolsEnabled()) { + if (!nsContentUtils::DevToolsEnabled(aCx)) { return; } AssertIsOnOwningThread(); diff --git a/dom/fetch/FetchObserver.cpp b/dom/fetch/FetchObserver.cpp index 3cea50da70ec..60bdb4dea086 100644 --- a/dom/fetch/FetchObserver.cpp +++ b/dom/fetch/FetchObserver.cpp @@ -26,6 +26,24 @@ NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) NS_IMPL_ADDREF_INHERITED(FetchObserver, DOMEventTargetHelper) NS_IMPL_RELEASE_INHERITED(FetchObserver, DOMEventTargetHelper) +/* static */ bool +FetchObserver::IsEnabled(JSContext* aCx, JSObject* aGlobal) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.fetchObserver.enabled", false); + } + + using namespace workers; + + // Otherwise, check the pref via the WorkerPrivate + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return false; + } + + return workerPrivate->FetchObserverEnabled(); +} + FetchObserver::FetchObserver(nsIGlobalObject* aGlobal, AbortSignal* aSignal) : DOMEventTargetHelper(aGlobal) diff --git a/dom/fetch/FetchObserver.h b/dom/fetch/FetchObserver.h index bd77f03633a0..442264185158 100644 --- a/dom/fetch/FetchObserver.h +++ b/dom/fetch/FetchObserver.h @@ -21,6 +21,9 @@ public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(FetchObserver, DOMEventTargetHelper) + static bool + IsEnabled(JSContext* aCx, JSObject* aGlobal); + FetchObserver(nsIGlobalObject* aGlobal, AbortSignal* aSignal); JSObject* diff --git a/dom/fetch/Request.cpp b/dom/fetch/Request.cpp index a28c6400c4a2..065ddc9d8159 100644 --- a/dom/fetch/Request.cpp +++ b/dom/fetch/Request.cpp @@ -77,6 +77,25 @@ Request::~Request() { } +// static +bool +Request::RequestContextEnabled(JSContext* aCx, JSObject* aObj) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.requestcontext.enabled", false); + } + + using namespace workers; + + // Otherwise, check the pref via the WorkerPrivate + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return false; + } + + return workerPrivate->RequestContextEnabled(); +} + already_AddRefed Request::GetInternalRequest() { diff --git a/dom/fetch/Request.h b/dom/fetch/Request.h index ede7d780f99b..dc80f9172c4d 100644 --- a/dom/fetch/Request.h +++ b/dom/fetch/Request.h @@ -35,6 +35,9 @@ public: Request(nsIGlobalObject* aOwner, InternalRequest* aRequest, AbortSignal* aSignal); + static bool + RequestContextEnabled(JSContext* aCx, JSObject* aObj); + JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override { diff --git a/dom/filesystem/Directory.cpp b/dom/filesystem/Directory.cpp index 888efcc033e7..6f0739846394 100644 --- a/dom/filesystem/Directory.cpp +++ b/dom/filesystem/Directory.cpp @@ -47,6 +47,24 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Directory) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END +/* static */ bool +Directory::WebkitBlinkDirectoryPickerEnabled(JSContext* aCx, JSObject* aObj) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false); + } + + // aCx can be null when this function is called by something else than WebIDL + // binding code. + workers::WorkerPrivate* workerPrivate = + workers::GetCurrentThreadWorkerPrivate(); + if (!workerPrivate) { + return false; + } + + return workerPrivate->WebkitBlinkDirectoryPickerEnabled(); +} + /* static */ already_AddRefed Directory::Constructor(const GlobalObject& aGlobal, const nsAString& aRealPath, diff --git a/dom/filesystem/Directory.h b/dom/filesystem/Directory.h index c24c19448b30..1411a514e8ff 100644 --- a/dom/filesystem/Directory.h +++ b/dom/filesystem/Directory.h @@ -29,6 +29,9 @@ public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Directory) + static bool + WebkitBlinkDirectoryPickerEnabled(JSContext* aCx, JSObject* aObj); + static already_AddRefed Constructor(const GlobalObject& aGlobal, const nsAString& aRealPath, diff --git a/dom/html/HTMLFormSubmission.cpp b/dom/html/HTMLFormSubmission.cpp index 026eff7134e9..2401a65c8e77 100644 --- a/dom/html/HTMLFormSubmission.cpp +++ b/dom/html/HTMLFormSubmission.cpp @@ -36,7 +36,6 @@ #include "nsContentUtils.h" #include "mozilla/dom/Directory.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/File.h" namespace mozilla { @@ -488,7 +487,7 @@ FSMultipartFormData::AddNameBlobOrNullPair(const nsAString& aName, Blob* aBlob) if (file) { nsAutoString relativePath; file->GetRelativePath(relativePath); - if (DOMPreferences::WebkitBlinkDirectoryPickerEnabled() && + if (Directory::WebkitBlinkDirectoryPickerEnabled(nullptr, nullptr) && !relativePath.IsEmpty()) { filename16 = relativePath; } @@ -547,7 +546,7 @@ nsresult FSMultipartFormData::AddNameDirectoryPair(const nsAString& aName, Directory* aDirectory) { - if (!DOMPreferences::WebkitBlinkDirectoryPickerEnabled()) { + if (!Directory::WebkitBlinkDirectoryPickerEnabled(nullptr, nullptr)) { return NS_OK; } diff --git a/dom/html/HTMLInputElement.cpp b/dom/html/HTMLInputElement.cpp index c28fe6163f04..3a4cf9893f91 100644 --- a/dom/html/HTMLInputElement.cpp +++ b/dom/html/HTMLInputElement.cpp @@ -11,7 +11,6 @@ #include "mozilla/DebugOnly.h" #include "mozilla/dom/Date.h" #include "mozilla/dom/Directory.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/HTMLFormSubmission.h" #include "mozilla/dom/FileSystemUtils.h" #include "mozilla/dom/GetFilesHelper.h" @@ -686,7 +685,7 @@ HTMLInputElement::nsFilePickerShownCallback::Done(int16_t aResult) RefPtr dispatchChangeEventCallback = new DispatchChangeEventCallback(mInput); - if (DOMPreferences::WebkitBlinkDirectoryPickerEnabled() && + if (IsWebkitDirPickerEnabled() && mInput->HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)) { ErrorResult error; GetFilesHelper* helper = mInput->GetOrCreateGetFilesHelper(true, error); @@ -2747,7 +2746,7 @@ HTMLInputElement::GetDisplayFileName(nsAString& aValue) const if (mFileData->mFilesOrDirectories.IsEmpty()) { if ((IsDirPickerEnabled() && Allowdirs()) || - (DOMPreferences::WebkitBlinkDirectoryPickerEnabled() && + (IsWebkitDirPickerEnabled() && HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory))) { nsContentUtils::GetLocalizedString(nsContentUtils::eFORMS_PROPERTIES, "NoDirSelected", value); @@ -2840,7 +2839,7 @@ HTMLInputElement::MozSetDndFilesAndDirectories(const nsTArray dispatchChangeEventCallback = new DispatchChangeEventCallback(this); - if (DOMPreferences::WebkitBlinkDirectoryPickerEnabled() && + if (IsWebkitDirPickerEnabled() && HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)) { ErrorResult rv; GetFilesHelper* helper = GetOrCreateGetFilesHelper(true /* recursionFlag */, @@ -2922,7 +2921,7 @@ HTMLInputElement::GetFiles() } if (IsDirPickerEnabled() && Allowdirs() && - (!DOMPreferences::WebkitBlinkDirectoryPickerEnabled() || + (!IsWebkitDirPickerEnabled() || !HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory))) { return nullptr; } @@ -4173,7 +4172,7 @@ HTMLInputElement::MaybeInitPickers(EventChainPostVisitor& aVisitor) if (target && target->FindFirstNonChromeOnlyAccessContent() == this && ((IsDirPickerEnabled() && Allowdirs()) || - (DOMPreferences::WebkitBlinkDirectoryPickerEnabled() && + (IsWebkitDirPickerEnabled() && HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory)))) { type = FILE_PICKER_DIRECTORY; } @@ -5634,6 +5633,21 @@ HTMLInputElement::IsDateTimeTypeSupported(uint8_t aDateTimeInputType) IsInputDateTimeOthersEnabled()); } +/* static */ bool +HTMLInputElement::IsWebkitDirPickerEnabled() +{ + static bool sWebkitDirPickerEnabled = false; + static bool sWebkitDirPickerPrefCached = false; + if (!sWebkitDirPickerPrefCached) { + sWebkitDirPickerPrefCached = true; + Preferences::AddBoolVarCache(&sWebkitDirPickerEnabled, + "dom.webkitBlink.dirPicker.enabled", + false); + } + + return sWebkitDirPickerEnabled; +} + /* static */ bool HTMLInputElement::IsWebkitFileSystemEnabled() { diff --git a/dom/html/HTMLInputElement.h b/dom/html/HTMLInputElement.h index 27c3c72e0f50..a0c061364f1a 100644 --- a/dom/html/HTMLInputElement.h +++ b/dom/html/HTMLInputElement.h @@ -1727,6 +1727,13 @@ private: static bool IsDateTimeTypeSupported(uint8_t aDateTimeInputType); + /** + * Checks preference "dom.webkitBlink.dirPicker.enabled" to determine if + * webkitdirectory should be supported. + */ + static bool + IsWebkitDirPickerEnabled(); + /** * Checks preference "dom.webkitBlink.filesystem.enabled" to determine if * webkitEntries should be supported. diff --git a/dom/html/ImageDocument.cpp b/dom/html/ImageDocument.cpp index 13d9236b9e24..ef2991878733 100644 --- a/dom/html/ImageDocument.cpp +++ b/dom/html/ImageDocument.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "ImageDocument.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/ImageDocumentBinding.h" #include "mozilla/dom/HTMLImageElement.h" #include "nsRect.h" @@ -50,7 +49,7 @@ //XXX A hack needed for Firefox's site specific zoom. static bool IsSiteSpecific() { - return !mozilla::dom::DOMPreferences::ResistFingerprintingEnabled() && + return !mozilla::Preferences::GetBool("privacy.resistFingerprinting", false) && mozilla::Preferences::GetBool("browser.zoom.siteSpecific", false); } diff --git a/dom/ipc/TabContext.cpp b/dom/ipc/TabContext.cpp index d972cd133797..8a6d462ab6ea 100644 --- a/dom/ipc/TabContext.cpp +++ b/dom/ipc/TabContext.cpp @@ -8,7 +8,6 @@ #include "mozilla/dom/PTabContext.h" #include "mozilla/dom/TabParent.h" #include "mozilla/dom/TabChild.h" -#include "mozilla/dom/DOMPreferences.h" #include "nsIScriptSecurityManager.h" #include "nsServiceManagerUtils.h" @@ -247,7 +246,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 (!DOMPreferences::ServiceWorkersEnabled()) { + if (!Preferences::GetBool("dom.serviceWorkers.enabled", false)) { mInvalidReason = "ServiceWorkers should be enabled."; return; } diff --git a/dom/network/Connection.cpp b/dom/network/Connection.cpp index 1d85f11543c3..98dcf2347981 100644 --- a/dom/network/Connection.cpp +++ b/dom/network/Connection.cpp @@ -106,6 +106,18 @@ Connection::Update(ConnectionType aType, bool aIsWifi, uint32_t aDHCPGateway, } } +/* static */ bool +Connection::IsEnabled(JSContext* aCx, JSObject* aObj) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.netinfo.enabled"); + } + + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + MOZ_ASSERT(workerPrivate); + return workerPrivate->NetworkInformationEnabled(); +} + /* static */ Connection* Connection::CreateForWindow(nsPIDOMWindowInner* aWindow) { diff --git a/dom/network/Connection.h b/dom/network/Connection.h index b36ade7ea170..45b23659be1c 100644 --- a/dom/network/Connection.h +++ b/dom/network/Connection.h @@ -37,6 +37,8 @@ public: NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper) + static bool IsEnabled(JSContext* aCx, JSObject* aObj); + static Connection* CreateForWindow(nsPIDOMWindowInner* aWindow); diff --git a/dom/notification/Notification.cpp b/dom/notification/Notification.cpp index cc9c6f68dac8..d74e5fdf4a71 100644 --- a/dom/notification/Notification.cpp +++ b/dom/notification/Notification.cpp @@ -19,7 +19,6 @@ #include "mozilla/dom/AppNotificationServiceOptionsBinding.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/ContentChild.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/NotificationEvent.h" #include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/Promise.h" @@ -894,22 +893,39 @@ 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) { - if (!NS_IsMainThread()) { - WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); - if (!workerPrivate) { - return false; - } - - if (workerPrivate->IsServiceWorker()) { - return DOMPreferences::NotificationEnabledInServiceWorkers(); - } + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.webnotifications.enabled", false); } - return DOMPreferences::NotificationEnabled(); + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + if (!workerPrivate) { + return false; + } + + if (workerPrivate->IsServiceWorker()) { + return workerPrivate->DOMServiceWorkerNotificationEnabled(); + } + + return workerPrivate->DOMWorkerNotificationEnabled(); } // static @@ -1724,7 +1740,7 @@ Notification::ShowInternal() bool inPrivateBrowsing = IsInPrivateBrowsing(); bool requireInteraction = mRequireInteraction; - if (!DOMPreferences::NotificationRIEnabled()) { + if (!Preferences::GetBool("dom.webnotifications.requireinteraction.enabled", false)) { requireInteraction = false; } diff --git a/dom/notification/Notification.h b/dom/notification/Notification.h index 3b4aab19b0f7..adcb72cbcd23 100644 --- a/dom/notification/Notification.h +++ b/dom/notification/Notification.h @@ -152,6 +152,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/performance/PerformanceMainThread.cpp b/dom/performance/PerformanceMainThread.cpp index 6a37b8b828c6..1d6b64d7f21d 100644 --- a/dom/performance/PerformanceMainThread.cpp +++ b/dom/performance/PerformanceMainThread.cpp @@ -6,7 +6,6 @@ #include "PerformanceMainThread.h" #include "PerformanceNavigation.h" -#include "mozilla/dom/DOMPreferences.h" #include "nsICacheInfoChannel.h" namespace mozilla { @@ -283,7 +282,7 @@ PerformanceMainThread::InsertUserEntry(PerformanceEntry* aEntry) nsAutoCString uri; uint64_t markCreationEpoch = 0; - if (DOMPreferences::PerformanceLoggingEnabled() || + if (nsContentUtils::IsUserTimingLoggingEnabled() || nsContentUtils::SendPerformanceTimingNotifications()) { nsresult rv = NS_ERROR_FAILURE; nsCOMPtr owner = GetOwner(); @@ -297,7 +296,7 @@ PerformanceMainThread::InsertUserEntry(PerformanceEntry* aEntry) } markCreationEpoch = static_cast(PR_Now() / PR_USEC_PER_MSEC); - if (DOMPreferences::PerformanceLoggingEnabled()) { + if (nsContentUtils::IsUserTimingLoggingEnabled()) { Performance::LogEntry(aEntry, uri); } } diff --git a/dom/performance/PerformanceWorker.cpp b/dom/performance/PerformanceWorker.cpp index bfe12ff60b21..f10c58446bec 100644 --- a/dom/performance/PerformanceWorker.cpp +++ b/dom/performance/PerformanceWorker.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "PerformanceWorker.h" -#include "mozilla/dom/DOMPreferences.h" #include "WorkerPrivate.h" namespace mozilla { @@ -27,7 +26,7 @@ PerformanceWorker::~PerformanceWorker() void PerformanceWorker::InsertUserEntry(PerformanceEntry* aEntry) { - if (DOMPreferences::PerformanceLoggingEnabled()) { + if (mWorkerPrivate->PerformanceLoggingEnabled()) { nsAutoCString uri; nsCOMPtr scriptURI = mWorkerPrivate->GetResolvedScriptURI(); if (!scriptURI || NS_FAILED(scriptURI->GetHost(uri))) { diff --git a/dom/push/PushManager.h b/dom/push/PushManager.h index fc608e7880e5..caafaf76a68e 100644 --- a/dom/push/PushManager.h +++ b/dom/push/PushManager.h @@ -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; diff --git a/dom/push/PushSubscription.h b/dom/push/PushSubscription.h index b68d042fc525..1a2b8081c69c 100644 --- a/dom/push/PushSubscription.h +++ b/dom/push/PushSubscription.h @@ -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" diff --git a/dom/push/PushSubscriptionOptions.h b/dom/push/PushSubscriptionOptions.h index 3df566f6b3a7..8b513b81e27b 100644 --- a/dom/push/PushSubscriptionOptions.h +++ b/dom/push/PushSubscriptionOptions.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; diff --git a/dom/quota/StorageManager.cpp b/dom/quota/StorageManager.cpp index 4bc145e2afe0..b0516824610e 100644 --- a/dom/quota/StorageManager.cpp +++ b/dom/quota/StorageManager.cpp @@ -6,7 +6,6 @@ #include "StorageManager.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/PromiseWorkerProxy.h" #include "mozilla/dom/quota/QuotaManagerService.h" #include "mozilla/dom/StorageManagerBinding.h" @@ -866,6 +865,20 @@ StorageManager::Estimate(ErrorResult& aRv) aRv); } +// static +bool +StorageManager::PrefEnabled(JSContext* aCx, JSObject* aObj) +{ + if (NS_IsMainThread()) { + return Preferences::GetBool("dom.storageManager.enabled"); + } + + WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx); + MOZ_ASSERT(workerPrivate); + + return workerPrivate->StorageManagerEnabled(); +} + NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(StorageManager, mOwner) NS_IMPL_CYCLE_COLLECTING_ADDREF(StorageManager) diff --git a/dom/quota/StorageManager.h b/dom/quota/StorageManager.h index 9f1d413573c2..781daad3b3e5 100644 --- a/dom/quota/StorageManager.h +++ b/dom/quota/StorageManager.h @@ -25,6 +25,10 @@ class StorageManager final nsCOMPtr mOwner; public: + // Return dom.quota.storageManager.enabled on main/worker thread. + static bool + PrefEnabled(JSContext* aCx, JSObject* aObj); + explicit StorageManager(nsIGlobalObject* aGlobal); diff --git a/dom/webidl/Cache.webidl b/dom/webidl/Cache.webidl index fed193510758..ed2cb88739f2 100644 --- a/dom/webidl/Cache.webidl +++ b/dom/webidl/Cache.webidl @@ -11,7 +11,7 @@ // https://slightlyoff.github.io/ServiceWorker/spec/service_worker/index.html#cache [Exposed=(Window,Worker), - Func="mozilla::dom::DOMPreferences::DOMCachesEnabled"] + Func="mozilla::dom::cache::Cache::PrefEnabled"] interface Cache { [NewObject] Promise match(RequestInfo request, optional CacheQueryOptions options); diff --git a/dom/webidl/CacheStorage.webidl b/dom/webidl/CacheStorage.webidl index 8c9afd493e25..cf5bad44b201 100644 --- a/dom/webidl/CacheStorage.webidl +++ b/dom/webidl/CacheStorage.webidl @@ -14,7 +14,7 @@ interface Principal; [Exposed=(Window,Worker), ChromeConstructor(CacheStorageNamespace namespace, Principal principal), - Func="mozilla::dom::DOMPreferences::DOMCachesEnabled"] + Func="mozilla::dom::cache::CacheStorage::PrefEnabled"] interface CacheStorage { [NewObject] Promise match(RequestInfo request, optional CacheQueryOptions options); diff --git a/dom/webidl/FetchObserver.webidl b/dom/webidl/FetchObserver.webidl index 0a7964cbd4b3..eecd67e668b5 100644 --- a/dom/webidl/FetchObserver.webidl +++ b/dom/webidl/FetchObserver.webidl @@ -16,7 +16,7 @@ enum FetchState { }; [Exposed=(Window,Worker), - Func="mozilla::dom::DOMPreferences::FetchObserverEnabled"] + Func="FetchObserver::IsEnabled"] interface FetchObserver : EventTarget { readonly attribute FetchState state; diff --git a/dom/webidl/File.webidl b/dom/webidl/File.webidl index 794cd7326859..74b55951a5ae 100644 --- a/dom/webidl/File.webidl +++ b/dom/webidl/File.webidl @@ -34,7 +34,7 @@ partial interface File { [GetterThrows, Deprecated="FileLastModifiedDate"] readonly attribute Date lastModifiedDate; - [BinaryName="relativePath", Func="mozilla::dom::DOMPreferences::WebkitBlinkDirectoryPickerEnabled"] + [BinaryName="relativePath", Func="mozilla::dom::Directory::WebkitBlinkDirectoryPickerEnabled"] readonly attribute USVString webkitRelativePath; [GetterThrows, ChromeOnly, NeedsCallerType] diff --git a/dom/webidl/ImageBitmap.webidl b/dom/webidl/ImageBitmap.webidl index 183453ee10fc..3cfabff12e77 100644 --- a/dom/webidl/ImageBitmap.webidl +++ b/dom/webidl/ImageBitmap.webidl @@ -403,10 +403,10 @@ dictionary ChannelPixelLayout { typedef sequence ImagePixelLayout; partial interface ImageBitmap { - [Throws, Func="mozilla::dom::DOMPreferences::ImageBitmapExtensionsEnabled"] + [Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"] ImageBitmapFormat findOptimalFormat (optional sequence aPossibleFormats); - [Throws, Func="mozilla::dom::DOMPreferences::ImageBitmapExtensionsEnabled"] + [Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"] long mappedDataLength (ImageBitmapFormat aFormat); - [Throws, Func="mozilla::dom::DOMPreferences::ImageBitmapExtensionsEnabled"] + [Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"] Promise mapDataInto (ImageBitmapFormat aFormat, BufferSource aBuffer, long aOffset); }; diff --git a/dom/webidl/Navigator.webidl b/dom/webidl/Navigator.webidl index 56c7e2223b76..4dd89cc89a74 100644 --- a/dom/webidl/Navigator.webidl +++ b/dom/webidl/Navigator.webidl @@ -89,7 +89,7 @@ interface NavigatorContentUtils { [SecureContext, NoInterfaceObject, Exposed=(Window,Worker)] interface NavigatorStorage { - [Func="mozilla::dom::DOMPreferences::StorageManagerEnabled"] + [Func="mozilla::dom::StorageManager::PrefEnabled"] readonly attribute StorageManager storage; }; diff --git a/dom/webidl/NetworkInformation.webidl b/dom/webidl/NetworkInformation.webidl index 4c331637ebef..79d85971f45c 100644 --- a/dom/webidl/NetworkInformation.webidl +++ b/dom/webidl/NetworkInformation.webidl @@ -18,7 +18,7 @@ enum ConnectionType { "unknown" }; -[Func="mozilla::dom::DOMPreferences::NetworkInformationEnabled", +[Func="mozilla::dom::network::Connection::IsEnabled", Exposed=(Window,Worker)] interface NetworkInformation : EventTarget { readonly attribute ConnectionType type; diff --git a/dom/webidl/Notification.webidl b/dom/webidl/Notification.webidl index 51b0d58627ca..06d6898d7a5c 100644 --- a/dom/webidl/Notification.webidl +++ b/dom/webidl/Notification.webidl @@ -51,7 +51,7 @@ interface Notification : EventTarget { [Pure] readonly attribute DOMString? icon; - [Constant, Func="mozilla::dom::DOMPreferences::NotificationRIEnabled"] + [Constant, Func="mozilla::dom::Notification::RequireInteractionEnabled"] readonly attribute boolean requireInteraction; [Constant] diff --git a/dom/webidl/OffscreenCanvas.webidl b/dom/webidl/OffscreenCanvas.webidl index b1519a7caf74..215c9329bc7d 100644 --- a/dom/webidl/OffscreenCanvas.webidl +++ b/dom/webidl/OffscreenCanvas.webidl @@ -9,7 +9,7 @@ [Constructor(unsigned long width, unsigned long height), Exposed=(Window,Worker), - Func="mozilla::dom::DOMPreferences::OffscreenCanvasEnabled"] + Func="mozilla::dom::OffscreenCanvas::PrefEnabled"] interface OffscreenCanvas : EventTarget { [Pure, SetterThrows] attribute unsigned long width; diff --git a/dom/webidl/PromiseRejectionEvent.webidl b/dom/webidl/PromiseRejectionEvent.webidl index e29ff92df090..21faf8bd09d0 100644 --- a/dom/webidl/PromiseRejectionEvent.webidl +++ b/dom/webidl/PromiseRejectionEvent.webidl @@ -6,7 +6,7 @@ [Constructor(DOMString type, PromiseRejectionEventInit eventInitDict), Exposed=(Window,Worker), - Func="mozilla::dom::DOMPreferences::PromiseRejectionEventsEnabled"] + Func="nsContentUtils::PromiseRejectionEventsEnabled"] interface PromiseRejectionEvent : Event { [BinaryName="rejectedPromise"] diff --git a/dom/webidl/PushEvent.webidl b/dom/webidl/PushEvent.webidl index b7925857cfbb..a4624e4512e9 100644 --- a/dom/webidl/PushEvent.webidl +++ b/dom/webidl/PushEvent.webidl @@ -8,7 +8,7 @@ */ [Constructor(DOMString type, optional PushEventInit eventInitDict), - Func="mozilla::dom::DOMPreferences::PushEnabled", + Func="nsContentUtils::PushEnabled", Exposed=ServiceWorker] interface PushEvent : ExtendableEvent { readonly attribute PushMessageData? data; diff --git a/dom/webidl/PushManager.webidl b/dom/webidl/PushManager.webidl index 732ac250871b..1c69c402e0ad 100644 --- a/dom/webidl/PushManager.webidl +++ b/dom/webidl/PushManager.webidl @@ -22,7 +22,7 @@ interface PushManagerImpl { Promise permissionState(optional PushSubscriptionOptionsInit options); }; -[Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled", +[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled", ChromeConstructor(DOMString scope)] interface PushManager { [Throws, UseCounter] diff --git a/dom/webidl/PushMessageData.webidl b/dom/webidl/PushMessageData.webidl index 14c019498c48..32da84f377ee 100644 --- a/dom/webidl/PushMessageData.webidl +++ b/dom/webidl/PushMessageData.webidl @@ -7,7 +7,7 @@ * https://w3c.github.io/push-api/ */ -[Func="mozilla::dom::DOMPreferences::PushEnabled", +[Func="nsContentUtils::PushEnabled", Exposed=ServiceWorker] interface PushMessageData { diff --git a/dom/webidl/PushSubscription.webidl b/dom/webidl/PushSubscription.webidl index 22c2b811f459..eab576d3cec4 100644 --- a/dom/webidl/PushSubscription.webidl +++ b/dom/webidl/PushSubscription.webidl @@ -36,7 +36,7 @@ dictionary PushSubscriptionInit BufferSource? appServerKey; }; -[Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled", +[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled", ChromeConstructor(PushSubscriptionInit initDict)] interface PushSubscription { diff --git a/dom/webidl/PushSubscriptionOptions.webidl b/dom/webidl/PushSubscriptionOptions.webidl index f5a10a7a60db..569a1ddae361 100644 --- a/dom/webidl/PushSubscriptionOptions.webidl +++ b/dom/webidl/PushSubscriptionOptions.webidl @@ -7,7 +7,7 @@ * https://w3c.github.io/push-api/ */ -[Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled"] +[Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled"] interface PushSubscriptionOptions { [SameObject, Throws] diff --git a/dom/webidl/Request.webidl b/dom/webidl/Request.webidl index 925a47c06205..b4928c965817 100644 --- a/dom/webidl/Request.webidl +++ b/dom/webidl/Request.webidl @@ -17,7 +17,7 @@ interface Request { readonly attribute USVString url; [SameObject] readonly attribute Headers headers; - [Func="mozilla::dom::DOMPreferences::RequestContextEnabled"] + [Func="mozilla::dom::Request::RequestContextEnabled"] readonly attribute RequestContext context; readonly attribute USVString referrer; readonly attribute ReferrerPolicy referrerPolicy; @@ -61,7 +61,7 @@ dictionary RequestInit { AbortSignal? signal; - [Func="mozilla::dom::DOMPreferences::FetchObserverEnabled"] + [Func="FetchObserver::IsEnabled"] ObserverCallback observe; }; diff --git a/dom/webidl/Response.webidl b/dom/webidl/Response.webidl index 54e7d5be8d11..e5ae3fb93d1f 100644 --- a/dom/webidl/Response.webidl +++ b/dom/webidl/Response.webidl @@ -35,7 +35,7 @@ Response implements Body; // This should be part of Body but we don't want to expose body to request yet. // See bug 1387483. partial interface Response { - [GetterThrows, Func="mozilla::dom::DOMPreferences::StreamsEnabled"] + [GetterThrows, Func="nsContentUtils::StreamsEnabled"] readonly attribute ReadableStream? body; }; diff --git a/dom/webidl/ServiceWorkerRegistration.webidl b/dom/webidl/ServiceWorkerRegistration.webidl index 932ee5dc9509..8285d9c39cec 100644 --- a/dom/webidl/ServiceWorkerRegistration.webidl +++ b/dom/webidl/ServiceWorkerRegistration.webidl @@ -9,7 +9,7 @@ * https://notifications.spec.whatwg.org/ */ -[Func="mozilla::dom::DOMPreferences::ServiceWorkersEnabled", +[Func="mozilla::dom::ServiceWorkerRegistration::Visible", Exposed=(Window,Worker)] interface ServiceWorkerRegistration : EventTarget { [Unforgeable] readonly attribute ServiceWorker? installing; @@ -38,14 +38,14 @@ enum ServiceWorkerUpdateViaCache { // https://w3c.github.io/push-api/ partial interface ServiceWorkerRegistration { - [Throws, Exposed=(Window,Worker), Func="mozilla::dom::DOMPreferences::PushEnabled"] + [Throws, Exposed=(Window,Worker), Func="nsContentUtils::PushEnabled"] readonly attribute PushManager pushManager; }; // https://notifications.spec.whatwg.org/ partial interface ServiceWorkerRegistration { - [Throws, Func="mozilla::dom::DOMPreferences::NotificationEnabledInServiceWorkers"] + [Throws, Func="mozilla::dom::ServiceWorkerRegistration::NotificationAPIVisible"] Promise showNotification(DOMString title, optional NotificationOptions options); - [Throws, Func="mozilla::dom::DOMPreferences::NotificationEnabledInServiceWorkers"] + [Throws, Func="mozilla::dom::ServiceWorkerRegistration::NotificationAPIVisible"] Promise> getNotifications(optional GetNotificationOptions filter); }; diff --git a/dom/webidl/StorageManager.webidl b/dom/webidl/StorageManager.webidl index 98e2534a6421..8078ce96a40e 100644 --- a/dom/webidl/StorageManager.webidl +++ b/dom/webidl/StorageManager.webidl @@ -10,7 +10,7 @@ [SecureContext, Exposed=(Window,Worker), - Func="mozilla::dom::DOMPreferences::StorageManagerEnabled"] + Func="mozilla::dom::StorageManager::PrefEnabled"] interface StorageManager { [Throws] Promise persisted(); diff --git a/dom/webidl/WebGLRenderingContext.webidl b/dom/webidl/WebGLRenderingContext.webidl index 387667e54622..b2cd316883a4 100644 --- a/dom/webidl/WebGLRenderingContext.webidl +++ b/dom/webidl/WebGLRenderingContext.webidl @@ -803,7 +803,7 @@ WebGLRenderingContext implements WebGLRenderingContextBase; // Reference: https://wiki.whatwg.org/wiki/OffscreenCanvas [Exposed=(Window,Worker)] partial interface WebGLRenderingContext { - [Func="mozilla::dom::DOMPreferences::OffscreenCanvasEnabled"] + [Func="mozilla::dom::OffscreenCanvas::PrefEnabled"] void commit(); }; diff --git a/dom/webidl/WindowOrWorkerGlobalScope.webidl b/dom/webidl/WindowOrWorkerGlobalScope.webidl index 63c38c48c1ab..1b6637b630bf 100644 --- a/dom/webidl/WindowOrWorkerGlobalScope.webidl +++ b/dom/webidl/WindowOrWorkerGlobalScope.webidl @@ -62,7 +62,7 @@ partial interface WindowOrWorkerGlobalScope { // https://w3c.github.io/ServiceWorker/#self-caches partial interface WindowOrWorkerGlobalScope { - [Throws, Func="mozilla::dom::DOMPreferences::DOMCachesEnabled", SameObject] + [Throws, Func="mozilla::dom::cache::CacheStorage::PrefEnabled", SameObject] readonly attribute CacheStorage caches; }; diff --git a/dom/webidl/WorkerNavigator.webidl b/dom/webidl/WorkerNavigator.webidl index 6bcdab289d6f..8622546eed94 100644 --- a/dom/webidl/WorkerNavigator.webidl +++ b/dom/webidl/WorkerNavigator.webidl @@ -16,6 +16,6 @@ WorkerNavigator implements NavigatorStorage; // http://wicg.github.io/netinfo/#extensions-to-the-navigator-interface [Exposed=(Worker)] partial interface WorkerNavigator { - [Func="mozilla::dom::DOMPreferences::NetworkInformationEnabled", Throws] + [Func="mozilla::dom::network::Connection::IsEnabled", Throws] readonly attribute NetworkInformation connection; }; diff --git a/dom/workers/RuntimeService.cpp b/dom/workers/RuntimeService.cpp index 64be2a7da9bd..d38248876998 100644 --- a/dom/workers/RuntimeService.cpp +++ b/dom/workers/RuntimeService.cpp @@ -1442,6 +1442,7 @@ struct RuntimeService::IdleThreadInfo // This is only touched on the main thread. Initialized in Init() below. JSSettings RuntimeService::sDefaultJSSettings; +bool RuntimeService::sDefaultPreferences[WORKERPREF_COUNT] = { false }; RuntimeService::RuntimeService() : mMutex("RuntimeService::mMutex"), mObserved(false), @@ -1965,17 +1966,17 @@ RuntimeService::Init() PREF_JS_OPTIONS_PREFIX PREF_GCZEAL)) || #endif +#define WORKER_SIMPLE_PREF(name, getter, NAME) \ + NS_FAILED(Preferences::RegisterCallbackAndCall( \ + WorkerPrefChanged, \ + name, \ + reinterpret_cast(WORKERPREF_##NAME))) || #define WORKER_PREF(name, callback) \ NS_FAILED(Preferences::RegisterCallbackAndCall( \ callback, \ name)) || - WORKER_PREF("intl.accept_languages", PrefLanguagesChanged) - WORKER_PREF("general.appname.override", AppNameOverrideChanged) - WORKER_PREF("general.appversion.override", AppVersionOverrideChanged) - WORKER_PREF("general.platform.override", PlatformOverrideChanged) -#ifdef JS_GC_ZEAL - WORKER_PREF("dom.workers.options.gcZeal", LoadGCZealOptions) -#endif +#include "WorkerPrefs.h" +#undef WORKER_SIMPLE_PREF #undef WORKER_PREF NS_FAILED(Preferences::RegisterPrefixCallbackAndCall( @@ -2261,17 +2262,17 @@ RuntimeService::Cleanup() NS_FAILED(Preferences::UnregisterPrefixCallback(LoadContextOptions, PREF_WORKERS_OPTIONS_PREFIX)) || +#define WORKER_SIMPLE_PREF(name, getter, NAME) \ + NS_FAILED(Preferences::UnregisterCallback( \ + WorkerPrefChanged, \ + name, \ + reinterpret_cast(WORKERPREF_##NAME))) || #define WORKER_PREF(name, callback) \ NS_FAILED(Preferences::UnregisterCallback( \ callback, \ name)) || - WORKER_PREF("intl.accept_languages", PrefLanguagesChanged) - WORKER_PREF("general.appname.override", AppNameOverrideChanged) - WORKER_PREF("general.appversion.override", AppVersionOverrideChanged) - WORKER_PREF("general.platform.override", PlatformOverrideChanged) -#ifdef JS_GC_ZEAL - WORKER_PREF("dom.workers.options.gcZeal", LoadGCZealOptions) -#endif +#include "WorkerPrefs.h" +#undef WORKER_SIMPLE_PREF #undef WORKER_PREF #ifdef JS_GC_ZEAL @@ -2671,6 +2672,12 @@ RuntimeService::UpdatePlatformOverridePreference(const nsAString& aValue) mNavigatorProperties.mPlatformOverridden = aValue; } +void +RuntimeService::UpdateAllWorkerPreference(WorkerPreference aPref, bool aValue) +{ + BROADCAST_ALL_WORKERS(UpdatePreference, aPref, aValue); +} + void RuntimeService::UpdateAllWorkerLanguages(const nsTArray& aLanguages) { @@ -2790,6 +2797,34 @@ RuntimeService::Observe(nsISupports* aSubject, const char* aTopic, return NS_OK; } +/* static */ void +RuntimeService::WorkerPrefChanged(const char* aPrefName, void* aClosure) +{ + AssertIsOnMainThread(); + + const WorkerPreference key = + static_cast(reinterpret_cast(aClosure)); + + switch (key) { +#define WORKER_SIMPLE_PREF(name, getter, NAME) case WORKERPREF_##NAME: +#define WORKER_PREF(name, callback) +#include "WorkerPrefs.h" +#undef WORKER_SIMPLE_PREF +#undef WORKER_PREF + sDefaultPreferences[key] = Preferences::GetBool(aPrefName, false); + break; + + default: + MOZ_ASSERT_UNREACHABLE("Invalid pref key"); + break; + } + + RuntimeService* rts = RuntimeService::GetService(); + if (rts) { + rts->UpdateAllWorkerPreference(key, sDefaultPreferences[key]); + } +} + bool LogViolationDetailsRunnable::MainThreadRun() { diff --git a/dom/workers/RuntimeService.h b/dom/workers/RuntimeService.h index de1152bae466..45c8642adc85 100644 --- a/dom/workers/RuntimeService.h +++ b/dom/workers/RuntimeService.h @@ -91,6 +91,7 @@ class RuntimeService final : public nsIObserver nsCOMPtr mIdleThreadTimer; static JSSettings sDefaultJSSettings; + static bool sDefaultPreferences[WORKERPREF_COUNT]; public: struct NavigatorProperties @@ -172,6 +173,13 @@ public: aSettings = sDefaultJSSettings; } + static void + GetDefaultPreferences(bool aPreferences[WORKERPREF_COUNT]) + { + AssertIsOnMainThread(); + memcpy(aPreferences, sDefaultPreferences, WORKERPREF_COUNT * sizeof(bool)); + } + static void SetDefaultContextOptions(const JS::ContextOptions& aContextOptions) { @@ -194,6 +202,9 @@ public: void UpdateAllWorkerLanguages(const nsTArray& aLanguages); + void + UpdateAllWorkerPreference(WorkerPreference aPref, bool aValue); + static void SetDefaultJSGCSettings(JSGCParamKey aKey, uint32_t aValue) { @@ -259,6 +270,9 @@ private: static void ShutdownIdleThreads(nsITimer* aTimer, void* aClosure); + static void + WorkerPrefChanged(const char* aPrefName, void* aClosure); + nsresult CreateSharedWorkerFromLoadInfo(JSContext* aCx, WorkerLoadInfo* aLoadInfo, diff --git a/dom/workers/ServiceWorker.cpp b/dom/workers/ServiceWorker.cpp index 6b347ab92ade..793de9cf8362 100644 --- a/dom/workers/ServiceWorker.cpp +++ b/dom/workers/ServiceWorker.cpp @@ -12,7 +12,7 @@ #include "ServiceWorkerPrivate.h" #include "WorkerPrivate.h" -#include "mozilla/dom/DOMPreferences.h" +#include "mozilla/Preferences.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 DOMPreferences::ServiceWorkersEnabled(); + return Preferences::GetBool("dom.serviceWorkers.enabled", false); } return IS_INSTANCE_OF(ServiceWorkerGlobalScope, aObj); diff --git a/dom/workers/ServiceWorkerContainer.cpp b/dom/workers/ServiceWorkerContainer.cpp index 966323f25297..82b6623d2a9d 100644 --- a/dom/workers/ServiceWorkerContainer.cpp +++ b/dom/workers/ServiceWorkerContainer.cpp @@ -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/DOMPreferences.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 DOMPreferences::ServiceWorkersEnabled(); + return Preferences::GetBool("dom.serviceWorkers.enabled", false); } ServiceWorkerContainer::ServiceWorkerContainer(nsPIDOMWindowInner* aWindow) diff --git a/dom/workers/ServiceWorkerManager.cpp b/dom/workers/ServiceWorkerManager.cpp index 6de54b9b1372..b3b315512e8b 100644 --- a/dom/workers/ServiceWorkerManager.cpp +++ b/dom/workers/ServiceWorkerManager.cpp @@ -40,7 +40,6 @@ #include "mozilla/dom/ClientHandle.h" #include "mozilla/dom/ClientManager.h" #include "mozilla/dom/ContentParent.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/ErrorEvent.h" #include "mozilla/dom/Headers.h" #include "mozilla/dom/InternalHeaders.h" @@ -757,7 +756,7 @@ ServiceWorkerManager::Register(mozIDOMWindow* aWindow, outerWindow->GetServiceWorkersTestingEnabled(); bool authenticatedOrigin; - if (DOMPreferences::ServiceWorkersTestingEnabled() || + if (Preferences::GetBool("dom.serviceWorkers.testing.enabled") || serviceWorkersTestingEnabled) { authenticatedOrigin = true; } else { diff --git a/dom/workers/ServiceWorkerPrivate.cpp b/dom/workers/ServiceWorkerPrivate.cpp index df5d7b7e1bca..7976d2018d5f 100644 --- a/dom/workers/ServiceWorkerPrivate.cpp +++ b/dom/workers/ServiceWorkerPrivate.cpp @@ -25,7 +25,6 @@ #include "WorkerRunnable.h" #include "WorkerScope.h" #include "mozilla/Assertions.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/Client.h" #include "mozilla/dom/ClientIPCTypes.h" #include "mozilla/dom/FetchUtil.h" @@ -1958,7 +1957,7 @@ ServiceWorkerPrivate::TerminateWorker() mIdleWorkerTimer->Cancel(); mIdleKeepAliveToken = nullptr; if (mWorkerPrivate) { - if (DOMPreferences::ServiceWorkersTestingEnabled()) { + if (Preferences::GetBool("dom.serviceWorkers.testing.enabled")) { nsCOMPtr os = services::GetObserverService(); if (os) { os->NotifyObservers(nullptr, "service-worker-shutdown", nullptr); diff --git a/dom/workers/ServiceWorkerRegistration.cpp b/dom/workers/ServiceWorkerRegistration.cpp index 9555fd3b5189..8504e709167b 100644 --- a/dom/workers/ServiceWorkerRegistration.cpp +++ b/dom/workers/ServiceWorkerRegistration.cpp @@ -7,7 +7,6 @@ #include "ServiceWorkerRegistration.h" #include "ipc/ErrorIPCUtils.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/Notification.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseWindowProxy.h" @@ -15,6 +14,7 @@ #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,6 +38,38 @@ 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(); +} + +/* static */ bool +ServiceWorkerRegistration::NotificationAPIVisible(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(); +} + //////////////////////////////////////////////////// // Main Thread implementation diff --git a/dom/workers/ServiceWorkerRegistration.h b/dom/workers/ServiceWorkerRegistration.h index 955b9b72c7d4..1e7f74404480 100644 --- a/dom/workers/ServiceWorkerRegistration.h +++ b/dom/workers/ServiceWorkerRegistration.h @@ -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" @@ -61,6 +61,13 @@ public: IMPL_EVENT_HANDLER(updatefound) + static bool + Visible(JSContext* aCx, JSObject* aObj); + + static bool + NotificationAPIVisible(JSContext* aCx, JSObject* aObj); + + static already_AddRefed CreateForMainThread(nsPIDOMWindowInner* aWindow, const nsAString& aScope); diff --git a/dom/workers/WorkerNavigator.cpp b/dom/workers/WorkerNavigator.cpp index eed9841dab08..1a22c3d45a92 100644 --- a/dom/workers/WorkerNavigator.cpp +++ b/dom/workers/WorkerNavigator.cpp @@ -5,7 +5,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/BindingUtils.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/PromiseWorkerProxy.h" #include "mozilla/dom/StorageManager.h" @@ -82,11 +81,11 @@ WorkerNavigator::GetAppName(nsString& aAppName, CallerType aCallerType) const MOZ_ASSERT(workerPrivate); if ((!mProperties.mAppNameOverridden.IsEmpty() || - DOMPreferences::ResistFingerprintingEnabled()) && + workerPrivate->ResistFingerprintingEnabled()) && !workerPrivate->UsesSystemPrincipal()) { // We will spoof this value when 'privacy.resistFingerprinting' is true. // See nsRFPService.h for spoofed value. - aAppName = DOMPreferences::ResistFingerprintingEnabled() ? + aAppName = workerPrivate->ResistFingerprintingEnabled() ? NS_LITERAL_STRING(SPOOFED_APPNAME) : mProperties.mAppNameOverridden; } else { aAppName = mProperties.mAppName; @@ -101,11 +100,11 @@ WorkerNavigator::GetAppVersion(nsString& aAppVersion, CallerType aCallerType, MOZ_ASSERT(workerPrivate); if ((!mProperties.mAppVersionOverridden.IsEmpty() || - DOMPreferences::ResistFingerprintingEnabled()) && + workerPrivate->ResistFingerprintingEnabled()) && !workerPrivate->UsesSystemPrincipal()) { // We will spoof this value when 'privacy.resistFingerprinting' is true. // See nsRFPService.h for spoofed value. - aAppVersion = DOMPreferences::ResistFingerprintingEnabled() ? + aAppVersion = workerPrivate->ResistFingerprintingEnabled() ? NS_LITERAL_STRING(SPOOFED_APPVERSION) : mProperties.mAppVersionOverridden; } else { aAppVersion = mProperties.mAppVersion; @@ -120,11 +119,11 @@ WorkerNavigator::GetPlatform(nsString& aPlatform, CallerType aCallerType, MOZ_ASSERT(workerPrivate); if ((!mProperties.mPlatformOverridden.IsEmpty() || - DOMPreferences::ResistFingerprintingEnabled()) && + workerPrivate->ResistFingerprintingEnabled()) && !workerPrivate->UsesSystemPrincipal()) { // We will spoof this value when 'privacy.resistFingerprinting' is true. // See nsRFPService.h for spoofed value. - aPlatform = DOMPreferences::ResistFingerprintingEnabled() ? + aPlatform = workerPrivate->ResistFingerprintingEnabled() ? NS_LITERAL_STRING(SPOOFED_PLATFORM) : mProperties.mPlatformOverridden; } else { aPlatform = mProperties.mPlatform; diff --git a/dom/workers/WorkerPrefs.h b/dom/workers/WorkerPrefs.h new file mode 100644 index 000000000000..1fcaaa07a528 --- /dev/null +++ b/dom/workers/WorkerPrefs.h @@ -0,0 +1,53 @@ +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set ts=8 sts=2 et sw=2 tw=80: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This is the list of the preferences that are exposed to workers. +// The format is as follows: +// +// WORKER_SIMPLE_PREF("foo.bar", FooBar, FOO_BAR, UpdaterFunction) +// +// * First argument is the name of the pref. +// * The name of the getter function. This defines a FindName() +// function that returns the value of the pref on WorkerPrivate. +// * The macro version of the name. This defines a WORKERPREF_FOO_BAR +// macro in Workers.h. +// * The name of the function that updates the new value of a pref. +// +// WORKER_PREF("foo.bar", UpdaterFunction) +// +// * First argument is the name of the pref. +// * The name of the function that updates the new value of a pref. + +#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) +WORKER_SIMPLE_PREF("browser.dom.window.dump.enabled", DumpEnabled, DUMP) +#endif +WORKER_SIMPLE_PREF("canvas.imagebitmap_extensions.enabled", ImageBitmapExtensionsEnabled, IMAGEBITMAP_EXTENSIONS_ENABLED) +WORKER_SIMPLE_PREF("dom.caches.enabled", DOMCachesEnabled, DOM_CACHES) +WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CACHES_TESTING) +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.storageManager.enabled", StorageManagerEnabled, STORAGEMANAGER_ENABLED) +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) +WORKER_SIMPLE_PREF("gfx.offscreencanvas.enabled", OffscreenCanvasEnabled, OFFSCREENCANVAS_ENABLED) +WORKER_SIMPLE_PREF("dom.webkitBlink.dirPicker.enabled", WebkitBlinkDirectoryPickerEnabled, DOM_WEBKITBLINK_DIRPICKER_WEBKITBLINK) +WORKER_SIMPLE_PREF("dom.netinfo.enabled", NetworkInformationEnabled, NETWORKINFORMATION_ENABLED) +WORKER_SIMPLE_PREF("dom.fetchObserver.enabled", FetchObserverEnabled, FETCHOBSERVER_ENABLED) +WORKER_SIMPLE_PREF("privacy.resistFingerprinting", ResistFingerprintingEnabled, RESISTFINGERPRINTING_ENABLED) +WORKER_SIMPLE_PREF("devtools.enabled", DevToolsEnabled, DEVTOOLS_ENABLED) +WORKER_PREF("intl.accept_languages", PrefLanguagesChanged) +WORKER_PREF("general.appname.override", AppNameOverrideChanged) +WORKER_PREF("general.appversion.override", AppVersionOverrideChanged) +WORKER_PREF("general.platform.override", PlatformOverrideChanged) +#ifdef JS_GC_ZEAL +WORKER_PREF("dom.workers.options.gcZeal", LoadGCZealOptions) +#endif diff --git a/dom/workers/WorkerPrivate.cpp b/dom/workers/WorkerPrivate.cpp index df265bc852e5..f40f9913c9cd 100644 --- a/dom/workers/WorkerPrivate.cpp +++ b/dom/workers/WorkerPrivate.cpp @@ -1377,6 +1377,28 @@ private: } }; +class UpdatePreferenceRunnable final : public WorkerControlRunnable +{ + WorkerPreference mPref; + bool mValue; + +public: + UpdatePreferenceRunnable(WorkerPrivate* aWorkerPrivate, + WorkerPreference aPref, + bool aValue) + : WorkerControlRunnable(aWorkerPrivate, WorkerThreadUnchangedBusyCount), + mPref(aPref), + mValue(aValue) + { } + + virtual bool + WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override + { + aWorkerPrivate->UpdatePreferenceInternal(mPref, mValue); + return true; + } +}; + class UpdateLanguagesRunnable final : public WorkerRunnable { nsTArray mLanguages; @@ -3490,6 +3512,20 @@ WorkerPrivateParent::UpdateContextOptions( } } +template +void +WorkerPrivateParent::UpdatePreference(WorkerPreference aPref, bool aValue) +{ + AssertIsOnParentThread(); + MOZ_ASSERT(aPref >= 0 && aPref < WORKERPREF_COUNT); + + RefPtr runnable = + new UpdatePreferenceRunnable(ParentAsWorkerPrivate(), aPref, aValue); + if (!runnable->Dispatch()) { + NS_WARNING("Failed to update worker preferences!"); + } +} + template void WorkerPrivateParent::UpdateLanguages(const nsTArray& aLanguages) @@ -4504,10 +4540,12 @@ WorkerPrivate::WorkerPrivate(WorkerPrivate* aParent, { if (aParent) { aParent->AssertIsOnWorkerThread(); + aParent->GetAllPreferences(mPreferences); mOnLine = aParent->OnLine(); } else { AssertIsOnMainThread(); + RuntimeService::GetDefaultPreferences(mPreferences); mOnLine = !NS_IsOffline(); } @@ -6825,6 +6863,19 @@ WorkerPrivate::UpdateLanguagesInternal(const nsTArray& aLanguages) } } +void +WorkerPrivate::UpdatePreferenceInternal(WorkerPreference aPref, bool aValue) +{ + AssertIsOnWorkerThread(); + MOZ_ASSERT(aPref >= 0 && aPref < WORKERPREF_COUNT); + + mPreferences[aPref] = aValue; + + for (uint32_t index = 0; index < mChildWorkers.Length(); index++) { + mChildWorkers[index]->UpdatePreference(aPref, aValue); + } +} + void WorkerPrivate::UpdateJSWorkerMemoryParameterInternal(JSContext* aCx, JSGCParamKey aKey, diff --git a/dom/workers/WorkerPrivate.h b/dom/workers/WorkerPrivate.h index 6dfed65a3333..f19b1509f76d 100644 --- a/dom/workers/WorkerPrivate.h +++ b/dom/workers/WorkerPrivate.h @@ -409,6 +409,9 @@ public: void UpdateLanguages(const nsTArray& aLanguages); + void + UpdatePreference(WorkerPreference aPref, bool aValue); + void UpdateJSWorkerMemoryParameter(JSGCParamKey key, uint32_t value); @@ -1076,6 +1079,7 @@ class WorkerPrivate : public WorkerPrivateParent bool mIdleGCTimerRunning; bool mWorkerScriptExecutedSuccessfully; bool mFetchHandlerWasAdded; + bool mPreferences[WORKERPREF_COUNT]; bool mOnLine; protected: @@ -1282,6 +1286,9 @@ public: void UpdateLanguagesInternal(const nsTArray& aLanguages); + void + UpdatePreferenceInternal(WorkerPreference aPref, bool aValue); + void UpdateJSWorkerMemoryParameterInternal(JSContext* aCx, JSGCParamKey key, uint32_t aValue); @@ -1404,6 +1411,18 @@ public: bool RegisterDebuggerBindings(JSContext* aCx, JS::Handle aGlobal); +#define WORKER_SIMPLE_PREF(name, getter, NAME) \ + bool \ + getter() const \ + { \ + AssertIsOnWorkerThread(); \ + return mPreferences[WORKERPREF_##NAME]; \ + } +#define WORKER_PREF(name, callback) +#include "WorkerPrefs.h" +#undef WORKER_SIMPLE_PREF +#undef WORKER_PREF + bool OnLine() const { @@ -1564,6 +1583,13 @@ private: const Sequence& aTransferable, ErrorResult& aRv); + void + GetAllPreferences(bool aPreferences[WORKERPREF_COUNT]) const + { + AssertIsOnWorkerThread(); + memcpy(aPreferences, mPreferences, WORKERPREF_COUNT * sizeof(bool)); + } + // If the worker shutdown status is equal or greater then aFailStatus, this // operation will fail and nullptr will be returned. See WorkerHolder.h for // more information about the correct value to use. diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index ca540f3755f1..f6cc2fd8b49d 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -12,7 +12,6 @@ #include "mozilla/dom/Clients.h" #include "mozilla/dom/Console.h" #include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/Fetch.h" #include "mozilla/dom/FunctionBinding.h" #include "mozilla/dom/IDBFactory.h" @@ -371,7 +370,7 @@ WorkerGlobalScope::Dump(const Optional& aString) const } #if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) - if (!DOMPreferences::DumpEnabled()) { + if (!mWorkerPrivate->DumpEnabled()) { return; } #endif @@ -480,7 +479,7 @@ WorkerGlobalScope::CreateImageBitmap(JSContext* aCx, const Sequence& aLayout, ErrorResult& aRv) { - if (!DOMPreferences::ImageBitmapExtensionsEnabled()) { + if (!ImageBitmap::ExtensionsEnabled(aCx)) { aRv.Throw(NS_ERROR_TYPE_ERR); return nullptr; } diff --git a/dom/workers/Workers.h b/dom/workers/Workers.h index ad9570413a84..01b860b99291 100644 --- a/dom/workers/Workers.h +++ b/dom/workers/Workers.h @@ -186,6 +186,16 @@ struct JSSettings } }; +enum WorkerPreference +{ +#define WORKER_SIMPLE_PREF(name, getter, NAME) WORKERPREF_ ## NAME, +#define WORKER_PREF(name, callback) +#include "mozilla/dom/WorkerPrefs.h" +#undef WORKER_SIMPLE_PREF +#undef WORKER_PREF + WORKERPREF_COUNT +}; + // Implemented in WorkerPrivate.cpp struct WorkerLoadInfo diff --git a/dom/workers/moz.build b/dom/workers/moz.build index aa98bf68d715..b36c7a6d8b2b 100644 --- a/dom/workers/moz.build +++ b/dom/workers/moz.build @@ -19,6 +19,7 @@ EXPORTS.mozilla.dom += [ 'ServiceWorkerRegistration.h', 'WorkerLocation.h', 'WorkerNavigator.h', + 'WorkerPrefs.h', 'WorkerPrivate.h', 'WorkerRunnable.h', 'WorkerScope.h', diff --git a/dom/worklet/WorkletGlobalScope.cpp b/dom/worklet/WorkletGlobalScope.cpp index 9f4c7f2df0d7..91540ab299b3 100644 --- a/dom/worklet/WorkletGlobalScope.cpp +++ b/dom/worklet/WorkletGlobalScope.cpp @@ -7,7 +7,7 @@ #include "WorkletGlobalScope.h" #include "mozilla/dom/WorkletGlobalScopeBinding.h" #include "mozilla/dom/Console.h" -#include "mozilla/dom/DOMPreferences.h" +#include "nsContentUtils.h" namespace mozilla { namespace dom { @@ -70,7 +70,7 @@ WorkletGlobalScope::GetConsole(ErrorResult& aRv) void WorkletGlobalScope::Dump(const Optional& aString) const { - if (!DOMPreferences::DumpEnabled()) { + if (!nsContentUtils::DOMWindowDumpEnabled()) { return; } diff --git a/js/xpconnect/loader/mozJSComponentLoader.cpp b/js/xpconnect/loader/mozJSComponentLoader.cpp index 76b58b74fbbf..73549f3e6cea 100644 --- a/js/xpconnect/loader/mozJSComponentLoader.cpp +++ b/js/xpconnect/loader/mozJSComponentLoader.cpp @@ -50,7 +50,6 @@ #include "mozilla/MacroForEach.h" #include "mozilla/Preferences.h" #include "mozilla/ScriptPreloader.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/ScriptSettings.h" #include "mozilla/UniquePtrExtensions.h" #include "mozilla/Unused.h" @@ -89,7 +88,7 @@ static LazyLogModule gJSCLLog("JSComponentLoader"); static bool Dump(JSContext* cx, unsigned argc, Value* vp) { - if (!mozilla::dom::DOMPreferences::DumpEnabled()) { + if (!nsContentUtils::DOMWindowDumpEnabled()) { return true; } diff --git a/js/xpconnect/src/Sandbox.cpp b/js/xpconnect/src/Sandbox.cpp index 5baefc1dfe00..c47f71c5bd6b 100644 --- a/js/xpconnect/src/Sandbox.cpp +++ b/js/xpconnect/src/Sandbox.cpp @@ -32,7 +32,6 @@ #include "mozilla/dom/cache/CacheStorage.h" #include "mozilla/dom/CSSBinding.h" #include "mozilla/dom/DirectoryBinding.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/IndexedDatabaseManager.h" #include "mozilla/dom/Fetch.h" #include "mozilla/dom/FileBinding.h" @@ -115,7 +114,7 @@ xpc::NewSandboxConstructor() static bool SandboxDump(JSContext* cx, unsigned argc, Value* vp) { - if (!DOMPreferences::DumpEnabled()) { + if (!nsContentUtils::DOMWindowDumpEnabled()) { return true; } diff --git a/js/xpconnect/src/XPCWrappedJSClass.cpp b/js/xpconnect/src/XPCWrappedJSClass.cpp index f76d29fe6e2f..65b47a413654 100644 --- a/js/xpconnect/src/XPCWrappedJSClass.cpp +++ b/js/xpconnect/src/XPCWrappedJSClass.cpp @@ -9,6 +9,7 @@ #include "xpcprivate.h" #include "jsprf.h" #include "nsArrayEnumerator.h" +#include "nsContentUtils.h" #include "nsINamed.h" #include "nsIScriptError.h" #include "nsWrapperCache.h" @@ -19,7 +20,6 @@ #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/DOMException.h" #include "mozilla/dom/DOMExceptionBinding.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "jsapi.h" @@ -948,7 +948,7 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx, } if (reportable) { - if (DOMPreferences::DumpEnabled()) { + if (nsContentUtils::DOMWindowDumpEnabled()) { static const char line[] = "************************************************************\n"; static const char preamble[] = diff --git a/js/xpconnect/src/nsXPConnect.cpp b/js/xpconnect/src/nsXPConnect.cpp index 93ddc2e4f878..8236cd3f5d26 100644 --- a/js/xpconnect/src/nsXPConnect.cpp +++ b/js/xpconnect/src/nsXPConnect.cpp @@ -23,7 +23,6 @@ #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/DOMException.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/Exceptions.h" #include "mozilla/dom/Promise.h" @@ -270,7 +269,7 @@ xpc::ErrorBase::AppendErrorDetailsTo(nsCString& error) void xpc::ErrorNote::LogToStderr() { - if (!DOMPreferences::DumpEnabled()) + if (!nsContentUtils::DOMWindowDumpEnabled()) return; nsAutoCString error; @@ -284,7 +283,7 @@ xpc::ErrorNote::LogToStderr() void xpc::ErrorReport::LogToStderr() { - if (!DOMPreferences::DumpEnabled()) + if (!nsContentUtils::DOMWindowDumpEnabled()) return; nsAutoCString error; diff --git a/layout/build/nsLayoutStatics.cpp b/layout/build/nsLayoutStatics.cpp index c4d740f447b0..abc7985d2c55 100644 --- a/layout/build/nsLayoutStatics.cpp +++ b/layout/build/nsLayoutStatics.cpp @@ -319,9 +319,6 @@ nsLayoutStatics::Initialize() mozilla::dom::IPCBlobInputStreamStorage::Initialize(); mozilla::dom::U2FTokenManager::Initialize(); - - mozilla::dom::DOMPreferences::Initialize(); - return NS_OK; } diff --git a/layout/forms/nsFileControlFrame.cpp b/layout/forms/nsFileControlFrame.cpp index 0a534513b371..57343acda4b7 100644 --- a/layout/forms/nsFileControlFrame.cpp +++ b/layout/forms/nsFileControlFrame.cpp @@ -12,7 +12,6 @@ #include "mozilla/dom/NodeInfo.h" #include "mozilla/dom/Element.h" #include "mozilla/dom/DataTransfer.h" -#include "mozilla/dom/DOMPreferences.h" #include "mozilla/dom/HTMLButtonElement.h" #include "mozilla/dom/HTMLInputElement.h" #include "mozilla/Preferences.h" @@ -355,7 +354,7 @@ nsFileControlFrame::DnDListener::GetBlobImplForWebkitDirectory(nsIDOMFileList* a HTMLInputElement* inputElement = HTMLInputElement::FromContent(mFrame->GetContent()); bool webkitDirPicker = - DOMPreferences::WebkitBlinkDirectoryPickerEnabled() && + Preferences::GetBool("dom.webkitBlink.dirPicker.enabled", false) && inputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::webkitdirectory); if (!webkitDirPicker) { return NS_OK; diff --git a/modules/libpref/Preferences.cpp b/modules/libpref/Preferences.cpp index ec4057ff8fa4..423a472f7ac7 100644 --- a/modules/libpref/Preferences.cpp +++ b/modules/libpref/Preferences.cpp @@ -4989,16 +4989,6 @@ Preferences::AddAtomicUintVarCache(Atomic* aCache, template nsresult Preferences::AddAtomicBoolVarCache(Atomic*, const char*, bool); -template nsresult -Preferences::AddAtomicBoolVarCache(Atomic*, - const char*, - bool); - -template nsresult -Preferences::AddAtomicBoolVarCache(Atomic*, - const char*, - bool); - template nsresult Preferences::AddAtomicIntVarCache(Atomic*, const char*,