2017-09-08 17:06:26 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* 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 PartiallySeekableInputStream_h
|
|
|
|
#define PartiallySeekableInputStream_h
|
|
|
|
|
|
|
|
#include "mozilla/Attributes.h"
|
2018-04-10 18:33:09 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2017-09-08 17:06:26 +03:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIAsyncInputStream.h"
|
|
|
|
#include "nsICloneableInputStream.h"
|
2018-05-23 08:12:35 +03:00
|
|
|
#include "nsIInputStreamLength.h"
|
2017-09-08 17:06:26 +03:00
|
|
|
#include "nsIIPCSerializableInputStream.h"
|
|
|
|
#include "nsISeekableStream.h"
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
// A wrapper for making a stream seekable for the first |aBufferSize| bytes.
|
2017-10-13 11:07:32 +03:00
|
|
|
// Note that this object takes the ownership of the underlying stream.
|
2017-09-08 17:06:26 +03:00
|
|
|
|
|
|
|
class PartiallySeekableInputStream final : public nsISeekableStream
|
|
|
|
, public nsIAsyncInputStream
|
|
|
|
, public nsICloneableInputStream
|
|
|
|
, public nsIIPCSerializableInputStream
|
|
|
|
, public nsIInputStreamCallback
|
2018-05-23 08:12:35 +03:00
|
|
|
, public nsIInputStreamLength
|
|
|
|
, public nsIAsyncInputStreamLength
|
|
|
|
, public nsIInputStreamLengthCallback
|
2017-09-08 17:06:26 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
|
|
|
NS_DECL_NSIINPUTSTREAM
|
|
|
|
NS_DECL_NSISEEKABLESTREAM
|
|
|
|
NS_DECL_NSIASYNCINPUTSTREAM
|
|
|
|
NS_DECL_NSICLONEABLEINPUTSTREAM
|
|
|
|
NS_DECL_NSIIPCSERIALIZABLEINPUTSTREAM
|
|
|
|
NS_DECL_NSIINPUTSTREAMCALLBACK
|
2018-05-23 08:12:35 +03:00
|
|
|
NS_DECL_NSIINPUTSTREAMLENGTH
|
|
|
|
NS_DECL_NSIASYNCINPUTSTREAMLENGTH
|
|
|
|
NS_DECL_NSIINPUTSTREAMLENGTHCALLBACK
|
2017-09-08 17:06:26 +03:00
|
|
|
|
2017-10-13 11:07:32 +03:00
|
|
|
explicit PartiallySeekableInputStream(already_AddRefed<nsIInputStream> aInputStream,
|
2017-09-08 17:06:26 +03:00
|
|
|
uint64_t aBufferSize = 4096);
|
|
|
|
|
|
|
|
private:
|
2017-12-13 17:56:31 +03:00
|
|
|
PartiallySeekableInputStream(already_AddRefed<nsIInputStream> aClonedBaseStream,
|
|
|
|
PartiallySeekableInputStream* aClonedFrom);
|
|
|
|
|
|
|
|
~PartiallySeekableInputStream() = default;
|
|
|
|
|
|
|
|
void
|
|
|
|
Init();
|
2017-09-08 17:06:26 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIInputStream> mInputStream;
|
|
|
|
|
|
|
|
// Raw pointers because these are just QI of mInputStream.
|
|
|
|
nsICloneableInputStream* mWeakCloneableInputStream;
|
|
|
|
nsIIPCSerializableInputStream* mWeakIPCSerializableInputStream;
|
|
|
|
nsIAsyncInputStream* mWeakAsyncInputStream;
|
2018-05-23 08:12:35 +03:00
|
|
|
nsIInputStreamLength* mWeakInputStreamLength;
|
|
|
|
nsIAsyncInputStreamLength* mWeakAsyncInputStreamLength;
|
2017-09-08 17:06:26 +03:00
|
|
|
|
2018-04-10 18:33:09 +03:00
|
|
|
// Protected by mutex.
|
2017-09-08 17:06:26 +03:00
|
|
|
nsCOMPtr<nsIInputStreamCallback> mAsyncWaitCallback;
|
|
|
|
|
2018-05-23 08:12:35 +03:00
|
|
|
// Protected by mutex.
|
|
|
|
nsCOMPtr<nsIInputStreamLengthCallback> mAsyncInputStreamLengthCallback;
|
|
|
|
|
2017-09-08 17:06:26 +03:00
|
|
|
nsTArray<char> mCachedBuffer;
|
|
|
|
|
|
|
|
uint64_t mBufferSize;
|
|
|
|
uint64_t mPos;
|
|
|
|
bool mClosed;
|
2018-04-10 18:33:09 +03:00
|
|
|
|
|
|
|
Mutex mMutex;
|
2017-09-08 17:06:26 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // net namespace
|
|
|
|
} // mozilla namespace
|
|
|
|
|
|
|
|
#endif // PartiallySeekableInputStream_h
|