FileRequestBase.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* -*- Mode: C++; tab-width: 8; 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 file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #ifndef mozilla_dom_FileRequest_h
  6. #define mozilla_dom_FileRequest_h
  7. #include "FileHandleCommon.h"
  8. #include "js/TypeDecls.h"
  9. #include "nsString.h"
  10. struct PRThread;
  11. namespace mozilla {
  12. namespace dom {
  13. class FileHandleBase;
  14. /**
  15. * This class provides a base for FileRequest implementations.
  16. */
  17. class FileRequestBase
  18. : public RefCountedThreadObject
  19. {
  20. nsString mEncoding;
  21. bool mHasEncoding;
  22. public:
  23. class ResultCallback;
  24. void
  25. SetEncoding(const nsAString& aEncoding)
  26. {
  27. mEncoding = aEncoding;
  28. mHasEncoding = true;
  29. }
  30. const nsAString&
  31. GetEncoding() const
  32. {
  33. return mEncoding;
  34. }
  35. bool
  36. HasEncoding() const
  37. {
  38. return mHasEncoding;
  39. }
  40. virtual FileHandleBase*
  41. FileHandle() const = 0;
  42. virtual void
  43. OnProgress(uint64_t aProgress, uint64_t aProgressMax) = 0;
  44. virtual void
  45. SetResultCallback(ResultCallback* aCallback) = 0;
  46. virtual void
  47. SetError(nsresult aError) = 0;
  48. protected:
  49. FileRequestBase(DEBUGONLY(PRThread* aOwningThread))
  50. : RefCountedThreadObject(DEBUGONLY(aOwningThread))
  51. , mHasEncoding(false)
  52. {
  53. AssertIsOnOwningThread();
  54. }
  55. virtual ~FileRequestBase()
  56. {
  57. AssertIsOnOwningThread();
  58. }
  59. };
  60. class NS_NO_VTABLE FileRequestBase::ResultCallback
  61. {
  62. public:
  63. virtual nsresult
  64. GetResult(JSContext* aCx, JS::MutableHandle<JS::Value> aResult) = 0;
  65. protected:
  66. ResultCallback()
  67. { }
  68. };
  69. } // namespace dom
  70. } // namespace mozilla
  71. #endif // mozilla_dom_FileRequest_h