ArchiveEvent.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_archivereader_domarchiveevent_h__
  6. #define mozilla_dom_archivereader_domarchiveevent_h__
  7. #include "ArchiveReader.h"
  8. #include "mozilla/dom/File.h"
  9. #include "nsISeekableStream.h"
  10. #include "nsIMIMEService.h"
  11. #include "ArchiveReaderCommon.h"
  12. BEGIN_ARCHIVEREADER_NAMESPACE
  13. /**
  14. * This class contains all the info needed for a single item
  15. * It must contain the implementation of the File() method.
  16. */
  17. class ArchiveItem : public nsISupports
  18. {
  19. public:
  20. NS_DECL_THREADSAFE_ISUPPORTS
  21. ArchiveItem();
  22. // Getter/Setter for the type
  23. nsCString GetType();
  24. void SetType(const nsCString& aType);
  25. // Getter for the filename
  26. virtual nsresult GetFilename(nsString& aFilename) = 0;
  27. // Generate a File
  28. virtual already_AddRefed<File> GetFile(ArchiveReader* aArchiveReader) = 0;
  29. protected:
  30. virtual ~ArchiveItem();
  31. nsCString mType;
  32. };
  33. /**
  34. * This class must be extended by any archive format supported by ArchiveReader API
  35. * This class runs in a different thread and it calls the 'exec()' method.
  36. * The exec() must populate mFileList and mStatus then it must call RunShare();
  37. */
  38. class ArchiveReaderEvent : public Runnable
  39. {
  40. public:
  41. NS_DECL_NSIRUNNABLE
  42. explicit ArchiveReaderEvent(ArchiveReader* aArchiveReader);
  43. protected:
  44. virtual ~ArchiveReaderEvent();
  45. public:
  46. // This must be implemented
  47. virtual nsresult Exec() = 0;
  48. protected:
  49. nsresult GetType(nsCString& aExt,
  50. nsCString& aMimeType);
  51. nsresult RunShare(nsresult aStatus);
  52. void ShareMainThread();
  53. protected: // data
  54. ArchiveReader* mArchiveReader;
  55. nsCOMPtr<nsIMIMEService> mMimeService;
  56. nsTArray<RefPtr<ArchiveItem> > mFileList; // this must be populated
  57. nsresult mStatus;
  58. };
  59. END_ARCHIVEREADER_NAMESPACE
  60. #endif // mozilla_dom_archivereader_domarchiveevent_h__