mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-05 00:25:27 +00:00
Bug 742395 - restrict device sensor events to windows. r=smaug
This commit is contained in:
parent
ddd76bb22d
commit
ffe6eab00e
@ -290,16 +290,9 @@ nsEventListenerManager::AddEventListener(nsIDOMEventListener *aListener,
|
||||
MutationBitForEventType(aType));
|
||||
}
|
||||
} else if (aTypeAtom == nsGkAtoms::ondeviceorientation) {
|
||||
nsPIDOMWindow* window = GetInnerWindowForTarget();
|
||||
if (window)
|
||||
window->EnableDeviceSensor(SENSOR_ORIENTATION);
|
||||
EnableDevice(NS_DEVICE_ORIENTATION);
|
||||
} else if (aTypeAtom == nsGkAtoms::ondevicemotion) {
|
||||
nsPIDOMWindow* window = GetInnerWindowForTarget();
|
||||
if (window) {
|
||||
window->EnableDeviceSensor(SENSOR_ACCELERATION);
|
||||
window->EnableDeviceSensor(SENSOR_LINEAR_ACCELERATION);
|
||||
window->EnableDeviceSensor(SENSOR_GYROSCOPE);
|
||||
}
|
||||
EnableDevice(NS_DEVICE_MOTION);
|
||||
} else if ((aType >= NS_MOZTOUCH_DOWN && aType <= NS_MOZTOUCH_UP) ||
|
||||
(aTypeAtom == nsGkAtoms::ontouchstart ||
|
||||
aTypeAtom == nsGkAtoms::ontouchend ||
|
||||
@ -341,12 +334,40 @@ nsEventListenerManager::IsDeviceType(PRUint32 aType)
|
||||
}
|
||||
|
||||
void
|
||||
nsEventListenerManager::DisableDevice(PRUint32 aType)
|
||||
nsEventListenerManager::EnableDevice(PRUint32 aType)
|
||||
{
|
||||
nsPIDOMWindow* window = GetInnerWindowForTarget();
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mTarget);
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
NS_ASSERTION(window->IsInnerWindow(), "Target should not be an outer window");
|
||||
|
||||
switch (aType) {
|
||||
case NS_DEVICE_ORIENTATION:
|
||||
window->EnableDeviceSensor(SENSOR_ORIENTATION);
|
||||
break;
|
||||
case NS_DEVICE_MOTION:
|
||||
window->EnableDeviceSensor(SENSOR_ACCELERATION);
|
||||
window->EnableDeviceSensor(SENSOR_LINEAR_ACCELERATION);
|
||||
window->EnableDeviceSensor(SENSOR_GYROSCOPE);
|
||||
break;
|
||||
default:
|
||||
NS_WARNING("Enabling an unknown device sensor.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
nsEventListenerManager::DisableDevice(PRUint32 aType)
|
||||
{
|
||||
nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(mTarget);
|
||||
if (!window) {
|
||||
return;
|
||||
}
|
||||
|
||||
NS_ASSERTION(window->IsInnerWindow(), "Target should not be an outer window");
|
||||
|
||||
switch (aType) {
|
||||
case NS_DEVICE_ORIENTATION:
|
||||
window->DisableDeviceSensor(SENSOR_ORIENTATION);
|
||||
|
@ -284,6 +284,7 @@ protected:
|
||||
nsListenerStruct **aListenerStruct);
|
||||
|
||||
bool IsDeviceType(PRUint32 aType);
|
||||
void EnableDevice(PRUint32 aType);
|
||||
void DisableDevice(PRUint32 aType);
|
||||
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user