diff --git a/dom/base/DOMPrefsInternal.h b/dom/base/DOMPrefsInternal.h index 463babfc2ef6..94d6a1073141 100644 --- a/dom/base/DOMPrefsInternal.h +++ b/dom/base/DOMPrefsInternal.h @@ -39,6 +39,7 @@ DOM_PREF(NetworkInformationEnabled, "dom.netinfo.enabled") DOM_PREF(FetchObserverEnabled, "dom.fetchObserver.enabled") DOM_PREF(ResistFingerprintingEnabled, "privacy.resistFingerprinting") DOM_PREF(DevToolsEnabled, "devtools.enabled") +DOM_PREF(PerformanceObserverEnabled, "dom.enable_performance_observer") DOM_WEBIDL_PREF(ImageBitmapExtensionsEnabled) DOM_WEBIDL_PREF(DOMCachesEnabled) @@ -54,3 +55,4 @@ DOM_WEBIDL_PREF(OffscreenCanvasEnabled) DOM_WEBIDL_PREF(WebkitBlinkDirectoryPickerEnabled) DOM_WEBIDL_PREF(NetworkInformationEnabled) DOM_WEBIDL_PREF(FetchObserverEnabled) +DOM_WEBIDL_PREF(PerformanceObserverEnabled) diff --git a/dom/performance/Performance.cpp b/dom/performance/Performance.cpp index 3b35967ce62f..c241123adbcf 100644 --- a/dom/performance/Performance.cpp +++ b/dom/performance/Performance.cpp @@ -36,38 +36,6 @@ namespace mozilla { namespace dom { -namespace { - -class PrefEnabledRunnable final - : public WorkerCheckAPIExposureOnMainThreadRunnable -{ -public: - PrefEnabledRunnable(WorkerPrivate* aWorkerPrivate, - const nsCString& aPrefName) - : WorkerCheckAPIExposureOnMainThreadRunnable(aWorkerPrivate) - , mEnabled(false) - , mPrefName(aPrefName) - { } - - bool MainThreadRun() override - { - MOZ_ASSERT(NS_IsMainThread()); - mEnabled = Preferences::GetBool(mPrefName.get(), false); - return true; - } - - bool IsEnabled() const - { - return mEnabled; - } - -private: - bool mEnabled; - nsCString mPrefName; -}; - -} // anonymous namespace - NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(Performance) NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper) @@ -539,24 +507,6 @@ Performance::QueueEntry(PerformanceEntry* aEntry) } } -/* static */ bool -Performance::IsObserverEnabled(JSContext* aCx, JSObject* aGlobal) -{ - if (NS_IsMainThread()) { - return Preferences::GetBool("dom.enable_performance_observer", false); - } - - WorkerPrivate* workerPrivate = GetCurrentThreadWorkerPrivate(); - MOZ_ASSERT(workerPrivate); - workerPrivate->AssertIsOnWorkerThread(); - - RefPtr runnable = - new PrefEnabledRunnable(workerPrivate, - NS_LITERAL_CSTRING("dom.enable_performance_observer")); - - return runnable->Dispatch() && runnable->IsEnabled(); -} - void Performance::MemoryPressure() { diff --git a/dom/performance/Performance.h b/dom/performance/Performance.h index 0bfe0d434195..2a529bd4a85e 100644 --- a/dom/performance/Performance.h +++ b/dom/performance/Performance.h @@ -9,6 +9,7 @@ #include "mozilla/Attributes.h" #include "mozilla/DOMEventTargetHelper.h" +#include "mozilla/dom/DOMPrefs.h" #include "nsCOMPtr.h" #include "nsDOMNavigationTiming.h" diff --git a/dom/performance/PerformanceObserverEntryList.h b/dom/performance/PerformanceObserverEntryList.h index e78ce7dfb326..e693b5522802 100644 --- a/dom/performance/PerformanceObserverEntryList.h +++ b/dom/performance/PerformanceObserverEntryList.h @@ -11,6 +11,7 @@ #include "nsISupports.h" #include "nsTArray.h" #include "nsWrapperCache.h" +#include "mozilla/dom/DOMPrefs.h" #include "mozilla/dom/PerformanceEntryBinding.h" namespace mozilla { diff --git a/dom/webidl/PerformanceObserver.webidl b/dom/webidl/PerformanceObserver.webidl index e275904e8693..7e6f370de017 100644 --- a/dom/webidl/PerformanceObserver.webidl +++ b/dom/webidl/PerformanceObserver.webidl @@ -15,7 +15,7 @@ dictionary PerformanceObserverInit { callback PerformanceObserverCallback = void (PerformanceObserverEntryList entries, PerformanceObserver observer); -[Func="Performance::IsObserverEnabled", +[Func="mozilla::dom::DOMPrefs::PerformanceObserverEnabled", Constructor(PerformanceObserverCallback callback), Exposed=(Window,Worker)] interface PerformanceObserver { diff --git a/dom/webidl/PerformanceObserverEntryList.webidl b/dom/webidl/PerformanceObserverEntryList.webidl index cff4ee1b034a..e944535d233a 100644 --- a/dom/webidl/PerformanceObserverEntryList.webidl +++ b/dom/webidl/PerformanceObserverEntryList.webidl @@ -14,7 +14,8 @@ dictionary PerformanceEntryFilterOptions { DOMString initiatorType; }; -[Func="Performance::IsObserverEnabled", Exposed=(Window,Worker)] +[Func="mozilla::dom::DOMPrefs::PerformanceObserverEnabled", + Exposed=(Window,Worker)] interface PerformanceObserverEntryList { PerformanceEntryList getEntries(optional PerformanceEntryFilterOptions filter); PerformanceEntryList getEntriesByType(DOMString entryType); diff --git a/dom/workers/WorkerRunnable.cpp b/dom/workers/WorkerRunnable.cpp index e14222e52e5b..17638b8228ae 100644 --- a/dom/workers/WorkerRunnable.cpp +++ b/dom/workers/WorkerRunnable.cpp @@ -626,24 +626,6 @@ WorkerMainThreadRunnable::Run() return NS_OK; } -WorkerCheckAPIExposureOnMainThreadRunnable::WorkerCheckAPIExposureOnMainThreadRunnable(WorkerPrivate* aWorkerPrivate): - WorkerMainThreadRunnable(aWorkerPrivate, - NS_LITERAL_CSTRING("WorkerCheckAPIExposureOnMainThread")) -{} - -WorkerCheckAPIExposureOnMainThreadRunnable::~WorkerCheckAPIExposureOnMainThreadRunnable() -{} - -bool -WorkerCheckAPIExposureOnMainThreadRunnable::Dispatch() -{ - ErrorResult rv; - WorkerMainThreadRunnable::Dispatch(Terminating, rv); - bool ok = !rv.Failed(); - rv.SuppressException(); - return ok; -} - bool WorkerSameThreadRunnable::PreDispatch(WorkerPrivate* aWorkerPrivate) { diff --git a/dom/workers/WorkerRunnable.h b/dom/workers/WorkerRunnable.h index 29b570e29683..ae571e269bcf 100644 --- a/dom/workers/WorkerRunnable.h +++ b/dom/workers/WorkerRunnable.h @@ -457,27 +457,6 @@ protected: UniquePtr mWorkerHolder; }; -// Class for checking API exposure. This totally violates the "MUST" in the -// comments on WorkerMainThreadRunnable::Dispatch, because API exposure checks -// can't throw. Maybe we should change it so they _could_ throw. But for now -// we are bad people and should be ashamed of ourselves. Let's hope none of -// them happen while a worker is shutting down. -// -// Do NOT copy what this class is doing elsewhere. Just don't. -class WorkerCheckAPIExposureOnMainThreadRunnable - : public WorkerMainThreadRunnable -{ -public: - explicit - WorkerCheckAPIExposureOnMainThreadRunnable(WorkerPrivate* aWorkerPrivate); - virtual - ~WorkerCheckAPIExposureOnMainThreadRunnable(); - - // Returns whether the dispatch succeeded. If this returns false, the API - // should not be exposed. - bool Dispatch(); -}; - // This runnable is used to stop a sync loop and it's meant to be used on the // main-thread only. As sync loops keep the busy count incremented as long as // they run this runnable does not modify the busy count