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