diff --git a/dom/system/nsDeviceSensors.cpp b/dom/system/nsDeviceSensors.cpp index bb8b28068f04..3faf6185e73f 100644 --- a/dom/system/nsDeviceSensors.cpp +++ b/dom/system/nsDeviceSensors.cpp @@ -7,6 +7,7 @@ #include "mozilla/Hal.h" #include "mozilla/HalSensor.h" +#include "nsContentUtils.h" #include "nsDeviceSensors.h" #include "nsIDOMEvent.h" @@ -128,7 +129,7 @@ nsDeviceSensors::~nsDeviceSensors() NS_IMETHODIMP nsDeviceSensors::HasWindowListener(uint32_t aType, nsIDOMWindow *aWindow, bool *aRetVal) { - if (!mEnabled) + if (AreSensorEventsDisabled(aWindow)) *aRetVal = false; else *aRetVal = mWindowListeners[aType]->IndexOf(aWindow) != NoIndex; @@ -169,7 +170,7 @@ static bool sTestSensorEvents = false; NS_IMETHODIMP nsDeviceSensors::AddWindowListener(uint32_t aType, nsIDOMWindow *aWindow) { - if (!mEnabled) + if (AreSensorEventsDisabled(aWindow)) return NS_OK; if (mWindowListeners[aType]->IndexOf(aWindow) != NoIndex) @@ -567,3 +568,19 @@ nsDeviceSensors::FireDOMMotionEvent(nsIDOMDocument *domdoc, mLastAcceleration.reset(); mLastDOMMotionEventTime = TimeStamp::Now(); } + +bool +nsDeviceSensors::AreSensorEventsDisabled(nsIDOMWindow* aWindow) +{ + if (!mEnabled) { + return true; + } + + nsCOMPtr window = do_QueryInterface(aWindow); + + if (!window) { + return false; + } + + return nsContentUtils::ShouldResistFingerprinting(window->GetDocShell()); +} diff --git a/dom/system/nsDeviceSensors.h b/dom/system/nsDeviceSensors.h index bed6cd69d9ef..1596f1428fcd 100644 --- a/dom/system/nsDeviceSensors.h +++ b/dom/system/nsDeviceSensors.h @@ -74,6 +74,8 @@ private: return mWindowListeners[aType]->Length() > 0; } + bool AreSensorEventsDisabled(nsIDOMWindow* aWindow); + mozilla::TimeStamp mLastDOMMotionEventTime; bool mIsUserProximityNear; mozilla::Maybe mLastAcceleration;