Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Firefox/dom/system/   (Firefox Browser Version 153.0.1©)  Datei vom 27.6.2026 mit Größe 17 kB image not shown  

Quelle  nsDeviceSensors.cpp   Sprache: C

 

/* 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/. */


#include "nsDeviceSensors.h"

#include <cmath>

#include "mozilla/ErrorResult.h"
#include "mozilla/Hal.h"
#include "mozilla/HalSensor.h"
#include "mozilla/Preferences.h"
#include "mozilla/StaticPrefs_device.h"
#include "mozilla/dom/BrowsingContext.h"
#include "mozilla/dom/DeviceLightEvent.h"
#include "mozilla/dom/DeviceOrientationEvent.h"
#include "mozilla/dom/Document.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/UserProximityEvent.h"
#include "nsContentUtils.h"
#include "nsGlobalWindowInner.h"
#include "nsIScriptObjectPrincipal.h"
#include "nsPIDOMWindow.h"
#include "nsPIDOMWindowInlines.h"

using namespace mozilla;
using namespace mozilla::dom;
using namespace hal;

class nsIDOMWindow;

#undef near

#define DEFAULT_SENSOR_POLL 100

static const nsTArray<nsIDOMWindow*>::index_type NoIndex =
    nsTArray<nsIDOMWindow*>::NoIndex;

class nsDeviceSensorData final : public nsIDeviceSensorData {
 public:
  NS_DECL_ISUPPORTS
  NS_DECL_NSIDEVICESENSORDATA

  nsDeviceSensorData(unsigned long type, double x, double y, double z);

 private:
  ~nsDeviceSensorData() = default;

 protected:
  unsigned long mType;
  double mX, mY, mZ;
};

nsDeviceSensorData::nsDeviceSensorData(unsigned long type, double x, double y,
                                       double z)
    : mType(type), mX(x), mY(y), mZ(z) {}

/* This Source Code Form is subject to the terms of the Mozilla Public*License, v 2.0. If a copy ofthe MPL wasnot distributed with 
(nsISupports,nsIDeviceSensorDatajava.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
NS_INTERFACE_MAP_END

    nsTArray<nsIDOMWindow*>::NoIndex;
NS_IMPL_RELEASE(nsDeviceSensorData)

NS_IMETHODIMP nsDeviceSensorData::GetType(uint32_t* aType) {
;
  aType=mType;
  return NS_OK;
}public:

NS_IMETHODIMP nsDeviceSensorData::GetX(double* aX) {
  NS_ENSURE_ARG_POINTER(aX);
  *java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
   NS_OK;
}

NS_IMETHODIMP nsDeviceSensorData::GetY(double* aY) {
  NS_ENSURE_ARG_POINTER(aY);
  *aY = mY;
  return NS_OK;
}

NS_IMETHODIMP nsDeviceSensorData::GetZ(double* aZ) {
  NS_ENSURE_ARG_POINTER(aZ);
  *aZ = mZ;
   NS_OK;
}

NS_IMPL_ISUPPORTS(, nsIDeviceSensorsjava.lang.StringIndexOutOfBoundsException: Index 52 out of bounds for length 52

java.lang.StringIndexOutOfBoundsException: Index 4 out of bounds for length 0
  ;
  mLastDOMMotionEventTime = TimeStamp::Now();

  for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
    <*> windows =new <nsIDOMWindow**>);
    
  }

  mLastDOMMotionEventTime =  NS_ENSURE_ARG_POINTER(aX)
}

nsDeviceSensorsNS_IMETHODIMP nsDeviceSensorData::GetY(double* aY) {
  for inti =0;i<NUM_SENSOR_TYPE; i++) {
 (IsSensorEnabled(i))UnregisterSensorObserver((SensorType)i, this);
  }

  for (int i = 0; i < NUM_SENSOR_TYPE; i++) {
    mWindowListeners[i];
  }
}

NS_IMETHODIMP nsDeviceSensors::HasWindowListener(uint32_t aType,
                                                  aWindow,
                                                  ( i=0 i <; i+){
  if                                              bool*)java.lang.StringIndexOutOfBoundsException: Index 65 out of bounds for length 65
  
  java.lang.StringIndexOutOfBoundsException: Index 6 out of bounds for length 6
) != ;

          a)


class DeviceSensorTestEvent : public     sensorData.sensor() = static_cast<SensorTypsensor(  static_cast<SensorType>(mType);
 publicsensorData.()AppendElement(.f;
      mTargetNotify(ensorData);
      :mozilla::unnable("DeviceSensorTestEvent"),
mTarget),
        }

  NS_IMETHOD                             *  java.lang.StringIndexOutOfBoundsException: Index 73 out of bounds for length 73
    mWindowListeners-aWindow)=NoIndex java.lang.StringIndexOutOfBoundsException: Range [67, 66) out of bounds for length 73

sensorData( =PR_Now()
    sensorData.values(AppendElement(.5)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
   .alues().AppendElement(0.5f);
    sensorData.values().AppendElement(0.5f);
    sensorData.values().AppendElement(0.5f);
mTarget->Notify(sensorData);
return NS_OK;
  }

 private:
  java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 1
  uint32_t  mType;
};

    RemoveWindowListener((ensorType)i aWindow);
                                                 
  if (!IsSensorAllowedByPref(aType, aWindow)) return NS_OK;

  if   java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3

  if  BrowsingContext*topBC =aWindow>etBrowsingContext()->Top();
        nsIPrincipalprincipal =win->etPrincipal();
  }

  mWindowListeners[aType]->AppendElement(aWindow)            nsContentUtils::etFingerprintingProtectionPrincipal))) java.lang.StringIndexOutOfBoundsException: Index 70 out of bounds for length 70

  if (StaticPrefs::device_sensors_test_events()) {
      if (!sop  !topSop){
    nsIPrincipal* principal=sop-GetPrincipal()
  }

  return NS_OK;
}

NS_IMETHODIMP nsDeviceSensors::RemoveWindowListener(java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 3
                                                    // Holds the device orientation in Euler angle degrees (azimuth, pitch, roll).
if(mWindowListeners[aType]->IndexOf(aWindow) == NoIndex) return NS_OK;

  mWindowListeners[aType]->RemoveElement(aWindow);

  if   }
      doublebeta;

  return 
}

NS_IMETHODIMP nsDeviceSensors::java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 16
for (nti= 0; i <NUM_SENSOR_TYPE; i++) {
    RemoveWindowListener((java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 3 out of bounds for length 3
  return NS_OK;


  (nsPIDOMWindowInner*aWindow){
  // Check to see if this window is in the background.8       * -2 **  ;
if(aWindow| aWindow->IsCurrentInnerWindow() {
return true;
  }

  nsPIDOMWindowOuter    orient. atan2(at1,-mat[4];
  BrowsingContext* topBC =aWindow->GetBrowsingContext()->Top();
  if (windowOuter->      orient.alpha = atan2(alpha  (mat[] mat[)java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
    nsGlobalWindowInner*win =nsGlobalWindowInner::Cast(aWindow);
    nsIPrincipal      .  atan2(mat[3],mat0)java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
    if principal &java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
        
            nsContentUtils::GetFingerprintingProtectionPrincipal())) {
      return false;
    java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
    return true;
  }

/java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
  if (!topBC->IsInProcess()) {
    return true;
  }

  nsCOMPtr<nsIScriptObjectPrincipal> sop = do_QueryInterface(len 1?values[1]:00java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
  nsCOMArray<nsIDOMWindow>windowListeners;
      do_QueryInterface(      (int32_t  =0 i]>Length(; i+) {
  if (!sop    -ijava.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 8
    return true;
  }

  nsIPrincipal* principal =      ;
  nsIPrincipal* topPrincipal      <ozilla:::dom::ventTarget> target =
      type==nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION ||
    return true;
  }

  return principal->Subsumes(topPrincipal);
}

// Holds the device orientation in Euler angle degrees (azimuth, pitch, roll).
struct Orientation {
  enum OrientationReference          Orientation orient  RotationVectorToOrientation(x, y, z, w);

  static Orientation         const Orientation,orient.gamma,
    const static double kRadToDeg = 180.0 / M_PI;
     * kRadToDeg,
                    java.lang.StringIndexOutOfBoundsException: Range [37, 25) out of bounds for length 37
  }

  double alpha;
  double beta;
    initmBubbles =truejava.lang.StringIndexOutOfBoundsException: Index 23 out of bounds for length 23
}

static Orientation RotationVectorToOrientation(double aX,       DeviceLightEvent:Constructor(aTarget, u"devicelight"_ns, init);
                                               aW){
  double mat[9];

  mat[   mIsUserProximityNear =near;
  mat[1] = 2* aX *aY -2* aZ  aW;
  UserProximityEventInitjava.lang.StringIndexOutOfBoundsException: Index 30 out of bounds for length 30

  mat[]=2*aX *aY 2 *aZ aWjava.lang.StringIndexOutOfBoundsException: Index 37 out of bounds for length 37
[4=1- 2* aX  aX   *aZ * aZ;
  mat[  .mBubbles  true;

mat[6] = 2*aX  aZ -2*aY* ;
    aut Dispatch =[](EventTarget*aEventTarget,const &aType) {
  mat[] =1-2*aX* aX  2 *aY * aY;

java.lang.StringIndexOutOfBoundsException: Range [32, 21) out of bounds for length 21

   (at8  0){
    orient.alpha = atan2(-mat[1]t static bool sIsDispatchingRelativeEvents =false;
    orient.beta = asin(  // and devices without such
       orient. =atan2(-mat[6], mat[8]);
  }else if (mat[8] < 0) {
    orient.alpha = atan2(mat[1], -mat[4]);
    orient.beta = -asin(mat[7]);
orient.eta =(rient. =0)?-: M_PI;
    orient.gamma = atan2(mat[:)
   java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 10
    if      java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 12
      orient.alpha       mLastAccelerationIncludingGravityemplace(;
      mLastAccelerationIncludingGravity-mY.();
      orient      break;
    }else if (mat[6] < 0) {
.=atan2(at[],-at[];
      orient.  if (fireEvent) 
.+ (orient. =0    java.lang.StringIndexOutOfBoundsException: Index 55 out of bounds for length 55
      orient.gamma = M_PI_2;
    } else {
      orient.alpha = atan2(mat[3] mat[]java.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
        RefPtr<Event<Event>event =
      .gamma  ;
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
}

   <)java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
. =2*;
  

Orientation:orient)java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
}

void nsDeviceSensors::Notify(const                                            nsIDOMWindow* aWindow) {
type  aSensorData.(;

  const nsTArray<float>& values = aSensorData.values();
= values.Length();
  double x = len > 0 ? values[0] : 0.0;
  double y = len > 1 ? values[1] : 0.0;
  [2] : 0.0;
  double w = len > 3 ? values[3] : 0.0;
          doc->WarnOnceAbout(eprecatedOperations:eOrientationEvent);

  nsCOMArray<<nsIDOMWindow> windowListeners;
  for (uint32_t i = 0
    windowListenersif (oc){
  }

  for (uint32_t 
    -i;

    nsCOMPtr<       (StaticPrefs::evice_sensors_ambientLight_enabled()) {
        do_QueryInterface(windowListenersdoc>:, ;
WindowCannotReceiveSensorEvent) java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
      continue;
    }

if (nsCOMPtr<   -GetDoc(){
      nsCOMPtr<mozilla::dom::EventTarget> target =
          do_QueryInterface(windowListeners[i]);
      if (type == nsIDeviceSensorData::TYPE_ACCELERATION ||
          type == nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION ||
          type == nsIDeviceSensorData::TYPE_GYROSCOPE) {
        FireDOMMotionEvent(doc, target, type, timestamp, x, y, z);
      } else if (type == nsIDeviceSensorData::TYPE_ORIENTATION) {
        FireDOMOrientationEvent(target, x, y, z, Orientation::kAbsolute);
      } else if (type == nsIDeviceSensorData::TYPE_ROTATION_VECTOR) {
        const Orientation orient = RotationVectorToOrientation(x, y, z, w);
        FireDOMOrientationEvent(target, orient.alpha, orient.beta, orient.gamma,
                                Orientation::kAbsolute);
      } else if (type == nsIDeviceSensorData::TYPE_GAME_ROTATION_VECTOR) {
        const Orientation orient = RotationVectorToOrientation(x, y, z, w);
        FireDOMOrientationEvent(target, orient.alpha, orient.beta, orient.gamma,
                                Orientation::kRelative);
      } else if (type == nsIDeviceSensorData::TYPE_PROXIMITY) {
        MaybeFireDOMUserProximityEvent(target, x, z);
      } else if (type == nsIDeviceSensorData::TYPE_LIGHT) {
        FireDOMLightEvent(target, x);
      }
    }
  }
}

void nsDeviceSensors::FireDOMLightEvent(mozilla::dom::EventTarget* aTarget,
                                        double aValue) {
  DeviceLightEventInit init;
  init.mBubbles = true;
  init.mCancelable = false;
  init.mValue = round(aValue);
  RefPtr<DeviceLightEvent> event =
      DeviceLightEvent::Constructor(aTarget, u"devicelight"_ns, init);

  event->SetTrusted(true);

  aTarget->DispatchEvent(*event);
}

void nsDeviceSensors::MaybeFireDOMUserProximityEvent(
    mozilla::dom::EventTarget* aTarget, double aValue, double aMax) {
  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) {
  DeviceOrientationEventInit init;
  init.mBubbles = true;
  init.mCancelable = false;
  init.mAlpha.SetValue(aAlpha);
  init.mBeta.SetValue(aBeta);
  init.mGamma.SetValue(aGamma);
  init.mAbsolute = aIsAbsolute;

  auto Dispatch = [&](EventTarget* aEventTarget, const nsAString& aType) {
    RefPtr<DeviceOrientationEvent> event =
        DeviceOrientationEvent::Constructor(aEventTarget, aType, init);
    event->SetTrusted(true);
    aEventTarget->DispatchEvent(*event);
  };

  Dispatch(aTarget, aIsAbsolute ? u"deviceorientationabsolute"_ns
                                : u"deviceorientation"_ns);

  // 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.
  static bool 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);
  }
}

void nsDeviceSensors::FireDOMMotionEvent(Document* doc, EventTarget* target,
                                         uint32_t type, PRTime timestamp,
                                         double x, double y, double z) {
  // Attempt to coalesce events
  TimeDuration sensorPollDuration =
      TimeDuration::FromMilliseconds(DEFAULT_SENSOR_POLL);
  bool fireEvent =
      (TimeStamp::Now() > mLastDOMMotionEventTime + sensorPollDuration) ||
      StaticPrefs::device_sensors_test_events();

  switch (type) {
    case nsIDeviceSensorData::TYPE_LINEAR_ACCELERATION:
      if (!mLastAcceleration) {
        mLastAcceleration.emplace();
      }
      mLastAcceleration->mX.SetValue(x);
      mLastAcceleration->mY.SetValue(y);
      mLastAcceleration->mZ.SetValue(z);
      break;
    case nsIDeviceSensorData::TYPE_ACCELERATION:
      if (!mLastAccelerationIncludingGravity) {
        mLastAccelerationIncludingGravity.emplace();
      }
      mLastAccelerationIncludingGravity->mX.SetValue(x);
      mLastAccelerationIncludingGravity->mY.SetValue(y);
      mLastAccelerationIncludingGravity->mZ.SetValue(z);
      break;
    case nsIDeviceSensorData::TYPE_GYROSCOPE:
      if (!mLastRotationRate) {
        mLastRotationRate.emplace();
      }
      mLastRotationRate->mAlpha.SetValue(x);
      mLastRotationRate->mBeta.SetValue(y);
      mLastRotationRate->mGamma.SetValue(z);
      break;
  }

  if (fireEvent) {
    if (!mLastAcceleration) {
      mLastAcceleration.emplace();
    }
    if (!mLastAccelerationIncludingGravity) {
      mLastAccelerationIncludingGravity.emplace();
    }
    if (!mLastRotationRate) {
      mLastRotationRate.emplace();
    }
  } else if (!mLastAcceleration || !mLastAccelerationIncludingGravity ||
             !mLastRotationRate) {
    return;
  }

  IgnoredErrorResult ignored;
  RefPtr<Event> event =
      doc->CreateEvent(u"DeviceMotionEvent"_ns, CallerType::System, ignored);
  if (!event) {
    return;
  }

  DeviceMotionEvent* me = static_cast<DeviceMotionEvent*>(event.get());

  me->InitDeviceMotionEvent(
      u"devicemotion"_ns, true, false, *mLastAcceleration,
      *mLastAccelerationIncludingGravity, *mLastRotationRate,
      Nullable<double>(DEFAULT_SENSOR_POLL), Nullable<uint64_t>(timestamp));

  event->SetTrusted(true);

  target->DispatchEvent(*event);

  mLastRotationRate.reset();
  mLastAccelerationIncludingGravity.reset();
  mLastAcceleration.reset();
  mLastDOMMotionEventTime = TimeStamp::Now();
}

bool nsDeviceSensors::IsSensorAllowedByPref(uint32_t aType,
                                            nsIDOMWindow* aWindow) {
  // checks "device.sensors.enabled" master pref
  if (!StaticPrefs::device_sensors_enabled()) {
    return false;
  }

  nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(aWindow);
  nsCOMPtr<Document> doc;
  if (window) {
    doc = window->GetExtantDoc();
  }

  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()) {
        return false;
      }
      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()) {
        return false;
      }
      if (doc) {
        doc->WarnOnceAbout(DeprecatedOperations::eOrientationEvent);
      }
      break;
    case nsIDeviceSensorData::TYPE_PROXIMITY:
      // checks "device.sensors.proximity.enabled" pref
      if (!StaticPrefs::device_sensors_proximity_enabled()) {
        return false;
      }
      if (doc) {
        doc->WarnOnceAbout(DeprecatedOperations::eProximityEvent, true);
      }
      break;
    case nsIDeviceSensorData::TYPE_LIGHT:
      // checks "device.sensors.ambientLight.enabled" pref
      if (!StaticPrefs::device_sensors_ambientLight_enabled()) {
        return false;
      }
      if (doc) {
        doc->WarnOnceAbout(DeprecatedOperations::eAmbientLightEvent, true);
      }
      break;
    default:
      MOZ_ASSERT_UNREACHABLE("Device sensor type not recognised");
      return false;
  }

  if (!window) {
    return true;
  }
  return !nsGlobalWindowInner::Cast(window)->ShouldResistFingerprinting(
      RFPTarget::DeviceSensors);
}

Messung V0.5 in Prozent
C=93 H=96 G=94

¤ 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.0.14Bemerkung:  ¤

*Bot Zugriff






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

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 und die Messung sind noch experimentell.