Bug 1454293 [wpt PR 10484] - null is not the correct origin for createDocument()...
[gecko.git] / hal / Hal.h
blob928304ab384db30a60d2c14868d06c15512d94fa
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 #ifndef mozilla_Hal_h
8 #define mozilla_Hal_h
10 #include "base/basictypes.h"
11 #include "base/platform_thread.h"
12 #include "nsTArray.h"
13 #include "mozilla/dom/battery/Types.h"
14 #include "mozilla/dom/network/Types.h"
15 #include "mozilla/dom/power/Types.h"
16 #include "mozilla/dom/ScreenOrientation.h"
17 #include "mozilla/hal_sandbox/PHal.h"
18 #include "mozilla/HalScreenConfiguration.h"
19 #include "mozilla/HalTypes.h"
20 #include "mozilla/Observer.h"
21 #include "mozilla/Types.h"
24 * Hal.h contains the public Hal API.
26 * By default, this file defines its functions in the hal namespace, but if
27 * MOZ_HAL_NAMESPACE is defined, we'll define our functions in that namespace.
29 * This is used by HalImpl.h and HalSandbox.h, which define copies of all the
30 * functions here in the hal_impl and hal_sandbox namespaces.
33 class nsPIDOMWindowInner;
35 #ifndef MOZ_HAL_NAMESPACE
36 # define MOZ_HAL_NAMESPACE hal
37 # define MOZ_DEFINED_HAL_NAMESPACE 1
38 #endif
40 namespace mozilla {
42 namespace hal {
44 class WindowIdentifier;
46 } // namespace hal
48 namespace MOZ_HAL_NAMESPACE {
50 /**
51 * Turn the default vibrator device on/off per the pattern specified
52 * by |pattern|. Each element in the pattern is the number of
53 * milliseconds to turn the vibrator on or off. The first element in
54 * |pattern| is an "on" element, the next is "off", and so on.
56 * If |pattern| is empty, any in-progress vibration is canceled.
58 * Only an active window within an active tab may call Vibrate; calls
59 * from inactive windows and windows on inactive tabs do nothing.
61 * If you're calling hal::Vibrate from the outside world, pass an
62 * nsIDOMWindow* in place of the WindowIdentifier parameter.
63 * The method with WindowIdentifier will be called automatically.
65 void Vibrate(const nsTArray<uint32_t>& pattern,
66 nsPIDOMWindowInner* aWindow);
67 void Vibrate(const nsTArray<uint32_t>& pattern,
68 const hal::WindowIdentifier &id);
70 /**
71 * Cancel a vibration started by the content window identified by
72 * WindowIdentifier.
74 * If the window was the last window to start a vibration, the
75 * cancellation request will go through even if the window is not
76 * active.
78 * As with hal::Vibrate(), if you're calling hal::CancelVibrate from the outside
79 * world, pass an nsIDOMWindow*. The method with WindowIdentifier will be called
80 * automatically.
82 void CancelVibrate(nsPIDOMWindowInner* aWindow);
83 void CancelVibrate(const hal::WindowIdentifier &id);
85 /**
86 * Inform the battery backend there is a new battery observer.
87 * @param aBatteryObserver The observer that should be added.
89 void RegisterBatteryObserver(BatteryObserver* aBatteryObserver);
91 /**
92 * Inform the battery backend a battery observer unregistered.
93 * @param aBatteryObserver The observer that should be removed.
95 void UnregisterBatteryObserver(BatteryObserver* aBatteryObserver);
97 /**
98 * Returns the current battery information.
100 void GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo);
103 * Notify of a change in the battery state.
104 * @param aBatteryInfo The new battery information.
106 void NotifyBatteryChange(const hal::BatteryInformation& aBatteryInfo);
109 * Register an observer for the sensor of given type.
111 * The observer will receive data whenever the data generated by the
112 * sensor is avaiable.
114 void RegisterSensorObserver(hal::SensorType aSensor,
115 hal::ISensorObserver *aObserver);
118 * Unregister an observer for the sensor of given type.
120 void UnregisterSensorObserver(hal::SensorType aSensor,
121 hal::ISensorObserver *aObserver);
124 * Post a value generated by a sensor.
126 * This API is internal to hal; clients shouldn't call it directly.
128 void NotifySensorChange(const hal::SensorData &aSensorData);
131 * Enable sensor notifications from the backend
133 * This method is only visible from implementation of sensor manager.
134 * Rest of the system should not try this.
136 void EnableSensorNotifications(hal::SensorType aSensor);
139 * Disable sensor notifications from the backend
141 * This method is only visible from implementation of sensor manager.
142 * Rest of the system should not try this.
144 void DisableSensorNotifications(hal::SensorType aSensor);
148 * Inform the network backend there is a new network observer.
149 * @param aNetworkObserver The observer that should be added.
151 void RegisterNetworkObserver(NetworkObserver* aNetworkObserver);
154 * Inform the network backend a network observer unregistered.
155 * @param aNetworkObserver The observer that should be removed.
157 void UnregisterNetworkObserver(NetworkObserver* aNetworkObserver);
160 * Returns the current network information.
162 void GetCurrentNetworkInformation(hal::NetworkInformation* aNetworkInfo);
165 * Notify of a change in the network state.
166 * @param aNetworkInfo The new network information.
168 void NotifyNetworkChange(const hal::NetworkInformation& aNetworkInfo);
171 * Enable wake lock notifications from the backend.
173 * This method is only used by WakeLockObserversManager.
175 void EnableWakeLockNotifications();
178 * Disable wake lock notifications from the backend.
180 * This method is only used by WakeLockObserversManager.
182 void DisableWakeLockNotifications();
185 * Inform the wake lock backend there is a new wake lock observer.
186 * @param aWakeLockObserver The observer that should be added.
188 void RegisterWakeLockObserver(WakeLockObserver* aObserver);
191 * Inform the wake lock backend a wake lock observer unregistered.
192 * @param aWakeLockObserver The observer that should be removed.
194 void UnregisterWakeLockObserver(WakeLockObserver* aObserver);
197 * Adjust a wake lock's counts on behalf of a given process.
199 * In most cases, you shouldn't need to pass the aProcessID argument; the
200 * default of CONTENT_PROCESS_ID_UNKNOWN is probably what you want.
202 * @param aTopic lock topic
203 * @param aLockAdjust to increase or decrease active locks
204 * @param aHiddenAdjust to increase or decrease hidden locks
205 * @param aProcessID indicates which process we're modifying the wake lock
206 * on behalf of. It is interpreted as
208 * CONTENT_PROCESS_ID_UNKNOWN: The current process
209 * CONTENT_PROCESS_ID_MAIN: The root process
210 * X: The process with ContentChild::GetID() == X
212 void ModifyWakeLock(const nsAString &aTopic,
213 hal::WakeLockControl aLockAdjust,
214 hal::WakeLockControl aHiddenAdjust,
215 uint64_t aProcessID = hal::CONTENT_PROCESS_ID_UNKNOWN);
218 * Query the wake lock numbers of aTopic.
219 * @param aTopic lock topic
220 * @param aWakeLockInfo wake lock numbers
222 void GetWakeLockInfo(const nsAString &aTopic, hal::WakeLockInformation *aWakeLockInfo);
225 * Notify of a change in the wake lock state.
226 * @param aWakeLockInfo The new wake lock information.
228 void NotifyWakeLockChange(const hal::WakeLockInformation& aWakeLockInfo);
231 * Inform the backend there is a new screen configuration observer.
232 * @param aScreenConfigurationObserver The observer that should be added.
234 void RegisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
237 * Inform the backend a screen configuration observer unregistered.
238 * @param aScreenConfigurationObserver The observer that should be removed.
240 void UnregisterScreenConfigurationObserver(hal::ScreenConfigurationObserver* aScreenConfigurationObserver);
243 * Returns the current screen configuration.
245 void GetCurrentScreenConfiguration(hal::ScreenConfiguration* aScreenConfiguration);
248 * Notify of a change in the screen configuration.
249 * @param aScreenConfiguration The new screen orientation.
251 void NotifyScreenConfigurationChange(const hal::ScreenConfiguration& aScreenConfiguration);
254 * Lock the screen orientation to the specific orientation.
255 * @return Whether the lock has been accepted.
257 MOZ_MUST_USE bool LockScreenOrientation(const dom::ScreenOrientationInternal& aOrientation);
260 * Unlock the screen orientation.
262 void UnlockScreenOrientation();
265 * Register an observer for the switch of given SwitchDevice.
267 * The observer will receive data whenever the data generated by the
268 * given switch.
270 void RegisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
273 * Unregister an observer for the switch of given SwitchDevice.
275 void UnregisterSwitchObserver(hal::SwitchDevice aDevice, hal::SwitchObserver *aSwitchObserver);
278 * Notify the state of the switch.
280 * This API is internal to hal; clients shouldn't call it directly.
282 void NotifySwitchChange(const hal::SwitchEvent& aEvent);
285 * Return true if the current platform supports the setting of process
286 * priority.
288 bool SetProcessPrioritySupported();
291 * Set the priority of the given process.
293 * Exactly what this does will vary between platforms. On *nix we might give
294 * background processes higher nice values. On other platforms, we might
295 * ignore this call entirely.
297 void SetProcessPriority(int aPid, hal::ProcessPriority aPriority);
300 * Start monitoring disk space for low space situations.
302 * This API is currently only allowed to be used from the main process.
304 void StartDiskSpaceWatcher();
307 * Stop monitoring disk space for low space situations.
309 * This API is currently only allowed to be used from the main process.
311 void StopDiskSpaceWatcher();
313 } // namespace MOZ_HAL_NAMESPACE
314 } // namespace mozilla
316 #ifdef MOZ_DEFINED_HAL_NAMESPACE
317 # undef MOZ_DEFINED_HAL_NAMESPACE
318 # undef MOZ_HAL_NAMESPACE
319 #endif
321 #endif // mozilla_Hal_h