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

This commit is contained in:
Andrea Marchesini 2017-12-13 14:02:44 -06:00
Родитель 606779ec4e
Коммит 6b770adcfa
14 изменённых файлов: 94 добавлений и 44 удалений

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

@ -0,0 +1,52 @@
/* -*- 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 {
#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
#undef PREF
#define PREF_WEBIDL(name) \
/* static */ bool \
DOMPreferences::name(JSContext* aCx, JSObject* aObj) \
{ \
return DOMPreferences::name(); \
}
// It will be useful, eventually.
#undef PREF_WEBIDL
} // dom namespace
} // mozilla namespace

23
dom/base/DOMPreferences.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_DOMPreferences_h
#define mozilla_dom_DOMPreferences_h
namespace mozilla {
namespace dom {
class DOMPreferences final
{
public:
// Returns true if the browser.dom.window.dump.enabled pref is set.
static bool DumpEnabled();
};
} // dom namespace
} // mozilla namespace
#endif // mozilla_dom_DOMPreferences_h

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

@ -171,6 +171,7 @@ EXPORTS.mozilla.dom += [
'DOMMatrix.h', 'DOMMatrix.h',
'DOMParser.h', 'DOMParser.h',
'DOMPoint.h', 'DOMPoint.h',
'DOMPreferences.h',
'DOMQuad.h', 'DOMQuad.h',
'DOMRect.h', 'DOMRect.h',
'DOMRequest.h', 'DOMRequest.h',
@ -248,6 +249,7 @@ UNIFIED_SOURCES += [
'DOMMatrix.cpp', 'DOMMatrix.cpp',
'DOMParser.cpp', 'DOMParser.cpp',
'DOMPoint.cpp', 'DOMPoint.cpp',
'DOMPreferences.cpp',
'DOMQuad.cpp', 'DOMQuad.cpp',
'DOMRect.cpp', 'DOMRect.cpp',
'DOMRequest.cpp', 'DOMRequest.cpp',

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

@ -337,10 +337,6 @@ nsIParser* nsContentUtils::sXMLFragmentParser = nullptr;
nsIFragmentContentSink* nsContentUtils::sXMLFragmentSink = nullptr; nsIFragmentContentSink* nsContentUtils::sXMLFragmentSink = nullptr;
bool nsContentUtils::sFragmentParsingActive = false; bool nsContentUtils::sFragmentParsingActive = false;
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
bool nsContentUtils::sDOMWindowDumpEnabled;
#endif
bool nsContentUtils::sDoNotTrackEnabled = false; bool nsContentUtils::sDoNotTrackEnabled = false;
mozilla::LazyLogModule nsContentUtils::sDOMDumpLog("Dump"); mozilla::LazyLogModule nsContentUtils::sDOMDumpLog("Dump");
@ -699,11 +695,6 @@ nsContentUtils::Init()
"network.cookie.cookieBehavior", "network.cookie.cookieBehavior",
nsICookieService::BEHAVIOR_ACCEPT); nsICookieService::BEHAVIOR_ACCEPT);
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
Preferences::AddBoolVarCache(&sDOMWindowDumpEnabled,
"browser.dom.window.dump.enabled");
#endif
Preferences::AddBoolVarCache(&sDoNotTrackEnabled, Preferences::AddBoolVarCache(&sDoNotTrackEnabled,
"privacy.donottrackheader.enabled", false); "privacy.donottrackheader.enabled", false);
@ -7611,19 +7602,6 @@ nsContentUtils::IsAllowedNonCorsContentType(const nsACString& aHeaderValue)
contentType.LowerCaseEqualsLiteral("multipart/form-data"); 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 bool
nsContentUtils::DoNotTrackEnabled() nsContentUtils::DoNotTrackEnabled()
{ {

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

@ -2690,11 +2690,6 @@ public:
*/ */
static mozilla::HTMLEditor* GetHTMLEditor(nsPresContext* aPresContext); 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. * Returns true if the privacy.donottrackheader.enabled pref is set.
*/ */
@ -3474,9 +3469,6 @@ private:
// bytecode out of the nsCacheInfoChannel. // bytecode out of the nsCacheInfoChannel.
static nsCString* sJSBytecodeMimeType; static nsCString* sJSBytecodeMimeType;
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
static bool sDOMWindowDumpEnabled;
#endif
static bool sDoNotTrackEnabled; static bool sDoNotTrackEnabled;
static mozilla::LazyLogModule sDOMDumpLog; static mozilla::LazyLogModule sDOMDumpLog;

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

@ -36,6 +36,7 @@
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/ScriptPreloader.h" #include "mozilla/ScriptPreloader.h"
#include "mozilla/Telemetry.h" #include "mozilla/Telemetry.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/dom/File.h" #include "mozilla/dom/File.h"
#include "mozilla/dom/MessagePort.h" #include "mozilla/dom/MessagePort.h"
#include "mozilla/dom/ContentParent.h" #include "mozilla/dom/ContentParent.h"
@ -805,7 +806,7 @@ nsFrameMessageManager::ReleaseCachedProcesses()
NS_IMETHODIMP NS_IMETHODIMP
nsFrameMessageManager::Dump(const nsAString& aStr) nsFrameMessageManager::Dump(const nsAString& aStr)
{ {
if (!nsContentUtils::DOMWindowDumpEnabled()) { if (!DOMPreferences::DumpEnabled()) {
return NS_OK; return NS_OK;
} }

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

@ -17,6 +17,7 @@
#include "nsHistory.h" #include "nsHistory.h"
#include "nsDOMNavigationTiming.h" #include "nsDOMNavigationTiming.h"
#include "nsIDOMStorageManager.h" #include "nsIDOMStorageManager.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/dom/LocalStorage.h" #include "mozilla/dom/LocalStorage.h"
#include "mozilla/dom/Storage.h" #include "mozilla/dom/Storage.h"
#include "mozilla/dom/IdleRequest.h" #include "mozilla/dom/IdleRequest.h"
@ -3382,7 +3383,7 @@ nsGlobalWindowInner::GetFullScreen()
void void
nsGlobalWindowInner::Dump(const nsAString& aStr) nsGlobalWindowInner::Dump(const nsAString& aStr)
{ {
if (!nsContentUtils::DOMWindowDumpEnabled()) { if (!DOMPreferences::DumpEnabled()) {
return; return;
} }

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

@ -21,9 +21,6 @@
// * First argument is the name of the pref. // * First argument is the name of the pref.
// * The name of the function that updates the new value of a 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("canvas.imagebitmap_extensions.enabled", ImageBitmapExtensionsEnabled, IMAGEBITMAP_EXTENSIONS_ENABLED)
WORKER_SIMPLE_PREF("dom.caches.enabled", DOMCachesEnabled, DOM_CACHES) WORKER_SIMPLE_PREF("dom.caches.enabled", DOMCachesEnabled, DOM_CACHES)
WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CACHES_TESTING) WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CACHES_TESTING)

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

@ -12,6 +12,7 @@
#include "mozilla/dom/Clients.h" #include "mozilla/dom/Clients.h"
#include "mozilla/dom/Console.h" #include "mozilla/dom/Console.h"
#include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h" #include "mozilla/dom/DedicatedWorkerGlobalScopeBinding.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/dom/Fetch.h" #include "mozilla/dom/Fetch.h"
#include "mozilla/dom/FunctionBinding.h" #include "mozilla/dom/FunctionBinding.h"
#include "mozilla/dom/IDBFactory.h" #include "mozilla/dom/IDBFactory.h"
@ -370,7 +371,7 @@ WorkerGlobalScope::Dump(const Optional<nsAString>& aString) const
} }
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP)) #if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
if (!mWorkerPrivate->DumpEnabled()) { if (!DOMPreferences::DumpEnabled()) {
return; return;
} }
#endif #endif

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

@ -7,7 +7,7 @@
#include "WorkletGlobalScope.h" #include "WorkletGlobalScope.h"
#include "mozilla/dom/WorkletGlobalScopeBinding.h" #include "mozilla/dom/WorkletGlobalScopeBinding.h"
#include "mozilla/dom/Console.h" #include "mozilla/dom/Console.h"
#include "nsContentUtils.h" #include "mozilla/dom/DOMPreferences.h"
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
@ -70,7 +70,7 @@ WorkletGlobalScope::GetConsole(ErrorResult& aRv)
void void
WorkletGlobalScope::Dump(const Optional<nsAString>& aString) const WorkletGlobalScope::Dump(const Optional<nsAString>& aString) const
{ {
if (!nsContentUtils::DOMWindowDumpEnabled()) { if (!DOMPreferences::DumpEnabled()) {
return; return;
} }

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

@ -50,6 +50,7 @@
#include "mozilla/MacroForEach.h" #include "mozilla/MacroForEach.h"
#include "mozilla/Preferences.h" #include "mozilla/Preferences.h"
#include "mozilla/ScriptPreloader.h" #include "mozilla/ScriptPreloader.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/dom/ScriptSettings.h" #include "mozilla/dom/ScriptSettings.h"
#include "mozilla/UniquePtrExtensions.h" #include "mozilla/UniquePtrExtensions.h"
#include "mozilla/Unused.h" #include "mozilla/Unused.h"
@ -88,7 +89,7 @@ static LazyLogModule gJSCLLog("JSComponentLoader");
static bool static bool
Dump(JSContext* cx, unsigned argc, Value* vp) Dump(JSContext* cx, unsigned argc, Value* vp)
{ {
if (!nsContentUtils::DOMWindowDumpEnabled()) { if (!mozilla::dom::DOMPreferences::DumpEnabled()) {
return true; return true;
} }

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

@ -32,6 +32,7 @@
#include "mozilla/dom/cache/CacheStorage.h" #include "mozilla/dom/cache/CacheStorage.h"
#include "mozilla/dom/CSSBinding.h" #include "mozilla/dom/CSSBinding.h"
#include "mozilla/dom/DirectoryBinding.h" #include "mozilla/dom/DirectoryBinding.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/dom/IndexedDatabaseManager.h" #include "mozilla/dom/IndexedDatabaseManager.h"
#include "mozilla/dom/Fetch.h" #include "mozilla/dom/Fetch.h"
#include "mozilla/dom/FileBinding.h" #include "mozilla/dom/FileBinding.h"
@ -114,7 +115,7 @@ xpc::NewSandboxConstructor()
static bool static bool
SandboxDump(JSContext* cx, unsigned argc, Value* vp) SandboxDump(JSContext* cx, unsigned argc, Value* vp)
{ {
if (!nsContentUtils::DOMWindowDumpEnabled()) { if (!DOMPreferences::DumpEnabled()) {
return true; return true;
} }

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

@ -9,7 +9,6 @@
#include "xpcprivate.h" #include "xpcprivate.h"
#include "jsprf.h" #include "jsprf.h"
#include "nsArrayEnumerator.h" #include "nsArrayEnumerator.h"
#include "nsContentUtils.h"
#include "nsINamed.h" #include "nsINamed.h"
#include "nsIScriptError.h" #include "nsIScriptError.h"
#include "nsWrapperCache.h" #include "nsWrapperCache.h"
@ -20,6 +19,7 @@
#include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMException.h" #include "mozilla/dom/DOMException.h"
#include "mozilla/dom/DOMExceptionBinding.h" #include "mozilla/dom/DOMExceptionBinding.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/jsipc/CrossProcessObjectWrappers.h" #include "mozilla/jsipc/CrossProcessObjectWrappers.h"
#include "jsapi.h" #include "jsapi.h"
@ -948,7 +948,7 @@ nsXPCWrappedJSClass::CheckForException(XPCCallContext & ccx,
} }
if (reportable) { if (reportable) {
if (nsContentUtils::DOMWindowDumpEnabled()) { if (DOMPreferences::DumpEnabled()) {
static const char line[] = static const char line[] =
"************************************************************\n"; "************************************************************\n";
static const char preamble[] = static const char preamble[] =

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

@ -23,6 +23,7 @@
#include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/DOMException.h" #include "mozilla/dom/DOMException.h"
#include "mozilla/dom/DOMPreferences.h"
#include "mozilla/dom/Exceptions.h" #include "mozilla/dom/Exceptions.h"
#include "mozilla/dom/Promise.h" #include "mozilla/dom/Promise.h"
@ -269,7 +270,7 @@ xpc::ErrorBase::AppendErrorDetailsTo(nsCString& error)
void void
xpc::ErrorNote::LogToStderr() xpc::ErrorNote::LogToStderr()
{ {
if (!nsContentUtils::DOMWindowDumpEnabled()) if (!DOMPreferences::DumpEnabled())
return; return;
nsAutoCString error; nsAutoCString error;
@ -283,7 +284,7 @@ xpc::ErrorNote::LogToStderr()
void void
xpc::ErrorReport::LogToStderr() xpc::ErrorReport::LogToStderr()
{ {
if (!nsContentUtils::DOMWindowDumpEnabled()) if (!DOMPreferences::DumpEnabled())
return; return;
nsAutoCString error; nsAutoCString error;