WebAPI/ResourceLockAPI

From MozillaWiki
Jump to: navigation, search

API

partial interface Navigator {
  WakeLock requestWakeLock(DOMString topic);
};

interface WakeLock {
  readonly attribute DOMString topic;
  void unlock();
};

There's also a set of defined topics:

  • screen: Prevent screen saver from being turned on and the device going to sleep automatically. This does not prevent the screen from being turned off if the user manually puts the device to sleep (for example by pressing power button).
  • cpu: If the user puts the device in sleep mode, don't disable the CPU as long as this lock is held. I.e. allow any applications to continue to run any calculations and save data to disk or network. The screen is however turned off as normal.
  • wifi: Prevent the wifi network connection from being disabled even if the device goes into sleep mode.

Outstanding issues: Should the cpu lock keep the wifi connection from being disconnected?

If a lock is requested that the implementation doesn't recognize, we return a useless WakeLock.

Security/Privacy implications

No locks except the screen lock is honored for non-installed pages.

We only honor screen lock of the currently active tab. Pages in iframes are allowed to request this lock.

ToDo

We should probably have a 'active' boolean attribute on WakeLock, and an associated event, which indicates if a lock was force-released by the implementation. This could ideally also be used to detect if an implementation supports a given lock.