Bug 697641, part 3: Make Sensor API available for Sandbox. r=cjones

Add Sensor API to PHal protocol that Sandbox can access sensors.
This commit is contained in:
Dão Gottwald 2012-01-16 14:37:49 +01:00
parent c50b5856a8
commit 51725adb51
3 changed files with 107 additions and 1 deletions

View File

@ -326,5 +326,63 @@ void SetScreenBrightness(double brightness)
PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(brightness, 0.0, 1.0)));
}
void
EnableSensorNotifications(SensorType aSensor) {
AssertMainThread();
PROXY_IF_SANDBOXED(EnableSensorNotifications(aSensor));
}
void
DisableSensorNotifications(SensorType aSensor) {
AssertMainThread();
PROXY_IF_SANDBOXED(DisableSensorNotifications(aSensor));
}
typedef ObserverList<SensorData> SensorObserverList;
static SensorObserverList *gSensorObservers = NULL;
static SensorObserverList &
GetSensorObservers(SensorType sensor_type) {
MOZ_ASSERT(sensor_type < NUM_SENSOR_TYPE);
if(gSensorObservers == NULL)
gSensorObservers = new SensorObserverList[NUM_SENSOR_TYPE];
return gSensorObservers[sensor_type];
}
void
RegisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
SensorObserverList &observers = GetSensorObservers(aSensor);
AssertMainThread();
observers.AddObserver(aObserver);
if(observers.Length() == 1) {
EnableSensorNotifications(aSensor);
}
}
void
UnregisterSensorObserver(SensorType aSensor, ISensorObserver *aObserver) {
SensorObserverList &observers = GetSensorObservers(aSensor);
AssertMainThread();
observers.RemoveObserver(aObserver);
if(observers.Length() == 0) {
DisableSensorNotifications(aSensor);
}
}
void
NotifySensorChange(const SensorData &aSensorData) {
SensorObserverList &observers = GetSensorObservers(aSensorData.sensor());
AssertMainThread();
observers.Broadcast(aSensorData);
}
} // namespace hal
} // namespace mozilla

View File

@ -84,6 +84,13 @@ parent:
sync GetScreenBrightness() returns (double brightness);
SetScreenBrightness(double brightness);
child:
NotifySensorChange(SensorData aSensorData);
parent:
EnableSensorNotifications(SensorType aSensor);
DisableSensorNotifications(SensorType aSensor);
__delete__();
};

View File

@ -133,8 +133,21 @@ SetScreenBrightness(double brightness)
Hal()->SendSetScreenBrightness(brightness);
}
void
EnableSensorNotifications(SensorType aSensor) {
Hal()->SendEnableSensorNotifications(aSensor);
}
void
DisableSensorNotifications(SensorType aSensor) {
Hal()->SendDisableSensorNotifications(aSensor);
}
class HalParent : public PHalParent
, public BatteryObserver {
, public BatteryObserver
, public ISensorObserver {
public:
NS_OVERRIDE virtual bool
RecvVibrate(const InfallibleTArray<unsigned int>& pattern,
@ -224,6 +237,23 @@ public:
hal::SetScreenBrightness(brightness);
return true;
}
NS_OVERRIDE virtual bool
RecvEnableSensorNotifications(const SensorType &aSensor) {
hal::RegisterSensorObserver(aSensor, this);
return true;
}
NS_OVERRIDE virtual bool
RecvDisableSensorNotifications(const SensorType &aSensor) {
hal::UnregisterSensorObserver(aSensor, this);
return true;
}
void Notify(const SensorData& aSensorData) {
unused << SendNotifySensorChange(aSensorData);
}
};
class HalChild : public PHalChild {
@ -233,8 +263,19 @@ public:
hal::NotifyBatteryChange(aBatteryInfo);
return true;
}
NS_OVERRIDE virtual bool
RecvNotifySensorChange(const hal::SensorData &aSensorData);
};
bool
HalChild::RecvNotifySensorChange(const hal::SensorData &aSensorData) {
hal::NotifySensorChange(aSensorData);
return true;
}
PHalChild* CreateHalChild() {
return new HalChild();
}