mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 13:21:05 +00:00
Bug 1419771 - Introduce DOMPrefs, a thread-safe access to preferences for DOM - part 1 - dump enabled, r=asuth
This commit is contained in:
parent
07b93afa55
commit
1a7b13aab4
51
dom/base/DOMPrefs.cpp
Normal file
51
dom/base/DOMPrefs.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
/* -*- 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 "DOMPrefs.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
#define PREF(name, pref) \
|
||||
/* static */ bool \
|
||||
DOMPrefs::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
|
||||
DOMPrefs::DumpEnabled()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
#undef PREF
|
||||
|
||||
#define PREF_WEBIDL(name) \
|
||||
/* static */ bool \
|
||||
DOMPrefs::name(JSContext* aCx, JSObject* aObj) \
|
||||
{ \
|
||||
return DOMPrefs::name(); \
|
||||
}
|
||||
|
||||
// It will be useful, eventually.
|
||||
|
||||
#undef PREF_WEBIDL
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
23
dom/base/DOMPrefs.h
Normal file
23
dom/base/DOMPrefs.h
Normal file
@ -0,0 +1,23 @@
|
||||
/* -*- 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_DOMPrefs_h
|
||||
#define mozilla_dom_DOMPrefs_h
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class DOMPrefs final
|
||||
{
|
||||
public:
|
||||
// Returns true if the browser.dom.window.dump.enabled pref is set.
|
||||
static bool DumpEnabled();
|
||||
};
|
||||
|
||||
} // dom namespace
|
||||
} // mozilla namespace
|
||||
|
||||
#endif // mozilla_dom_DOMPrefs_h
|
@ -172,6 +172,7 @@ EXPORTS.mozilla.dom += [
|
||||
'DOMMatrix.h',
|
||||
'DOMParser.h',
|
||||
'DOMPoint.h',
|
||||
'DOMPrefs.h',
|
||||
'DOMQuad.h',
|
||||
'DOMRect.h',
|
||||
'DOMRequest.h',
|
||||
@ -250,6 +251,7 @@ UNIFIED_SOURCES += [
|
||||
'DOMMatrix.cpp',
|
||||
'DOMParser.cpp',
|
||||
'DOMPoint.cpp',
|
||||
'DOMPrefs.cpp',
|
||||
'DOMQuad.cpp',
|
||||
'DOMRect.cpp',
|
||||
'DOMRequest.cpp',
|
||||
|
@ -334,10 +334,6 @@ 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");
|
||||
@ -694,11 +690,6 @@ 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);
|
||||
|
||||
@ -7586,19 +7577,6 @@ 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()
|
||||
{
|
||||
|
@ -2695,11 +2695,6 @@ 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.
|
||||
*/
|
||||
@ -3472,9 +3467,6 @@ 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;
|
||||
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/ScriptPreloader.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/File.h"
|
||||
#include "mozilla/dom/MessagePort.h"
|
||||
#include "mozilla/dom/ContentParent.h"
|
||||
@ -805,7 +806,7 @@ nsFrameMessageManager::ReleaseCachedProcesses()
|
||||
NS_IMETHODIMP
|
||||
nsFrameMessageManager::Dump(const nsAString& aStr)
|
||||
{
|
||||
if (!nsContentUtils::DOMWindowDumpEnabled()) {
|
||||
if (!DOMPrefs::DumpEnabled()) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -17,6 +17,7 @@
|
||||
#include "nsHistory.h"
|
||||
#include "nsDOMNavigationTiming.h"
|
||||
#include "nsIDOMStorageManager.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/LocalStorage.h"
|
||||
#include "mozilla/dom/Storage.h"
|
||||
#include "mozilla/dom/IdleRequest.h"
|
||||
@ -3520,7 +3521,7 @@ nsGlobalWindowInner::GetFullScreen()
|
||||
void
|
||||
nsGlobalWindowInner::Dump(const nsAString& aStr)
|
||||
{
|
||||
if (!nsContentUtils::DOMWindowDumpEnabled()) {
|
||||
if (!DOMPrefs::DumpEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,9 +21,6 @@
|
||||
// * 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)
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include "mozilla/dom/Clients.h"
|
||||
#include "mozilla/dom/Console.h"
|
||||
#include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/Fetch.h"
|
||||
#include "mozilla/dom/FunctionBinding.h"
|
||||
#include "mozilla/dom/IDBFactory.h"
|
||||
@ -371,7 +372,7 @@ WorkerGlobalScope::Dump(const Optional<nsAString>& aString) const
|
||||
}
|
||||
|
||||
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
|
||||
if (!mWorkerPrivate->DumpEnabled()) {
|
||||
if (!DOMPrefs::DumpEnabled()) {
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "WorkletGlobalScope.h"
|
||||
#include "mozilla/dom/WorkletGlobalScopeBinding.h"
|
||||
#include "mozilla/dom/Console.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
@ -71,7 +71,7 @@ WorkletGlobalScope::GetConsole(ErrorResult& aRv)
|
||||
void
|
||||
WorkletGlobalScope::Dump(const Optional<nsAString>& aString) const
|
||||
{
|
||||
if (!nsContentUtils::DOMWindowDumpEnabled()) {
|
||||
if (!DOMPrefs::DumpEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "mozilla/MacroForEach.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/ScriptPreloader.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
#include "mozilla/UniquePtrExtensions.h"
|
||||
#include "mozilla/Unused.h"
|
||||
@ -88,7 +89,7 @@ static LazyLogModule gJSCLLog("JSComponentLoader");
|
||||
static bool
|
||||
Dump(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
if (!nsContentUtils::DOMWindowDumpEnabled()) {
|
||||
if (!mozilla::dom::DOMPrefs::DumpEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -32,6 +32,7 @@
|
||||
#include "mozilla/dom/cache/CacheStorage.h"
|
||||
#include "mozilla/dom/CSSBinding.h"
|
||||
#include "mozilla/dom/DirectoryBinding.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/IndexedDatabaseManager.h"
|
||||
#include "mozilla/dom/Fetch.h"
|
||||
#include "mozilla/dom/FileBinding.h"
|
||||
@ -114,7 +115,7 @@ xpc::NewSandboxConstructor()
|
||||
static bool
|
||||
SandboxDump(JSContext* cx, unsigned argc, Value* vp)
|
||||
{
|
||||
if (!nsContentUtils::DOMWindowDumpEnabled()) {
|
||||
if (!DOMPrefs::DumpEnabled()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@
|
||||
#include "xpcprivate.h"
|
||||
#include "jsprf.h"
|
||||
#include "nsArrayEnumerator.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "nsINamed.h"
|
||||
#include "nsIScriptError.h"
|
||||
#include "nsWrapperCache.h"
|
||||
@ -20,6 +19,7 @@
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/DOMException.h"
|
||||
#include "mozilla/dom/DOMExceptionBinding.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/jsipc/CrossProcessObjectWrappers.h"
|
||||
|
||||
#include "jsapi.h"
|
||||
@ -948,7 +948,7 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
|
||||
}
|
||||
|
||||
if (reportable) {
|
||||
if (nsContentUtils::DOMWindowDumpEnabled()) {
|
||||
if (DOMPrefs::DumpEnabled()) {
|
||||
static const char line[] =
|
||||
"************************************************************\n";
|
||||
static const char preamble[] =
|
||||
|
@ -23,6 +23,7 @@
|
||||
|
||||
#include "mozilla/dom/BindingUtils.h"
|
||||
#include "mozilla/dom/DOMException.h"
|
||||
#include "mozilla/dom/DOMPrefs.h"
|
||||
#include "mozilla/dom/Exceptions.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
|
||||
@ -269,7 +270,7 @@ xpc::ErrorBase::AppendErrorDetailsTo(nsCString& error)
|
||||
void
|
||||
xpc::ErrorNote::LogToStderr()
|
||||
{
|
||||
if (!nsContentUtils::DOMWindowDumpEnabled())
|
||||
if (!DOMPrefs::DumpEnabled())
|
||||
return;
|
||||
|
||||
nsAutoCString error;
|
||||
@ -283,7 +284,7 @@ xpc::ErrorNote::LogToStderr()
|
||||
void
|
||||
xpc::ErrorReport::LogToStderr()
|
||||
{
|
||||
if (!nsContentUtils::DOMWindowDumpEnabled())
|
||||
if (!DOMPrefs::DumpEnabled())
|
||||
return;
|
||||
|
||||
nsAutoCString error;
|
||||
|
Loading…
Reference in New Issue
Block a user