Skip to content

Commit

Permalink
Bug 1699707 - Remove DeviceProximityEvent and UserProximityEvent r=ag…
Browse files Browse the repository at this point in the history
…i,annevk,smaug

Note that this removes `window.ondeviceproximity` and `window.onuserproximity` which unexpectedly have been exposed unconditionally.

Differential Revision: https://phabricator.services.mozilla.com/D109160
  • Loading branch information
saschanaz committed Mar 22, 2021
1 parent 79390b2 commit 24e9b29
Show file tree
Hide file tree
Showing 20 changed files with 2 additions and 199 deletions.
1 change: 0 additions & 1 deletion dom/base/nsDeprecatedOperationList.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ DEPRECATED_OPERATION(ImageBitmapRenderingContext_TransferImageBitmap)
DEPRECATED_OPERATION(WindowContentUntrusted)
DEPRECATED_OPERATION(MotionEvent)
DEPRECATED_OPERATION(OrientationEvent)
DEPRECATED_OPERATION(ProximityEvent)
DEPRECATED_OPERATION(AmbientLightEvent)
DEPRECATED_OPERATION(IDBOpenDBOptions_StorageType)
DEPRECATED_OPERATION(MozBoxOrInlineBoxDisplay)
Expand Down
13 changes: 0 additions & 13 deletions dom/events/EventListenerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ void EventListenerManager::AddEventListenerInternal(
EnableDevice(eDeviceOrientation);
} else if (aTypeAtom == nsGkAtoms::onabsolutedeviceorientation) {
EnableDevice(eAbsoluteDeviceOrientation);
} else if (aTypeAtom == nsGkAtoms::ondeviceproximity ||
aTypeAtom == nsGkAtoms::onuserproximity) {
EnableDevice(eDeviceProximity);
} else if (aTypeAtom == nsGkAtoms::ondevicelight) {
EnableDevice(eDeviceLight);
} else if (aTypeAtom == nsGkAtoms::ondevicemotion) {
Expand Down Expand Up @@ -487,8 +484,6 @@ bool EventListenerManager::IsDeviceType(EventMessage aEventMessage) {
case eAbsoluteDeviceOrientation:
case eDeviceMotion:
case eDeviceLight:
case eDeviceProximity:
case eUserProximity:
#if defined(MOZ_WIDGET_ANDROID)
case eOrientationChange:
#endif
Expand Down Expand Up @@ -524,10 +519,6 @@ void EventListenerManager::EnableDevice(EventMessage aEventMessage) {
window->EnableDeviceSensor(SENSOR_ORIENTATION);
#endif
break;
case eDeviceProximity:
case eUserProximity:
window->EnableDeviceSensor(SENSOR_PROXIMITY);
break;
case eDeviceLight:
window->EnableDeviceSensor(SENSOR_LIGHT);
break;
Expand Down Expand Up @@ -573,10 +564,6 @@ void EventListenerManager::DisableDevice(EventMessage aEventMessage) {
window->DisableDeviceSensor(SENSOR_LINEAR_ACCELERATION);
window->DisableDeviceSensor(SENSOR_GYROSCOPE);
break;
case eDeviceProximity:
case eUserProximity:
window->DisableDeviceSensor(SENSOR_PROXIMITY);
break;
case eDeviceLight:
window->DisableDeviceSensor(SENSOR_LIGHT);
break;
Expand Down
4 changes: 0 additions & 4 deletions dom/events/EventNameList.h
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,6 @@ WINDOW_ONLY_EVENT(deviceorientation, eDeviceOrientation, EventNameType_None,
eBasicEventClass)
WINDOW_ONLY_EVENT(absolutedeviceorientation, eAbsoluteDeviceOrientation,
EventNameType_None, eBasicEventClass)
WINDOW_ONLY_EVENT(deviceproximity, eDeviceProximity, EventNameType_None,
eBasicEventClass)
WINDOW_ONLY_EVENT(userproximity, eUserProximity, EventNameType_None,
eBasicEventClass)
WINDOW_ONLY_EVENT(devicelight, eDeviceLight, EventNameType_None,
eBasicEventClass)
WINDOW_ONLY_EVENT(vrdisplayactivate, eVRDisplayActivate, EventNameType_None,
Expand Down
5 changes: 0 additions & 5 deletions dom/events/test/test_deviceSensor.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@
dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_GAME_ROTATION_VECTOR, window);
}

function hasProximityListeners() {
return dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_PROXIMITY, window);
}

function hasMotionListeners() {
return dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_ACCELERATION, window) ||
dss.hasWindowListener(Ci.nsIDeviceSensorData.TYPE_LINEAR_ACCELERATION, window) ||
Expand Down Expand Up @@ -117,7 +113,6 @@
});

await test_event_presence("device.sensors.ambientLight.enabled", hasLightListeners, "devicelight");
await test_event_presence("device.sensors.proximity.enabled", hasProximityListeners, "deviceproximity");
await test_event_presence("device.sensors.motion.enabled", hasMotionListeners, "devicemotion");
await test_event_presence("device.sensors.orientation.enabled", hasOrientationListeners, "deviceorientation");

Expand Down
5 changes: 1 addition & 4 deletions dom/events/test/test_disabled_events.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1359076">Mozilla Bug 1359076</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">
Expand All @@ -22,11 +22,8 @@
SpecialPowers.pushPrefEnv({"set": [
["device.sensors.orientation.enabled", false],
["device.sensors.motion.enabled", false],
["device.sensors.proximity.enabled", false],
["device.sensors.ambientLight.enabled", false]
]}, () => {
is("DeviceProximityEvent" in window, false, "DeviceProximityEvent does not exist");
is("UserProximityEvent" in window, false, "UserProximityEvent does not exist");
is("DeviceLightEvent" in window, false, "DeviceLightEvent does not exist");
is("DeviceOrientationEvent" in window, false, "DeviceOrientationEvent does not exist");
is("DeviceMotionEvent" in window, false, "DeviceMotionEvent does not exist");
Expand Down
24 changes: 1 addition & 23 deletions dom/events/test/test_eventctors_sensors.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=675884">Mozilla Bug 675884</a>
<p id="display"></p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script type="application/javascript">
Expand All @@ -23,32 +23,10 @@
["device.sensors.enabled", true],
["device.sensors.orientation.enabled", true],
["device.sensors.motion.enabled", true],
["device.sensors.proximity.enabled", true],
["device.sensors.ambientLight.enabled", true]
]}, () => {
let receivedEvent;
document.addEventListener("hello", function(e) { receivedEvent = e; }, true);
// DeviceProximityEvent
let e = new DeviceProximityEvent("hello", {min: 0, value: 1, max: 2});
is(e.type, "hello", "Wrong event type!");
ok(!e.isTrusted, "Event should not be trusted");
is(e.value, 1, "value should be 1");
is(e.min, 0, "min should be 0");
is(e.max, 2, "max should be 2");
document.dispatchEvent(e);
is(receivedEvent, e, "Wrong event!");
e = new DeviceProximityEvent("hello");
is(e.value, Infinity, "Uninitialized value should be infinity");
is(e.min, -Infinity, "Uninitialized min should be -infinity");
is(e.max, Infinity, "Uninitialized max should be infinity");

// UserProximityEvent
e = new UserProximityEvent("hello", {near: true});
is(e.type, "hello", "Wrong event type!");
ok(!e.isTrusted, "Event should not be trusted");
is(e.near, true, "near should be true");
document.dispatchEvent(e);
is(receivedEvent, e, "Wrong event!");

// DeviceLightEvent
e = new DeviceLightEvent("hello", {value: 1} );
Expand Down
54 changes: 0 additions & 54 deletions dom/system/nsDeviceSensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/DeviceLightEvent.h"
#include "mozilla/dom/DeviceOrientationEvent.h"
#include "mozilla/dom/DeviceProximityEvent.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/UserProximityEvent.h"
#include "mozilla/ErrorResult.h"

#include <cmath>
Expand Down Expand Up @@ -94,7 +92,6 @@ NS_IMETHODIMP nsDeviceSensorData::GetZ(double* aZ) {
NS_IMPL_ISUPPORTS(nsDeviceSensors, nsIDeviceSensors)

nsDeviceSensors::nsDeviceSensors() {
mIsUserProximityNear = false;
mLastDOMMotionEventTime = TimeStamp::Now();

for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
Expand Down Expand Up @@ -330,8 +327,6 @@ void nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData) {
const Orientation orient = RotationVectorToOrientation(x, y, z, w);
FireDOMOrientationEvent(target, orient.alpha, orient.beta, orient.gamma,
Orientation::kRelative);
} else if (type == nsIDeviceSensorData::TYPE_PROXIMITY) {
FireDOMProximityEvent(target, x, y, z);
} else if (type == nsIDeviceSensorData::TYPE_LIGHT) {
FireDOMLightEvent(target, x);
}
Expand All @@ -353,47 +348,6 @@ void nsDeviceSensors::FireDOMLightEvent(mozilla::dom::EventTarget* aTarget,
aTarget->DispatchEvent(*event);
}

void nsDeviceSensors::FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget,
double aValue, double aMin,
double aMax) {
DeviceProximityEventInit init;
init.mBubbles = true;
init.mCancelable = false;
init.mValue = aValue;
init.mMin = aMin;
init.mMax = aMax;
RefPtr<DeviceProximityEvent> event =
DeviceProximityEvent::Constructor(aTarget, u"deviceproximity"_ns, init);
event->SetTrusted(true);

aTarget->DispatchEvent(*event);

// Some proximity sensors only support a binary near or
// far measurement. In this case, the sensor should report
// its maximum range value in the far state and a lesser
// value in the near state.

bool near = (aValue < aMax);
if (mIsUserProximityNear != near) {
mIsUserProximityNear = near;
FireDOMUserProximityEvent(aTarget, mIsUserProximityNear);
}
}

void nsDeviceSensors::FireDOMUserProximityEvent(
mozilla::dom::EventTarget* aTarget, bool aNear) {
UserProximityEventInit init;
init.mBubbles = true;
init.mCancelable = false;
init.mNear = aNear;
RefPtr<UserProximityEvent> event =
UserProximityEvent::Constructor(aTarget, u"userproximity"_ns, init);

event->SetTrusted(true);

aTarget->DispatchEvent(*event);
}

void nsDeviceSensors::FireDOMOrientationEvent(EventTarget* aTarget,
double aAlpha, double aBeta,
double aGamma, bool aIsAbsolute) {
Expand Down Expand Up @@ -542,14 +496,6 @@ bool nsDeviceSensors::IsSensorAllowedByPref(uint32_t aType,
doc->WarnOnceAbout(DeprecatedOperations::eOrientationEvent);
}
break;
case nsIDeviceSensorData::TYPE_PROXIMITY:
// checks "device.sensors.proximity.enabled" pref
if (!StaticPrefs::device_sensors_proximity_enabled()) {
return false;
} else if (doc) {
doc->WarnOnceAbout(DeprecatedOperations::eProximityEvent, true);
}
break;
case nsIDeviceSensorData::TYPE_LIGHT:
// checks "device.sensors.ambientLight.enabled" pref
if (!StaticPrefs::device_sensors_ambientLight_enabled()) {
Expand Down
7 changes: 0 additions & 7 deletions dom/system/nsDeviceSensors.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ class nsDeviceSensors : public nsIDeviceSensors,

void FireDOMLightEvent(mozilla::dom::EventTarget* aTarget, double value);

void FireDOMProximityEvent(mozilla::dom::EventTarget* aTarget, double aValue,
double aMin, double aMax);

void FireDOMUserProximityEvent(mozilla::dom::EventTarget* aTarget,
bool aNear);

void FireDOMOrientationEvent(mozilla::dom::EventTarget* target, double aAlpha,
double aBeta, double aGamma, bool aIsAbsolute);

Expand All @@ -65,7 +59,6 @@ class nsDeviceSensors : public nsIDeviceSensors,
bool IsSensorAllowedByPref(uint32_t aType, nsIDOMWindow* aWindow);

mozilla::TimeStamp mLastDOMMotionEventTime;
bool mIsUserProximityNear;
mozilla::Maybe<DeviceAccelerationInit> mLastAcceleration;
mozilla::Maybe<DeviceAccelerationInit> mLastAccelerationIncludingGravity;
mozilla::Maybe<DeviceRotationRateInit> mLastRotationRate;
Expand Down
24 changes: 0 additions & 24 deletions dom/webidl/DeviceProximityEvent.webidl

This file was deleted.

20 changes: 0 additions & 20 deletions dom/webidl/UserProximityEvent.webidl

This file was deleted.

2 changes: 0 additions & 2 deletions dom/webidl/Window.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,6 @@ partial interface Window {
attribute EventHandler ondevicemotion;
attribute EventHandler ondeviceorientation;
attribute EventHandler onabsolutedeviceorientation;
attribute EventHandler ondeviceproximity;
attribute EventHandler onuserproximity;
attribute EventHandler ondevicelight;

void dump(DOMString str);
Expand Down
5 changes: 0 additions & 5 deletions dom/webidl/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,6 @@ with Files("UIEvent.webidl"):
with Files("URL.webidl"):
BUG_COMPONENT = ("Core", "Audio/Video")

with Files("UserProximityEvent.webidl"):
BUG_COMPONENT = ("Core", "DOM: UI Events & Focus Handling")

with Files("VTT*"):
BUG_COMPONENT = ("Core", "Audio/Video")

Expand Down Expand Up @@ -1074,7 +1071,6 @@ GENERATED_EVENTS_WEBIDL_FILES = [
"CloseEvent.webidl",
"DeviceLightEvent.webidl",
"DeviceOrientationEvent.webidl",
"DeviceProximityEvent.webidl",
"ErrorEvent.webidl",
"FontFaceSetLoadEvent.webidl",
"FormDataEvent.webidl",
Expand Down Expand Up @@ -1110,7 +1106,6 @@ GENERATED_EVENTS_WEBIDL_FILES = [
"TCPSocketEvent.webidl",
"TrackEvent.webidl",
"UDPMessageEvent.webidl",
"UserProximityEvent.webidl",
"WebGLContextEvent.webidl",
"XRInputSourceEvent.webidl",
"XRInputSourcesChangeEvent.webidl",
Expand Down
1 change: 0 additions & 1 deletion hal/HalSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace hal {
enum SensorType {
SENSOR_ORIENTATION = 0,
SENSOR_ACCELERATION = 1,
SENSOR_PROXIMITY = 2,
SENSOR_LINEAR_ACCELERATION = 3,
SENSOR_GYROSCOPE = 4,
SENSOR_LIGHT = 5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ public static synchronized void appendAppNotesToCrashReport(final String notes)
private static Sensor gLinearAccelerometerSensor;
private static Sensor gGyroscopeSensor;
private static Sensor gOrientationSensor;
private static Sensor gProximitySensor;
private static Sensor gLightSensor;
private static Sensor gRotationVectorSensor;
private static Sensor gGameRotationVectorSensor;
Expand Down Expand Up @@ -401,12 +400,6 @@ public void onSensorChanged(final SensorEvent s) {
z = (float) Math.toDegrees(s.values[2]);
break;

case Sensor.TYPE_PROXIMITY:
halType = GeckoHalDefines.SENSOR_PROXIMITY;
x = s.values[0];
z = s.sensor.getMaximumRange();
break;

case Sensor.TYPE_LIGHT:
halType = GeckoHalDefines.SENSOR_LIGHT;
x = s.values[0];
Expand Down Expand Up @@ -618,17 +611,6 @@ private static void enableSensor(final int aSensortype) {
}
break;

case GeckoHalDefines.SENSOR_PROXIMITY:
if (gProximitySensor == null) {
gProximitySensor = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
}
if (gProximitySensor != null) {
sm.registerListener(sAndroidListeners,
gProximitySensor,
SensorManager.SENSOR_DELAY_NORMAL);
}
break;

case GeckoHalDefines.SENSOR_LIGHT:
if (gLightSensor == null) {
gLightSensor = sm.getDefaultSensor(Sensor.TYPE_LIGHT);
Expand Down Expand Up @@ -702,12 +684,6 @@ private static void disableSensor(final int aSensortype) {
}
break;

case GeckoHalDefines.SENSOR_PROXIMITY:
if (gProximitySensor != null) {
sm.unregisterListener(sAndroidListeners, gProximitySensor);
}
break;

case GeckoHalDefines.SENSOR_LIGHT:
if (gLightSensor != null) {
sm.unregisterListener(sAndroidListeners, gLightSensor);
Expand Down
Loading

0 comments on commit 24e9b29

Please sign in to comment.