Backed out 22 changesets (bug 1419771) for build bustage build/src/dom/base/FuzzingFunctions.cpp on a CLOSED TREE

Backed out changeset b2b7b46c8ad0 (bug 1419771)
Backed out changeset 0206657d2ea2 (bug 1419771)
Backed out changeset f0f4b98a07b6 (bug 1419771)
Backed out changeset 4b52904694f4 (bug 1419771)
Backed out changeset 9f40cc12d6c6 (bug 1419771)
Backed out changeset f500a61f564c (bug 1419771)
Backed out changeset 0bd9d964df8a (bug 1419771)
Backed out changeset 1397a6bbb446 (bug 1419771)
Backed out changeset 7e77a00fa8b5 (bug 1419771)
Backed out changeset 5f6df771459a (bug 1419771)
Backed out changeset 7624e70b2965 (bug 1419771)
Backed out changeset b9d674bdc723 (bug 1419771)
Backed out changeset 5e44aeda4196 (bug 1419771)
Backed out changeset 601b49f51b41 (bug 1419771)
Backed out changeset d12dc5557982 (bug 1419771)
Backed out changeset 6c863ab2e986 (bug 1419771)
Backed out changeset 0866d79873ab (bug 1419771)
Backed out changeset 8ecc91474621 (bug 1419771)
Backed out changeset 19b14deed8fe (bug 1419771)
Backed out changeset 000c8d5fbc03 (bug 1419771)
Backed out changeset 2e263a2519c5 (bug 1419771)
Backed out changeset b628d9298be8 (bug 1419771)
This commit is contained in:
Gurzau Raul 2017-12-13 23:41:49 +02:00
parent 9a740413a5
commit 321347c110
88 changed files with 670 additions and 365 deletions

View File

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

View File

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

View File

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

View File

@ -8,9 +8,6 @@
#define mozilla_dom_FuzzingFunctions
namespace mozilla {
class ErrorResult;
namespace dom {
class GlobalObject;

View File

@ -10,10 +10,6 @@
#include "mozIMozIntl.h"
#include "nsContentUtils.h"
#ifdef XP_WIN
#undef GetLocaleInfo
#endif
namespace mozilla {
namespace dom {

View File

@ -10,10 +10,6 @@
#include "nsWrapperCache.h"
#include "xpcprivate.h"
#ifdef XP_WIN
#undef GetLocaleInfo
#endif
class nsPIDOMWindowInner;
namespace mozilla {

View File

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

View File

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

View File

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

View File

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

View File

@ -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<ChannelPixelLayout>& aLayout,
ErrorResult& aRv)
{
if (!DOMPreferences::ImageBitmapExtensionsEnabled()) {
if (!ImageBitmap::ExtensionsEnabled(aCx)) {
aRv.Throw(NS_ERROR_TYPE_ERR);
return nullptr;
}

View File

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

24
dom/cache/Cache.cpp vendored
View File

@ -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<RequestOrUSVString>& 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
{

2
dom/cache/Cache.h vendored
View File

@ -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<JSObject*> aGivenProto) override;

View File

@ -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>
CacheStorage::Constructor(const GlobalObject& aGlobal,

View File

@ -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<JSObject*> aGivenProto) override;

View File

@ -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<Sequence<ImageBitmapFormat>>& aPossibleFormats,

View File

@ -152,6 +152,12 @@ public:
nsTArray<RefPtr<gfx::DataSourceSurface>>& 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;

View File

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

View File

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

View File

@ -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<JS::Value>& 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<JS::Value>& aData)
{
// Make all Console API no-op if DevTools aren't enabled.
if (!DOMPreferences::DevToolsEnabled()) {
if (!nsContentUtils::DevToolsEnabled(aCx)) {
return;
}
AssertIsOnOwningThread();

View File

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

View File

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

View File

@ -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<InternalRequest>
Request::GetInternalRequest()
{

View File

@ -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<JSObject*> aGivenProto) override
{

View File

@ -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>
Directory::Constructor(const GlobalObject& aGlobal,
const nsAString& aRealPath,

View File

@ -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<Directory>
Constructor(const GlobalObject& aGlobal,
const nsAString& aRealPath,

View File

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

View File

@ -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> 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<OwningFileOrDirect
RefPtr<DispatchChangeEventCallback> 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()
{

View File

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

View File

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

View File

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

View File

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

View File

@ -37,6 +37,8 @@ public:
NS_REALLY_FORWARD_NSIDOMEVENTTARGET(DOMEventTargetHelper)
static bool IsEnabled(JSContext* aCx, JSObject* aObj);
static Connection*
CreateForWindow(nsPIDOMWindowInner* aWindow);

View File

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

View File

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

View File

@ -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<nsPIDOMWindowInner> owner = GetOwner();
@ -297,7 +296,7 @@ PerformanceMainThread::InsertUserEntry(PerformanceEntry* aEntry)
}
markCreationEpoch = static_cast<uint64_t>(PR_Now() / PR_USEC_PER_MSEC);
if (DOMPreferences::PerformanceLoggingEnabled()) {
if (nsContentUtils::IsUserTimingLoggingEnabled()) {
Performance::LogEntry(aEntry, uri);
}
}

View File

@ -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<nsIURI> scriptURI = mWorkerPrivate->GetResolvedScriptURI();
if (!scriptURI || NS_FAILED(scriptURI->GetHost(uri))) {

View File

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

View File

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

View File

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

View File

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

View File

@ -25,6 +25,10 @@ class StorageManager final
nsCOMPtr<nsIGlobalObject> mOwner;
public:
// Return dom.quota.storageManager.enabled on main/worker thread.
static bool
PrefEnabled(JSContext* aCx, JSObject* aObj);
explicit
StorageManager(nsIGlobalObject* aGlobal);

View File

@ -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<Response> match(RequestInfo request, optional CacheQueryOptions options);

View File

@ -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<Response> match(RequestInfo request, optional CacheQueryOptions options);

View File

@ -16,7 +16,7 @@ enum FetchState {
};
[Exposed=(Window,Worker),
Func="mozilla::dom::DOMPreferences::FetchObserverEnabled"]
Func="FetchObserver::IsEnabled"]
interface FetchObserver : EventTarget {
readonly attribute FetchState state;

View File

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

View File

@ -403,10 +403,10 @@ dictionary ChannelPixelLayout {
typedef sequence<ChannelPixelLayout> ImagePixelLayout;
partial interface ImageBitmap {
[Throws, Func="mozilla::dom::DOMPreferences::ImageBitmapExtensionsEnabled"]
[Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"]
ImageBitmapFormat findOptimalFormat (optional sequence<ImageBitmapFormat> 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<ImagePixelLayout> mapDataInto (ImageBitmapFormat aFormat, BufferSource aBuffer, long aOffset);
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -22,7 +22,7 @@ interface PushManagerImpl {
Promise<PushPermissionState> 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]

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<void> showNotification(DOMString title, optional NotificationOptions options);
[Throws, Func="mozilla::dom::DOMPreferences::NotificationEnabledInServiceWorkers"]
[Throws, Func="mozilla::dom::ServiceWorkerRegistration::NotificationAPIVisible"]
Promise<sequence<Notification>> getNotifications(optional GetNotificationOptions filter);
};

View File

@ -10,7 +10,7 @@
[SecureContext,
Exposed=(Window,Worker),
Func="mozilla::dom::DOMPreferences::StorageManagerEnabled"]
Func="mozilla::dom::StorageManager::PrefEnabled"]
interface StorageManager {
[Throws]
Promise<boolean> persisted();

View File

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

View File

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

View File

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

View File

@ -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<void*>(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<void*>(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<nsString>& 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<WorkerPreference>(reinterpret_cast<uintptr_t>(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()
{

View File

@ -91,6 +91,7 @@ class RuntimeService final : public nsIObserver
nsCOMPtr<nsITimer> 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<nsString>& 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,

View File

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

View File

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

View File

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

View File

@ -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<nsIObserverService> os = services::GetObserverService();
if (os) {
os->NotifyObservers(nullptr, "service-worker-shutdown", nullptr);

View File

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

View File

@ -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<ServiceWorkerRegistration>
CreateForMainThread(nsPIDOMWindowInner* aWindow,
const nsAString& aScope);

View File

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

53
dom/workers/WorkerPrefs.h Normal file
View File

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

View File

@ -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<nsString> mLanguages;
@ -3490,6 +3512,20 @@ WorkerPrivateParent<Derived>::UpdateContextOptions(
}
}
template <class Derived>
void
WorkerPrivateParent<Derived>::UpdatePreference(WorkerPreference aPref, bool aValue)
{
AssertIsOnParentThread();
MOZ_ASSERT(aPref >= 0 && aPref < WORKERPREF_COUNT);
RefPtr<UpdatePreferenceRunnable> runnable =
new UpdatePreferenceRunnable(ParentAsWorkerPrivate(), aPref, aValue);
if (!runnable->Dispatch()) {
NS_WARNING("Failed to update worker preferences!");
}
}
template <class Derived>
void
WorkerPrivateParent<Derived>::UpdateLanguages(const nsTArray<nsString>& 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<nsString>& 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,

View File

@ -409,6 +409,9 @@ public:
void
UpdateLanguages(const nsTArray<nsString>& aLanguages);
void
UpdatePreference(WorkerPreference aPref, bool aValue);
void
UpdateJSWorkerMemoryParameter(JSGCParamKey key, uint32_t value);
@ -1076,6 +1079,7 @@ class WorkerPrivate : public WorkerPrivateParent<WorkerPrivate>
bool mIdleGCTimerRunning;
bool mWorkerScriptExecutedSuccessfully;
bool mFetchHandlerWasAdded;
bool mPreferences[WORKERPREF_COUNT];
bool mOnLine;
protected:
@ -1282,6 +1286,9 @@ public:
void
UpdateLanguagesInternal(const nsTArray<nsString>& 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<JSObject*> 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<JSObject*>& 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.

View File

@ -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<nsAString>& 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<ChannelPixelLayout>& aLayout,
ErrorResult& aRv)
{
if (!DOMPreferences::ImageBitmapExtensionsEnabled()) {
if (!ImageBitmap::ExtensionsEnabled(aCx)) {
aRv.Throw(NS_ERROR_TYPE_ERR);
return nullptr;
}

View File

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

View File

@ -19,6 +19,7 @@ EXPORTS.mozilla.dom += [
'ServiceWorkerRegistration.h',
'WorkerLocation.h',
'WorkerNavigator.h',
'WorkerPrefs.h',
'WorkerPrivate.h',
'WorkerRunnable.h',
'WorkerScope.h',

View File

@ -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<nsAString>& aString) const
{
if (!DOMPreferences::DumpEnabled()) {
if (!nsContentUtils::DOMWindowDumpEnabled()) {
return;
}

View File

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

View File

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

View File

@ -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[] =

View File

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

View File

@ -319,9 +319,6 @@ nsLayoutStatics::Initialize()
mozilla::dom::IPCBlobInputStreamStorage::Initialize();
mozilla::dom::U2FTokenManager::Initialize();
mozilla::dom::DOMPreferences::Initialize();
return NS_OK;
}

View File

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

View File

@ -4989,16 +4989,6 @@ Preferences::AddAtomicUintVarCache(Atomic<uint32_t, Order>* aCache,
template nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, Relaxed>*, const char*, bool);
template nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, ReleaseAcquire>*,
const char*,
bool);
template nsresult
Preferences::AddAtomicBoolVarCache(Atomic<bool, SequentiallyConsistent>*,
const char*,
bool);
template nsresult
Preferences::AddAtomicIntVarCache(Atomic<int32_t, Relaxed>*,
const char*,