nsIIncrementalStreamLoader.idl 4.0 KB

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