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