Bug 1436744 - Get rid of WorkerCheckAPIExposureOnMainThreadRunnable, r=catalinb

This commit is contained in:
Andrea Marchesini 2018-02-12 21:02:22 +01:00
parent 3088ddd210
commit dce09604e1
8 changed files with 7 additions and 91 deletions

View file

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

View file

@ -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<PrefEnabledRunnable> runnable =
new PrefEnabledRunnable(workerPrivate,
NS_LITERAL_CSTRING("dom.enable_performance_observer"));
return runnable->Dispatch() && runnable->IsEnabled();
}
void
Performance::MemoryPressure()
{

View file

@ -9,6 +9,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/dom/DOMPrefs.h"
#include "nsCOMPtr.h"
#include "nsDOMNavigationTiming.h"

View file

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

View file

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

View file

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

View file

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

View file

@ -457,27 +457,6 @@ protected:
UniquePtr<WorkerHolder> 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