/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "domstubs.idl"

interface nsIIdleObserver;

[scriptable, uuid(c148ed5a-31c1-4a21-a13b-341f592579ff)]
interface nsIDOMNavigator : nsISupports
{
  readonly attribute DOMString             appCodeName;
  readonly attribute DOMString             appName;
  readonly attribute DOMString             appVersion;
  readonly attribute DOMString             language;
  readonly attribute nsIDOMMimeTypeArray   mimeTypes;
  readonly attribute DOMString             platform;
  readonly attribute DOMString             oscpu;
  readonly attribute DOMString             vendor;
  readonly attribute DOMString             vendorSub;
  readonly attribute DOMString             product;
  readonly attribute DOMString             productSub;
  readonly attribute nsIDOMPluginArray     plugins;
  readonly attribute DOMString             userAgent;
  readonly attribute boolean               cookieEnabled;
  readonly attribute boolean               onLine;
  readonly attribute DOMString             buildID;
  readonly attribute DOMString             doNotTrack;
  readonly attribute nsIDOMMozPowerManager mozPower;

  boolean                   javaEnabled();
  boolean                   taintEnabled();

  /**
   * Pulse the device's vibrator, if it has one.  If the device does not have a
   * vibrator, this function does nothing.  If the window is hidden, this
   * function does nothing.
   *
   * mozVibrate takes one argument, which specifies either how long to vibrate
   * for or gives a pattern of vibrator-on/vibrator-off timings.
   *
   * If a vibration pattern is in effect when this function is called, this
   * call will overwrite the existing pattern, if this call successfully
   * completes.
   *
   * We handle the argument to mozVibrate as follows.
   *
   * - If the argument is undefined or null, we throw
   *   NS_ERROR_DOM_NOT_SUPPORTED_ERR.
   *
   * - If the argument is 0, the empty list, or a list containing entirely 0s,
   *   we cancel any outstanding vibration pattern; that is, we stop the device
   *   from vibrating.
   *
   * - Otherwise, if the argument X is not a list, we treat it as though it's
   *   the singleton list [X] and then proceed as below.
   *
   * - If the argument is a list (or if we wrapped it as a list above), then we
   *   try to convert each element in the list to an integer, by first
   *   converting it to a number and then rounding.  If there is some element
   *   that we can't convert to an integer, or if any of the integers are
   *   negative, we throw NS_ERROR_DOM_NOT_SUPPORTED_ERR.
   *
   *   This list of integers specifies a vibration pattern.  Given a list of
   *   numbers
   *
   *      [a_1, b_1, a_2, b_2, ..., a_n]
   *
   *   the device will vibrate for a_1 milliseconds, then be still for b_1
   *   milliseconds, then vibrate for a_2 milliseconds, and so on.
   *
   *   The list may contain an even or an odd number of elements, but if you
   *   pass an even number of elements (that is, if your list ends with b_n
   *   instead of a_n), the final element doesn't specify anything meaningful.
   *
   *   We may throw NS_ERROR_DOM_NOT_SUPPORTED_ERR if the vibration pattern is
   *   too long, or if any of its elements is too large.
   */
  [implicit_jscontext]
  void mozVibrate(in jsval aPattern);

  /** 
   * Navigator requests to add an idle observer to the existing window.
   */
  void addIdleObserver(in nsIIdleObserver aIdleObserver);
  
  /** 
   * Navigator requests to remove an idle observer from the existing window.
   */
  void removeIdleObserver(in nsIIdleObserver aIdleObserver);

  /**
   * Request a wake lock for a resource.
   *
   * A page holds a wake lock to request that a resource not be turned
   * off (or otherwise made unavailable).
   *
   * The topic is the name of a resource that might be made unavailable for
   * various reasons. For example, on a mobile device the power manager might
   * decide to turn off the screen after a period of idle time to save power.
   *
   * The resource manager checks the lock state of a topic before turning off
   * the associated resource. For example, a page could hold a lock on the
   * "screen" topic to prevent the screensaver from appearing or the screen
   * from turning off.
   *
   * The resource manager defines what each topic means and sets policy.  For
   * example, the resource manager might decide to ignore 'screen' wake locks
   * held by pages which are not visible.
   *
   * One topic can be locked multiple times; it is considered released only when
   * all locks on the topic have been released.
   *
   * The returned nsIDOMMozWakeLock object is a token of the lock.  You can
   * unlock the lock via the object's |unlock| method.  The lock is released
   * automatically when its associated window is unloaded.
   *
   * @param aTopic resource name
   */
  nsIDOMMozWakeLock requestWakeLock(in DOMString aTopic);
};
