nsIStreamConverterService.idl 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  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 "nsISupports.idl"
  6. interface nsIInputStream;
  7. interface nsIStreamListener;
  8. %{C++
  9. #define NS_ISTREAMCONVERTER_KEY "@mozilla.org/streamconv;1"
  10. %}
  11. /**
  12. * The nsIStreamConverterService is a higher level stream converter factory
  13. * responsible for locating and creating stream converters
  14. * (nsIStreamConverter).
  15. *
  16. * This service retrieves an interface that can convert data from a particular
  17. * MIME type, to a particular MIME type. It is responsible for any intermediary
  18. * conversion required in order to get from X to Z, assuming direct conversion
  19. * is not possible.
  20. *
  21. * @author Jud Valeski
  22. * @see nsIStreamConverter
  23. */
  24. [scriptable, uuid(f2b1ab53-f0bd-4adb-9365-e59b1701a258)]
  25. interface nsIStreamConverterService : nsISupports {
  26. /**
  27. * Tests whether conversion between the two specified types is possible.
  28. * This is cheaper than calling convert()/asyncConvertData(); it is not
  29. * necessary to call this function before calling one of those, though.
  30. */
  31. boolean canConvert(in string aFromType, in string aToType);
  32. /**
  33. * <b>SYNCHRONOUS VERSION</b>
  34. * Converts a stream of one type, to a stream of another type.
  35. *
  36. * Use this method when you have a stream you want to convert.
  37. *
  38. * @param aFromStream The stream representing the original/raw data.
  39. * @param aFromType The MIME type of aFromStream.
  40. * @param aToType The MIME type of the returned stream.
  41. * @param aContext Either an opaque context, or a converter specific
  42. * context (implementation specific).
  43. * @return The converted stream. NOTE: The returned stream
  44. * may not already be converted. An efficient stream
  45. * converter implementation will convert data on
  46. * demand rather than buffering the converted data
  47. * until it is used.
  48. */
  49. nsIInputStream convert(in nsIInputStream aFromStream,
  50. in string aFromType,
  51. in string aToType,
  52. in nsISupports aContext);
  53. /**
  54. * <b>ASYNCHRONOUS VERSION</b>
  55. * Retrieves a nsIStreamListener that receives the original/raw data via its
  56. * nsIStreamListener::OnDataAvailable() callback, then converts and pushes
  57. * the data to aListener.
  58. *
  59. * Use this method when you want to proxy (and convert) nsIStreamListener
  60. * callbacks asynchronously.
  61. *
  62. * @param aFromType The MIME type of the original/raw data.
  63. * @param aToType The MIME type of the converted data.
  64. * @param aListener The listener that receives the converted data.
  65. * @param aCtxt Either an opaque context, or a converter specific
  66. * context (implementation specific).
  67. * @return A nsIStreamListener that receives data via its
  68. * OnDataAvailable() method.
  69. */
  70. nsIStreamListener asyncConvertData(in string aFromType,
  71. in string aToType,
  72. in nsIStreamListener aListener,
  73. in nsISupports aContext);
  74. };