Blame uriloader/exthandler/nsIHandlerService.idl

Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
#include "nsISupports.idl"
Packit f0b94e
Packit f0b94e
interface nsIHandlerInfo;
Packit f0b94e
interface nsISimpleEnumerator;
Packit f0b94e
Packit f0b94e
[scriptable, uuid(53f0ad17-ec62-46a1-adbc-efccc06babcd)]
Packit f0b94e
interface nsIHandlerService : nsISupports
Packit f0b94e
{
Packit f0b94e
  /**
Packit f0b94e
   * Asynchronously performs any IO that the nsIHandlerService needs to do
Packit f0b94e
   * before it can be of use.
Packit f0b94e
   */
Packit f0b94e
  void asyncInit();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Retrieve a list of all handlers in the datastore.  This list is not
Packit f0b94e
   * guaranteed to be in any particular order, and callers should not assume
Packit f0b94e
   * it will remain in the same order in the future.
Packit f0b94e
   *
Packit f0b94e
   * @returns a list of all handlers in the datastore
Packit f0b94e
   */
Packit f0b94e
  nsISimpleEnumerator enumerate();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Fill a handler info object with information from the datastore.
Packit f0b94e
   *
Packit f0b94e
   * Note: because of the way the external helper app service currently mixes
Packit f0b94e
   * OS and user handler info in the same handler info object, this method
Packit f0b94e
   * takes an existing handler info object (probably retrieved from the OS)
Packit f0b94e
   * and "fills it in" with information from the datastore, overriding any
Packit f0b94e
   * existing properties on the object with properties from the datastore.
Packit f0b94e
   *
Packit f0b94e
   * Ultimately, however, we're going to separate OS and user handler info
Packit f0b94e
   * into separate objects, at which point this method should be renamed to
Packit f0b94e
   * something like "get" or "retrieve", take a class and type (or perhaps
Packit f0b94e
   * a type whose class can be determined by querying the type, for example
Packit f0b94e
   * an nsIContentType which is also an nsIMIMEType or an nsIProtocolScheme),
Packit f0b94e
   * and return a handler info object representing only the user info.
Packit f0b94e
   *
Packit f0b94e
   * Note: if you specify an override type, then the service will fill in
Packit f0b94e
   * the handler info object with information about that type instead of
Packit f0b94e
   * the type specified by the object's nsIHandlerInfo::type attribute.
Packit f0b94e
   *
Packit f0b94e
   * This is useful when you are trying to retrieve information about a MIME
Packit f0b94e
   * type that doesn't exist in the datastore, but you have a file extension
Packit f0b94e
   * for that type, and nsIHandlerService::getTypeFromExtension returns another
Packit f0b94e
   * MIME type that does exist in the datastore and can handle that extension.
Packit f0b94e
   *
Packit f0b94e
   * For example, the user clicks on a link, and the content has a MIME type
Packit f0b94e
   * that isn't in the datastore, but the link has a file extension, and that
Packit f0b94e
   * extension is associated with another MIME type in the datastore (perhaps
Packit f0b94e
   * an unofficial MIME type preceded an official one, like with image/x-png
Packit f0b94e
   * and image/png).
Packit f0b94e
   *
Packit f0b94e
   * In that situation, you can call this method to fill in the handler info
Packit f0b94e
   * object with information about that other type by passing the other type
Packit f0b94e
   * as the aOverrideType parameter.
Packit f0b94e
   *
Packit f0b94e
   * @param aHandlerInfo   the handler info object
Packit f0b94e
   * @param aOverrideType  a type to use instead of aHandlerInfo::type
Packit f0b94e
   *
Packit f0b94e
   * Note: if there is no information in the datastore about this type,
Packit f0b94e
   * this method throws NS_ERROR_NOT_AVAILABLE. Callers are encouraged to
Packit f0b94e
   * check exists() before calling fillHandlerInfo(), to prevent spamming the
Packit f0b94e
   * console with XPCOM exception errors.
Packit f0b94e
   */
Packit f0b94e
  void fillHandlerInfo(in nsIHandlerInfo aHandlerInfo,
Packit f0b94e
                       in ACString aOverrideType);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Save the preferred action, preferred handler, possible handlers, and
Packit f0b94e
   * always ask properties of the given handler info object to the datastore.
Packit f0b94e
   * Updates an existing record or creates a new one if necessary.
Packit f0b94e
   *
Packit f0b94e
   * Note: if preferred action is undefined or invalid, then we assume
Packit f0b94e
   * the default value nsIHandlerInfo::useHelperApp.
Packit f0b94e
   *
Packit f0b94e
   * @param aHandlerInfo  the handler info object
Packit f0b94e
   */
Packit f0b94e
  void store(in nsIHandlerInfo aHandlerInfo);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Whether or not a record for the given handler info object exists
Packit f0b94e
   * in the datastore. If the datastore is corrupt (or some other error
Packit f0b94e
   * is caught in the implementation), false will be returned.
Packit f0b94e
   *
Packit f0b94e
   * @param aHandlerInfo  a handler info object
Packit f0b94e
   *
Packit f0b94e
   * @returns whether or not a record exists
Packit f0b94e
   */
Packit f0b94e
  boolean exists(in nsIHandlerInfo aHandlerInfo);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Remove the given handler info object from the datastore.  Deletes all
Packit f0b94e
   * records associated with the object, including the preferred handler, info,
Packit f0b94e
   * and type records plus the entry in the list of types, if they exist.
Packit f0b94e
   * Otherwise, it does nothing and does not return an error.
Packit f0b94e
   *
Packit f0b94e
   * @param aHandlerInfo  the handler info object
Packit f0b94e
   */
Packit f0b94e
  void remove(in nsIHandlerInfo aHandlerInfo);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Get the MIME type mapped to the given file extension in the datastore.
Packit f0b94e
   *
Packit f0b94e
   * XXX If we ever support extension -> protocol scheme mappings, then this
Packit f0b94e
   * method should work for those as well.
Packit f0b94e
   *
Packit f0b94e
   * Note: in general, you should use nsIMIMEService::getTypeFromExtension
Packit f0b94e
   * to get a MIME type from a file extension, as that method checks a variety
Packit f0b94e
   * of other sources besides just the datastore.  Use this only when you want
Packit f0b94e
   * to specifically get only the mapping available in the datastore.
Packit f0b94e
   *
Packit f0b94e
   * @param aFileExtension  the file extension
Packit f0b94e
   *
Packit f0b94e
   * @returns the MIME type, if any; otherwise returns an empty string ("").
Packit f0b94e
   */
Packit f0b94e
  ACString getTypeFromExtension(in ACString aFileExtension);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Whether or not there is a handler known to the OS for the
Packit f0b94e
   * specified protocol type.
Packit f0b94e
   *
Packit f0b94e
   * @param aProtocolScheme scheme to check for support
Packit f0b94e
   *
Packit f0b94e
   * @returns whether or not a handler exists
Packit f0b94e
   */
Packit f0b94e
  boolean existsForProtocol(in ACString aProtocolScheme);
Packit f0b94e
};