netwerk/streamconv/public/nsIStreamConverter.idl

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/streamconv/public/nsIStreamConverter.idl	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,100 @@
     1.4 +/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsIStreamListener.idl"
    1.10 +
    1.11 +interface nsIInputStream;
    1.12 +
    1.13 +/**
    1.14 + * nsIStreamConverter provides an interface to implement when you have code
    1.15 + * that converts data from one type to another.
    1.16 + *
    1.17 + * Suppose you had code that converted plain text into HTML. You could implement
    1.18 + * this interface to allow everyone else to use your conversion logic using a 
    1.19 + * standard api.
    1.20 + * <p>
    1.21 + * <b>STREAM CONVERTER USERS</b>
    1.22 + *
    1.23 + * There are currently two ways to use a stream converter:
    1.24 + * <ol>
    1.25 + * <li> <b>SYNCHRONOUS</b> Stream to Stream
    1.26 + *    You can supply the service with a stream of type X
    1.27 + *    and it will convert it to your desired output type and return
    1.28 + *    a converted (blocking) stream to you.</li>
    1.29 + *
    1.30 + * <li> <b>ASYNCHRONOUS</b> nsIStreamListener to nsIStreamListener
    1.31 + *    You can supply data directly to the converter by calling it's
    1.32 + *    nsIStreamListener::OnDataAvailable() method. It will then
    1.33 + *    convert that data from type X to your desired output type and
    1.34 + *    return converted data to you via the nsIStreamListener you passed
    1.35 + *    in by calling its OnDataAvailable() method.</li>
    1.36 + * </ol>
    1.37 + * <p>
    1.38 + *
    1.39 + * <b>STREAM CONVERTER SUPPLIERS</b>
    1.40 + *
    1.41 + * Registering a stream converter:
    1.42 + * Stream converter registration is a two step process. First of all the stream
    1.43 + * converter implementation must register itself with the component manager using
    1.44 + * a contractid in the format below. Second, the stream converter must add the contractid
    1.45 + * to the registry.
    1.46 + *
    1.47 + * Stream converter contractid format (the stream converter root key is defined in this
    1.48 + * file):
    1.49 + *
    1.50 + * <pre>@mozilla.org/streamconv;1?from=FROM_MIME_TYPE&to=TO_MIME_TYPE</pre>
    1.51 + *
    1.52 + * @author Jud Valeski
    1.53 + * @see nsIStreamConverterService
    1.54 + */
    1.55 +
    1.56 +[scriptable, uuid(0b6e2c69-5cf5-48b0-9dfd-c95950e2cc7b)]
    1.57 +interface nsIStreamConverter : nsIStreamListener {
    1.58 +
    1.59 +    /**
    1.60 +     * <b>SYNCRONOUS VERSION</b>
    1.61 +     * Converts a stream of one type, to a stream of another type.
    1.62 +     *
    1.63 +     * Use this method when you have a stream you want to convert.
    1.64 +     *
    1.65 +     * @param aFromStream   The stream representing the original/raw data.
    1.66 +     * @param aFromType     The MIME type of aFromStream.
    1.67 +     * @param aToType       The MIME type of the returned stream.
    1.68 +     * @param aCtxt         Either an opaque context, or a converter specific context
    1.69 +     *                      (implementation specific).
    1.70 +     * @return              The converted stream. NOTE: The returned stream may not
    1.71 +     *                      already be converted. An efficient stream converter
    1.72 +     *                      implementation will converter data on demand rather than
    1.73 +     *                      buffering the converted data until it is used.
    1.74 +     */
    1.75 +    nsIInputStream convert(in nsIInputStream aFromStream,
    1.76 +                           in string aFromType,
    1.77 +                           in string aToType,
    1.78 +                           in nsISupports aCtxt);
    1.79 +
    1.80 +    /**
    1.81 +     * <b>ASYNCRONOUS VERSION</b>
    1.82 +     * Converts data arriving via the converter's nsIStreamListener::OnDataAvailable() 
    1.83 +     * method from one type to another, pushing the converted data out to the caller 
    1.84 +     * via aListener::OnDataAvailable().
    1.85 +     *
    1.86 +     * Use this method when you want to proxy (and convert) nsIStreamListener callbacks
    1.87 +     * asynchronously.
    1.88 +     *
    1.89 +     * @param aFromType     The MIME type of the original/raw data.
    1.90 +     * @param aToType       The MIME type of the converted data.
    1.91 +     * @param aListener     The listener who receives the converted data.
    1.92 +     * @param aCtxt         Either an opaque context, or a converter specific context
    1.93 +     *                      (implementation specific).
    1.94 +     */
    1.95 +    void asyncConvertData(in string aFromType,
    1.96 +                          in string aToType,
    1.97 +                          in nsIStreamListener aListener,
    1.98 +                          in nsISupports aCtxt);
    1.99 +};
   1.100 +
   1.101 +%{C++
   1.102 +#define NS_ISTREAMCONVERTER_KEY         "@mozilla.org/streamconv;1"
   1.103 +%}

mercurial