nsUnicharStreamLoader.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #ifndef nsUnicharStreamLoader_h__
  6. #define nsUnicharStreamLoader_h__
  7. #include "nsIChannel.h"
  8. #include "nsIUnicharStreamLoader.h"
  9. #include "nsIUnicodeDecoder.h"
  10. #include "nsCOMPtr.h"
  11. #include "nsString.h"
  12. class nsIInputStream;
  13. class nsUnicharStreamLoader : public nsIUnicharStreamLoader
  14. {
  15. public:
  16. NS_DECL_ISUPPORTS
  17. NS_DECL_NSIUNICHARSTREAMLOADER
  18. NS_DECL_NSIREQUESTOBSERVER
  19. NS_DECL_NSISTREAMLISTENER
  20. nsUnicharStreamLoader() {}
  21. static nsresult Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
  22. protected:
  23. virtual ~nsUnicharStreamLoader() {}
  24. nsresult DetermineCharset();
  25. /**
  26. * callback method used for ReadSegments
  27. */
  28. static nsresult WriteSegmentFun(nsIInputStream *, void *, const char *,
  29. uint32_t, uint32_t, uint32_t *);
  30. nsCOMPtr<nsIUnicharStreamLoaderObserver> mObserver;
  31. nsCOMPtr<nsIUnicodeDecoder> mDecoder;
  32. nsCOMPtr<nsISupports> mContext;
  33. nsCOMPtr<nsIChannel> mChannel;
  34. nsCString mCharset;
  35. // This holds the first up-to-512 bytes of the raw stream.
  36. // It will be passed to the OnDetermineCharset callback.
  37. nsCString mRawData;
  38. // Holds complete raw bytes as received so that SRI checks can be
  39. // calculated on the raw data prior to character conversion.
  40. nsCString mRawBuffer;
  41. // This holds the complete contents of the stream so far, after
  42. // decoding to UTF-16. It will be passed to the OnStreamComplete
  43. // callback.
  44. nsString mBuffer;
  45. };
  46. #endif // nsUnicharStreamLoader_h__