hal/sandbox/SandboxHal.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/hal/sandbox/SandboxHal.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,937 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set sw=2 ts=8 et ft=cpp : */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "Hal.h"
    1.11 +#include "mozilla/AppProcessChecker.h"
    1.12 +#include "mozilla/dom/ContentChild.h"
    1.13 +#include "mozilla/dom/ContentParent.h"
    1.14 +#include "mozilla/hal_sandbox/PHalChild.h"
    1.15 +#include "mozilla/hal_sandbox/PHalParent.h"
    1.16 +#include "mozilla/dom/TabParent.h"
    1.17 +#include "mozilla/dom/TabChild.h"
    1.18 +#include "mozilla/dom/battery/Types.h"
    1.19 +#include "mozilla/dom/network/Types.h"
    1.20 +#include "mozilla/dom/ScreenOrientation.h"
    1.21 +#include "mozilla/Observer.h"
    1.22 +#include "mozilla/unused.h"
    1.23 +#include "WindowIdentifier.h"
    1.24 +
    1.25 +using namespace mozilla;
    1.26 +using namespace mozilla::dom;
    1.27 +using namespace mozilla::hal;
    1.28 +
    1.29 +namespace mozilla {
    1.30 +namespace hal_sandbox {
    1.31 +
    1.32 +static bool sHalChildDestroyed = false;
    1.33 +
    1.34 +bool
    1.35 +HalChildDestroyed()
    1.36 +{
    1.37 +  return sHalChildDestroyed;
    1.38 +}
    1.39 +
    1.40 +static PHalChild* sHal;
    1.41 +static PHalChild*
    1.42 +Hal()
    1.43 +{
    1.44 +  if (!sHal) {
    1.45 +    sHal = ContentChild::GetSingleton()->SendPHalConstructor();
    1.46 +  }
    1.47 +  return sHal;
    1.48 +}
    1.49 +
    1.50 +void
    1.51 +Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
    1.52 +{
    1.53 +  HAL_LOG(("Vibrate: Sending to parent process."));
    1.54 +
    1.55 +  AutoInfallibleTArray<uint32_t, 8> p(pattern);
    1.56 +
    1.57 +  WindowIdentifier newID(id);
    1.58 +  newID.AppendProcessID();
    1.59 +  Hal()->SendVibrate(p, newID.AsArray(), TabChild::GetFrom(newID.GetWindow()));
    1.60 +}
    1.61 +
    1.62 +void
    1.63 +CancelVibrate(const WindowIdentifier &id)
    1.64 +{
    1.65 +  HAL_LOG(("CancelVibrate: Sending to parent process."));
    1.66 +
    1.67 +  WindowIdentifier newID(id);
    1.68 +  newID.AppendProcessID();
    1.69 +  Hal()->SendCancelVibrate(newID.AsArray(), TabChild::GetFrom(newID.GetWindow()));
    1.70 +}
    1.71 +
    1.72 +void
    1.73 +EnableBatteryNotifications()
    1.74 +{
    1.75 +  Hal()->SendEnableBatteryNotifications();
    1.76 +}
    1.77 +
    1.78 +void
    1.79 +DisableBatteryNotifications()
    1.80 +{
    1.81 +  Hal()->SendDisableBatteryNotifications();
    1.82 +}
    1.83 +
    1.84 +void
    1.85 +GetCurrentBatteryInformation(BatteryInformation* aBatteryInfo)
    1.86 +{
    1.87 +  Hal()->SendGetCurrentBatteryInformation(aBatteryInfo);
    1.88 +}
    1.89 +
    1.90 +void
    1.91 +EnableNetworkNotifications()
    1.92 +{
    1.93 +  Hal()->SendEnableNetworkNotifications();
    1.94 +}
    1.95 +
    1.96 +void
    1.97 +DisableNetworkNotifications()
    1.98 +{
    1.99 +  Hal()->SendDisableNetworkNotifications();
   1.100 +}
   1.101 +
   1.102 +void
   1.103 +GetCurrentNetworkInformation(NetworkInformation* aNetworkInfo)
   1.104 +{
   1.105 +  Hal()->SendGetCurrentNetworkInformation(aNetworkInfo);
   1.106 +}
   1.107 +
   1.108 +void
   1.109 +EnableScreenConfigurationNotifications()
   1.110 +{
   1.111 +  Hal()->SendEnableScreenConfigurationNotifications();
   1.112 +}
   1.113 +
   1.114 +void
   1.115 +DisableScreenConfigurationNotifications()
   1.116 +{
   1.117 +  Hal()->SendDisableScreenConfigurationNotifications();
   1.118 +}
   1.119 +
   1.120 +void
   1.121 +GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
   1.122 +{
   1.123 +  Hal()->SendGetCurrentScreenConfiguration(aScreenConfiguration);
   1.124 +}
   1.125 +
   1.126 +bool
   1.127 +LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
   1.128 +{
   1.129 +  bool allowed;
   1.130 +  Hal()->SendLockScreenOrientation(aOrientation, &allowed);
   1.131 +  return allowed;
   1.132 +}
   1.133 +
   1.134 +void
   1.135 +UnlockScreenOrientation()
   1.136 +{
   1.137 +  Hal()->SendUnlockScreenOrientation();
   1.138 +}
   1.139 +
   1.140 +bool
   1.141 +GetScreenEnabled()
   1.142 +{
   1.143 +  bool enabled = false;
   1.144 +  Hal()->SendGetScreenEnabled(&enabled);
   1.145 +  return enabled;
   1.146 +}
   1.147 +
   1.148 +void
   1.149 +SetScreenEnabled(bool enabled)
   1.150 +{
   1.151 +  Hal()->SendSetScreenEnabled(enabled);
   1.152 +}
   1.153 +
   1.154 +bool
   1.155 +GetCpuSleepAllowed()
   1.156 +{
   1.157 +  bool allowed = true;
   1.158 +  Hal()->SendGetCpuSleepAllowed(&allowed);
   1.159 +  return allowed;
   1.160 +}
   1.161 +
   1.162 +void
   1.163 +SetCpuSleepAllowed(bool allowed)
   1.164 +{
   1.165 +  Hal()->SendSetCpuSleepAllowed(allowed);
   1.166 +}
   1.167 +
   1.168 +double
   1.169 +GetScreenBrightness()
   1.170 +{
   1.171 +  double brightness = 0;
   1.172 +  Hal()->SendGetScreenBrightness(&brightness);
   1.173 +  return brightness;
   1.174 +}
   1.175 +
   1.176 +void
   1.177 +SetScreenBrightness(double brightness)
   1.178 +{
   1.179 +  Hal()->SendSetScreenBrightness(brightness);
   1.180 +}
   1.181 +
   1.182 +bool
   1.183 +SetLight(hal::LightType light, const hal::LightConfiguration& aConfig)
   1.184 +{
   1.185 +  bool status;
   1.186 +  Hal()->SendSetLight(light, aConfig, &status);
   1.187 +  return status;
   1.188 +}
   1.189 +
   1.190 +bool
   1.191 +GetLight(hal::LightType light, hal::LightConfiguration* aConfig)
   1.192 +{
   1.193 +  bool status;
   1.194 +  Hal()->SendGetLight(light, aConfig, &status);
   1.195 +  return status;
   1.196 +}
   1.197 +
   1.198 +void 
   1.199 +AdjustSystemClock(int64_t aDeltaMilliseconds)
   1.200 +{
   1.201 +  Hal()->SendAdjustSystemClock(aDeltaMilliseconds);
   1.202 +}
   1.203 +
   1.204 +void
   1.205 +SetTimezone(const nsCString& aTimezoneSpec)
   1.206 +{
   1.207 +  Hal()->SendSetTimezone(nsCString(aTimezoneSpec));
   1.208 +} 
   1.209 +
   1.210 +nsCString
   1.211 +GetTimezone()
   1.212 +{
   1.213 +  nsCString timezone;
   1.214 +  Hal()->SendGetTimezone(&timezone);
   1.215 +  return timezone;
   1.216 +}
   1.217 +
   1.218 +int32_t
   1.219 +GetTimezoneOffset()
   1.220 +{
   1.221 +  int32_t timezoneOffset;
   1.222 +  Hal()->SendGetTimezoneOffset(&timezoneOffset);
   1.223 +  return timezoneOffset;
   1.224 +}
   1.225 +
   1.226 +void
   1.227 +EnableSystemClockChangeNotifications()
   1.228 +{
   1.229 +  Hal()->SendEnableSystemClockChangeNotifications();
   1.230 +}
   1.231 +
   1.232 +void
   1.233 +DisableSystemClockChangeNotifications()
   1.234 +{
   1.235 +  Hal()->SendDisableSystemClockChangeNotifications();
   1.236 +}
   1.237 +
   1.238 +void
   1.239 +EnableSystemTimezoneChangeNotifications()
   1.240 +{
   1.241 +  Hal()->SendEnableSystemTimezoneChangeNotifications();
   1.242 +}
   1.243 +
   1.244 +void
   1.245 +DisableSystemTimezoneChangeNotifications()
   1.246 +{
   1.247 +  Hal()->SendDisableSystemTimezoneChangeNotifications();
   1.248 +}
   1.249 +
   1.250 +void
   1.251 +Reboot()
   1.252 +{
   1.253 +  NS_RUNTIMEABORT("Reboot() can't be called from sandboxed contexts.");
   1.254 +}
   1.255 +
   1.256 +void
   1.257 +PowerOff()
   1.258 +{
   1.259 +  NS_RUNTIMEABORT("PowerOff() can't be called from sandboxed contexts.");
   1.260 +}
   1.261 +
   1.262 +void
   1.263 +StartForceQuitWatchdog(ShutdownMode aMode, int32_t aTimeoutSecs)
   1.264 +{
   1.265 +  NS_RUNTIMEABORT("StartForceQuitWatchdog() can't be called from sandboxed contexts.");
   1.266 +}
   1.267 +
   1.268 +void
   1.269 +EnableSensorNotifications(SensorType aSensor) {
   1.270 +  Hal()->SendEnableSensorNotifications(aSensor);
   1.271 +}
   1.272 +
   1.273 +void
   1.274 +DisableSensorNotifications(SensorType aSensor) {
   1.275 +  Hal()->SendDisableSensorNotifications(aSensor);
   1.276 +}
   1.277 +
   1.278 +//TODO: bug 852944 - IPC implementations of these
   1.279 +void StartMonitoringGamepadStatus()
   1.280 +{}
   1.281 +
   1.282 +void StopMonitoringGamepadStatus()
   1.283 +{}
   1.284 +
   1.285 +void
   1.286 +EnableWakeLockNotifications()
   1.287 +{
   1.288 +  Hal()->SendEnableWakeLockNotifications();
   1.289 +}
   1.290 +
   1.291 +void
   1.292 +DisableWakeLockNotifications()
   1.293 +{
   1.294 +  Hal()->SendDisableWakeLockNotifications();
   1.295 +}
   1.296 +
   1.297 +void
   1.298 +ModifyWakeLock(const nsAString &aTopic,
   1.299 +               WakeLockControl aLockAdjust,
   1.300 +               WakeLockControl aHiddenAdjust,
   1.301 +               uint64_t aProcessID)
   1.302 +{
   1.303 +  MOZ_ASSERT(aProcessID != CONTENT_PROCESS_ID_UNKNOWN);
   1.304 +  Hal()->SendModifyWakeLock(nsString(aTopic), aLockAdjust, aHiddenAdjust, aProcessID);
   1.305 +}
   1.306 +
   1.307 +void
   1.308 +GetWakeLockInfo(const nsAString &aTopic, WakeLockInformation *aWakeLockInfo)
   1.309 +{
   1.310 +  Hal()->SendGetWakeLockInfo(nsString(aTopic), aWakeLockInfo);
   1.311 +}
   1.312 +
   1.313 +void
   1.314 +EnableSwitchNotifications(SwitchDevice aDevice)
   1.315 +{
   1.316 +  Hal()->SendEnableSwitchNotifications(aDevice);
   1.317 +}
   1.318 +
   1.319 +void
   1.320 +DisableSwitchNotifications(SwitchDevice aDevice)
   1.321 +{
   1.322 +  Hal()->SendDisableSwitchNotifications(aDevice);
   1.323 +}
   1.324 +
   1.325 +SwitchState
   1.326 +GetCurrentSwitchState(SwitchDevice aDevice)
   1.327 +{
   1.328 +  SwitchState state;
   1.329 +  Hal()->SendGetCurrentSwitchState(aDevice, &state);
   1.330 +  return state;
   1.331 +}
   1.332 +
   1.333 +void
   1.334 +NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState)
   1.335 +{
   1.336 +  Hal()->SendNotifySwitchStateFromInputDevice(aDevice, aState);
   1.337 +}
   1.338 +
   1.339 +bool
   1.340 +EnableAlarm()
   1.341 +{
   1.342 +  NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts.  Yet.");
   1.343 +  return false;
   1.344 +}
   1.345 +
   1.346 +void
   1.347 +DisableAlarm()
   1.348 +{
   1.349 +  NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts.  Yet.");
   1.350 +}
   1.351 +
   1.352 +bool
   1.353 +SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
   1.354 +{
   1.355 +  NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts.  Yet.");
   1.356 +  return false;
   1.357 +}
   1.358 +
   1.359 +void
   1.360 +SetProcessPriority(int aPid,
   1.361 +                   ProcessPriority aPriority,
   1.362 +                   ProcessCPUPriority aCPUPriority,
   1.363 +                   uint32_t aBackgroundLRU)
   1.364 +{
   1.365 +  NS_RUNTIMEABORT("Only the main process may set processes' priorities.");
   1.366 +}
   1.367 +
   1.368 +void
   1.369 +EnableFMRadio(const hal::FMRadioSettings& aSettings)
   1.370 +{
   1.371 +  NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
   1.372 +}
   1.373 +
   1.374 +void
   1.375 +DisableFMRadio()
   1.376 +{
   1.377 +  NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
   1.378 +}
   1.379 +
   1.380 +void
   1.381 +FMRadioSeek(const hal::FMRadioSeekDirection& aDirection)
   1.382 +{
   1.383 +  NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
   1.384 +}
   1.385 +
   1.386 +void
   1.387 +GetFMRadioSettings(FMRadioSettings* aSettings)
   1.388 +{
   1.389 +  NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
   1.390 +}
   1.391 +
   1.392 +void
   1.393 +SetFMRadioFrequency(const uint32_t aFrequency)
   1.394 +{
   1.395 +  NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
   1.396 +}
   1.397 +
   1.398 +uint32_t
   1.399 +GetFMRadioFrequency()
   1.400 +{
   1.401 +  NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
   1.402 +  return 0;
   1.403 +}
   1.404 +
   1.405 +bool
   1.406 +IsFMRadioOn()
   1.407 +{
   1.408 +  NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
   1.409 +  return false;
   1.410 +}
   1.411 +
   1.412 +uint32_t
   1.413 +GetFMRadioSignalStrength()
   1.414 +{
   1.415 +  NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
   1.416 +  return 0;
   1.417 +}
   1.418 +
   1.419 +void
   1.420 +CancelFMRadioSeek()
   1.421 +{
   1.422 +  NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
   1.423 +}
   1.424 +
   1.425 +void
   1.426 +FactoryReset()
   1.427 +{
   1.428 +  Hal()->SendFactoryReset();
   1.429 +}
   1.430 +
   1.431 +void
   1.432 +StartDiskSpaceWatcher()
   1.433 +{
   1.434 +  NS_RUNTIMEABORT("StartDiskSpaceWatcher() can't be called from sandboxed contexts.");
   1.435 +}
   1.436 +
   1.437 +void
   1.438 +StopDiskSpaceWatcher()
   1.439 +{
   1.440 +  NS_RUNTIMEABORT("StopDiskSpaceWatcher() can't be called from sandboxed contexts.");
   1.441 +}
   1.442 +
   1.443 +class HalParent : public PHalParent
   1.444 +                , public BatteryObserver
   1.445 +                , public NetworkObserver
   1.446 +                , public ISensorObserver
   1.447 +                , public WakeLockObserver
   1.448 +                , public ScreenConfigurationObserver
   1.449 +                , public SwitchObserver
   1.450 +                , public SystemClockChangeObserver
   1.451 +                , public SystemTimezoneChangeObserver
   1.452 +{
   1.453 +public:
   1.454 +  virtual void
   1.455 +  ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE
   1.456 +  {
   1.457 +    // NB: you *must* unconditionally unregister your observer here,
   1.458 +    // if it *may* be registered below.
   1.459 +    hal::UnregisterBatteryObserver(this);
   1.460 +    hal::UnregisterNetworkObserver(this);
   1.461 +    hal::UnregisterScreenConfigurationObserver(this);
   1.462 +    for (int32_t sensor = SENSOR_UNKNOWN + 1;
   1.463 +         sensor < NUM_SENSOR_TYPE; ++sensor) {
   1.464 +      hal::UnregisterSensorObserver(SensorType(sensor), this);
   1.465 +    }
   1.466 +    hal::UnregisterWakeLockObserver(this);
   1.467 +    hal::UnregisterSystemClockChangeObserver(this);
   1.468 +    hal::UnregisterSystemTimezoneChangeObserver(this);
   1.469 +    for (int32_t switchDevice = SWITCH_DEVICE_UNKNOWN + 1;
   1.470 +         switchDevice < NUM_SWITCH_DEVICE; ++switchDevice) {
   1.471 +      hal::UnregisterSwitchObserver(SwitchDevice(switchDevice), this);
   1.472 +    }
   1.473 +  }
   1.474 +
   1.475 +  virtual bool
   1.476 +  RecvVibrate(const InfallibleTArray<unsigned int>& pattern,
   1.477 +              const InfallibleTArray<uint64_t> &id,
   1.478 +              PBrowserParent *browserParent) MOZ_OVERRIDE
   1.479 +  {
   1.480 +    // We give all content vibration permission.
   1.481 +    TabParent *tabParent = static_cast<TabParent*>(browserParent);
   1.482 +    nsCOMPtr<nsIDOMWindow> window =
   1.483 +      do_QueryInterface(tabParent->GetBrowserDOMWindow());
   1.484 +    WindowIdentifier newID(id, window);
   1.485 +    hal::Vibrate(pattern, newID);
   1.486 +    return true;
   1.487 +  }
   1.488 +
   1.489 +  virtual bool
   1.490 +  RecvCancelVibrate(const InfallibleTArray<uint64_t> &id,
   1.491 +                    PBrowserParent *browserParent) MOZ_OVERRIDE
   1.492 +  {
   1.493 +    TabParent *tabParent = static_cast<TabParent*>(browserParent);
   1.494 +    nsCOMPtr<nsIDOMWindow> window =
   1.495 +      do_QueryInterface(tabParent->GetBrowserDOMWindow());
   1.496 +    WindowIdentifier newID(id, window);
   1.497 +    hal::CancelVibrate(newID);
   1.498 +    return true;
   1.499 +  }
   1.500 +
   1.501 +  virtual bool
   1.502 +  RecvEnableBatteryNotifications() MOZ_OVERRIDE {
   1.503 +    // We give all content battery-status permission.
   1.504 +    hal::RegisterBatteryObserver(this);
   1.505 +    return true;
   1.506 +  }
   1.507 +
   1.508 +  virtual bool
   1.509 +  RecvDisableBatteryNotifications() MOZ_OVERRIDE {
   1.510 +    hal::UnregisterBatteryObserver(this);
   1.511 +    return true;
   1.512 +  }
   1.513 +
   1.514 +  virtual bool
   1.515 +  RecvGetCurrentBatteryInformation(BatteryInformation* aBatteryInfo) MOZ_OVERRIDE {
   1.516 +    // We give all content battery-status permission.
   1.517 +    hal::GetCurrentBatteryInformation(aBatteryInfo);
   1.518 +    return true;
   1.519 +  }
   1.520 +
   1.521 +  void Notify(const BatteryInformation& aBatteryInfo) MOZ_OVERRIDE {
   1.522 +    unused << SendNotifyBatteryChange(aBatteryInfo);
   1.523 +  }
   1.524 +
   1.525 +  virtual bool
   1.526 +  RecvEnableNetworkNotifications() MOZ_OVERRIDE {
   1.527 +    // We give all content access to this network-status information.
   1.528 +    hal::RegisterNetworkObserver(this);
   1.529 +    return true;
   1.530 +  }
   1.531 +
   1.532 +  virtual bool
   1.533 +  RecvDisableNetworkNotifications() MOZ_OVERRIDE {
   1.534 +    hal::UnregisterNetworkObserver(this);
   1.535 +    return true;
   1.536 +  }
   1.537 +
   1.538 +  virtual bool
   1.539 +  RecvGetCurrentNetworkInformation(NetworkInformation* aNetworkInfo) MOZ_OVERRIDE {
   1.540 +    hal::GetCurrentNetworkInformation(aNetworkInfo);
   1.541 +    return true;
   1.542 +  }
   1.543 +
   1.544 +  void Notify(const NetworkInformation& aNetworkInfo) {
   1.545 +    unused << SendNotifyNetworkChange(aNetworkInfo);
   1.546 +  }
   1.547 +
   1.548 +  virtual bool
   1.549 +  RecvEnableScreenConfigurationNotifications() MOZ_OVERRIDE {
   1.550 +    // Screen configuration is used to implement CSS and DOM
   1.551 +    // properties, so all content already has access to this.
   1.552 +    hal::RegisterScreenConfigurationObserver(this);
   1.553 +    return true;
   1.554 +  }
   1.555 +
   1.556 +  virtual bool
   1.557 +  RecvDisableScreenConfigurationNotifications() MOZ_OVERRIDE {
   1.558 +    hal::UnregisterScreenConfigurationObserver(this);
   1.559 +    return true;
   1.560 +  }
   1.561 +
   1.562 +  virtual bool
   1.563 +  RecvGetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) MOZ_OVERRIDE {
   1.564 +    hal::GetCurrentScreenConfiguration(aScreenConfiguration);
   1.565 +    return true;
   1.566 +  }
   1.567 +
   1.568 +  virtual bool
   1.569 +  RecvLockScreenOrientation(const dom::ScreenOrientation& aOrientation, bool* aAllowed) MOZ_OVERRIDE
   1.570 +  {
   1.571 +    // FIXME/bug 777980: unprivileged content may only lock
   1.572 +    // orientation while fullscreen.  We should check whether the
   1.573 +    // request comes from an actor in a process that might be
   1.574 +    // fullscreen.  We don't have that information currently.
   1.575 +    *aAllowed = hal::LockScreenOrientation(aOrientation);
   1.576 +    return true;
   1.577 +  }
   1.578 +
   1.579 +  virtual bool
   1.580 +  RecvUnlockScreenOrientation() MOZ_OVERRIDE
   1.581 +  {
   1.582 +    hal::UnlockScreenOrientation();
   1.583 +    return true;
   1.584 +  }
   1.585 +
   1.586 +  void Notify(const ScreenConfiguration& aScreenConfiguration) {
   1.587 +    unused << SendNotifyScreenConfigurationChange(aScreenConfiguration);
   1.588 +  }
   1.589 +
   1.590 +  virtual bool
   1.591 +  RecvGetScreenEnabled(bool *enabled) MOZ_OVERRIDE
   1.592 +  {
   1.593 +    if (!AssertAppProcessPermission(this, "power")) {
   1.594 +      return false;
   1.595 +    }
   1.596 +    *enabled = hal::GetScreenEnabled();
   1.597 +    return true;
   1.598 +  }
   1.599 +
   1.600 +  virtual bool
   1.601 +  RecvSetScreenEnabled(const bool &enabled) MOZ_OVERRIDE
   1.602 +  {
   1.603 +    if (!AssertAppProcessPermission(this, "power")) {
   1.604 +      return false;
   1.605 +    }
   1.606 +    hal::SetScreenEnabled(enabled);
   1.607 +    return true;
   1.608 +  }
   1.609 +
   1.610 +  virtual bool
   1.611 +  RecvGetCpuSleepAllowed(bool *allowed) MOZ_OVERRIDE
   1.612 +  {
   1.613 +    if (!AssertAppProcessPermission(this, "power")) {
   1.614 +      return false;
   1.615 +    }
   1.616 +    *allowed = hal::GetCpuSleepAllowed();
   1.617 +    return true;
   1.618 +  }
   1.619 +
   1.620 +  virtual bool
   1.621 +  RecvSetCpuSleepAllowed(const bool &allowed) MOZ_OVERRIDE
   1.622 +  {
   1.623 +    if (!AssertAppProcessPermission(this, "power")) {
   1.624 +      return false;
   1.625 +    }
   1.626 +    hal::SetCpuSleepAllowed(allowed);
   1.627 +    return true;
   1.628 +  }
   1.629 +
   1.630 +  virtual bool
   1.631 +  RecvGetScreenBrightness(double *brightness) MOZ_OVERRIDE
   1.632 +  {
   1.633 +    if (!AssertAppProcessPermission(this, "power")) {
   1.634 +      return false;
   1.635 +    }
   1.636 +    *brightness = hal::GetScreenBrightness();
   1.637 +    return true;
   1.638 +  }
   1.639 +
   1.640 +  virtual bool
   1.641 +  RecvSetScreenBrightness(const double &brightness) MOZ_OVERRIDE
   1.642 +  {
   1.643 +    if (!AssertAppProcessPermission(this, "power")) {
   1.644 +      return false;
   1.645 +    }
   1.646 +    hal::SetScreenBrightness(brightness);
   1.647 +    return true;
   1.648 +  }
   1.649 +
   1.650 +  virtual bool
   1.651 +  RecvSetLight(const LightType& aLight,  const hal::LightConfiguration& aConfig, bool *status) MOZ_OVERRIDE
   1.652 +  {
   1.653 +    // XXX currently, the hardware key light and screen backlight are
   1.654 +    // controlled as a unit.  Those are set through the power API, and
   1.655 +    // there's no other way to poke lights currently, so we require
   1.656 +    // "power" privileges here.
   1.657 +    if (!AssertAppProcessPermission(this, "power")) {
   1.658 +      return false;
   1.659 +    }
   1.660 +    *status = hal::SetLight(aLight, aConfig);
   1.661 +    return true;
   1.662 +  }
   1.663 +
   1.664 +  virtual bool
   1.665 +  RecvGetLight(const LightType& aLight, LightConfiguration* aConfig, bool* status) MOZ_OVERRIDE
   1.666 +  {
   1.667 +    if (!AssertAppProcessPermission(this, "power")) {
   1.668 +      return false;
   1.669 +    }
   1.670 +    *status = hal::GetLight(aLight, aConfig);
   1.671 +    return true;
   1.672 +  }
   1.673 +
   1.674 +  virtual bool
   1.675 +  RecvAdjustSystemClock(const int64_t &aDeltaMilliseconds) MOZ_OVERRIDE
   1.676 +  {
   1.677 +    if (!AssertAppProcessPermission(this, "time")) {
   1.678 +      return false;
   1.679 +    }
   1.680 +    hal::AdjustSystemClock(aDeltaMilliseconds);
   1.681 +    return true;
   1.682 +  }
   1.683 +
   1.684 +  virtual bool 
   1.685 +  RecvSetTimezone(const nsCString& aTimezoneSpec) MOZ_OVERRIDE
   1.686 +  {
   1.687 +    if (!AssertAppProcessPermission(this, "time")) {
   1.688 +      return false;
   1.689 +    }
   1.690 +    hal::SetTimezone(aTimezoneSpec);
   1.691 +    return true;  
   1.692 +  }
   1.693 +
   1.694 +  virtual bool
   1.695 +  RecvGetTimezone(nsCString *aTimezoneSpec) MOZ_OVERRIDE
   1.696 +  {
   1.697 +    if (!AssertAppProcessPermission(this, "time")) {
   1.698 +      return false;
   1.699 +    }
   1.700 +    *aTimezoneSpec = hal::GetTimezone();
   1.701 +    return true;
   1.702 +  }
   1.703 +
   1.704 +  virtual bool
   1.705 +  RecvGetTimezoneOffset(int32_t *aTimezoneOffset) MOZ_OVERRIDE
   1.706 +  {
   1.707 +    if (!AssertAppProcessPermission(this, "time")) {
   1.708 +      return false;
   1.709 +    }
   1.710 +    *aTimezoneOffset = hal::GetTimezoneOffset();
   1.711 +    return true;
   1.712 +  }
   1.713 +
   1.714 +  virtual bool
   1.715 +  RecvEnableSystemClockChangeNotifications() MOZ_OVERRIDE
   1.716 +  {
   1.717 +    hal::RegisterSystemClockChangeObserver(this);
   1.718 +    return true;
   1.719 +  }
   1.720 +
   1.721 +  virtual bool
   1.722 +  RecvDisableSystemClockChangeNotifications() MOZ_OVERRIDE
   1.723 +  {
   1.724 +    hal::UnregisterSystemClockChangeObserver(this);
   1.725 +    return true;
   1.726 +  }
   1.727 +
   1.728 +  virtual bool
   1.729 +  RecvEnableSystemTimezoneChangeNotifications() MOZ_OVERRIDE
   1.730 +  {
   1.731 +    hal::RegisterSystemTimezoneChangeObserver(this);
   1.732 +    return true;
   1.733 +  }
   1.734 +
   1.735 +  virtual bool
   1.736 +  RecvDisableSystemTimezoneChangeNotifications() MOZ_OVERRIDE
   1.737 +  {
   1.738 +    hal::UnregisterSystemTimezoneChangeObserver(this);
   1.739 +    return true;
   1.740 +  }
   1.741 +
   1.742 +  virtual bool
   1.743 +  RecvEnableSensorNotifications(const SensorType &aSensor) MOZ_OVERRIDE {
   1.744 +    // We currently allow any content to register device-sensor
   1.745 +    // listeners.
   1.746 +    hal::RegisterSensorObserver(aSensor, this);
   1.747 +    return true;
   1.748 +  }
   1.749 +   
   1.750 +  virtual bool
   1.751 +  RecvDisableSensorNotifications(const SensorType &aSensor) MOZ_OVERRIDE {
   1.752 +    hal::UnregisterSensorObserver(aSensor, this);
   1.753 +    return true;
   1.754 +  }
   1.755 +  
   1.756 +  void Notify(const SensorData& aSensorData) {
   1.757 +    unused << SendNotifySensorChange(aSensorData);
   1.758 +  }
   1.759 +
   1.760 +  virtual bool
   1.761 +  RecvModifyWakeLock(const nsString& aTopic,
   1.762 +                     const WakeLockControl& aLockAdjust,
   1.763 +                     const WakeLockControl& aHiddenAdjust,
   1.764 +                     const uint64_t& aProcessID) MOZ_OVERRIDE
   1.765 +  {
   1.766 +    MOZ_ASSERT(aProcessID != CONTENT_PROCESS_ID_UNKNOWN);
   1.767 +
   1.768 +    // We allow arbitrary content to use wake locks.
   1.769 +    hal::ModifyWakeLock(aTopic, aLockAdjust, aHiddenAdjust, aProcessID);
   1.770 +    return true;
   1.771 +  }
   1.772 +
   1.773 +  virtual bool
   1.774 +  RecvEnableWakeLockNotifications() MOZ_OVERRIDE
   1.775 +  {
   1.776 +    // We allow arbitrary content to use wake locks.
   1.777 +    hal::RegisterWakeLockObserver(this);
   1.778 +    return true;
   1.779 +  }
   1.780 +   
   1.781 +  virtual bool
   1.782 +  RecvDisableWakeLockNotifications() MOZ_OVERRIDE
   1.783 +  {
   1.784 +    hal::UnregisterWakeLockObserver(this);
   1.785 +    return true;
   1.786 +  }
   1.787 +
   1.788 +  virtual bool
   1.789 +  RecvGetWakeLockInfo(const nsString &aTopic, WakeLockInformation *aWakeLockInfo) MOZ_OVERRIDE
   1.790 +  {
   1.791 +    hal::GetWakeLockInfo(aTopic, aWakeLockInfo);
   1.792 +    return true;
   1.793 +  }
   1.794 +  
   1.795 +  void Notify(const WakeLockInformation& aWakeLockInfo)
   1.796 +  {
   1.797 +    unused << SendNotifyWakeLockChange(aWakeLockInfo);
   1.798 +  }
   1.799 +
   1.800 +  virtual bool
   1.801 +  RecvEnableSwitchNotifications(const SwitchDevice& aDevice) MOZ_OVERRIDE
   1.802 +  {
   1.803 +    // Content has no reason to listen to switch events currently.
   1.804 +    hal::RegisterSwitchObserver(aDevice, this);
   1.805 +    return true;
   1.806 +  }
   1.807 +
   1.808 +  virtual bool
   1.809 +  RecvDisableSwitchNotifications(const SwitchDevice& aDevice) MOZ_OVERRIDE
   1.810 +  {
   1.811 +    hal::UnregisterSwitchObserver(aDevice, this);
   1.812 +    return true;
   1.813 +  }
   1.814 +
   1.815 +  void Notify(const SwitchEvent& aSwitchEvent)
   1.816 +  {
   1.817 +    unused << SendNotifySwitchChange(aSwitchEvent);
   1.818 +  }
   1.819 +
   1.820 +  virtual bool
   1.821 +  RecvGetCurrentSwitchState(const SwitchDevice& aDevice, hal::SwitchState *aState) MOZ_OVERRIDE
   1.822 +  {
   1.823 +    // Content has no reason to listen to switch events currently.
   1.824 +    *aState = hal::GetCurrentSwitchState(aDevice);
   1.825 +    return true;
   1.826 +  }
   1.827 +
   1.828 +  virtual bool
   1.829 +  RecvNotifySwitchStateFromInputDevice(const SwitchDevice& aDevice,
   1.830 +                                       const SwitchState& aState) MOZ_OVERRIDE
   1.831 +  {
   1.832 +    hal::NotifySwitchStateFromInputDevice(aDevice, aState);
   1.833 +    return true;
   1.834 +  }
   1.835 +
   1.836 +  void Notify(const int64_t& aClockDeltaMS)
   1.837 +  {
   1.838 +    unused << SendNotifySystemClockChange(aClockDeltaMS);
   1.839 +  }
   1.840 +
   1.841 +  void Notify(const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
   1.842 +  {
   1.843 +    unused << SendNotifySystemTimezoneChange(aSystemTimezoneChangeInfo);
   1.844 +  }
   1.845 +
   1.846 +  virtual bool
   1.847 +  RecvFactoryReset()
   1.848 +  {
   1.849 +    if (!AssertAppProcessPermission(this, "power")) {
   1.850 +      return false;
   1.851 +    }
   1.852 +    hal::FactoryReset();
   1.853 +    return true;
   1.854 +  }
   1.855 +
   1.856 +  virtual mozilla::ipc::IProtocol*
   1.857 +  CloneProtocol(Channel* aChannel,
   1.858 +                mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE
   1.859 +  {
   1.860 +    ContentParent* contentParent = aCtx->GetContentParent();
   1.861 +    nsAutoPtr<PHalParent> actor(contentParent->AllocPHalParent());
   1.862 +    if (!actor || !contentParent->RecvPHalConstructor(actor)) {
   1.863 +      return nullptr;
   1.864 +    }
   1.865 +    return actor.forget();
   1.866 +  }
   1.867 +};
   1.868 +
   1.869 +class HalChild : public PHalChild {
   1.870 +public:
   1.871 +  virtual void
   1.872 +  ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE
   1.873 +  {
   1.874 +    sHalChildDestroyed = true;
   1.875 +  }
   1.876 +
   1.877 +  virtual bool
   1.878 +  RecvNotifyBatteryChange(const BatteryInformation& aBatteryInfo) MOZ_OVERRIDE {
   1.879 +    hal::NotifyBatteryChange(aBatteryInfo);
   1.880 +    return true;
   1.881 +  }
   1.882 +
   1.883 +  virtual bool
   1.884 +  RecvNotifySensorChange(const hal::SensorData &aSensorData) MOZ_OVERRIDE;
   1.885 +
   1.886 +  virtual bool
   1.887 +  RecvNotifyNetworkChange(const NetworkInformation& aNetworkInfo) MOZ_OVERRIDE {
   1.888 +    hal::NotifyNetworkChange(aNetworkInfo);
   1.889 +    return true;
   1.890 +  }
   1.891 +
   1.892 +  virtual bool
   1.893 +  RecvNotifyWakeLockChange(const WakeLockInformation& aWakeLockInfo) MOZ_OVERRIDE {
   1.894 +    hal::NotifyWakeLockChange(aWakeLockInfo);
   1.895 +    return true;
   1.896 +  }
   1.897 +
   1.898 +  virtual bool
   1.899 +  RecvNotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration) MOZ_OVERRIDE {
   1.900 +    hal::NotifyScreenConfigurationChange(aScreenConfiguration);
   1.901 +    return true;
   1.902 +  }
   1.903 +
   1.904 +  virtual bool
   1.905 +  RecvNotifySwitchChange(const mozilla::hal::SwitchEvent& aEvent) MOZ_OVERRIDE {
   1.906 +    hal::NotifySwitchChange(aEvent);
   1.907 +    return true;
   1.908 +  }
   1.909 +
   1.910 +  virtual bool
   1.911 +  RecvNotifySystemClockChange(const int64_t& aClockDeltaMS) {
   1.912 +    hal::NotifySystemClockChange(aClockDeltaMS);
   1.913 +    return true;
   1.914 +  }
   1.915 +
   1.916 +  virtual bool
   1.917 +  RecvNotifySystemTimezoneChange(
   1.918 +    const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo) {
   1.919 +    hal::NotifySystemTimezoneChange(aSystemTimezoneChangeInfo);
   1.920 +    return true;
   1.921 +  }
   1.922 +};
   1.923 +
   1.924 +bool
   1.925 +HalChild::RecvNotifySensorChange(const hal::SensorData &aSensorData) {
   1.926 +  hal::NotifySensorChange(aSensorData);
   1.927 +  
   1.928 +  return true;
   1.929 +}
   1.930 +
   1.931 +PHalChild* CreateHalChild() {
   1.932 +  return new HalChild();
   1.933 +}
   1.934 +
   1.935 +PHalParent* CreateHalParent() {
   1.936 +  return new HalParent();
   1.937 +}
   1.938 +
   1.939 +} // namespace hal_sandbox
   1.940 +} // namespace mozilla

mercurial