Merge mozilla-central to autoland. CLOSED TREE
[gecko.git] / netwerk / base / nsIStreamLoader.idl
blob1b54f59074d06ead2952ef1761345992236c215c
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 "nsIThreadRetargetableStreamListener.idl"
8 interface nsIRequest;
9 interface nsIStreamLoader;
11 [scriptable, uuid(359F7990-D4E9-11d3-A1A5-0050041CAF44)]
12 interface nsIStreamLoaderObserver : nsISupports
14 /**
15 * Called when the entire stream has been loaded.
17 * @param loader the stream loader that loaded the stream.
18 * @param ctxt the context parameter of the underlying channel
19 * @param status the status of the underlying channel
20 * @param resultLength the length of the data loaded
21 * @param result the data
23 * This method will always be called asynchronously by the
24 * nsIStreamLoader involved, on the thread that called the
25 * loader's init() method.
27 * If the observer wants to take over responsibility for the
28 * data buffer (result), it returns NS_SUCCESS_ADOPTED_DATA
29 * in place of NS_OK as its success code. The loader will then
30 * "forget" about the data and not free() it after
31 * onStreamComplete() returns; observer must call free()
32 * when the data is no longer required.
34 void onStreamComplete(in nsIStreamLoader loader,
35 in nsISupports ctxt,
36 in nsresult status,
37 in unsigned long resultLength,
38 [const,array,size_is(resultLength)] in octet result);
41 /**
42 * Asynchronously loads a channel into a memory buffer.
44 * To use this interface, first call init() with a nsIStreamLoaderObserver
45 * that will be notified when the data has been loaded. Then call asyncOpen()
46 * on the channel with the nsIStreamLoader as the listener. The context
47 * argument in the asyncOpen() call will be passed to the onStreamComplete()
48 * callback.
50 * XXX define behaviour for sizes >4 GB
52 [scriptable, uuid(323bcff1-7513-4e1f-a541-1c9213c2ed1b)]
53 interface nsIStreamLoader : nsIThreadRetargetableStreamListener
55 /**
56 * Initialize this stream loader, and start loading the data.
58 * @param aStreamObserver
59 * An observer that will be notified when the data is complete.
60 * @param aRequestObserver
61 * An optional observer that will be notified when the request
62 * has started or stopped.
64 void init(in nsIStreamLoaderObserver aStreamObserver,
65 [optional] in nsIRequestObserver aRequestObserver);
67 /**
68 * Gets the number of bytes read so far.
70 readonly attribute unsigned long numBytesRead;
72 /**
73 * Gets the request that loaded this file.
74 * null after the request has finished loading.
76 readonly attribute nsIRequest request;