michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 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 "nsIStreamListener.idl" michael@0: michael@0: interface nsIRequest; michael@0: interface nsIStreamLoader; michael@0: michael@0: [scriptable, uuid(359F7990-D4E9-11d3-A1A5-0050041CAF44)] michael@0: interface nsIStreamLoaderObserver : nsISupports michael@0: { michael@0: /** michael@0: * Called when the entire stream has been loaded. michael@0: * michael@0: * @param loader the stream loader that loaded the stream. michael@0: * @param ctxt the context parameter of the underlying channel michael@0: * @param status the status of the underlying channel michael@0: * @param resultLength the length of the data loaded michael@0: * @param result the data michael@0: * michael@0: * This method will always be called asynchronously by the michael@0: * nsIStreamLoader involved, on the thread that called the michael@0: * loader's init() method. michael@0: * michael@0: * If the observer wants to take over responsibility for the michael@0: * data buffer (result), it returns NS_SUCCESS_ADOPTED_DATA michael@0: * in place of NS_OK as its success code. The loader will then michael@0: * "forget" about the data and not NS_Free() it after michael@0: * onStreamComplete() returns; observer must call NS_Free() michael@0: * when the data is no longer required. michael@0: */ michael@0: void onStreamComplete(in nsIStreamLoader loader, michael@0: in nsISupports ctxt, michael@0: in nsresult status, michael@0: in unsigned long resultLength, michael@0: [const,array,size_is(resultLength)] in octet result); michael@0: }; michael@0: michael@0: /** michael@0: * Asynchronously loads a channel into a memory buffer. michael@0: * michael@0: * To use this interface, first call init() with a nsIStreamLoaderObserver michael@0: * that will be notified when the data has been loaded. Then call asyncOpen() michael@0: * on the channel with the nsIStreamLoader as the listener. The context michael@0: * argument in the asyncOpen() call will be passed to the onStreamComplete() michael@0: * callback. michael@0: * michael@0: * XXX define behaviour for sizes >4 GB michael@0: */ michael@0: [scriptable, uuid(8ea7e890-8211-11d9-8bde-f66bad1e3f3a)] michael@0: interface nsIStreamLoader : nsIStreamListener michael@0: { michael@0: /** michael@0: * Initialize this stream loader, and start loading the data. michael@0: * michael@0: * @param aObserver michael@0: * An observer that will be notified when the data is complete. michael@0: */ michael@0: void init(in nsIStreamLoaderObserver aObserver); michael@0: michael@0: /** michael@0: * Gets the number of bytes read so far. michael@0: */ michael@0: readonly attribute unsigned long numBytesRead; michael@0: michael@0: /** michael@0: * Gets the request that loaded this file. michael@0: * null after the request has finished loading. michael@0: */ michael@0: readonly attribute nsIRequest request; michael@0: };