nsIStreamLoader.idl 2.8 KB

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