Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set sw=2 ts=8 et ft=cpp : */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "Hal.h"
8 #include "mozilla/AppProcessChecker.h"
9 #include "mozilla/dom/ContentChild.h"
10 #include "mozilla/dom/ContentParent.h"
11 #include "mozilla/hal_sandbox/PHalChild.h"
12 #include "mozilla/hal_sandbox/PHalParent.h"
13 #include "mozilla/dom/TabParent.h"
14 #include "mozilla/dom/TabChild.h"
15 #include "mozilla/dom/battery/Types.h"
16 #include "mozilla/dom/network/Types.h"
17 #include "mozilla/dom/ScreenOrientation.h"
18 #include "mozilla/Observer.h"
19 #include "mozilla/unused.h"
20 #include "WindowIdentifier.h"
22 using namespace mozilla;
23 using namespace mozilla::dom;
24 using namespace mozilla::hal;
26 namespace mozilla {
27 namespace hal_sandbox {
29 static bool sHalChildDestroyed = false;
31 bool
32 HalChildDestroyed()
33 {
34 return sHalChildDestroyed;
35 }
37 static PHalChild* sHal;
38 static PHalChild*
39 Hal()
40 {
41 if (!sHal) {
42 sHal = ContentChild::GetSingleton()->SendPHalConstructor();
43 }
44 return sHal;
45 }
47 void
48 Vibrate(const nsTArray<uint32_t>& pattern, const WindowIdentifier &id)
49 {
50 HAL_LOG(("Vibrate: Sending to parent process."));
52 AutoInfallibleTArray<uint32_t, 8> p(pattern);
54 WindowIdentifier newID(id);
55 newID.AppendProcessID();
56 Hal()->SendVibrate(p, newID.AsArray(), TabChild::GetFrom(newID.GetWindow()));
57 }
59 void
60 CancelVibrate(const WindowIdentifier &id)
61 {
62 HAL_LOG(("CancelVibrate: Sending to parent process."));
64 WindowIdentifier newID(id);
65 newID.AppendProcessID();
66 Hal()->SendCancelVibrate(newID.AsArray(), TabChild::GetFrom(newID.GetWindow()));
67 }
69 void
70 EnableBatteryNotifications()
71 {
72 Hal()->SendEnableBatteryNotifications();
73 }
75 void
76 DisableBatteryNotifications()
77 {
78 Hal()->SendDisableBatteryNotifications();
79 }
81 void
82 GetCurrentBatteryInformation(BatteryInformation* aBatteryInfo)
83 {
84 Hal()->SendGetCurrentBatteryInformation(aBatteryInfo);
85 }
87 void
88 EnableNetworkNotifications()
89 {
90 Hal()->SendEnableNetworkNotifications();
91 }
93 void
94 DisableNetworkNotifications()
95 {
96 Hal()->SendDisableNetworkNotifications();
97 }
99 void
100 GetCurrentNetworkInformation(NetworkInformation* aNetworkInfo)
101 {
102 Hal()->SendGetCurrentNetworkInformation(aNetworkInfo);
103 }
105 void
106 EnableScreenConfigurationNotifications()
107 {
108 Hal()->SendEnableScreenConfigurationNotifications();
109 }
111 void
112 DisableScreenConfigurationNotifications()
113 {
114 Hal()->SendDisableScreenConfigurationNotifications();
115 }
117 void
118 GetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration)
119 {
120 Hal()->SendGetCurrentScreenConfiguration(aScreenConfiguration);
121 }
123 bool
124 LockScreenOrientation(const dom::ScreenOrientation& aOrientation)
125 {
126 bool allowed;
127 Hal()->SendLockScreenOrientation(aOrientation, &allowed);
128 return allowed;
129 }
131 void
132 UnlockScreenOrientation()
133 {
134 Hal()->SendUnlockScreenOrientation();
135 }
137 bool
138 GetScreenEnabled()
139 {
140 bool enabled = false;
141 Hal()->SendGetScreenEnabled(&enabled);
142 return enabled;
143 }
145 void
146 SetScreenEnabled(bool enabled)
147 {
148 Hal()->SendSetScreenEnabled(enabled);
149 }
151 bool
152 GetCpuSleepAllowed()
153 {
154 bool allowed = true;
155 Hal()->SendGetCpuSleepAllowed(&allowed);
156 return allowed;
157 }
159 void
160 SetCpuSleepAllowed(bool allowed)
161 {
162 Hal()->SendSetCpuSleepAllowed(allowed);
163 }
165 double
166 GetScreenBrightness()
167 {
168 double brightness = 0;
169 Hal()->SendGetScreenBrightness(&brightness);
170 return brightness;
171 }
173 void
174 SetScreenBrightness(double brightness)
175 {
176 Hal()->SendSetScreenBrightness(brightness);
177 }
179 bool
180 SetLight(hal::LightType light, const hal::LightConfiguration& aConfig)
181 {
182 bool status;
183 Hal()->SendSetLight(light, aConfig, &status);
184 return status;
185 }
187 bool
188 GetLight(hal::LightType light, hal::LightConfiguration* aConfig)
189 {
190 bool status;
191 Hal()->SendGetLight(light, aConfig, &status);
192 return status;
193 }
195 void
196 AdjustSystemClock(int64_t aDeltaMilliseconds)
197 {
198 Hal()->SendAdjustSystemClock(aDeltaMilliseconds);
199 }
201 void
202 SetTimezone(const nsCString& aTimezoneSpec)
203 {
204 Hal()->SendSetTimezone(nsCString(aTimezoneSpec));
205 }
207 nsCString
208 GetTimezone()
209 {
210 nsCString timezone;
211 Hal()->SendGetTimezone(&timezone);
212 return timezone;
213 }
215 int32_t
216 GetTimezoneOffset()
217 {
218 int32_t timezoneOffset;
219 Hal()->SendGetTimezoneOffset(&timezoneOffset);
220 return timezoneOffset;
221 }
223 void
224 EnableSystemClockChangeNotifications()
225 {
226 Hal()->SendEnableSystemClockChangeNotifications();
227 }
229 void
230 DisableSystemClockChangeNotifications()
231 {
232 Hal()->SendDisableSystemClockChangeNotifications();
233 }
235 void
236 EnableSystemTimezoneChangeNotifications()
237 {
238 Hal()->SendEnableSystemTimezoneChangeNotifications();
239 }
241 void
242 DisableSystemTimezoneChangeNotifications()
243 {
244 Hal()->SendDisableSystemTimezoneChangeNotifications();
245 }
247 void
248 Reboot()
249 {
250 NS_RUNTIMEABORT("Reboot() can't be called from sandboxed contexts.");
251 }
253 void
254 PowerOff()
255 {
256 NS_RUNTIMEABORT("PowerOff() can't be called from sandboxed contexts.");
257 }
259 void
260 StartForceQuitWatchdog(ShutdownMode aMode, int32_t aTimeoutSecs)
261 {
262 NS_RUNTIMEABORT("StartForceQuitWatchdog() can't be called from sandboxed contexts.");
263 }
265 void
266 EnableSensorNotifications(SensorType aSensor) {
267 Hal()->SendEnableSensorNotifications(aSensor);
268 }
270 void
271 DisableSensorNotifications(SensorType aSensor) {
272 Hal()->SendDisableSensorNotifications(aSensor);
273 }
275 //TODO: bug 852944 - IPC implementations of these
276 void StartMonitoringGamepadStatus()
277 {}
279 void StopMonitoringGamepadStatus()
280 {}
282 void
283 EnableWakeLockNotifications()
284 {
285 Hal()->SendEnableWakeLockNotifications();
286 }
288 void
289 DisableWakeLockNotifications()
290 {
291 Hal()->SendDisableWakeLockNotifications();
292 }
294 void
295 ModifyWakeLock(const nsAString &aTopic,
296 WakeLockControl aLockAdjust,
297 WakeLockControl aHiddenAdjust,
298 uint64_t aProcessID)
299 {
300 MOZ_ASSERT(aProcessID != CONTENT_PROCESS_ID_UNKNOWN);
301 Hal()->SendModifyWakeLock(nsString(aTopic), aLockAdjust, aHiddenAdjust, aProcessID);
302 }
304 void
305 GetWakeLockInfo(const nsAString &aTopic, WakeLockInformation *aWakeLockInfo)
306 {
307 Hal()->SendGetWakeLockInfo(nsString(aTopic), aWakeLockInfo);
308 }
310 void
311 EnableSwitchNotifications(SwitchDevice aDevice)
312 {
313 Hal()->SendEnableSwitchNotifications(aDevice);
314 }
316 void
317 DisableSwitchNotifications(SwitchDevice aDevice)
318 {
319 Hal()->SendDisableSwitchNotifications(aDevice);
320 }
322 SwitchState
323 GetCurrentSwitchState(SwitchDevice aDevice)
324 {
325 SwitchState state;
326 Hal()->SendGetCurrentSwitchState(aDevice, &state);
327 return state;
328 }
330 void
331 NotifySwitchStateFromInputDevice(SwitchDevice aDevice, SwitchState aState)
332 {
333 Hal()->SendNotifySwitchStateFromInputDevice(aDevice, aState);
334 }
336 bool
337 EnableAlarm()
338 {
339 NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts. Yet.");
340 return false;
341 }
343 void
344 DisableAlarm()
345 {
346 NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts. Yet.");
347 }
349 bool
350 SetAlarm(int32_t aSeconds, int32_t aNanoseconds)
351 {
352 NS_RUNTIMEABORT("Alarms can't be programmed from sandboxed contexts. Yet.");
353 return false;
354 }
356 void
357 SetProcessPriority(int aPid,
358 ProcessPriority aPriority,
359 ProcessCPUPriority aCPUPriority,
360 uint32_t aBackgroundLRU)
361 {
362 NS_RUNTIMEABORT("Only the main process may set processes' priorities.");
363 }
365 void
366 EnableFMRadio(const hal::FMRadioSettings& aSettings)
367 {
368 NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
369 }
371 void
372 DisableFMRadio()
373 {
374 NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
375 }
377 void
378 FMRadioSeek(const hal::FMRadioSeekDirection& aDirection)
379 {
380 NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
381 }
383 void
384 GetFMRadioSettings(FMRadioSettings* aSettings)
385 {
386 NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
387 }
389 void
390 SetFMRadioFrequency(const uint32_t aFrequency)
391 {
392 NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
393 }
395 uint32_t
396 GetFMRadioFrequency()
397 {
398 NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
399 return 0;
400 }
402 bool
403 IsFMRadioOn()
404 {
405 NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
406 return false;
407 }
409 uint32_t
410 GetFMRadioSignalStrength()
411 {
412 NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
413 return 0;
414 }
416 void
417 CancelFMRadioSeek()
418 {
419 NS_RUNTIMEABORT("FM radio cannot be called from sandboxed contexts.");
420 }
422 void
423 FactoryReset()
424 {
425 Hal()->SendFactoryReset();
426 }
428 void
429 StartDiskSpaceWatcher()
430 {
431 NS_RUNTIMEABORT("StartDiskSpaceWatcher() can't be called from sandboxed contexts.");
432 }
434 void
435 StopDiskSpaceWatcher()
436 {
437 NS_RUNTIMEABORT("StopDiskSpaceWatcher() can't be called from sandboxed contexts.");
438 }
440 class HalParent : public PHalParent
441 , public BatteryObserver
442 , public NetworkObserver
443 , public ISensorObserver
444 , public WakeLockObserver
445 , public ScreenConfigurationObserver
446 , public SwitchObserver
447 , public SystemClockChangeObserver
448 , public SystemTimezoneChangeObserver
449 {
450 public:
451 virtual void
452 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE
453 {
454 // NB: you *must* unconditionally unregister your observer here,
455 // if it *may* be registered below.
456 hal::UnregisterBatteryObserver(this);
457 hal::UnregisterNetworkObserver(this);
458 hal::UnregisterScreenConfigurationObserver(this);
459 for (int32_t sensor = SENSOR_UNKNOWN + 1;
460 sensor < NUM_SENSOR_TYPE; ++sensor) {
461 hal::UnregisterSensorObserver(SensorType(sensor), this);
462 }
463 hal::UnregisterWakeLockObserver(this);
464 hal::UnregisterSystemClockChangeObserver(this);
465 hal::UnregisterSystemTimezoneChangeObserver(this);
466 for (int32_t switchDevice = SWITCH_DEVICE_UNKNOWN + 1;
467 switchDevice < NUM_SWITCH_DEVICE; ++switchDevice) {
468 hal::UnregisterSwitchObserver(SwitchDevice(switchDevice), this);
469 }
470 }
472 virtual bool
473 RecvVibrate(const InfallibleTArray<unsigned int>& pattern,
474 const InfallibleTArray<uint64_t> &id,
475 PBrowserParent *browserParent) MOZ_OVERRIDE
476 {
477 // We give all content vibration permission.
478 TabParent *tabParent = static_cast<TabParent*>(browserParent);
479 nsCOMPtr<nsIDOMWindow> window =
480 do_QueryInterface(tabParent->GetBrowserDOMWindow());
481 WindowIdentifier newID(id, window);
482 hal::Vibrate(pattern, newID);
483 return true;
484 }
486 virtual bool
487 RecvCancelVibrate(const InfallibleTArray<uint64_t> &id,
488 PBrowserParent *browserParent) MOZ_OVERRIDE
489 {
490 TabParent *tabParent = static_cast<TabParent*>(browserParent);
491 nsCOMPtr<nsIDOMWindow> window =
492 do_QueryInterface(tabParent->GetBrowserDOMWindow());
493 WindowIdentifier newID(id, window);
494 hal::CancelVibrate(newID);
495 return true;
496 }
498 virtual bool
499 RecvEnableBatteryNotifications() MOZ_OVERRIDE {
500 // We give all content battery-status permission.
501 hal::RegisterBatteryObserver(this);
502 return true;
503 }
505 virtual bool
506 RecvDisableBatteryNotifications() MOZ_OVERRIDE {
507 hal::UnregisterBatteryObserver(this);
508 return true;
509 }
511 virtual bool
512 RecvGetCurrentBatteryInformation(BatteryInformation* aBatteryInfo) MOZ_OVERRIDE {
513 // We give all content battery-status permission.
514 hal::GetCurrentBatteryInformation(aBatteryInfo);
515 return true;
516 }
518 void Notify(const BatteryInformation& aBatteryInfo) MOZ_OVERRIDE {
519 unused << SendNotifyBatteryChange(aBatteryInfo);
520 }
522 virtual bool
523 RecvEnableNetworkNotifications() MOZ_OVERRIDE {
524 // We give all content access to this network-status information.
525 hal::RegisterNetworkObserver(this);
526 return true;
527 }
529 virtual bool
530 RecvDisableNetworkNotifications() MOZ_OVERRIDE {
531 hal::UnregisterNetworkObserver(this);
532 return true;
533 }
535 virtual bool
536 RecvGetCurrentNetworkInformation(NetworkInformation* aNetworkInfo) MOZ_OVERRIDE {
537 hal::GetCurrentNetworkInformation(aNetworkInfo);
538 return true;
539 }
541 void Notify(const NetworkInformation& aNetworkInfo) {
542 unused << SendNotifyNetworkChange(aNetworkInfo);
543 }
545 virtual bool
546 RecvEnableScreenConfigurationNotifications() MOZ_OVERRIDE {
547 // Screen configuration is used to implement CSS and DOM
548 // properties, so all content already has access to this.
549 hal::RegisterScreenConfigurationObserver(this);
550 return true;
551 }
553 virtual bool
554 RecvDisableScreenConfigurationNotifications() MOZ_OVERRIDE {
555 hal::UnregisterScreenConfigurationObserver(this);
556 return true;
557 }
559 virtual bool
560 RecvGetCurrentScreenConfiguration(ScreenConfiguration* aScreenConfiguration) MOZ_OVERRIDE {
561 hal::GetCurrentScreenConfiguration(aScreenConfiguration);
562 return true;
563 }
565 virtual bool
566 RecvLockScreenOrientation(const dom::ScreenOrientation& aOrientation, bool* aAllowed) MOZ_OVERRIDE
567 {
568 // FIXME/bug 777980: unprivileged content may only lock
569 // orientation while fullscreen. We should check whether the
570 // request comes from an actor in a process that might be
571 // fullscreen. We don't have that information currently.
572 *aAllowed = hal::LockScreenOrientation(aOrientation);
573 return true;
574 }
576 virtual bool
577 RecvUnlockScreenOrientation() MOZ_OVERRIDE
578 {
579 hal::UnlockScreenOrientation();
580 return true;
581 }
583 void Notify(const ScreenConfiguration& aScreenConfiguration) {
584 unused << SendNotifyScreenConfigurationChange(aScreenConfiguration);
585 }
587 virtual bool
588 RecvGetScreenEnabled(bool *enabled) MOZ_OVERRIDE
589 {
590 if (!AssertAppProcessPermission(this, "power")) {
591 return false;
592 }
593 *enabled = hal::GetScreenEnabled();
594 return true;
595 }
597 virtual bool
598 RecvSetScreenEnabled(const bool &enabled) MOZ_OVERRIDE
599 {
600 if (!AssertAppProcessPermission(this, "power")) {
601 return false;
602 }
603 hal::SetScreenEnabled(enabled);
604 return true;
605 }
607 virtual bool
608 RecvGetCpuSleepAllowed(bool *allowed) MOZ_OVERRIDE
609 {
610 if (!AssertAppProcessPermission(this, "power")) {
611 return false;
612 }
613 *allowed = hal::GetCpuSleepAllowed();
614 return true;
615 }
617 virtual bool
618 RecvSetCpuSleepAllowed(const bool &allowed) MOZ_OVERRIDE
619 {
620 if (!AssertAppProcessPermission(this, "power")) {
621 return false;
622 }
623 hal::SetCpuSleepAllowed(allowed);
624 return true;
625 }
627 virtual bool
628 RecvGetScreenBrightness(double *brightness) MOZ_OVERRIDE
629 {
630 if (!AssertAppProcessPermission(this, "power")) {
631 return false;
632 }
633 *brightness = hal::GetScreenBrightness();
634 return true;
635 }
637 virtual bool
638 RecvSetScreenBrightness(const double &brightness) MOZ_OVERRIDE
639 {
640 if (!AssertAppProcessPermission(this, "power")) {
641 return false;
642 }
643 hal::SetScreenBrightness(brightness);
644 return true;
645 }
647 virtual bool
648 RecvSetLight(const LightType& aLight, const hal::LightConfiguration& aConfig, bool *status) MOZ_OVERRIDE
649 {
650 // XXX currently, the hardware key light and screen backlight are
651 // controlled as a unit. Those are set through the power API, and
652 // there's no other way to poke lights currently, so we require
653 // "power" privileges here.
654 if (!AssertAppProcessPermission(this, "power")) {
655 return false;
656 }
657 *status = hal::SetLight(aLight, aConfig);
658 return true;
659 }
661 virtual bool
662 RecvGetLight(const LightType& aLight, LightConfiguration* aConfig, bool* status) MOZ_OVERRIDE
663 {
664 if (!AssertAppProcessPermission(this, "power")) {
665 return false;
666 }
667 *status = hal::GetLight(aLight, aConfig);
668 return true;
669 }
671 virtual bool
672 RecvAdjustSystemClock(const int64_t &aDeltaMilliseconds) MOZ_OVERRIDE
673 {
674 if (!AssertAppProcessPermission(this, "time")) {
675 return false;
676 }
677 hal::AdjustSystemClock(aDeltaMilliseconds);
678 return true;
679 }
681 virtual bool
682 RecvSetTimezone(const nsCString& aTimezoneSpec) MOZ_OVERRIDE
683 {
684 if (!AssertAppProcessPermission(this, "time")) {
685 return false;
686 }
687 hal::SetTimezone(aTimezoneSpec);
688 return true;
689 }
691 virtual bool
692 RecvGetTimezone(nsCString *aTimezoneSpec) MOZ_OVERRIDE
693 {
694 if (!AssertAppProcessPermission(this, "time")) {
695 return false;
696 }
697 *aTimezoneSpec = hal::GetTimezone();
698 return true;
699 }
701 virtual bool
702 RecvGetTimezoneOffset(int32_t *aTimezoneOffset) MOZ_OVERRIDE
703 {
704 if (!AssertAppProcessPermission(this, "time")) {
705 return false;
706 }
707 *aTimezoneOffset = hal::GetTimezoneOffset();
708 return true;
709 }
711 virtual bool
712 RecvEnableSystemClockChangeNotifications() MOZ_OVERRIDE
713 {
714 hal::RegisterSystemClockChangeObserver(this);
715 return true;
716 }
718 virtual bool
719 RecvDisableSystemClockChangeNotifications() MOZ_OVERRIDE
720 {
721 hal::UnregisterSystemClockChangeObserver(this);
722 return true;
723 }
725 virtual bool
726 RecvEnableSystemTimezoneChangeNotifications() MOZ_OVERRIDE
727 {
728 hal::RegisterSystemTimezoneChangeObserver(this);
729 return true;
730 }
732 virtual bool
733 RecvDisableSystemTimezoneChangeNotifications() MOZ_OVERRIDE
734 {
735 hal::UnregisterSystemTimezoneChangeObserver(this);
736 return true;
737 }
739 virtual bool
740 RecvEnableSensorNotifications(const SensorType &aSensor) MOZ_OVERRIDE {
741 // We currently allow any content to register device-sensor
742 // listeners.
743 hal::RegisterSensorObserver(aSensor, this);
744 return true;
745 }
747 virtual bool
748 RecvDisableSensorNotifications(const SensorType &aSensor) MOZ_OVERRIDE {
749 hal::UnregisterSensorObserver(aSensor, this);
750 return true;
751 }
753 void Notify(const SensorData& aSensorData) {
754 unused << SendNotifySensorChange(aSensorData);
755 }
757 virtual bool
758 RecvModifyWakeLock(const nsString& aTopic,
759 const WakeLockControl& aLockAdjust,
760 const WakeLockControl& aHiddenAdjust,
761 const uint64_t& aProcessID) MOZ_OVERRIDE
762 {
763 MOZ_ASSERT(aProcessID != CONTENT_PROCESS_ID_UNKNOWN);
765 // We allow arbitrary content to use wake locks.
766 hal::ModifyWakeLock(aTopic, aLockAdjust, aHiddenAdjust, aProcessID);
767 return true;
768 }
770 virtual bool
771 RecvEnableWakeLockNotifications() MOZ_OVERRIDE
772 {
773 // We allow arbitrary content to use wake locks.
774 hal::RegisterWakeLockObserver(this);
775 return true;
776 }
778 virtual bool
779 RecvDisableWakeLockNotifications() MOZ_OVERRIDE
780 {
781 hal::UnregisterWakeLockObserver(this);
782 return true;
783 }
785 virtual bool
786 RecvGetWakeLockInfo(const nsString &aTopic, WakeLockInformation *aWakeLockInfo) MOZ_OVERRIDE
787 {
788 hal::GetWakeLockInfo(aTopic, aWakeLockInfo);
789 return true;
790 }
792 void Notify(const WakeLockInformation& aWakeLockInfo)
793 {
794 unused << SendNotifyWakeLockChange(aWakeLockInfo);
795 }
797 virtual bool
798 RecvEnableSwitchNotifications(const SwitchDevice& aDevice) MOZ_OVERRIDE
799 {
800 // Content has no reason to listen to switch events currently.
801 hal::RegisterSwitchObserver(aDevice, this);
802 return true;
803 }
805 virtual bool
806 RecvDisableSwitchNotifications(const SwitchDevice& aDevice) MOZ_OVERRIDE
807 {
808 hal::UnregisterSwitchObserver(aDevice, this);
809 return true;
810 }
812 void Notify(const SwitchEvent& aSwitchEvent)
813 {
814 unused << SendNotifySwitchChange(aSwitchEvent);
815 }
817 virtual bool
818 RecvGetCurrentSwitchState(const SwitchDevice& aDevice, hal::SwitchState *aState) MOZ_OVERRIDE
819 {
820 // Content has no reason to listen to switch events currently.
821 *aState = hal::GetCurrentSwitchState(aDevice);
822 return true;
823 }
825 virtual bool
826 RecvNotifySwitchStateFromInputDevice(const SwitchDevice& aDevice,
827 const SwitchState& aState) MOZ_OVERRIDE
828 {
829 hal::NotifySwitchStateFromInputDevice(aDevice, aState);
830 return true;
831 }
833 void Notify(const int64_t& aClockDeltaMS)
834 {
835 unused << SendNotifySystemClockChange(aClockDeltaMS);
836 }
838 void Notify(const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo)
839 {
840 unused << SendNotifySystemTimezoneChange(aSystemTimezoneChangeInfo);
841 }
843 virtual bool
844 RecvFactoryReset()
845 {
846 if (!AssertAppProcessPermission(this, "power")) {
847 return false;
848 }
849 hal::FactoryReset();
850 return true;
851 }
853 virtual mozilla::ipc::IProtocol*
854 CloneProtocol(Channel* aChannel,
855 mozilla::ipc::ProtocolCloneContext* aCtx) MOZ_OVERRIDE
856 {
857 ContentParent* contentParent = aCtx->GetContentParent();
858 nsAutoPtr<PHalParent> actor(contentParent->AllocPHalParent());
859 if (!actor || !contentParent->RecvPHalConstructor(actor)) {
860 return nullptr;
861 }
862 return actor.forget();
863 }
864 };
866 class HalChild : public PHalChild {
867 public:
868 virtual void
869 ActorDestroy(ActorDestroyReason aWhy) MOZ_OVERRIDE
870 {
871 sHalChildDestroyed = true;
872 }
874 virtual bool
875 RecvNotifyBatteryChange(const BatteryInformation& aBatteryInfo) MOZ_OVERRIDE {
876 hal::NotifyBatteryChange(aBatteryInfo);
877 return true;
878 }
880 virtual bool
881 RecvNotifySensorChange(const hal::SensorData &aSensorData) MOZ_OVERRIDE;
883 virtual bool
884 RecvNotifyNetworkChange(const NetworkInformation& aNetworkInfo) MOZ_OVERRIDE {
885 hal::NotifyNetworkChange(aNetworkInfo);
886 return true;
887 }
889 virtual bool
890 RecvNotifyWakeLockChange(const WakeLockInformation& aWakeLockInfo) MOZ_OVERRIDE {
891 hal::NotifyWakeLockChange(aWakeLockInfo);
892 return true;
893 }
895 virtual bool
896 RecvNotifyScreenConfigurationChange(const ScreenConfiguration& aScreenConfiguration) MOZ_OVERRIDE {
897 hal::NotifyScreenConfigurationChange(aScreenConfiguration);
898 return true;
899 }
901 virtual bool
902 RecvNotifySwitchChange(const mozilla::hal::SwitchEvent& aEvent) MOZ_OVERRIDE {
903 hal::NotifySwitchChange(aEvent);
904 return true;
905 }
907 virtual bool
908 RecvNotifySystemClockChange(const int64_t& aClockDeltaMS) {
909 hal::NotifySystemClockChange(aClockDeltaMS);
910 return true;
911 }
913 virtual bool
914 RecvNotifySystemTimezoneChange(
915 const SystemTimezoneChangeInformation& aSystemTimezoneChangeInfo) {
916 hal::NotifySystemTimezoneChange(aSystemTimezoneChangeInfo);
917 return true;
918 }
919 };
921 bool
922 HalChild::RecvNotifySensorChange(const hal::SensorData &aSensorData) {
923 hal::NotifySensorChange(aSensorData);
925 return true;
926 }
928 PHalChild* CreateHalChild() {
929 return new HalChild();
930 }
932 PHalParent* CreateHalParent() {
933 return new HalParent();
934 }
936 } // namespace hal_sandbox
937 } // namespace mozilla