1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/base/public/nsIUnicharStreamLoader.idl Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,82 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 nsIUnicharInputStream; 1.12 +interface nsIUnicharStreamLoader; 1.13 +interface nsIChannel; 1.14 + 1.15 +[scriptable, uuid(c2982b39-2e48-429e-92b7-99348a1633c5)] 1.16 +interface nsIUnicharStreamLoaderObserver : nsISupports 1.17 +{ 1.18 + /** 1.19 + * Called as soon as at least 512 octets of data have arrived. 1.20 + * If the stream receives fewer than 512 octets of data in total, 1.21 + * called upon stream completion but before calling OnStreamComplete. 1.22 + * Will not be called if the stream receives no data at all. 1.23 + * 1.24 + * @param aLoader the unichar stream loader 1.25 + * @param aContext the context parameter of the underlying channel 1.26 + * @param aSegment up to 512 octets of raw data from the stream 1.27 + * 1.28 + * @return the name of the character set to be used to decode this stream 1.29 + */ 1.30 + ACString onDetermineCharset(in nsIUnicharStreamLoader aLoader, 1.31 + in nsISupports aContext, 1.32 + in ACString aSegment); 1.33 + 1.34 + /** 1.35 + * Called when the entire stream has been loaded and decoded. 1.36 + * 1.37 + * @param aLoader the unichar stream loader 1.38 + * @param aContext the context parameter of the underlying channel 1.39 + * @param aStatus the status of the underlying channel 1.40 + * @param aBuffer the contents of the stream, decoded to UTF-16. 1.41 + * 1.42 + * This method will always be called asynchronously by the 1.43 + * nsUnicharIStreamLoader involved, on the thread that called the 1.44 + * loader's init() method. If onDetermineCharset fails, 1.45 + * onStreamComplete will still be called, but aStatus will be an 1.46 + * error code. 1.47 + */ 1.48 + void onStreamComplete(in nsIUnicharStreamLoader aLoader, 1.49 + in nsISupports aContext, 1.50 + in nsresult aStatus, 1.51 + in AString aBuffer); 1.52 +}; 1.53 + 1.54 +/** 1.55 + * Asynchronously load a channel, converting the data to UTF-16. 1.56 + * 1.57 + * To use this interface, first call init() with a 1.58 + * nsIUnicharStreamLoaderObserver that will be notified when the data has been 1.59 + * loaded. Then call asyncOpen() on the channel with the nsIUnicharStreamLoader 1.60 + * as the listener. The context argument in the asyncOpen() call will be 1.61 + * passed to the onStreamComplete() callback. 1.62 + */ 1.63 +[scriptable, uuid(afb62060-37c7-4713-8a84-4a0c1199ba5c)] 1.64 +interface nsIUnicharStreamLoader : nsIStreamListener 1.65 +{ 1.66 + /** 1.67 + * Initializes the unichar stream loader 1.68 + * 1.69 + * @param aObserver the observer to notify when a charset is needed and when 1.70 + * the load is complete 1.71 + */ 1.72 + void init(in nsIUnicharStreamLoaderObserver aObserver); 1.73 + 1.74 + /** 1.75 + * The channel attribute is only valid inside the onDetermineCharset 1.76 + * and onStreamComplete callbacks. Otherwise it will be null. 1.77 + */ 1.78 + readonly attribute nsIChannel channel; 1.79 + 1.80 + /** 1.81 + * The charset that onDetermineCharset returned, if that's been 1.82 + * called. 1.83 + */ 1.84 + readonly attribute ACString charset; 1.85 +};