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/. */
9 #include "HalSandbox.h"
10 #include "nsThreadUtils.h"
11 #include "nsXULAppAPI.h"
12 #include "mozilla/Observer.h"
13 #include "nsIDocument.h"
14 #include "nsIDOMDocument.h"
15 #include "nsPIDOMWindow.h"
16 #include "nsIDOMWindow.h"
17 #include "mozilla/Services.h"
18 #include "nsIWebNavigation.h"
19 #include "nsITabChild.h"
20 #include "nsIDocShell.h"
21 #include "mozilla/StaticPtr.h"
22 #include "mozilla/ClearOnShutdown.h"
23 #include "WindowIdentifier.h"
24 #include "mozilla/dom/ScreenOrientation.h"
25 #include "mozilla/dom/ContentChild.h"
26 #include "mozilla/dom/ContentParent.h"
30 #define getpid _getpid
33 using namespace mozilla::services
;
34 using namespace mozilla::dom
;
36 #define PROXY_IF_SANDBOXED(_call) \
39 if (!hal_sandbox::HalChildDestroyed()) { \
47 #define RETURN_PROXY_IF_SANDBOXED(_call, defValue)\
50 if (hal_sandbox::HalChildDestroyed()) { \
53 return hal_sandbox::_call; \
55 return hal_impl::_call; \
65 static PRLogModuleInfo
*sHalLog
;
67 sHalLog
= PR_NewLogModule("hal");
77 MOZ_ASSERT(NS_IsMainThread());
83 return GeckoProcessType_Content
== XRE_GetProcessType();
89 MOZ_ASSERT(GeckoProcessType_Default
== XRE_GetProcessType());
93 WindowIsActive(nsIDOMWindow
* aWindow
)
95 nsCOMPtr
<nsPIDOMWindow
> window
= do_QueryInterface(aWindow
);
96 NS_ENSURE_TRUE(window
, false);
98 nsIDocument
* document
= window
->GetDoc();
99 NS_ENSURE_TRUE(document
, false);
101 return !document
->Hidden();
104 StaticAutoPtr
<WindowIdentifier::IDArrayType
> gLastIDToVibrate
;
106 void InitLastIDToVibrate()
108 gLastIDToVibrate
= new WindowIdentifier::IDArrayType();
109 ClearOnShutdown(&gLastIDToVibrate
);
112 } // anonymous namespace
115 Vibrate(const nsTArray
<uint32_t>& pattern
, nsIDOMWindow
* window
)
117 Vibrate(pattern
, WindowIdentifier(window
));
121 Vibrate(const nsTArray
<uint32_t>& pattern
, const WindowIdentifier
&id
)
125 // Only active windows may start vibrations. If |id| hasn't gone
126 // through the IPC layer -- that is, if our caller is the outside
127 // world, not hal_proxy -- check whether the window is active. If
128 // |id| has gone through IPC, don't check the window's visibility;
129 // only the window corresponding to the bottommost process has its
130 // visibility state set correctly.
131 if (!id
.HasTraveledThroughIPC() && !WindowIsActive(id
.GetWindow())) {
132 HAL_LOG(("Vibrate: Window is inactive, dropping vibrate."));
137 if (!gLastIDToVibrate
) {
138 InitLastIDToVibrate();
140 *gLastIDToVibrate
= id
.AsArray();
143 // Don't forward our ID if we are not in the sandbox, because hal_impl
144 // doesn't need it, and we don't want it to be tempted to read it. The
145 // empty identifier will assert if it's used.
146 PROXY_IF_SANDBOXED(Vibrate(pattern
, InSandbox() ? id
: WindowIdentifier()));
150 CancelVibrate(nsIDOMWindow
* window
)
152 CancelVibrate(WindowIdentifier(window
));
156 CancelVibrate(const WindowIdentifier
&id
)
160 // Although only active windows may start vibrations, a window may
161 // cancel its own vibration even if it's no longer active.
163 // After a window is marked as inactive, it sends a CancelVibrate
164 // request. We want this request to cancel a playing vibration
165 // started by that window, so we certainly don't want to reject the
166 // cancellation request because the window is now inactive.
168 // But it could be the case that, after this window became inactive,
169 // some other window came along and started a vibration. We don't
170 // want this window's cancellation request to cancel that window's
171 // actively-playing vibration!
173 // To solve this problem, we keep track of the id of the last window
174 // to start a vibration, and only accepts cancellation requests from
175 // the same window. All other cancellation requests are ignored.
177 if (InSandbox() || (gLastIDToVibrate
&& *gLastIDToVibrate
== id
.AsArray())) {
178 // Don't forward our ID if we are not in the sandbox, because hal_impl
179 // doesn't need it, and we don't want it to be tempted to read it. The
180 // empty identifier will assert if it's used.
181 PROXY_IF_SANDBOXED(CancelVibrate(InSandbox() ? id
: WindowIdentifier()));
185 template <class InfoType
>
186 class ObserversManager
189 void AddObserver(Observer
<InfoType
>* aObserver
) {
191 mObservers
= new mozilla::ObserverList
<InfoType
>();
194 mObservers
->AddObserver(aObserver
);
196 if (mObservers
->Length() == 1) {
197 EnableNotifications();
201 void RemoveObserver(Observer
<InfoType
>* aObserver
) {
202 bool removed
= mObservers
&& mObservers
->RemoveObserver(aObserver
);
204 NS_WARNING("RemoveObserver() called for unregistered observer");
208 if (mObservers
->Length() == 0) {
209 DisableNotifications();
211 OnNotificationsDisabled();
214 mObservers
= nullptr;
218 void BroadcastInformation(const InfoType
& aInfo
) {
219 // It is possible for mObservers to be nullptr here on some platforms,
220 // because a call to BroadcastInformation gets queued up asynchronously
221 // while RemoveObserver is running (and before the notifications are
222 // disabled). The queued call can then get run after mObservers has
223 // been nulled out. See bug 757025.
227 mObservers
->Broadcast(aInfo
);
231 virtual void EnableNotifications() = 0;
232 virtual void DisableNotifications() = 0;
233 virtual void OnNotificationsDisabled() {}
236 mozilla::ObserverList
<InfoType
>* mObservers
;
239 template <class InfoType
>
240 class CachingObserversManager
: public ObserversManager
<InfoType
>
243 InfoType
GetCurrentInformation() {
244 if (mHasValidCache
) {
248 GetCurrentInformationInternal(&mInfo
);
249 mHasValidCache
= true;
253 void CacheInformation(const InfoType
& aInfo
) {
254 mHasValidCache
= true;
258 void BroadcastCachedInformation() {
259 this->BroadcastInformation(mInfo
);
263 virtual void GetCurrentInformationInternal(InfoType
*) = 0;
265 virtual void OnNotificationsDisabled() {
266 mHasValidCache
= false;
274 class BatteryObserversManager
: public CachingObserversManager
<BatteryInformation
>
277 void EnableNotifications() {
278 PROXY_IF_SANDBOXED(EnableBatteryNotifications());
281 void DisableNotifications() {
282 PROXY_IF_SANDBOXED(DisableBatteryNotifications());
285 void GetCurrentInformationInternal(BatteryInformation
* aInfo
) {
286 PROXY_IF_SANDBOXED(GetCurrentBatteryInformation(aInfo
));
290 static BatteryObserversManager sBatteryObservers
;
292 class NetworkObserversManager
: public CachingObserversManager
<NetworkInformation
>
295 void EnableNotifications() {
296 PROXY_IF_SANDBOXED(EnableNetworkNotifications());
299 void DisableNotifications() {
300 PROXY_IF_SANDBOXED(DisableNetworkNotifications());
303 void GetCurrentInformationInternal(NetworkInformation
* aInfo
) {
304 PROXY_IF_SANDBOXED(GetCurrentNetworkInformation(aInfo
));
308 static NetworkObserversManager sNetworkObservers
;
310 class WakeLockObserversManager
: public ObserversManager
<WakeLockInformation
>
313 void EnableNotifications() {
314 PROXY_IF_SANDBOXED(EnableWakeLockNotifications());
317 void DisableNotifications() {
318 PROXY_IF_SANDBOXED(DisableWakeLockNotifications());
322 static WakeLockObserversManager sWakeLockObservers
;
324 class ScreenConfigurationObserversManager
: public CachingObserversManager
<ScreenConfiguration
>
327 void EnableNotifications() {
328 PROXY_IF_SANDBOXED(EnableScreenConfigurationNotifications());
331 void DisableNotifications() {
332 PROXY_IF_SANDBOXED(DisableScreenConfigurationNotifications());
335 void GetCurrentInformationInternal(ScreenConfiguration
* aInfo
) {
336 PROXY_IF_SANDBOXED(GetCurrentScreenConfiguration(aInfo
));
340 static ScreenConfigurationObserversManager sScreenConfigurationObservers
;
343 RegisterBatteryObserver(BatteryObserver
* aObserver
)
346 sBatteryObservers
.AddObserver(aObserver
);
350 UnregisterBatteryObserver(BatteryObserver
* aObserver
)
353 sBatteryObservers
.RemoveObserver(aObserver
);
357 GetCurrentBatteryInformation(BatteryInformation
* aInfo
)
360 *aInfo
= sBatteryObservers
.GetCurrentInformation();
364 NotifyBatteryChange(const BatteryInformation
& aInfo
)
367 sBatteryObservers
.CacheInformation(aInfo
);
368 sBatteryObservers
.BroadcastCachedInformation();
371 bool GetScreenEnabled()
374 RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled(), false);
377 void SetScreenEnabled(bool aEnabled
)
380 PROXY_IF_SANDBOXED(SetScreenEnabled(aEnabled
));
383 bool GetKeyLightEnabled()
386 RETURN_PROXY_IF_SANDBOXED(GetKeyLightEnabled(), false);
389 void SetKeyLightEnabled(bool aEnabled
)
392 PROXY_IF_SANDBOXED(SetKeyLightEnabled(aEnabled
));
395 bool GetCpuSleepAllowed()
397 // Generally for interfaces that are accessible by normal web content
398 // we should cache the result and be notified on state changes, like
399 // what the battery API does. But since this is only used by
400 // privileged interface, the synchronous getter is OK here.
402 RETURN_PROXY_IF_SANDBOXED(GetCpuSleepAllowed(), true);
405 void SetCpuSleepAllowed(bool aAllowed
)
408 PROXY_IF_SANDBOXED(SetCpuSleepAllowed(aAllowed
));
411 double GetScreenBrightness()
414 RETURN_PROXY_IF_SANDBOXED(GetScreenBrightness(), 0);
417 void SetScreenBrightness(double aBrightness
)
420 PROXY_IF_SANDBOXED(SetScreenBrightness(clamped(aBrightness
, 0.0, 1.0)));
423 class SystemClockChangeObserversManager
: public ObserversManager
<int64_t>
426 void EnableNotifications() {
427 PROXY_IF_SANDBOXED(EnableSystemClockChangeNotifications());
430 void DisableNotifications() {
431 PROXY_IF_SANDBOXED(DisableSystemClockChangeNotifications());
435 static SystemClockChangeObserversManager sSystemClockChangeObservers
;
438 RegisterSystemClockChangeObserver(SystemClockChangeObserver
* aObserver
)
441 sSystemClockChangeObservers
.AddObserver(aObserver
);
445 UnregisterSystemClockChangeObserver(SystemClockChangeObserver
* aObserver
)
448 sSystemClockChangeObservers
.RemoveObserver(aObserver
);
452 NotifySystemClockChange(const int64_t& aClockDeltaMS
)
454 sSystemClockChangeObservers
.BroadcastInformation(aClockDeltaMS
);
457 class SystemTimezoneChangeObserversManager
: public ObserversManager
<SystemTimezoneChangeInformation
>
460 void EnableNotifications() {
461 PROXY_IF_SANDBOXED(EnableSystemTimezoneChangeNotifications());
464 void DisableNotifications() {
465 PROXY_IF_SANDBOXED(DisableSystemTimezoneChangeNotifications());
469 static SystemTimezoneChangeObserversManager sSystemTimezoneChangeObservers
;
472 RegisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver
* aObserver
)
475 sSystemTimezoneChangeObservers
.AddObserver(aObserver
);
479 UnregisterSystemTimezoneChangeObserver(SystemTimezoneChangeObserver
* aObserver
)
482 sSystemTimezoneChangeObservers
.RemoveObserver(aObserver
);
486 NotifySystemTimezoneChange(const SystemTimezoneChangeInformation
& aSystemTimezoneChangeInfo
)
488 sSystemTimezoneChangeObservers
.BroadcastInformation(aSystemTimezoneChangeInfo
);
492 AdjustSystemClock(int64_t aDeltaMilliseconds
)
495 PROXY_IF_SANDBOXED(AdjustSystemClock(aDeltaMilliseconds
));
499 SetTimezone(const nsCString
& aTimezoneSpec
)
502 PROXY_IF_SANDBOXED(SetTimezone(aTimezoneSpec
));
509 RETURN_PROXY_IF_SANDBOXED(GetTimezoneOffset(), 0);
516 RETURN_PROXY_IF_SANDBOXED(GetTimezone(), nsCString(""));
520 EnableSensorNotifications(SensorType aSensor
) {
522 PROXY_IF_SANDBOXED(EnableSensorNotifications(aSensor
));
526 DisableSensorNotifications(SensorType aSensor
) {
528 PROXY_IF_SANDBOXED(DisableSensorNotifications(aSensor
));
531 typedef mozilla::ObserverList
<SensorData
> SensorObserverList
;
532 static SensorObserverList
* gSensorObservers
= nullptr;
534 static SensorObserverList
&
535 GetSensorObservers(SensorType sensor_type
) {
536 MOZ_ASSERT(sensor_type
< NUM_SENSOR_TYPE
);
538 if(!gSensorObservers
) {
539 gSensorObservers
= new SensorObserverList
[NUM_SENSOR_TYPE
];
541 return gSensorObservers
[sensor_type
];
545 RegisterSensorObserver(SensorType aSensor
, ISensorObserver
*aObserver
) {
546 SensorObserverList
&observers
= GetSensorObservers(aSensor
);
550 observers
.AddObserver(aObserver
);
551 if(observers
.Length() == 1) {
552 EnableSensorNotifications(aSensor
);
557 UnregisterSensorObserver(SensorType aSensor
, ISensorObserver
*aObserver
) {
560 if (!gSensorObservers
) {
564 SensorObserverList
&observers
= GetSensorObservers(aSensor
);
565 if (!observers
.RemoveObserver(aObserver
) || observers
.Length() > 0) {
568 DisableSensorNotifications(aSensor
);
570 // Destroy sSensorObservers only if all observer lists are empty.
571 for (int i
= 0; i
< NUM_SENSOR_TYPE
; i
++) {
572 if (gSensorObservers
[i
].Length() > 0) {
576 delete [] gSensorObservers
;
577 gSensorObservers
= nullptr;
581 NotifySensorChange(const SensorData
&aSensorData
) {
582 SensorObserverList
&observers
= GetSensorObservers(aSensorData
.sensor());
586 observers
.Broadcast(aSensorData
);
590 RegisterNetworkObserver(NetworkObserver
* aObserver
)
593 sNetworkObservers
.AddObserver(aObserver
);
597 UnregisterNetworkObserver(NetworkObserver
* aObserver
)
600 sNetworkObservers
.RemoveObserver(aObserver
);
604 GetCurrentNetworkInformation(NetworkInformation
* aInfo
)
607 *aInfo
= sNetworkObservers
.GetCurrentInformation();
611 NotifyNetworkChange(const NetworkInformation
& aInfo
)
613 sNetworkObservers
.CacheInformation(aInfo
);
614 sNetworkObservers
.BroadcastCachedInformation();
621 PROXY_IF_SANDBOXED(Reboot());
628 PROXY_IF_SANDBOXED(PowerOff());
631 void StartForceQuitWatchdog(ShutdownMode aMode
, int32_t aTimeoutSecs
)
635 PROXY_IF_SANDBOXED(StartForceQuitWatchdog(aMode
, aTimeoutSecs
));
638 void StartMonitoringGamepadStatus()
640 PROXY_IF_SANDBOXED(StartMonitoringGamepadStatus());
643 void StopMonitoringGamepadStatus()
645 PROXY_IF_SANDBOXED(StopMonitoringGamepadStatus());
649 RegisterWakeLockObserver(WakeLockObserver
* aObserver
)
652 sWakeLockObservers
.AddObserver(aObserver
);
656 UnregisterWakeLockObserver(WakeLockObserver
* aObserver
)
659 sWakeLockObservers
.RemoveObserver(aObserver
);
663 ModifyWakeLock(const nsAString
& aTopic
,
664 WakeLockControl aLockAdjust
,
665 WakeLockControl aHiddenAdjust
,
666 uint64_t aProcessID
/* = CONTENT_PROCESS_ID_UNKNOWN */)
670 if (aProcessID
== CONTENT_PROCESS_ID_UNKNOWN
) {
671 aProcessID
= InSandbox() ? ContentChild::GetSingleton()->GetID() :
672 CONTENT_PROCESS_ID_MAIN
;
675 PROXY_IF_SANDBOXED(ModifyWakeLock(aTopic
, aLockAdjust
,
676 aHiddenAdjust
, aProcessID
));
680 GetWakeLockInfo(const nsAString
& aTopic
, WakeLockInformation
* aWakeLockInfo
)
683 PROXY_IF_SANDBOXED(GetWakeLockInfo(aTopic
, aWakeLockInfo
));
687 NotifyWakeLockChange(const WakeLockInformation
& aInfo
)
690 sWakeLockObservers
.BroadcastInformation(aInfo
);
694 RegisterScreenConfigurationObserver(ScreenConfigurationObserver
* aObserver
)
697 sScreenConfigurationObservers
.AddObserver(aObserver
);
701 UnregisterScreenConfigurationObserver(ScreenConfigurationObserver
* aObserver
)
704 sScreenConfigurationObservers
.RemoveObserver(aObserver
);
708 GetCurrentScreenConfiguration(ScreenConfiguration
* aScreenConfiguration
)
711 *aScreenConfiguration
= sScreenConfigurationObservers
.GetCurrentInformation();
715 NotifyScreenConfigurationChange(const ScreenConfiguration
& aScreenConfiguration
)
717 sScreenConfigurationObservers
.CacheInformation(aScreenConfiguration
);
718 sScreenConfigurationObservers
.BroadcastCachedInformation();
722 LockScreenOrientation(const dom::ScreenOrientation
& aOrientation
)
725 RETURN_PROXY_IF_SANDBOXED(LockScreenOrientation(aOrientation
), false);
729 UnlockScreenOrientation()
732 PROXY_IF_SANDBOXED(UnlockScreenOrientation());
736 EnableSwitchNotifications(SwitchDevice aDevice
) {
738 PROXY_IF_SANDBOXED(EnableSwitchNotifications(aDevice
));
742 DisableSwitchNotifications(SwitchDevice aDevice
) {
744 PROXY_IF_SANDBOXED(DisableSwitchNotifications(aDevice
));
747 SwitchState
GetCurrentSwitchState(SwitchDevice aDevice
)
750 RETURN_PROXY_IF_SANDBOXED(GetCurrentSwitchState(aDevice
), SWITCH_STATE_UNKNOWN
);
753 void NotifySwitchStateFromInputDevice(SwitchDevice aDevice
, SwitchState aState
)
756 PROXY_IF_SANDBOXED(NotifySwitchStateFromInputDevice(aDevice
, aState
));
759 typedef mozilla::ObserverList
<SwitchEvent
> SwitchObserverList
;
761 static SwitchObserverList
*sSwitchObserverLists
= nullptr;
763 static SwitchObserverList
&
764 GetSwitchObserverList(SwitchDevice aDevice
) {
765 MOZ_ASSERT(0 <= aDevice
&& aDevice
< NUM_SWITCH_DEVICE
);
766 if (sSwitchObserverLists
== nullptr) {
767 sSwitchObserverLists
= new SwitchObserverList
[NUM_SWITCH_DEVICE
];
769 return sSwitchObserverLists
[aDevice
];
773 ReleaseObserversIfNeeded() {
774 for (int i
= 0; i
< NUM_SWITCH_DEVICE
; i
++) {
775 if (sSwitchObserverLists
[i
].Length() != 0)
779 //The length of every list is 0, no observer in the list.
780 delete [] sSwitchObserverLists
;
781 sSwitchObserverLists
= nullptr;
785 RegisterSwitchObserver(SwitchDevice aDevice
, SwitchObserver
*aObserver
)
788 SwitchObserverList
& observer
= GetSwitchObserverList(aDevice
);
789 observer
.AddObserver(aObserver
);
790 if (observer
.Length() == 1) {
791 EnableSwitchNotifications(aDevice
);
796 UnregisterSwitchObserver(SwitchDevice aDevice
, SwitchObserver
*aObserver
)
800 if (!sSwitchObserverLists
) {
804 SwitchObserverList
& observer
= GetSwitchObserverList(aDevice
);
805 if (!observer
.RemoveObserver(aObserver
) || observer
.Length() > 0) {
809 DisableSwitchNotifications(aDevice
);
810 ReleaseObserversIfNeeded();
814 NotifySwitchChange(const SwitchEvent
& aEvent
)
816 // When callback this notification, main thread may call unregister function
817 // first. We should check if this pointer is valid.
818 if (!sSwitchObserverLists
)
821 SwitchObserverList
& observer
= GetSwitchObserverList(aEvent
.device());
822 observer
.Broadcast(aEvent
);
825 static AlarmObserver
* sAlarmObserver
;
828 RegisterTheOneAlarmObserver(AlarmObserver
* aObserver
)
830 MOZ_ASSERT(!InSandbox());
831 MOZ_ASSERT(!sAlarmObserver
);
833 sAlarmObserver
= aObserver
;
834 RETURN_PROXY_IF_SANDBOXED(EnableAlarm(), false);
838 UnregisterTheOneAlarmObserver()
840 if (sAlarmObserver
) {
841 sAlarmObserver
= nullptr;
842 PROXY_IF_SANDBOXED(DisableAlarm());
849 if (sAlarmObserver
) {
850 sAlarmObserver
->Notify(void_t());
855 SetAlarm(int32_t aSeconds
, int32_t aNanoseconds
)
857 // It's pointless to program an alarm nothing is going to observe ...
858 MOZ_ASSERT(sAlarmObserver
);
859 RETURN_PROXY_IF_SANDBOXED(SetAlarm(aSeconds
, aNanoseconds
), false);
863 SetProcessPriority(int aPid
,
864 ProcessPriority aPriority
,
865 ProcessCPUPriority aCPUPriority
,
866 uint32_t aBackgroundLRU
)
868 // n.b. The sandboxed implementation crashes; SetProcessPriority works only
869 // from the main process.
870 MOZ_ASSERT(aBackgroundLRU
== 0 || aPriority
== PROCESS_PRIORITY_BACKGROUND
);
871 PROXY_IF_SANDBOXED(SetProcessPriority(aPid
, aPriority
, aCPUPriority
,
876 SetCurrentThreadPriority(hal::ThreadPriority aThreadPriority
)
878 PROXY_IF_SANDBOXED(SetCurrentThreadPriority(aThreadPriority
));
883 ProcessPriorityToString(ProcessPriority aPriority
)
886 case PROCESS_PRIORITY_MASTER
:
888 case PROCESS_PRIORITY_PREALLOC
:
890 case PROCESS_PRIORITY_FOREGROUND_HIGH
:
891 return "FOREGROUND_HIGH";
892 case PROCESS_PRIORITY_FOREGROUND
:
894 case PROCESS_PRIORITY_FOREGROUND_KEYBOARD
:
895 return "FOREGROUND_KEYBOARD";
896 case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE
:
897 return "BACKGROUND_PERCEIVABLE";
898 case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN
:
899 return "BACKGROUND_HOMESCREEN";
900 case PROCESS_PRIORITY_BACKGROUND
:
902 case PROCESS_PRIORITY_UNKNOWN
:
911 ThreadPriorityToString(ThreadPriority aPriority
)
914 case THREAD_PRIORITY_COMPOSITOR
:
924 ProcessPriorityToString(ProcessPriority aPriority
,
925 ProcessCPUPriority aCPUPriority
)
927 // Sorry this is ugly. At least it's all in one place.
929 // We intentionally fall through if aCPUPriority is invalid; we won't hit any
930 // of the if statements further down, so it's OK.
933 case PROCESS_PRIORITY_MASTER
:
934 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
935 return "MASTER:CPU_NORMAL";
937 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
938 return "MASTER:CPU_LOW";
940 case PROCESS_PRIORITY_PREALLOC
:
941 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
942 return "PREALLOC:CPU_NORMAL";
944 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
945 return "PREALLOC:CPU_LOW";
947 case PROCESS_PRIORITY_FOREGROUND_HIGH
:
948 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
949 return "FOREGROUND_HIGH:CPU_NORMAL";
951 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
952 return "FOREGROUND_HIGH:CPU_LOW";
954 case PROCESS_PRIORITY_FOREGROUND
:
955 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
956 return "FOREGROUND:CPU_NORMAL";
958 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
959 return "FOREGROUND:CPU_LOW";
961 case PROCESS_PRIORITY_FOREGROUND_KEYBOARD
:
962 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
963 return "FOREGROUND_KEYBOARD:CPU_NORMAL";
965 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
966 return "FOREGROUND_KEYBOARD:CPU_LOW";
968 case PROCESS_PRIORITY_BACKGROUND_PERCEIVABLE
:
969 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
970 return "BACKGROUND_PERCEIVABLE:CPU_NORMAL";
972 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
973 return "BACKGROUND_PERCEIVABLE:CPU_LOW";
975 case PROCESS_PRIORITY_BACKGROUND_HOMESCREEN
:
976 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
977 return "BACKGROUND_HOMESCREEN:CPU_NORMAL";
979 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
980 return "BACKGROUND_HOMESCREEN:CPU_LOW";
982 case PROCESS_PRIORITY_BACKGROUND
:
983 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
984 return "BACKGROUND:CPU_NORMAL";
986 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
987 return "BACKGROUND:CPU_LOW";
989 case PROCESS_PRIORITY_UNKNOWN
:
990 if (aCPUPriority
== PROCESS_CPU_PRIORITY_NORMAL
) {
991 return "UNKNOWN:CPU_NORMAL";
993 if (aCPUPriority
== PROCESS_CPU_PRIORITY_LOW
) {
994 return "UNKNOWN:CPU_LOW";
997 // Fall through. (|default| is here to silence warnings.)
1005 static StaticAutoPtr
<ObserverList
<FMRadioOperationInformation
> > sFMRadioObservers
;
1008 InitializeFMRadioObserver()
1010 if (!sFMRadioObservers
) {
1011 sFMRadioObservers
= new ObserverList
<FMRadioOperationInformation
>;
1012 ClearOnShutdown(&sFMRadioObservers
);
1017 RegisterFMRadioObserver(FMRadioObserver
* aFMRadioObserver
) {
1019 InitializeFMRadioObserver();
1020 sFMRadioObservers
->AddObserver(aFMRadioObserver
);
1024 UnregisterFMRadioObserver(FMRadioObserver
* aFMRadioObserver
) {
1026 InitializeFMRadioObserver();
1027 sFMRadioObservers
->RemoveObserver(aFMRadioObserver
);
1031 NotifyFMRadioStatus(const FMRadioOperationInformation
& aFMRadioState
) {
1032 InitializeFMRadioObserver();
1033 sFMRadioObservers
->Broadcast(aFMRadioState
);
1037 EnableFMRadio(const FMRadioSettings
& aInfo
) {
1039 PROXY_IF_SANDBOXED(EnableFMRadio(aInfo
));
1045 PROXY_IF_SANDBOXED(DisableFMRadio());
1049 FMRadioSeek(const FMRadioSeekDirection
& aDirection
) {
1051 PROXY_IF_SANDBOXED(FMRadioSeek(aDirection
));
1055 GetFMRadioSettings(FMRadioSettings
* aInfo
) {
1057 PROXY_IF_SANDBOXED(GetFMRadioSettings(aInfo
));
1061 SetFMRadioFrequency(const uint32_t aFrequency
) {
1063 PROXY_IF_SANDBOXED(SetFMRadioFrequency(aFrequency
));
1067 GetFMRadioFrequency() {
1069 RETURN_PROXY_IF_SANDBOXED(GetFMRadioFrequency(), 0);
1075 RETURN_PROXY_IF_SANDBOXED(IsFMRadioOn(), false);
1079 GetFMRadioSignalStrength() {
1081 RETURN_PROXY_IF_SANDBOXED(GetFMRadioSignalStrength(), 0);
1085 CancelFMRadioSeek() {
1087 PROXY_IF_SANDBOXED(CancelFMRadioSeek());
1091 GetFMBandSettings(FMRadioCountry aCountry
) {
1092 FMRadioSettings settings
;
1095 case FM_RADIO_COUNTRY_US
:
1096 case FM_RADIO_COUNTRY_EU
:
1097 settings
.upperLimit() = 108000;
1098 settings
.lowerLimit() = 87800;
1099 settings
.spaceType() = 200;
1100 settings
.preEmphasis() = 75;
1102 case FM_RADIO_COUNTRY_JP_STANDARD
:
1103 settings
.upperLimit() = 76000;
1104 settings
.lowerLimit() = 90000;
1105 settings
.spaceType() = 100;
1106 settings
.preEmphasis() = 50;
1108 case FM_RADIO_COUNTRY_CY
:
1109 case FM_RADIO_COUNTRY_DE
:
1110 case FM_RADIO_COUNTRY_DK
:
1111 case FM_RADIO_COUNTRY_ES
:
1112 case FM_RADIO_COUNTRY_FI
:
1113 case FM_RADIO_COUNTRY_FR
:
1114 case FM_RADIO_COUNTRY_HU
:
1115 case FM_RADIO_COUNTRY_IR
:
1116 case FM_RADIO_COUNTRY_IT
:
1117 case FM_RADIO_COUNTRY_KW
:
1118 case FM_RADIO_COUNTRY_LT
:
1119 case FM_RADIO_COUNTRY_ML
:
1120 case FM_RADIO_COUNTRY_NO
:
1121 case FM_RADIO_COUNTRY_OM
:
1122 case FM_RADIO_COUNTRY_PG
:
1123 case FM_RADIO_COUNTRY_NL
:
1124 case FM_RADIO_COUNTRY_CZ
:
1125 case FM_RADIO_COUNTRY_UK
:
1126 case FM_RADIO_COUNTRY_RW
:
1127 case FM_RADIO_COUNTRY_SN
:
1128 case FM_RADIO_COUNTRY_SI
:
1129 case FM_RADIO_COUNTRY_ZA
:
1130 case FM_RADIO_COUNTRY_SE
:
1131 case FM_RADIO_COUNTRY_CH
:
1132 case FM_RADIO_COUNTRY_TW
:
1133 case FM_RADIO_COUNTRY_UA
:
1134 settings
.upperLimit() = 108000;
1135 settings
.lowerLimit() = 87500;
1136 settings
.spaceType() = 100;
1137 settings
.preEmphasis() = 50;
1139 case FM_RADIO_COUNTRY_VA
:
1140 case FM_RADIO_COUNTRY_MA
:
1141 case FM_RADIO_COUNTRY_TR
:
1142 settings
.upperLimit() = 10800;
1143 settings
.lowerLimit() = 87500;
1144 settings
.spaceType() = 100;
1145 settings
.preEmphasis() = 75;
1147 case FM_RADIO_COUNTRY_AU
:
1148 case FM_RADIO_COUNTRY_BD
:
1149 settings
.upperLimit() = 108000;
1150 settings
.lowerLimit() = 87500;
1151 settings
.spaceType() = 200;
1152 settings
.preEmphasis() = 75;
1154 case FM_RADIO_COUNTRY_AW
:
1155 case FM_RADIO_COUNTRY_BS
:
1156 case FM_RADIO_COUNTRY_CO
:
1157 case FM_RADIO_COUNTRY_KR
:
1158 settings
.upperLimit() = 108000;
1159 settings
.lowerLimit() = 88000;
1160 settings
.spaceType() = 200;
1161 settings
.preEmphasis() = 75;
1163 case FM_RADIO_COUNTRY_EC
:
1164 settings
.upperLimit() = 108000;
1165 settings
.lowerLimit() = 88000;
1166 settings
.spaceType() = 200;
1167 settings
.preEmphasis() = 0;
1169 case FM_RADIO_COUNTRY_GM
:
1170 settings
.upperLimit() = 108000;
1171 settings
.lowerLimit() = 88000;
1172 settings
.spaceType() = 0;
1173 settings
.preEmphasis() = 75;
1175 case FM_RADIO_COUNTRY_QA
:
1176 settings
.upperLimit() = 108000;
1177 settings
.lowerLimit() = 88000;
1178 settings
.spaceType() = 200;
1179 settings
.preEmphasis() = 50;
1181 case FM_RADIO_COUNTRY_SG
:
1182 settings
.upperLimit() = 108000;
1183 settings
.lowerLimit() = 88000;
1184 settings
.spaceType() = 200;
1185 settings
.preEmphasis() = 50;
1187 case FM_RADIO_COUNTRY_IN
:
1188 settings
.upperLimit() = 100000;
1189 settings
.lowerLimit() = 108000;
1190 settings
.spaceType() = 100;
1191 settings
.preEmphasis() = 50;
1193 case FM_RADIO_COUNTRY_NZ
:
1194 settings
.upperLimit() = 100000;
1195 settings
.lowerLimit() = 88000;
1196 settings
.spaceType() = 50;
1197 settings
.preEmphasis() = 50;
1199 case FM_RADIO_COUNTRY_USER_DEFINED
:
1208 void FactoryReset(mozilla::dom::FactoryResetReason
& aReason
)
1211 PROXY_IF_SANDBOXED(FactoryReset(aReason
));
1215 StartDiskSpaceWatcher()
1217 AssertMainProcess();
1219 PROXY_IF_SANDBOXED(StartDiskSpaceWatcher());
1223 StopDiskSpaceWatcher()
1225 AssertMainProcess();
1227 PROXY_IF_SANDBOXED(StopDiskSpaceWatcher());
1231 GetTotalSystemMemory()
1233 return hal_impl::GetTotalSystemMemory();
1237 GetTotalSystemMemoryLevel()
1239 return hal_impl::GetTotalSystemMemoryLevel();
1242 bool IsHeadphoneEventFromInputDev()
1245 RETURN_PROXY_IF_SANDBOXED(IsHeadphoneEventFromInputDev(), false);
1249 } // namespace mozilla