FileSnapshot.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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_indexeddb_filesnapshot_h__
  6. #define mozilla_dom_indexeddb_filesnapshot_h__
  7. #include "mozilla/Attributes.h"
  8. #include "mozilla/dom/File.h"
  9. #include "nsISupports.h"
  10. #include "nsWeakPtr.h"
  11. #define FILEIMPLSNAPSHOT_IID \
  12. {0x0dfc11b1, 0x75d3, 0x473b, {0x8c, 0x67, 0xb7, 0x23, 0xf4, 0x67, 0xd6, 0x73}}
  13. class PIBlobImplSnapshot : public nsISupports
  14. {
  15. public:
  16. NS_DECLARE_STATIC_IID_ACCESSOR(FILEIMPLSNAPSHOT_IID)
  17. virtual mozilla::dom::BlobImpl*
  18. GetBlobImpl() const = 0;
  19. };
  20. NS_DEFINE_STATIC_IID_ACCESSOR(PIBlobImplSnapshot, FILEIMPLSNAPSHOT_IID)
  21. namespace mozilla {
  22. namespace dom {
  23. class IDBFileHandle;
  24. namespace indexedDB {
  25. class BlobImplSnapshot final
  26. : public BlobImpl
  27. , public PIBlobImplSnapshot
  28. {
  29. RefPtr<BlobImpl> mBlobImpl;
  30. nsWeakPtr mFileHandle;
  31. public:
  32. BlobImplSnapshot(BlobImpl* aImpl,
  33. IDBFileHandle* aFileHandle);
  34. NS_DECL_ISUPPORTS_INHERITED
  35. private:
  36. BlobImplSnapshot(BlobImpl* aImpl,
  37. nsIWeakReference* aFileHandle);
  38. ~BlobImplSnapshot();
  39. // BlobImpl
  40. virtual void
  41. GetName(nsAString& aName) const override
  42. {
  43. mBlobImpl->GetName(aName);
  44. }
  45. virtual void
  46. GetDOMPath(nsAString& aPath) const override
  47. {
  48. mBlobImpl->GetDOMPath(aPath);
  49. }
  50. virtual void
  51. SetDOMPath(const nsAString& aPath) override
  52. {
  53. mBlobImpl->SetDOMPath(aPath);
  54. }
  55. virtual int64_t
  56. GetLastModified(ErrorResult& aRv) override
  57. {
  58. return mBlobImpl->GetLastModified(aRv);
  59. }
  60. virtual void
  61. SetLastModified(int64_t aLastModified) override
  62. {
  63. mBlobImpl->SetLastModified(aLastModified);
  64. }
  65. virtual void
  66. GetMozFullPath(nsAString& aName, ErrorResult& aRv) const override
  67. {
  68. mBlobImpl->GetMozFullPath(aName, aRv);
  69. }
  70. virtual void
  71. GetMozFullPathInternal(nsAString& aFileName, ErrorResult& aRv) const override
  72. {
  73. mBlobImpl->GetMozFullPathInternal(aFileName, aRv);
  74. }
  75. virtual uint64_t
  76. GetSize(ErrorResult& aRv) override
  77. {
  78. return mBlobImpl->GetSize(aRv);
  79. }
  80. virtual void
  81. GetType(nsAString& aType) override
  82. {
  83. mBlobImpl->GetType(aType);
  84. }
  85. virtual uint64_t
  86. GetSerialNumber() const override
  87. {
  88. return mBlobImpl->GetSerialNumber();
  89. }
  90. virtual already_AddRefed<BlobImpl>
  91. CreateSlice(uint64_t aStart,
  92. uint64_t aLength,
  93. const nsAString& aContentType,
  94. ErrorResult& aRv) override;
  95. virtual const nsTArray<RefPtr<BlobImpl>>*
  96. GetSubBlobImpls() const override
  97. {
  98. return mBlobImpl->GetSubBlobImpls();
  99. }
  100. virtual void
  101. GetInternalStream(nsIInputStream** aStream,
  102. ErrorResult& aRv) override;
  103. virtual int64_t
  104. GetFileId() override
  105. {
  106. return mBlobImpl->GetFileId();
  107. }
  108. virtual nsresult
  109. GetSendInfo(nsIInputStream** aBody,
  110. uint64_t* aContentLength,
  111. nsACString& aContentType,
  112. nsACString& aCharset) override
  113. {
  114. return mBlobImpl->GetSendInfo(aBody,
  115. aContentLength,
  116. aContentType,
  117. aCharset);
  118. }
  119. virtual nsresult
  120. GetMutable(bool* aMutable) const override
  121. {
  122. return mBlobImpl->GetMutable(aMutable);
  123. }
  124. virtual nsresult
  125. SetMutable(bool aMutable) override
  126. {
  127. return mBlobImpl->SetMutable(aMutable);
  128. }
  129. virtual void
  130. SetLazyData(const nsAString& aName,
  131. const nsAString& aContentType,
  132. uint64_t aLength,
  133. int64_t aLastModifiedDate) override
  134. {
  135. MOZ_CRASH("This should never be called!");
  136. }
  137. virtual bool
  138. IsMemoryFile() const override
  139. {
  140. return mBlobImpl->IsMemoryFile();
  141. }
  142. virtual bool
  143. IsSizeUnknown() const override
  144. {
  145. return mBlobImpl->IsSizeUnknown();
  146. }
  147. virtual bool
  148. IsDateUnknown() const override
  149. {
  150. return mBlobImpl->IsDateUnknown();
  151. }
  152. virtual bool
  153. IsFile() const override
  154. {
  155. return mBlobImpl->IsFile();
  156. }
  157. virtual bool
  158. MayBeClonedToOtherThreads() const override
  159. {
  160. return false;
  161. }
  162. // PIBlobImplSnapshot
  163. virtual BlobImpl*
  164. GetBlobImpl() const override;
  165. };
  166. } // namespace indexedDB
  167. } // namespace dom
  168. } // namespace mozilla
  169. #endif // mozilla_dom_indexeddb_filesnapshot_h__