/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 *
 * The contents of this file are subject to the Mozilla Public License Version
 * 1.1 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 * for the specific language governing rights and limitations under the
 * License.
 *
 * The Original Code is the Application Update Service
 *
 * The Initial Developer of the Original Code is Google Inc.
 * Portions created by the Initial Developer are Copyright (C) 2005
 * the Initial Developer. All Rights Reserved.
 *
 * Contributor(s):
 *  Ben Goodger <ben@mozilla.org>
 *
 * Alternatively, the contents of this file may be used under the terms of
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 * in which case the provisions of the GPL or the LGPL are applicable instead
 * of those above. If you wish to allow use of your version of this file only
 * under the terms of either the GPL or the LGPL, and not to allow others to
 * use your version of this file under the terms of the MPL, indicate your
 * decision by deleting the provisions above and replace them with the notice
 * and other provisions required by the GPL or the LGPL. If you do not delete
 * the provisions above, a recipient may use your version of this file under
 * the terms of any one of the MPL, the GPL or the LGPL.
 *
 * ***** END LICENSE BLOCK ***** */

#include "nsISupports.idl"

interface nsIRequest;
interface nsIRequestObserver;
interface nsISimpleEnumerator;
interface nsITimerCallback;

[scriptable, uuid(56863a67-bd69-42de-9f40-583e625b457d)]
interface nsIUpdatePatch : nsISupports
{
  /**
   *
   */
  attribute AString type;
  /**
   *
   */
  attribute AString url;
  /**
   *
   */
  attribute AString hashfunction;
  /**
   *
   */
  attribute AString hashvalue;
  
  /**
   *
   */
  attribute unsigned long size;
};

[scriptable, uuid(bd75a4c6-b813-45b2-a96e-41a429c857c4)]
interface nsIUpdate : nsISupports
{
  /**
   * The type of update:
   *   "major"  A major new version of the Application
   *   "minor"  A minor update to the Application (e.g. security update)
   */
  attribute AString type;

  /**
   * The Application version of this update. 
   */
  attribute AString version;

  /**
   * The Addon version of this update. Used by the Extension System to track 
   * compatibility of installed addons with this update. 
   */
  attribute AString extensionversion;

  /**
   * The URL to a page which offers details about the content of this 
   * update. Ideally, this page is not the release notes but some other page
   * that summarizes the differences between this update and the previous,
   * which also links to the release notes.
   */
  attribute AString detailsurl;

  /**
   * The URL to a HTML fragment that contains a license for this update. If
   * this is specified, the user is shown the license file after they choose
   * to install the update and they must agree to it before the download 
   * commences.
   */
  attribute AString licenseurl;

  /**
   * Whether or not the update being downloaded is a complete replacement of
   * the user's existing installation or a patch representing the difference
   * between the new version and the previous version.
   */
  attribute boolean isCompleteUpdate;

  /**
   * When the update was installed.
   */
  attribute long long installDate;

  /**
   * The number of patches supplied by this update.
   */
  readonly attribute unsigned long patchCount;

  /**
   * Retrieves a patch. 
   * @param   index
   *          The index of the patch to retrieve.
   * @returns The nsIUpdatePatch at the specified index.
   */
  nsIUpdatePatch getPatchAt(in unsigned long index);  
};

[scriptable, uuid(8cbceb6e-8e27-46f2-8808-444c6499f836)]
interface nsIUpdateCheckListener : nsISupports
{
  /**
   *
   */
  void onProgress(in nsIRequest request, 
                  in unsigned long position,
                  in unsigned long totalSize);

  /**
   *
   */
  void onCheckComplete([array, size_is(updateCount)] in nsIUpdate updates,
                       in unsigned long updateCount);

  /**
   *
   */
  void onError();
};

[scriptable, uuid(22b00276-ec23-4034-a764-395da539b4be)]
interface nsIUpdatePrompt : nsISupports
{
  /**
   * Shows a user interface that checks for and then displays the available
   * updates.
   */
  void checkForUpdates();

  /**
   * Show a message advising that an update is available for download and
   * install.
   * @param   update
   *          The update to be downloaded and installed
   */
  void showUpdateAvailable(in nsIUpdate update);

  /**
   * Shows a list of all updates installed to date.
   */
  void showInstalledUpdates();
};

[scriptable, uuid(877ace25-8bc5-452a-8586-9c1cf2871994)]
interface nsIUpdateChecker : nsISupports
{
  /**
   * Ends any pending update check.
   */
  void stopChecking();
};

[scriptable, uuid(9849c4bf-5197-4d22-baa8-e3b44a1703d2)]
interface nsIApplicationUpdateService : nsISupports
{
  /**
   *
   */
  nsIUpdateChecker checkForUpdates(in nsIUpdateCheckListener listener);

  /**
   * Adds a listener that receives progress and state information about the 
   * update that is currently being downloaded, e.g. to update a user 
   * interface.
   * @param   listener
   *          An object implementing nsIRequestObserver and optionally
   *          nsIProgressEventSink that is to be notified of state and
   *          progress information as the update is downloaded.
   */
  void addDownloadListener(in nsIRequestObserver listener);

  /**
   * Removes a listener that is receiving progress and state information
   * about the update that is currently being downloaded. 
   * @param   listener
   *          The listener object to remove.
   */
  void removeDownloadListener(in nsIRequestObserver listener);

  /**
   * Selects the best update to install from a list of available updates.
   * @param   updates
   *          An array of updates that are available
   * @param   updateCount
   *          The length of the |updates| array
   */
  nsIUpdate selectUpdate([array, size_is(updateCount)] in nsIUpdate updates,
                         in unsigned long updateCount);

  /**
   * 
   */
  AString downloadUpdate(in nsIUpdate update, in boolean background);

  /**
   * Pauses the active update download process
   */
  void pauseDownload();
};

[scriptable, uuid(fede66a9-9f96-4507-a22a-775ee885577e)]
interface nsIUpdateManager : nsISupports
{
  /**
   *
   */
  nsIUpdate getUpdateAt(in long index);

  /**
   * 
   */
  readonly attribute long updateCount;

  /**
   *
   */
  attribute nsIUpdate activeUpdate;

  /**
   *
   */
  void addUpdate(in nsIUpdate update);

  /**
   *
   */
  void removeUpdate(in nsIUpdate update);

  /**
   *
   */
  void saveUpdates();
};

[scriptable, uuid(0765c92c-6145-4253-9db4-594d8023087e)]
interface nsIUpdateTimerManager : nsISupports
{
    /**
     *
     */
    void registerTimer(in AString id, 
                       in nsITimerCallback callback, 
                       in unsigned long interval,
                       in unsigned long type);
};

[scriptable, uuid(22d35700-5765-42e1-914b-a0da7c911a8c)]
interface nsIVersionChecker : nsISupports
{
  // -ve      if B is newer
  // equal    if A == B
  // +ve      if A is newer
  long compare(in AString aVersionA, in AString aVersionB);

  boolean isValidVersion(in AString aVersion);
};

