michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set sw=2 ts=8 et ft=cpp : */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "Hal.h" michael@0: #include "mozilla/AppProcessChecker.h" michael@0: #include "mozilla/dom/ContentChild.h" michael@0: #include "mozilla/dom/ContentParent.h" michael@0: #include "mozilla/hal_sandbox/PHalChild.h" michael@0: #include "mozilla/hal_sandbox/PHalParent.h" michael@0: #include "mozilla/dom/TabParent.h" michael@0: #include "mozilla/dom/TabChild.h" michael@0: #include "mozilla/dom/battery/Types.h" michael@0: #include "mozilla/dom/network/Types.h" michael@0: #include "mozilla/dom/ScreenOrientation.h" michael@0: #include "mozilla/Observer.h" michael@0: #include "mozilla/unused.h" michael@0: #include "WindowIdentifier.h" michael@0: michael@0: using namespace mozilla; michael@0: using namespace mozilla::dom; michael@0: using namespace mozilla::hal; michael@0: michael@0: namespace mozilla { michael@0: namespace hal_sandbox { michael@0: michael@0: static bool sHalChildDestroyed = false; michael@0: michael@0: bool michael@0: HalChildDestroyed() michael@0: { michael@0: return sHalChildDestroyed; michael@0: } michael@0: michael@0: static PHalChild* sHal; michael@0: static PHalChild* michael@0: Hal() michael@0: { michael@0: if (!sHal) { michael@0: sHal = ContentChild::GetSingleton()->SendPHalConstructor(); michael@0: } michael@0: return sHal; michael@0: } michael@0: michael@0: void michael@0: Vibrate(const nsTArray& pattern, const WindowIdentifier &id) michael@0: { michael@0: HAL_LOG(("Vibrate: Sending to parent process.")); michael@0: michael@0: AutoInfallibleTArray p(pattern); michael@0: michael@0: WindowIdentifier newID(id); michael@0: newID.AppendProcessID(); michael@0: Hal()->SendVibrate(p, newID.AsArray(), TabChild::GetFrom(newID.GetWindow())); michael@0: } michael@0: michael@0: void michael@0: CancelVibrate(const WindowIdentifier &id) michael@0: { michael@0: HAL_LOG(("CancelVibrate: Sending to parent process.")); michael@0: michael@0: WindowIdentifier newID(id); michael@0: newID.AppendProcessID(); michael@0: Hal()->SendCancelVibrate(newID.AsArray(), TabChild::GetFrom(newID.GetWindow())); michael@0: } michael@0: michael@0: void michael@0: EnableBatteryNotifications() michael@0: { michael@0: Hal()->SendEnableBatteryNotifications(); michael@0: } michael@0: michael@0: void michael@0: DisableBatteryNotifications() michael@0: { michael@0: Hal()->SendDisableBatteryNotifications(); michael@0: } michael@0: michael@0: void michael@0: GetCurrentBatteryInformation(BatteryInformation* aBatteryInfo) michael@0: { michael@0: Hal()->SendGetCurrentBatteryInformation(aBatteryInfo); michael@0: } michael@0: michael@0: void michael@0: EnableNetworkNotifications() michael@0: { michael@0: Hal()->SendEnableNetworkNotifications(); michael@0: } michael@0: michael@0: void michael@0: DisableNetworkNotifications() michael@0: { michael@0: Hal()->SendDisableNetworkNotifications(); michael@0: } michael@0: michael@0: void michael@0: GetCurrentNetworkInformation(NetworkInformation* aNetworkInfo) michael@0: { michael@0: Hal()->SendGetCurrentNetworkInformation(aNetworkInfo); michael@0: } michael@0: michael@0: void michael@0: EnableScreenConfigurationNotifications() michael@0: { michael@0: Hal()->SendEnableScreenConfigurationNotifications(); michael@0: } michael@0: michael@0: void michael@0: DisableScreenConfigurationNotifications() michael@0: { michael@0: Hal()->SendDisableScreenConfigurationNotifications(); michael@0: } michael@0: michael@0: void michael@0: GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) michael@0: { michael@0: Hal()->SendGetCurrentScreenConfiguration(aScreenConfiguration); michael@0: } michael@0: michael@0: bool michael@0: LockScreenOrientation(const dom::ScreenOrientation& aOrientation) michael@0: { michael@0: bool allowed; michael@0: Hal()->SendLockScreenOrientation(aOrientation, &allowed); michael@0: return allowed; michael@0: } michael@0: michael@0: void michael@0: UnlockScreenOrientation() michael@0: { michael@0: Hal()->SendUnlockScreenOrientation(); michael@0: } michael@0: michael@0: bool michael@0: GetScreenEnabled() michael@0: { michael@0: bool enabled = false; michael@0: Hal()->SendGetScreenEnabled(&enabled); michael@0: return enabled; michael@0: } michael@0: michael@0: void michael@0: SetScreenEnabled(bool enabled) michael@0: { michael@0: Hal()->SendSetScreenEnabled(enabled); michael@0: } michael@0: michael@0: bool michael@0: GetCpuSleepAllowed() michael@0: { michael@0: bool allowed = true; michael@0: Hal()->SendGetCpuSleepAllowed(&allowed); michael@0: return allowed; michael@0: } michael@0: michael@0: void michael@0: SetCpuSleepAllowed(bool allowed) michael@0: { michael@0: Hal()->SendSetCpuSleepAllowed(allowed); michael@0: } michael@0: michael@0: double michael@0: GetScreenBrightness() michael@0: { michael@0: double brightness = 0; michael@0: Hal()->SendGetScreenBrightness(&brightness); michael@0: return brightness; michael@0: } michael@0: michael@0: void michael@0: SetScreenBrightness(double brightness) michael@0: { michael@0: Hal()->SendSetScreenBrightness(brightness); michael@0: } michael@0: michael@0: bool michael@0: SetLight(hal::LightType light, const hal::LightConfiguration& aConfig) michael@0: { michael@0: bool status; michael@0: Hal()->SendSetLight(light, aConfig, &status); michael@0: return status; michael@0: } michael@0: michael@0: bool michael@0: GetLight(hal::LightType light, hal::LightConfiguration* aConfig) michael@0: { michael@0: bool status; michael@0: Hal()->SendGetLight(light, aConfig, &status); michael@0: return status; michael@0: } michael@0: michael@0: void michael@0: AdjustSystemClock(int64_t aDeltaMilliseconds) michael@0: { michael@0: Hal()->SendAdjustSystemClock(aDeltaMilliseconds); michael@0: } michael@0: michael@0: void michael@0: SetTimezone(const nsCString& aTimezoneSpec) michael@0: { michael@0: Hal()->SendSetTimezone(nsCString(aTimezoneSpec)); michael@0: } michael@0: michael@0: nsCString michael@0: GetTimezone() michael@0: { michael@0: nsCString timezone; michael@0: Hal()->SendGetTimezone(&timezone); michael@0: return timezone; michael@0: } michael@0: michael@0: int32_t michael@0: GetTimezoneOffset() michael@0: { michael@0: int32_t timezoneOffset; michael@0: Hal()->SendGetTimezoneOffset(&timezoneOffset); michael@0: return timezoneOffset; michael@0: } michael@0: michael@0: void michael@0: EnableSystemClockChangeNotifications() michael@0: { michael@0: Hal()->SendEnableSystemClockChangeNotifications(); michael@0: } michael@0: michael@0: void michael@0: DisableSystemClockChangeNotifications() michael@0: { michael@0: Hal()->SendDisableSystemClockChangeNotifications(); michael@0: } michael@0: michael@0: void michael@0: EnableSystemTimezoneChangeNotifications() michael@0: { michael@0: Hal()->SendEnableSystemTimezoneChangeNotifications(); michael@0: } michael@0: michael@0: void michael@0: DisableSystemTimezoneChangeNotifications() michael@0: { michael@0: Hal()->SendDisableSystemTimezoneChangeNotifications(); michael@0: } michael@0: michael@0: void michael@0: Reboot() michael@0: { michael@0: NS_RUNTIMEABORT("Reboot() can't be called from sandboxed contexts."); michael@0: } michael@0: michael@0: void michael@0: PowerOff() michael@0: { michael@0: NS_RUNTIMEABORT("PowerOff() can't be called from sandboxed contexts."); michael@0: } michael@0: michael@0: void michael@0: StartForceQuitWatchdog(ShutdownMode aMode, int32_t aTimeoutSecs) michael@0: { michael@0: NS_RUNTIMEABORT("StartForceQuitWatchdog() can't be called from sandboxed contexts."); michael@0: } michael@0: michael@0: void michael@0: EnableSensorNotifications(SensorType aSensor) { michael@0: Hal()->SendEnableSensorNotifications(aSensor); michael@0: } michael@0: michael@0: void michael@0: DisableSensorNotifications(SensorType aSensor) { michael@0: Hal()->SendDisableSensorNotifications(aSensor); michael@0: } michael@0: michael@0: //TODO: bug 852944 - IPC implementations of these michael@0: void StartMonitoringGamepadStatus() michael@0: {} michael@0: michael@0: void StopMonitoringGamepadStatus() michael@0: {} michael@0: michael@0: void michael@0: EnableWakeLockNotifications() michael@0: { michael@0: Hal()->SendEnableWakeLockNotifications(); michael@0: } michael@0: michael@0: void michael@0: DisableWakeLockNotifications() michael@0: { michael@0: Hal()->SendDisableWakeLockNotifications(); michael@0: } michael@0: michael@0: void michael@0: ModifyWakeLock(const nsAString &aTopic, michael@0: WakeLockControl aLockAdjust, michael@0: WakeLockControl aHiddenAdjust, michael@0: uint64_t aProcessID) michael@0: { michael@0: MOZ_ASSERT(aProcessID != CONTENT_PROCESS_ID_UNKNOWN); michael@0: Hal()->SendModifyWakeLock(nsString(aTopic), aLockAdjust, aHiddenAdjust, aProcessID); michael@0: } michael@0: michael@0: void michael@0: GetWakeLockInfo(const nsAString &aTopic, WakeLockInformation *aWakeLockInfo) michael@0: { michael@0: Hal()->SendGetWakeLockInfo(nsString(aTopic), aWakeLockInfo); michael@0: } michael@0: michael@0: void michael@0: EnableSwitchNotifications(SwitchDevice aDevice) michael@0: { michael@0: Hal()->SendEnableSwitchNotifications(aDevice); michael@0: } michael@0: michael@0: void michael@0: DisableSwitchNotifications(SwitchDevice aDevice) michael@0: { michael@0: Hal()->SendDisableSwitchNotifications(aDevice); michael@0: } michael@0: michael@0: SwitchState michael@0: GetCurrentSwitchState(SwitchDevice aDevice) michael@0: { michael@0: SwitchState state; michael@0: Hal()->SendGetCurrentSwitchState(aDevice, &state); michael@0: return state; michael@0: } michael@0: michael@0: void michael@0: NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState) michael@0: { michael@0: Hal()->SendNotifySwitchStateFromInputDevice(aDevice, aState); michael@0: } michael@0: michael@0: bool michael@0: EnableAlarm() michael@0: { michael@0: NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts. Yet."); michael@0: return false; michael@0: } michael@0: michael@0: void michael@0: DisableAlarm() michael@0: { michael@0: NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts. Yet."); michael@0: } michael@0: michael@0: bool michael@0: SetAlarm(int32_t aSeconds, int32_t aNanoseconds) michael@0: { michael@0: NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts. Yet."); michael@0: return false; michael@0: } michael@0: michael@0: void michael@0: SetProcessPriority(int aPid, michael@0: ProcessPriority aPriority, michael@0: ProcessCPUPriority aCPUPriority, michael@0: uint32_t aBackgroundLRU) michael@0: { michael@0: NS_RUNTIMEABORT("Only the main process may set processes' priorities."); michael@0: } michael@0: michael@0: void michael@0: EnableFMRadio(const hal::FMRadioSettings& aSettings) michael@0: { michael@0: NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts."); michael@0: } michael@0: michael@0: void michael@0: DisableFMRadio() michael@0: { michael@0: NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts."); michael@0: } michael@0: michael@0: void michael@0: FMRadioSeek(const hal::FMRadioSeekDirection& aDirection) michael@0: { michael@0: NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts."); michael@0: } michael@0: michael@0: void michael@0: GetFMRadioSettings(FMRadioSettings* aSettings) michael@0: { michael@0: NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts."); michael@0: } michael@0: michael@0: void michael@0: SetFMRadioFrequency(const uint32_t aFrequency) michael@0: { michael@0: NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts."); michael@0: } michael@0: michael@0: uint32_t michael@0: GetFMRadioFrequency() michael@0: { michael@0: NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts."); michael@0: return 0; michael@0: } michael@0: michael@0: bool michael@0: IsFMRadioOn() michael@0: { michael@0: NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts."); michael@0: return false; michael@0: } michael@0: michael@0: uint32_t michael@0: GetFMRadioSignalStrength() michael@0: { michael@0: NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts."); michael@0: return 0; michael@0: } michael@0: michael@0: void michael@0: CancelFMRadioSeek() michael@0: { michael@0: NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts."); michael@0: } michael@0: michael@0: void michael@0: FactoryReset() michael@0: { michael@0: Hal()->SendFactoryReset(); michael@0: } michael@0: michael@0: void michael@0: StartDiskSpaceWatcher() michael@0: { michael@0: NS_RUNTIMEABORT("StartDiskSpaceWatcher() can't be called from sandboxed contexts."); michael@0: } michael@0: michael@0: void michael@0: StopDiskSpaceWatcher() michael@0: { michael@0: NS_RUNTIMEABORT("StopDiskSpaceWatcher() can't be called from sandboxed contexts."); michael@0: } michael@0: michael@0: class HalParent : public PHalParent michael@0: , public BatteryObserver michael@0: , public NetworkObserver michael@0: , public ISensorObserver michael@0: , public WakeLockObserver michael@0: , public ScreenConfigurationObserver michael@0: , public SwitchObserver michael@0: , public SystemClockChangeObserver michael@0: , public SystemTimezoneChangeObserver michael@0: { michael@0: public: michael@0: virtual void michael@0: ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE michael@0: { michael@0: // NB: you *must* unconditionally unregister your observer here, michael@0: // if it *may* be registered below. michael@0: hal::UnregisterBatteryObserver(this); michael@0: hal::UnregisterNetworkObserver(this); michael@0: hal::UnregisterScreenConfigurationObserver(this); michael@0: for (int32_t sensor = SENSOR_UNKNOWN + 1; michael@0: sensor < NUM_SENSOR_TYPE; ++sensor) { michael@0: hal::UnregisterSensorObserver(SensorType(sensor), this); michael@0: } michael@0: hal::UnregisterWakeLockObserver(this); michael@0: hal::UnregisterSystemClockChangeObserver(this); michael@0: hal::UnregisterSystemTimezoneChangeObserver(this); michael@0: for (int32_t switchDevice = SWITCH_DEVICE_UNKNOWN + 1; michael@0: switchDevice < NUM_SWITCH_DEVICE; ++switchDevice) { michael@0: hal::UnregisterSwitchObserver(SwitchDevice(switchDevice), this); michael@0: } michael@0: } michael@0: michael@0: virtual bool michael@0: RecvVibrate(const InfallibleTArray& pattern, michael@0: const InfallibleTArray &id, michael@0: PBrowserParent *browserParent) MOZ_OVERRIDE michael@0: { michael@0: // We give all content vibration permission. michael@0: TabParent *tabParent = static_cast(browserParent); michael@0: nsCOMPtr window = michael@0: do_QueryInterface(tabParent->GetBrowserDOMWindow()); michael@0: WindowIdentifier newID(id, window); michael@0: hal::Vibrate(pattern, newID); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvCancelVibrate(const InfallibleTArray &id, michael@0: PBrowserParent *browserParent) MOZ_OVERRIDE michael@0: { michael@0: TabParent *tabParent = static_cast(browserParent); michael@0: nsCOMPtr window = michael@0: do_QueryInterface(tabParent->GetBrowserDOMWindow()); michael@0: WindowIdentifier newID(id, window); michael@0: hal::CancelVibrate(newID); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvEnableBatteryNotifications() MOZ_OVERRIDE { michael@0: // We give all content battery-status permission. michael@0: hal::RegisterBatteryObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvDisableBatteryNotifications() MOZ_OVERRIDE { michael@0: hal::UnregisterBatteryObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetCurrentBatteryInformation(BatteryInformation* aBatteryInfo) MOZ_OVERRIDE { michael@0: // We give all content battery-status permission. michael@0: hal::GetCurrentBatteryInformation(aBatteryInfo); michael@0: return true; michael@0: } michael@0: michael@0: void Notify(const BatteryInformation& aBatteryInfo) MOZ_OVERRIDE { michael@0: unused << SendNotifyBatteryChange(aBatteryInfo); michael@0: } michael@0: michael@0: virtual bool michael@0: RecvEnableNetworkNotifications() MOZ_OVERRIDE { michael@0: // We give all content access to this network-status information. michael@0: hal::RegisterNetworkObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvDisableNetworkNotifications() MOZ_OVERRIDE { michael@0: hal::UnregisterNetworkObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetCurrentNetworkInformation(NetworkInformation* aNetworkInfo) MOZ_OVERRIDE { michael@0: hal::GetCurrentNetworkInformation(aNetworkInfo); michael@0: return true; michael@0: } michael@0: michael@0: void Notify(const NetworkInformation& aNetworkInfo) { michael@0: unused << SendNotifyNetworkChange(aNetworkInfo); michael@0: } michael@0: michael@0: virtual bool michael@0: RecvEnableScreenConfigurationNotifications() MOZ_OVERRIDE { michael@0: // Screen configuration is used to implement CSS and DOM michael@0: // properties, so all content already has access to this. michael@0: hal::RegisterScreenConfigurationObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvDisableScreenConfigurationNotifications() MOZ_OVERRIDE { michael@0: hal::UnregisterScreenConfigurationObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) MOZ_OVERRIDE { michael@0: hal::GetCurrentScreenConfiguration(aScreenConfiguration); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvLockScreenOrientation(const dom::ScreenOrientation& aOrientation, bool* aAllowed) MOZ_OVERRIDE michael@0: { michael@0: // FIXME/bug 777980: unprivileged content may only lock michael@0: // orientation while fullscreen. We should check whether the michael@0: // request comes from an actor in a process that might be michael@0: // fullscreen. We don't have that information currently. michael@0: *aAllowed = hal::LockScreenOrientation(aOrientation); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvUnlockScreenOrientation() MOZ_OVERRIDE michael@0: { michael@0: hal::UnlockScreenOrientation(); michael@0: return true; michael@0: } michael@0: michael@0: void Notify(const ScreenConfiguration& aScreenConfiguration) { michael@0: unused << SendNotifyScreenConfigurationChange(aScreenConfiguration); michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetScreenEnabled(bool *enabled) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "power")) { michael@0: return false; michael@0: } michael@0: *enabled = hal::GetScreenEnabled(); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvSetScreenEnabled(const bool &enabled) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "power")) { michael@0: return false; michael@0: } michael@0: hal::SetScreenEnabled(enabled); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetCpuSleepAllowed(bool *allowed) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "power")) { michael@0: return false; michael@0: } michael@0: *allowed = hal::GetCpuSleepAllowed(); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvSetCpuSleepAllowed(const bool &allowed) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "power")) { michael@0: return false; michael@0: } michael@0: hal::SetCpuSleepAllowed(allowed); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetScreenBrightness(double *brightness) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "power")) { michael@0: return false; michael@0: } michael@0: *brightness = hal::GetScreenBrightness(); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvSetScreenBrightness(const double &brightness) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "power")) { michael@0: return false; michael@0: } michael@0: hal::SetScreenBrightness(brightness); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvSetLight(const LightType& aLight, const hal::LightConfiguration& aConfig, bool *status) MOZ_OVERRIDE michael@0: { michael@0: // XXX currently, the hardware key light and screen backlight are michael@0: // controlled as a unit. Those are set through the power API, and michael@0: // there's no other way to poke lights currently, so we require michael@0: // "power" privileges here. michael@0: if (!AssertAppProcessPermission(this, "power")) { michael@0: return false; michael@0: } michael@0: *status = hal::SetLight(aLight, aConfig); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetLight(const LightType& aLight, LightConfiguration* aConfig, bool* status) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "power")) { michael@0: return false; michael@0: } michael@0: *status = hal::GetLight(aLight, aConfig); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvAdjustSystemClock(const int64_t &aDeltaMilliseconds) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "time")) { michael@0: return false; michael@0: } michael@0: hal::AdjustSystemClock(aDeltaMilliseconds); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvSetTimezone(const nsCString& aTimezoneSpec) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "time")) { michael@0: return false; michael@0: } michael@0: hal::SetTimezone(aTimezoneSpec); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetTimezone(nsCString *aTimezoneSpec) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "time")) { michael@0: return false; michael@0: } michael@0: *aTimezoneSpec = hal::GetTimezone(); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetTimezoneOffset(int32_t *aTimezoneOffset) MOZ_OVERRIDE michael@0: { michael@0: if (!AssertAppProcessPermission(this, "time")) { michael@0: return false; michael@0: } michael@0: *aTimezoneOffset = hal::GetTimezoneOffset(); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvEnableSystemClockChangeNotifications() MOZ_OVERRIDE michael@0: { michael@0: hal::RegisterSystemClockChangeObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvDisableSystemClockChangeNotifications() MOZ_OVERRIDE michael@0: { michael@0: hal::UnregisterSystemClockChangeObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvEnableSystemTimezoneChangeNotifications() MOZ_OVERRIDE michael@0: { michael@0: hal::RegisterSystemTimezoneChangeObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvDisableSystemTimezoneChangeNotifications() MOZ_OVERRIDE michael@0: { michael@0: hal::UnregisterSystemTimezoneChangeObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvEnableSensorNotifications(const SensorType &aSensor) MOZ_OVERRIDE { michael@0: // We currently allow any content to register device-sensor michael@0: // listeners. michael@0: hal::RegisterSensorObserver(aSensor, this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvDisableSensorNotifications(const SensorType &aSensor) MOZ_OVERRIDE { michael@0: hal::UnregisterSensorObserver(aSensor, this); michael@0: return true; michael@0: } michael@0: michael@0: void Notify(const SensorData& aSensorData) { michael@0: unused << SendNotifySensorChange(aSensorData); michael@0: } michael@0: michael@0: virtual bool michael@0: RecvModifyWakeLock(const nsString& aTopic, michael@0: const WakeLockControl& aLockAdjust, michael@0: const WakeLockControl& aHiddenAdjust, michael@0: const uint64_t& aProcessID) MOZ_OVERRIDE michael@0: { michael@0: MOZ_ASSERT(aProcessID != CONTENT_PROCESS_ID_UNKNOWN); michael@0: michael@0: // We allow arbitrary content to use wake locks. michael@0: hal::ModifyWakeLock(aTopic, aLockAdjust, aHiddenAdjust, aProcessID); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvEnableWakeLockNotifications() MOZ_OVERRIDE michael@0: { michael@0: // We allow arbitrary content to use wake locks. michael@0: hal::RegisterWakeLockObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvDisableWakeLockNotifications() MOZ_OVERRIDE michael@0: { michael@0: hal::UnregisterWakeLockObserver(this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetWakeLockInfo(const nsString &aTopic, WakeLockInformation *aWakeLockInfo) MOZ_OVERRIDE michael@0: { michael@0: hal::GetWakeLockInfo(aTopic, aWakeLockInfo); michael@0: return true; michael@0: } michael@0: michael@0: void Notify(const WakeLockInformation& aWakeLockInfo) michael@0: { michael@0: unused << SendNotifyWakeLockChange(aWakeLockInfo); michael@0: } michael@0: michael@0: virtual bool michael@0: RecvEnableSwitchNotifications(const SwitchDevice& aDevice) MOZ_OVERRIDE michael@0: { michael@0: // Content has no reason to listen to switch events currently. michael@0: hal::RegisterSwitchObserver(aDevice, this); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvDisableSwitchNotifications(const SwitchDevice& aDevice) MOZ_OVERRIDE michael@0: { michael@0: hal::UnregisterSwitchObserver(aDevice, this); michael@0: return true; michael@0: } michael@0: michael@0: void Notify(const SwitchEvent& aSwitchEvent) michael@0: { michael@0: unused << SendNotifySwitchChange(aSwitchEvent); michael@0: } michael@0: michael@0: virtual bool michael@0: RecvGetCurrentSwitchState(const SwitchDevice& aDevice, hal::SwitchState *aState) MOZ_OVERRIDE michael@0: { michael@0: // Content has no reason to listen to switch events currently. michael@0: *aState = hal::GetCurrentSwitchState(aDevice); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvNotifySwitchStateFromInputDevice(const SwitchDevice& aDevice, michael@0: const SwitchState& aState) MOZ_OVERRIDE michael@0: { michael@0: hal::NotifySwitchStateFromInputDevice(aDevice, aState); michael@0: return true; michael@0: } michael@0: michael@0: void Notify(const int64_t& aClockDeltaMS) michael@0: { michael@0: unused << SendNotifySystemClockChange(aClockDeltaMS); michael@0: } michael@0: michael@0: void Notify(const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo) michael@0: { michael@0: unused << SendNotifySystemTimezoneChange(aSystemTimezoneChangeInfo); michael@0: } michael@0: michael@0: virtual bool michael@0: RecvFactoryReset() michael@0: { michael@0: if (!AssertAppProcessPermission(this, "power")) { michael@0: return false; michael@0: } michael@0: hal::FactoryReset(); michael@0: return true; michael@0: } michael@0: michael@0: virtual mozilla::ipc::IProtocol* michael@0: CloneProtocol(Channel* aChannel, michael@0: mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE michael@0: { michael@0: ContentParent* contentParent = aCtx->GetContentParent(); michael@0: nsAutoPtr actor(contentParent->AllocPHalParent()); michael@0: if (!actor || !contentParent->RecvPHalConstructor(actor)) { michael@0: return nullptr; michael@0: } michael@0: return actor.forget(); michael@0: } michael@0: }; michael@0: michael@0: class HalChild : public PHalChild { michael@0: public: michael@0: virtual void michael@0: ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE michael@0: { michael@0: sHalChildDestroyed = true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvNotifyBatteryChange(const BatteryInformation& aBatteryInfo) MOZ_OVERRIDE { michael@0: hal::NotifyBatteryChange(aBatteryInfo); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvNotifySensorChange(const hal::SensorData &aSensorData) MOZ_OVERRIDE; michael@0: michael@0: virtual bool michael@0: RecvNotifyNetworkChange(const NetworkInformation& aNetworkInfo) MOZ_OVERRIDE { michael@0: hal::NotifyNetworkChange(aNetworkInfo); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvNotifyWakeLockChange(const WakeLockInformation& aWakeLockInfo) MOZ_OVERRIDE { michael@0: hal::NotifyWakeLockChange(aWakeLockInfo); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvNotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration) MOZ_OVERRIDE { michael@0: hal::NotifyScreenConfigurationChange(aScreenConfiguration); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvNotifySwitchChange(const mozilla::hal::SwitchEvent& aEvent) MOZ_OVERRIDE { michael@0: hal::NotifySwitchChange(aEvent); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvNotifySystemClockChange(const int64_t& aClockDeltaMS) { michael@0: hal::NotifySystemClockChange(aClockDeltaMS); michael@0: return true; michael@0: } michael@0: michael@0: virtual bool michael@0: RecvNotifySystemTimezoneChange( michael@0: const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo) { michael@0: hal::NotifySystemTimezoneChange(aSystemTimezoneChangeInfo); michael@0: return true; michael@0: } michael@0: }; michael@0: michael@0: bool michael@0: HalChild::RecvNotifySensorChange(const hal::SensorData &aSensorData) { michael@0: hal::NotifySensorChange(aSensorData); michael@0: michael@0: return true; michael@0: } michael@0: michael@0: PHalChild* CreateHalChild() { michael@0: return new HalChild(); michael@0: } michael@0: michael@0: PHalParent* CreateHalParent() { michael@0: return new HalParent(); michael@0: } michael@0: michael@0: } // namespace hal_sandbox michael@0: } // namespace mozilla