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"
9 interface nsIIncrementalStreamLoader
;
11 [scriptable
, uuid(07c3d2cc
-5454-4618-9f4f
-cd93de9504a4
)]
12 interface nsIIncrementalStreamLoaderObserver
: nsISupports
15 * Same as nsIRequestObserver.onStartRequest.
16 * Called when the loader observes onStartRequest.
18 * @param aRequest request being observed
20 void onStartRequest
(in nsIRequest aRequest
);
23 * Called when new data has arrived on the stream.
25 * @param loader the stream loader that loaded the stream.
26 * @param ctxt the context parameter of the underlying channel
27 * @param dataLength the length of the new data received
28 * @param data the contents of the new data received.
30 * This method will always be called asynchronously by the
31 * nsIIncrementalStreamLoader involved, on the thread that called the
32 * loader's init() method.
34 * If the observer wants to not accumulate all or portional of the data in
35 * the internal buffer, the consumedLength shall be set to the value of
36 * the dataLength or less. By default the consumedLength value is assumed 0.
37 * The data and dataLength reflect the non-consumed data and will be
38 * accumulated if consumedLength is not set.
40 * In comparison with onStreamComplete(), the data buffer cannot be
41 * adopted if this method returns NS_SUCCESS_ADOPTED_DATA.
43 void onIncrementalData
(in nsIIncrementalStreamLoader loader
,
45 in unsigned long dataLength
,
46 [const,array
,size_is(dataLength
)] in octet data
,
47 inout
unsigned long consumedLength
);
50 * Called when the entire stream has been loaded.
52 * @param loader the stream loader that loaded the stream.
53 * @param ctxt the context parameter of the underlying channel
54 * @param status the status of the underlying channel
55 * @param resultLength the length of the data loaded
56 * @param result the data
58 * This method will always be called asynchronously by the
59 * nsIIncrementalStreamLoader involved, on the thread that called the
60 * loader's init() method.
62 * If the observer wants to take over responsibility for the
63 * data buffer (result), it returns NS_SUCCESS_ADOPTED_DATA
64 * in place of NS_OK as its success code. The loader will then
65 * "forget" about the data and not free() it after
66 * onStreamComplete() returns; observer must call free()
67 * when the data is no longer required.
69 void onStreamComplete
(in nsIIncrementalStreamLoader loader
,
72 in unsigned long resultLength
,
73 [const,array
,size_is(resultLength
)] in octet result
);
77 * Asynchronously loads a channel into a memory buffer.
79 * To use this interface, first call init() with a nsIIncrementalStreamLoaderObserver
80 * that will be notified when the data has been loaded. Then call asyncOpen()
81 * on the channel with the nsIIncrementalStreamLoader as the listener. The context
82 * argument in the asyncOpen() call will be passed to the onStreamComplete()
85 * XXX define behaviour for sizes >4 GB
87 [scriptable
, uuid(a023b060
-ba23
-431a
-b449
-2dd63e220554
)]
88 interface nsIIncrementalStreamLoader
: nsIThreadRetargetableStreamListener
91 * Initialize this stream loader, and start loading the data.
94 * An observer that will be notified when the data is complete.
96 void init
(in nsIIncrementalStreamLoaderObserver aObserver
);
99 * Gets the number of bytes read so far.
101 readonly attribute
unsigned long numBytesRead
;
104 * Gets the request that loaded this file.
105 * null after the request has finished loading.
107 readonly attribute nsIRequest request
;