netwerk/base/public/nsIUnicharStreamLoader.idl

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #include "nsIStreamListener.idl"
     8 interface nsIUnicharInputStream;
     9 interface nsIUnicharStreamLoader;
    10 interface nsIChannel;
    12 [scriptable, uuid(c2982b39-2e48-429e-92b7-99348a1633c5)]
    13 interface nsIUnicharStreamLoaderObserver : nsISupports
    14 {
    15   /**
    16    * Called as soon as at least 512 octets of data have arrived.
    17    * If the stream receives fewer than 512 octets of data in total,
    18    * called upon stream completion but before calling OnStreamComplete.
    19    * Will not be called if the stream receives no data at all.
    20    *
    21    * @param aLoader the unichar stream loader
    22    * @param aContext the context parameter of the underlying channel
    23    * @param aSegment up to 512 octets of raw data from the stream
    24    *
    25    * @return the name of the character set to be used to decode this stream
    26    */
    27   ACString onDetermineCharset(in nsIUnicharStreamLoader aLoader,
    28                               in nsISupports aContext,
    29                               in ACString aSegment);
    31   /**
    32    * Called when the entire stream has been loaded and decoded.
    33    *
    34    * @param aLoader the unichar stream loader
    35    * @param aContext the context parameter of the underlying channel
    36    * @param aStatus the status of the underlying channel
    37    * @param aBuffer the contents of the stream, decoded to UTF-16.
    38    *
    39    * This method will always be called asynchronously by the
    40    * nsUnicharIStreamLoader involved, on the thread that called the
    41    * loader's init() method.  If onDetermineCharset fails,
    42    * onStreamComplete will still be called, but aStatus will be an
    43    * error code.
    44    */
    45   void onStreamComplete(in nsIUnicharStreamLoader aLoader,
    46                         in nsISupports aContext,
    47                         in nsresult aStatus,
    48                         in AString aBuffer);
    49 };
    51 /**
    52  * Asynchronously load a channel, converting the data to UTF-16.
    53  *
    54  * To use this interface, first call init() with a
    55  * nsIUnicharStreamLoaderObserver that will be notified when the data has been
    56  * loaded. Then call asyncOpen() on the channel with the nsIUnicharStreamLoader
    57  * as the listener. The context argument in the asyncOpen() call will be
    58  * passed to the onStreamComplete() callback.
    59  */
    60 [scriptable, uuid(afb62060-37c7-4713-8a84-4a0c1199ba5c)]
    61 interface nsIUnicharStreamLoader : nsIStreamListener
    62 {
    63   /**
    64    * Initializes the unichar stream loader
    65    *
    66    * @param aObserver the observer to notify when a charset is needed and when
    67    *                  the load is complete
    68    */
    69   void init(in nsIUnicharStreamLoaderObserver aObserver);
    71   /**
    72    * The channel attribute is only valid inside the onDetermineCharset
    73    * and onStreamComplete callbacks.  Otherwise it will be null.
    74    */
    75   readonly attribute nsIChannel channel;
    77   /**
    78    * The charset that onDetermineCharset returned, if that's been
    79    * called.
    80    */
    81   readonly attribute ACString charset;
    82 };

mercurial