/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim: set ts=8 sts=2 et sw=2 tw=80: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
nsTArray<nsIDOMWindow*>* windows = new nsTArray<nsIDOMWindow*>();
mWindowListeners.AppendElement(windows);
}
mLastDOMMotionEventTime = TimeStamp::Now();
}
nsDeviceSensors::~nsDeviceSensors() { for (int i = 0; i < NUM_SENSOR_TYPE; i++) { if (IsSensorEnabled(i)) UnregisterSensorObserver((SensorType)i, this);
}
for (int i = 0; i < NUM_SENSOR_TYPE; i++) { delete mWindowListeners[i];
}
}
if (mWindowListeners[aType]->Length() == 0)
UnregisterSensorObserver((SensorType)aType, this);
return NS_OK;
}
NS_IMETHODIMP nsDeviceSensors::RemoveWindowAsListener(nsIDOMWindow* aWindow) { for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
RemoveWindowListener((SensorType)i, aWindow);
} return NS_OK;
}
staticbool WindowCannotReceiveSensorEvent(nsPIDOMWindowInner* aWindow) { // Check to see if this window is in the background. if (!aWindow || !aWindow->IsCurrentInnerWindow()) { returntrue;
}
void nsDeviceSensors::Notify(const mozilla::hal::SensorData& aSensorData) {
uint32_t type = aSensorData.sensor();
const nsTArray<float>& values = aSensorData.values();
size_t len = values.Length(); double x = len > 0 ? values[0] : 0.0; double y = len > 1 ? values[1] : 0.0; double z = len > 2 ? values[2] : 0.0; double w = len > 3 ? values[3] : 0.0;
PRTime timestamp = aSensorData.timestamp();
nsCOMArray<nsIDOMWindow> windowListeners; for (uint32_t i = 0; i < mWindowListeners[type]->Length(); i++) {
windowListeners.AppendObject(mWindowListeners[type]->SafeElementAt(i));
}
for (uint32_t i = windowListeners.Count(); i > 0;) {
--i;
nsCOMPtr<nsPIDOMWindowInner> pwindow =
do_QueryInterface(windowListeners[i]); if (WindowCannotReceiveSensorEvent(pwindow)) { continue;
}
// This is used to determine whether relative events have been dispatched // during the current session, in which case we don't dispatch the additional // compatibility events. staticbool sIsDispatchingRelativeEvents = false;
sIsDispatchingRelativeEvents = sIsDispatchingRelativeEvents || !aIsAbsolute;
// Android devices with SENSOR_GAME_ROTATION_VECTOR support dispatch // relative events for "deviceorientation" by default, while other platforms // and devices without such support dispatch absolute events by default. if (aIsAbsolute && !sIsDispatchingRelativeEvents) { // For absolute events on devices without support for relative events, // we need to additionally dispatch type "deviceorientation" to keep // backwards-compatibility.
Dispatch(aTarget, u"deviceorientation"_ns);
}
}
switch (aType) { case nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION: case nsIDeviceSensorData::TYPE_ACCELERATION: case nsIDeviceSensorData::TYPE_GYROSCOPE: // checks "device.sensors.motion.enabled" pref if (!StaticPrefs::device_sensors_motion_enabled()) { returnfalse;
} if (doc) {
doc->WarnOnceAbout(DeprecatedOperations::eMotionEvent);
} break; case nsIDeviceSensorData::TYPE_GAME_ROTATION_VECTOR: case nsIDeviceSensorData::TYPE_ORIENTATION: case nsIDeviceSensorData::TYPE_ROTATION_VECTOR: // checks "device.sensors.orientation.enabled" pref if (!StaticPrefs::device_sensors_orientation_enabled()) { returnfalse;
} if (doc) {
doc->WarnOnceAbout(DeprecatedOperations::eOrientationEvent);
} break; case nsIDeviceSensorData::TYPE_PROXIMITY: // checks "device.sensors.proximity.enabled" pref if (!StaticPrefs::device_sensors_proximity_enabled()) { returnfalse;
} if (doc) {
doc->WarnOnceAbout(DeprecatedOperations::eProximityEvent, true);
} break; case nsIDeviceSensorData::TYPE_LIGHT: // checks "device.sensors.ambientLight.enabled" pref if (!StaticPrefs::device_sensors_ambientLight_enabled()) { returnfalse;
} if (doc) {
doc->WarnOnceAbout(DeprecatedOperations::eAmbientLightEvent, true);
} break; default:
MOZ_ASSERT_UNREACHABLE("Device sensor type not recognised"); returnfalse;
}
if (!window) { returntrue;
} return !nsGlobalWindowInner::Cast(window)->ShouldResistFingerprinting(
RFPTarget::DeviceSensors);
}
¤ Dauer der Verarbeitung: 0.2 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.