summaryrefslogtreecommitdiff
path: root/dom/indexedDB/FileSnapshot.h
blob: 6b577fcc36c76ff922ef804e31071ebc65899cdc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_dom_indexeddb_filesnapshot_h__
#define mozilla_dom_indexeddb_filesnapshot_h__

#include "mozilla/Attributes.h"
#include "mozilla/dom/File.h"
#include "nsISupports.h"
#include "nsWeakPtr.h"

#define FILEIMPLSNAPSHOT_IID \
  {0x0dfc11b1, 0x75d3, 0x473b, {0x8c, 0x67, 0xb7, 0x23, 0xf4, 0x67, 0xd6, 0x73}}

class PIBlobImplSnapshot : public nsISupports
{
public:
  NS_DECLARE_STATIC_IID_ACCESSOR(FILEIMPLSNAPSHOT_IID)

  virtual mozilla::dom::BlobImpl*
  GetBlobImpl() const = 0;
};

NS_DEFINE_STATIC_IID_ACCESSOR(PIBlobImplSnapshot, FILEIMPLSNAPSHOT_IID)

namespace mozilla {
namespace dom {

class IDBFileHandle;

namespace indexedDB {

class BlobImplSnapshot final
  : public BlobImpl
  , public PIBlobImplSnapshot
{
  RefPtr<BlobImpl> mBlobImpl;
  nsWeakPtr mFileHandle;

public:
  BlobImplSnapshot(BlobImpl* aImpl,
                   IDBFileHandle* aFileHandle);

  NS_DECL_ISUPPORTS_INHERITED

private:
  BlobImplSnapshot(BlobImpl* aImpl,
                   nsIWeakReference* aFileHandle);

  ~BlobImplSnapshot();

  // BlobImpl
  virtual void
  GetName(nsAString& aName) const override
  {
    mBlobImpl->GetName(aName);
  }

  virtual void
  GetDOMPath(nsAString& aPath) const override
  {
    mBlobImpl->GetDOMPath(aPath);
  }

  virtual void
  SetDOMPath(const nsAString& aPath) override
  {
    mBlobImpl->SetDOMPath(aPath);
  }

  virtual int64_t
  GetLastModified(ErrorResult& aRv) override
  {
    return mBlobImpl->GetLastModified(aRv);
  }

  virtual void
  SetLastModified(int64_t aLastModified) override
  {
    mBlobImpl->SetLastModified(aLastModified);
  }

  virtual void
  GetMozFullPath(nsAString& aName, ErrorResult& aRv) const override
  {
    mBlobImpl->GetMozFullPath(aName, aRv);
  }

  virtual void
  GetMozFullPathInternal(nsAString& aFileName, ErrorResult& aRv) const override
  {
    mBlobImpl->GetMozFullPathInternal(aFileName, aRv);
  }

  virtual uint64_t
  GetSize(ErrorResult& aRv) override
  {
    return mBlobImpl->GetSize(aRv);
  }

  virtual void
  GetType(nsAString& aType) override
  {
    mBlobImpl->GetType(aType);
  }

  virtual uint64_t
  GetSerialNumber() const override
  {
    return mBlobImpl->GetSerialNumber();
  }

  virtual already_AddRefed<BlobImpl>
  CreateSlice(uint64_t aStart,
              uint64_t aLength,
              const nsAString& aContentType,
              ErrorResult& aRv) override;

  virtual const nsTArray<RefPtr<BlobImpl>>*
  GetSubBlobImpls() const override
  {
    return mBlobImpl->GetSubBlobImpls();
  }

  virtual void
  GetInternalStream(nsIInputStream** aStream,
                    ErrorResult& aRv) override;

  virtual int64_t
  GetFileId() override
  {
    return mBlobImpl->GetFileId();
  }

  virtual nsresult
  GetSendInfo(nsIInputStream** aBody,
              uint64_t* aContentLength,
              nsACString& aContentType,
              nsACString& aCharset) override
  {
    return mBlobImpl->GetSendInfo(aBody,
                                  aContentLength,
                                  aContentType,
                                  aCharset);
  }

  virtual nsresult
  GetMutable(bool* aMutable) const override
  {
    return mBlobImpl->GetMutable(aMutable);
  }

  virtual nsresult
  SetMutable(bool aMutable) override
  {
    return mBlobImpl->SetMutable(aMutable);
  }

  virtual void
  SetLazyData(const nsAString& aName,
              const nsAString& aContentType,
              uint64_t aLength,
              int64_t aLastModifiedDate) override
  {
    MOZ_CRASH("This should never be called!");
  }

  virtual bool
  IsMemoryFile() const override
  {
    return mBlobImpl->IsMemoryFile();
  }

  virtual bool
  IsSizeUnknown() const override
  {
    return mBlobImpl->IsSizeUnknown();
  }

  virtual bool
  IsDateUnknown() const override
  {
    return mBlobImpl->IsDateUnknown();
  }

  virtual bool
  IsFile() const override
  {
    return mBlobImpl->IsFile();
  }

  virtual bool
  MayBeClonedToOtherThreads() const override
  {
    return false;
  }

  // PIBlobImplSnapshot
  virtual BlobImpl*
  GetBlobImpl() const override;
};

} // namespace indexedDB
} // namespace dom
} // namespace mozilla

#endif // mozilla_dom_indexeddb_filesnapshot_h__