nsIUnicharStreamLoader.idl 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 nsIUnicharInputStream;
  7. interface nsIUnicharStreamLoader;
  8. interface nsIChannel;
  9. [scriptable, uuid(c2982b39-2e48-429e-92b7-99348a1633c5)]
  10. interface nsIUnicharStreamLoaderObserver : nsISupports
  11. {
  12. /**
  13. * Called as soon as at least 512 octets of data have arrived.
  14. * If the stream receives fewer than 512 octets of data in total,
  15. * called upon stream completion but before calling OnStreamComplete.
  16. * Will not be called if the stream receives no data at all.
  17. *
  18. * @param aLoader the unichar stream loader
  19. * @param aContext the context parameter of the underlying channel
  20. * @param aSegment up to 512 octets of raw data from the stream
  21. *
  22. * @return the name of the character set to be used to decode this stream
  23. */
  24. ACString onDetermineCharset(in nsIUnicharStreamLoader aLoader,
  25. in nsISupports aContext,
  26. in ACString aSegment);
  27. /**
  28. * Called when the entire stream has been loaded and decoded.
  29. *
  30. * @param aLoader the unichar stream loader
  31. * @param aContext the context parameter of the underlying channel
  32. * @param aStatus the status of the underlying channel
  33. * @param aBuffer the contents of the stream, decoded to UTF-16.
  34. *
  35. * This method will always be called asynchronously by the
  36. * nsUnicharIStreamLoader involved, on the thread that called the
  37. * loader's init() method. If onDetermineCharset fails,
  38. * onStreamComplete will still be called, but aStatus will be an
  39. * error code.
  40. */
  41. void onStreamComplete(in nsIUnicharStreamLoader aLoader,
  42. in nsISupports aContext,
  43. in nsresult aStatus,
  44. in AString aBuffer);
  45. };
  46. /**
  47. * Asynchronously load a channel, converting the data to UTF-16.
  48. *
  49. * To use this interface, first call init() with a
  50. * nsIUnicharStreamLoaderObserver that will be notified when the data has been
  51. * loaded. Then call asyncOpen() on the channel with the nsIUnicharStreamLoader
  52. * as the listener. The context argument in the asyncOpen() call will be
  53. * passed to the onStreamComplete() callback.
  54. */
  55. [scriptable, uuid(afb62060-37c7-4713-8a84-4a0c1199ba5c)]
  56. interface nsIUnicharStreamLoader : nsIStreamListener
  57. {
  58. /**
  59. * Initializes the unichar stream loader
  60. *
  61. * @param aObserver the observer to notify when a charset is needed and when
  62. * the load is complete
  63. */
  64. void init(in nsIUnicharStreamLoaderObserver aObserver);
  65. /**
  66. * The channel attribute is only valid inside the onDetermineCharset
  67. * and onStreamComplete callbacks. Otherwise it will be null.
  68. */
  69. readonly attribute nsIChannel channel;
  70. /**
  71. * The charset that onDetermineCharset returned, if that's been
  72. * called.
  73. */
  74. readonly attribute ACString charset;
  75. /**
  76. * Get the raw bytes as seen on the wire prior to character converstion.
  77. * Used by Subresource Integrity checker to generate the correct hash.
  78. */
  79. readonly attribute ACString rawBuffer;
  80. };