mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-28 19:37:32 +09:00
Issue #1288 - Part 1b: Rewrite nsHTTPCompressConv.
This also includes formatting changes.
This commit is contained in:
parent
729ee0f18a
commit
0d109e3c9f
2 changed files with 466 additions and 405 deletions
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
// brotli headers
|
||||
#include "state.h"
|
||||
#include "decode.h"
|
||||
#include "brotli/decode.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace net {
|
||||
|
|
@ -33,7 +33,8 @@ NS_IMPL_ISUPPORTS(nsHTTPCompressConv,
|
|||
nsIStreamConverter,
|
||||
nsIStreamListener,
|
||||
nsIRequestObserver,
|
||||
nsICompressConvStats)
|
||||
nsICompressConvStats,
|
||||
nsIThreadRetargetableStreamListener)
|
||||
|
||||
// nsFTPDirListingConv methods
|
||||
nsHTTPCompressConv::nsHTTPCompressConv()
|
||||
|
|
@ -45,11 +46,14 @@ nsHTTPCompressConv::nsHTTPCompressConv()
|
|||
, mCheckHeaderDone(false)
|
||||
, mStreamEnded(false)
|
||||
, mStreamInitialized(false)
|
||||
, mDummyStreamInitialised(false)
|
||||
, d_stream{}
|
||||
, mLen(0)
|
||||
, hMode(0)
|
||||
, mSkipCount(0)
|
||||
, mFlags(0)
|
||||
, mDecodedDataLength(0)
|
||||
, mMutex("nsHTTPCompressConv")
|
||||
{
|
||||
LOG(("nsHttpCompresssConv %p ctor\n", this));
|
||||
if (NS_IsMainThread()) {
|
||||
|
|
@ -60,8 +64,7 @@ nsHTTPCompressConv::nsHTTPCompressConv()
|
|||
}
|
||||
}
|
||||
|
||||
nsHTTPCompressConv::~nsHTTPCompressConv()
|
||||
{
|
||||
nsHTTPCompressConv::~nsHTTPCompressConv() {
|
||||
LOG(("nsHttpCompresssConv %p dtor\n", this));
|
||||
if (mInpBuffer) {
|
||||
free(mInpBuffer);
|
||||
|
|
@ -79,18 +82,15 @@ nsHTTPCompressConv::~nsHTTPCompressConv()
|
|||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::GetDecodedDataLength(uint64_t *aDecodedDataLength)
|
||||
{
|
||||
nsHTTPCompressConv::GetDecodedDataLength(uint64_t* aDecodedDataLength) {
|
||||
*aDecodedDataLength = mDecodedDataLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::AsyncConvertData(const char *aFromType,
|
||||
const char *aToType,
|
||||
nsHTTPCompressConv::AsyncConvertData(const char* aFromType, const char* aToType,
|
||||
nsIStreamListener* aListener,
|
||||
nsISupports *aCtxt)
|
||||
{
|
||||
nsISupports* aCtxt) {
|
||||
if (!PL_strncasecmp(aFromType, HTTP_COMPRESS_TYPE, sizeof(HTTP_COMPRESS_TYPE) - 1) ||
|
||||
!PL_strncasecmp(aFromType, HTTP_X_COMPRESS_TYPE, sizeof(HTTP_X_COMPRESS_TYPE) - 1)) {
|
||||
mMode = HTTP_COMPRESS_COMPRESS;
|
||||
|
|
@ -102,29 +102,33 @@ nsHTTPCompressConv::AsyncConvertData(const char *aFromType,
|
|||
} else if (!PL_strncasecmp(aFromType, HTTP_BROTLI_TYPE, sizeof(HTTP_BROTLI_TYPE) - 1)) {
|
||||
mMode = HTTP_COMPRESS_BROTLI;
|
||||
}
|
||||
LOG(("nsHttpCompresssConv %p AsyncConvertData %s %s mode %d\n",
|
||||
this, aFromType, aToType, mMode));
|
||||
LOG(("nsHttpCompresssConv %p AsyncConvertData %s %s mode %d\n", this,
|
||||
aFromType, aToType, (CompressMode)mMode));
|
||||
|
||||
MutexAutoLock lock(mMutex);
|
||||
// hook ourself up with the receiving listener.
|
||||
mListener = aListener;
|
||||
|
||||
mAsyncConvContext = aCtxt;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::OnStartRequest(nsIRequest* request, nsISupports *aContext)
|
||||
{
|
||||
nsHTTPCompressConv::OnStartRequest(nsIRequest* request, nsISupports* aContext) {
|
||||
LOG(("nsHttpCompresssConv %p onstart\n", this));
|
||||
return mListener->OnStartRequest(request, aContext);
|
||||
nsCOMPtr<nsIStreamListener> listener;
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
listener = mListener;
|
||||
}
|
||||
return listener->OnStartRequest(request, aContext);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::OnStopRequest(nsIRequest* request, nsISupports* aContext,
|
||||
nsresult aStatus)
|
||||
{
|
||||
nsresult aStatus) {
|
||||
nsresult status = aStatus;
|
||||
LOG(("nsHttpCompresssConv %p onstop %x\n", this, aStatus));
|
||||
LOG(("nsHttpCompresssConv %p onstop %" PRIx32 "\n", this,
|
||||
static_cast<uint32_t>(aStatus)));
|
||||
|
||||
// Framing integrity is enforced for content-encoding: gzip, but not for
|
||||
// content-encoding: deflate. Note that gzip vs deflate is NOT determined
|
||||
|
|
@ -144,22 +148,31 @@ nsHTTPCompressConv::OnStopRequest(nsIRequest* request, nsISupports *aContext,
|
|||
if (fpChannel && !isPending) {
|
||||
fpChannel->ForcePending(true);
|
||||
}
|
||||
if (mBrotli && (mBrotli->mTotalOut == 0) && !BrotliStateIsStreamEnd(&mBrotli->mState)) {
|
||||
if (mBrotli && (mBrotli->mTotalOut == 0) && !mBrotli->mBrotliStateIsStreamEnd) {
|
||||
status = NS_ERROR_INVALID_CONTENT_ENCODING;
|
||||
}
|
||||
LOG(("nsHttpCompresssConv %p onstop brotlihandler rv %x\n", this, status));
|
||||
LOG(("nsHttpCompresssConv %p onstop brotlihandler rv %" PRIx32 "\n", this,
|
||||
static_cast<uint32_t>(status)));
|
||||
if (fpChannel && !isPending) {
|
||||
fpChannel->ForcePending(false);
|
||||
}
|
||||
}
|
||||
return mListener->OnStopRequest(request, aContext, status);
|
||||
|
||||
nsCOMPtr<nsIStreamListener> listener;
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
listener = mListener;
|
||||
}
|
||||
return listener->OnStopRequest(request, aContext, status);
|
||||
}
|
||||
|
||||
|
||||
/* static */ nsresult
|
||||
nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const char *dataIn,
|
||||
uint32_t, uint32_t aAvail, uint32_t *countRead)
|
||||
{
|
||||
/* static */
|
||||
nsresult nsHTTPCompressConv::BrotliHandler(nsIInputStream* stream,
|
||||
void* closure,
|
||||
const char* dataIn,
|
||||
uint32_t,
|
||||
uint32_t aAvail,
|
||||
uint32_t* countRead) {
|
||||
MOZ_ASSERT(stream);
|
||||
nsHTTPCompressConv* self = static_cast<nsHTTPCompressConv*>(closure);
|
||||
*countRead = 0;
|
||||
|
|
@ -168,7 +181,7 @@ nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const c
|
|||
uint8_t* outPtr;
|
||||
size_t outSize;
|
||||
size_t avail = aAvail;
|
||||
BrotliResult res;
|
||||
BrotliDecoderResult res;
|
||||
|
||||
if (!self->mBrotli) {
|
||||
*countRead = aAvail;
|
||||
|
|
@ -186,15 +199,21 @@ nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const c
|
|||
outPtr = outBuffer.get();
|
||||
|
||||
// brotli api is documented in brotli/dec/decode.h and brotli/dec/decode.c
|
||||
LOG(("nsHttpCompresssConv %p brotlihandler decompress %d\n", self, avail));
|
||||
res = ::BrotliDecompressStream(
|
||||
&avail, reinterpret_cast<const unsigned char **>(&dataIn),
|
||||
&outSize, &outPtr, &self->mBrotli->mTotalOut, &self->mBrotli->mState);
|
||||
LOG(("nsHttpCompresssConv %p brotlihandler decompress %zu\n", self, avail));
|
||||
size_t totalOut = self->mBrotli->mTotalOut;
|
||||
res = ::BrotliDecoderDecompressStream(
|
||||
&self->mBrotli->mState, &avail,
|
||||
reinterpret_cast<const unsigned char**>(&dataIn), &outSize, &outPtr,
|
||||
&totalOut);
|
||||
outSize = kOutSize - outSize;
|
||||
LOG(("nsHttpCompresssConv %p brotlihandler decompress rv=%x out=%d\n",
|
||||
self, res, outSize));
|
||||
self->mBrotli->mTotalOut = totalOut;
|
||||
self->mBrotli->mBrotliStateIsStreamEnd =
|
||||
BrotliDecoderIsFinished(&self->mBrotli->mState);
|
||||
LOG(("nsHttpCompresssConv %p brotlihandler decompress rv=%" PRIx32
|
||||
" out=%zu\n",
|
||||
self, static_cast<uint32_t>(res), outSize));
|
||||
|
||||
if (res == BROTLI_RESULT_ERROR) {
|
||||
if (res == BROTLI_DECODER_RESULT_ERROR) {
|
||||
LOG(("nsHttpCompressConv %p marking invalid encoding", self));
|
||||
self->mBrotli->mStatus = NS_ERROR_INVALID_CONTENT_ENCODING;
|
||||
return self->mBrotli->mStatus;
|
||||
|
|
@ -202,7 +221,7 @@ nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const c
|
|||
|
||||
// in 'the current implementation' brotli must consume everything before
|
||||
// asking for more input
|
||||
if (res == BROTLI_RESULT_NEEDS_MORE_INPUT) {
|
||||
if (res == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT) {
|
||||
MOZ_ASSERT(!avail);
|
||||
if (avail) {
|
||||
LOG(("nsHttpCompressConv %p did not consume all input", self));
|
||||
|
|
@ -216,20 +235,21 @@ nsHTTPCompressConv::BrotliHandler(nsIInputStream *stream, void *closure, const c
|
|||
self->mBrotli->mSourceOffset,
|
||||
reinterpret_cast<const char*>(outBuffer.get()),
|
||||
outSize);
|
||||
LOG(("nsHttpCompressConv %p BrotliHandler ODA rv=%x", self, rv));
|
||||
LOG(("nsHttpCompressConv %p BrotliHandler ODA rv=%" PRIx32, self,
|
||||
static_cast<uint32_t>(rv)));
|
||||
if (NS_FAILED(rv)) {
|
||||
self->mBrotli->mStatus = rv;
|
||||
return self->mBrotli->mStatus;
|
||||
}
|
||||
}
|
||||
|
||||
if (res == BROTLI_RESULT_SUCCESS ||
|
||||
res == BROTLI_RESULT_NEEDS_MORE_INPUT) {
|
||||
if (res == BROTLI_DECODER_RESULT_SUCCESS ||
|
||||
res == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT) {
|
||||
*countRead = aAvail;
|
||||
return NS_OK;
|
||||
}
|
||||
MOZ_ASSERT (res == BROTLI_RESULT_NEEDS_MORE_OUTPUT);
|
||||
} while (res == BROTLI_RESULT_NEEDS_MORE_OUTPUT);
|
||||
MOZ_ASSERT(res == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT);
|
||||
} while (res == BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT);
|
||||
|
||||
self->mBrotli->mStatus = NS_ERROR_UNEXPECTED;
|
||||
return self->mBrotli->mStatus;
|
||||
|
|
@ -240,8 +260,7 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
|||
nsISupports* aContext,
|
||||
nsIInputStream* iStr,
|
||||
uint64_t aSourceOffset,
|
||||
uint32_t aCount)
|
||||
{
|
||||
uint32_t aCount) {
|
||||
nsresult rv = NS_ERROR_INVALID_CONTENT_ENCODING;
|
||||
uint32_t streamLen = aCount;
|
||||
LOG(("nsHttpCompressConv %p OnDataAvailable %d", this, aCount));
|
||||
|
|
@ -276,10 +295,16 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
|||
case HTTP_COMPRESS_DEFLATE:
|
||||
|
||||
if (mInpBuffer != nullptr && streamLen > mInpBufferLen) {
|
||||
mInpBuffer = (unsigned char *) realloc(mInpBuffer, mInpBufferLen = streamLen);
|
||||
unsigned char* originalInpBuffer = mInpBuffer;
|
||||
if (!(mInpBuffer = (unsigned char*)realloc(originalInpBuffer, mInpBufferLen = streamLen))) {
|
||||
free(originalInpBuffer);
|
||||
}
|
||||
|
||||
if (mOutBufferLen < streamLen * 2) {
|
||||
mOutBuffer = (unsigned char *) realloc(mOutBuffer, mOutBufferLen = streamLen * 3);
|
||||
unsigned char* originalOutBuffer = mOutBuffer;
|
||||
if (!(mOutBuffer = (unsigned char*)realloc(mOutBuffer, mOutBufferLen = streamLen * 3))) {
|
||||
free(originalOutBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
if (mInpBuffer == nullptr || mOutBuffer == nullptr) {
|
||||
|
|
@ -350,10 +375,9 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
|||
}
|
||||
break;
|
||||
} else if (code == Z_DATA_ERROR) {
|
||||
// some servers (notably Apache with mod_deflate) don't generate zlib headers
|
||||
// insert a dummy header and try again
|
||||
static char dummy_head[2] =
|
||||
{
|
||||
// some servers (notably Apache with mod_deflate) don't generate
|
||||
// zlib headers insert a dummy header and try again
|
||||
static char dummy_head[2] = {
|
||||
0x8 + 0x7 * 0x10,
|
||||
(((0x8 + 0x7 * 0x10) * 0x100 + 30) / 31 * 31) & 0xFF,
|
||||
};
|
||||
|
|
@ -366,9 +390,11 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// stop an endless loop caused by non-deflate data being labelled as deflate
|
||||
// stop an endless loop caused by non-deflate data being labelled as
|
||||
// deflate
|
||||
if (mDummyStreamInitialised) {
|
||||
NS_WARNING("endless loop detected"
|
||||
NS_WARNING(
|
||||
"endless loop detected"
|
||||
" - invalid deflate");
|
||||
return NS_ERROR_INVALID_CONTENT_ENCODING;
|
||||
}
|
||||
|
|
@ -434,14 +460,13 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
|||
} /* gzip */
|
||||
break;
|
||||
|
||||
case HTTP_COMPRESS_BROTLI:
|
||||
{
|
||||
case HTTP_COMPRESS_BROTLI: {
|
||||
if (!mBrotli) {
|
||||
mBrotli = new BrotliWrapper();
|
||||
}
|
||||
|
||||
mBrotli->mRequest = request;
|
||||
mBrotli->mContext = aContext;
|
||||
mBrotli->mContext = nullptr;
|
||||
mBrotli->mSourceOffset = aSourceOffset;
|
||||
|
||||
uint32_t countRead;
|
||||
|
|
@ -452,11 +477,15 @@ nsHTTPCompressConv::OnDataAvailable(nsIRequest* request,
|
|||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
default:
|
||||
rv = mListener->OnDataAvailable(request, aContext, iStr, aSourceOffset, aCount);
|
||||
nsCOMPtr<nsIStreamListener> listener;
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
listener = mListener;
|
||||
}
|
||||
rv = listener->OnDataAvailable(request, aContext, iStr, aSourceOffset, aCount);
|
||||
if (NS_FAILED(rv)) {
|
||||
return rv;
|
||||
}
|
||||
|
|
@ -472,16 +501,15 @@ nsHTTPCompressConv::Convert(nsIInputStream *aFromStream,
|
|||
const char* aFromType,
|
||||
const char* aToType,
|
||||
nsISupports* aCtxt,
|
||||
nsIInputStream **_retval)
|
||||
{
|
||||
nsIInputStream** _retval) {
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTTPCompressConv::do_OnDataAvailable(nsIRequest* request,
|
||||
nsISupports *context, uint64_t offset,
|
||||
const char *buffer, uint32_t count)
|
||||
{
|
||||
nsresult nsHTTPCompressConv::do_OnDataAvailable(nsIRequest* request,
|
||||
nsISupports* context,
|
||||
uint64_t offset,
|
||||
const char* buffer,
|
||||
uint32_t count) {
|
||||
if (!mStream) {
|
||||
mStream = do_CreateInstance(NS_STRINGINPUTSTREAM_CONTRACTID);
|
||||
NS_ENSURE_STATE(mStream);
|
||||
|
|
@ -489,8 +517,12 @@ nsHTTPCompressConv::do_OnDataAvailable(nsIRequest* request,
|
|||
|
||||
mStream->ShareData(buffer, count);
|
||||
|
||||
nsresult rv = mListener->OnDataAvailable(request, context, mStream,
|
||||
offset, count);
|
||||
nsCOMPtr<nsIStreamListener> listener;
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
listener = mListener;
|
||||
}
|
||||
nsresult rv = listener->OnDataAvailable(request, context, mStream, offset, count);
|
||||
|
||||
// Make sure the stream no longer references |buffer| in case our listener
|
||||
// is crazy enough to try to read from |mStream| after ODA.
|
||||
|
|
@ -509,10 +541,18 @@ nsHTTPCompressConv::do_OnDataAvailable(nsIRequest* request,
|
|||
|
||||
static unsigned gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
|
||||
|
||||
uint32_t
|
||||
nsHTTPCompressConv::check_header(nsIInputStream *iStr, uint32_t streamLen, nsresult *rs)
|
||||
{
|
||||
enum { GZIP_INIT = 0, GZIP_OS, GZIP_EXTRA0, GZIP_EXTRA1, GZIP_EXTRA2, GZIP_ORIG, GZIP_COMMENT, GZIP_CRC };
|
||||
uint32_t nsHTTPCompressConv::check_header(nsIInputStream* iStr,
|
||||
uint32_t streamLen, nsresult* rs) {
|
||||
enum {
|
||||
GZIP_INIT = 0,
|
||||
GZIP_OS,
|
||||
GZIP_EXTRA0,
|
||||
GZIP_EXTRA1,
|
||||
GZIP_EXTRA2,
|
||||
GZIP_ORIG,
|
||||
GZIP_COMMENT,
|
||||
GZIP_CRC
|
||||
};
|
||||
char c;
|
||||
|
||||
*rs = NS_OK;
|
||||
|
|
@ -598,8 +638,7 @@ nsHTTPCompressConv::check_header(nsIInputStream *iStr, uint32_t streamLen, nsres
|
|||
if (mFlags & ORIG_NAME) {
|
||||
iStr->Read(&c, 1, &unused);
|
||||
streamLen--;
|
||||
if (c == 0)
|
||||
hMode = GZIP_COMMENT;
|
||||
if (c == 0) hMode = GZIP_COMMENT;
|
||||
} else {
|
||||
hMode = GZIP_COMMENT;
|
||||
}
|
||||
|
|
@ -638,13 +677,27 @@ nsHTTPCompressConv::check_header(nsIInputStream *iStr, uint32_t streamLen, nsres
|
|||
return streamLen;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPCompressConv::CheckListenerChain() {
|
||||
nsCOMPtr<nsIThreadRetargetableStreamListener> listener;
|
||||
{
|
||||
MutexAutoLock lock(mMutex);
|
||||
listener = do_QueryInterface(mListener);
|
||||
}
|
||||
|
||||
if (!listener) {
|
||||
return NS_ERROR_NO_INTERFACE;
|
||||
}
|
||||
|
||||
return listener->CheckListenerChain();
|
||||
}
|
||||
|
||||
} // namespace net
|
||||
} // namespace mozilla
|
||||
|
||||
nsresult
|
||||
NS_NewHTTPCompressConv(mozilla::net::nsHTTPCompressConv **aHTTPCompressConv)
|
||||
{
|
||||
NS_PRECONDITION(aHTTPCompressConv != nullptr, "null ptr");
|
||||
nsresult NS_NewHTTPCompressConv(
|
||||
mozilla::net::nsHTTPCompressConv** aHTTPCompressConv) {
|
||||
MOZ_ASSERT(aHTTPCompressConv != nullptr, "null ptr");
|
||||
if (!aHTTPCompressConv) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,8 +9,11 @@
|
|||
|
||||
#include "nsIStreamConverter.h"
|
||||
#include "nsICompressConvStats.h"
|
||||
#include "nsIThreadRetargetableStreamListener.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsAutoPtr.h"
|
||||
#include "mozilla/Atomics.h"
|
||||
#include "mozilla/Mutex.h"
|
||||
|
||||
#include "zlib.h"
|
||||
|
||||
|
|
@ -30,7 +33,6 @@ class nsIStringInputStream;
|
|||
{0xab, 0xf4, 0x07, 0x98, 0x61, 0x51, 0x02, 0x2d} \
|
||||
}
|
||||
|
||||
|
||||
#define HTTP_DEFLATE_TYPE "deflate"
|
||||
#define HTTP_GZIP_TYPE "gzip"
|
||||
#define HTTP_X_GZIP_TYPE "x-gzip"
|
||||
|
|
@ -51,39 +53,39 @@ typedef enum {
|
|||
HTTP_COMPRESS_IDENTITY
|
||||
} CompressMode;
|
||||
|
||||
class BrotliWrapper
|
||||
{
|
||||
class BrotliWrapper {
|
||||
public:
|
||||
BrotliWrapper()
|
||||
: mTotalOut(0)
|
||||
, mStatus(NS_OK)
|
||||
{
|
||||
BrotliStateInit(&mState);
|
||||
}
|
||||
~BrotliWrapper()
|
||||
{
|
||||
BrotliStateCleanup(&mState);
|
||||
: mTotalOut(0),
|
||||
mStatus(NS_OK),
|
||||
mBrotliStateIsStreamEnd(false),
|
||||
mRequest(nullptr),
|
||||
mContext(nullptr),
|
||||
mSourceOffset(0) {
|
||||
BrotliDecoderStateInit(&mState, 0, 0, 0);
|
||||
}
|
||||
~BrotliWrapper() { BrotliDecoderStateCleanup(&mState); }
|
||||
|
||||
BrotliState mState;
|
||||
size_t mTotalOut;
|
||||
BrotliDecoderState mState;
|
||||
Atomic<size_t, Relaxed> mTotalOut;
|
||||
nsresult mStatus;
|
||||
Atomic<bool, Relaxed> mBrotliStateIsStreamEnd;
|
||||
|
||||
nsIRequest* mRequest;
|
||||
nsISupports* mContext;
|
||||
uint64_t mSourceOffset;
|
||||
};
|
||||
|
||||
class nsHTTPCompressConv
|
||||
: public nsIStreamConverter
|
||||
, public nsICompressConvStats
|
||||
{
|
||||
class nsHTTPCompressConv : public nsIStreamConverter,
|
||||
public nsICompressConvStats,
|
||||
public nsIThreadRetargetableStreamListener {
|
||||
public:
|
||||
// nsISupports methods
|
||||
NS_DECL_THREADSAFE_ISUPPORTS
|
||||
NS_DECL_NSIREQUESTOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSICOMPRESSCONVSTATS
|
||||
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
||||
|
||||
// nsIStreamConverter methods
|
||||
NS_DECL_NSISTREAMCONVERTER
|
||||
|
|
@ -94,7 +96,7 @@ private:
|
|||
virtual ~nsHTTPCompressConv();
|
||||
|
||||
nsCOMPtr<nsIStreamListener> mListener; // this guy gets the converted data via his OnDataAvailable ()
|
||||
CompressMode mMode;
|
||||
Atomic<CompressMode, Relaxed> mMode;
|
||||
|
||||
unsigned char* mOutBuffer;
|
||||
unsigned char* mInpBuffer;
|
||||
|
|
@ -104,19 +106,23 @@ private:
|
|||
|
||||
nsAutoPtr<BrotliWrapper> mBrotli;
|
||||
|
||||
nsCOMPtr<nsISupports> mAsyncConvContext;
|
||||
nsCOMPtr<nsIStringInputStream> mStream;
|
||||
|
||||
static nsresult
|
||||
BrotliHandler(nsIInputStream *stream, void *closure, const char *dataIn,
|
||||
uint32_t, uint32_t avail, uint32_t *countRead);
|
||||
static nsresult BrotliHandler(nsIInputStream* stream,
|
||||
void* closure,
|
||||
const char* dataIn,
|
||||
uint32_t,
|
||||
uint32_t avail,
|
||||
uint32_t* countRead);
|
||||
|
||||
nsresult do_OnDataAvailable (nsIRequest *request, nsISupports *aContext,
|
||||
uint64_t aSourceOffset, const char *buffer,
|
||||
nsresult do_OnDataAvailable(nsIRequest* request,
|
||||
nsISupports* aContext,
|
||||
uint64_t aSourceOffset,
|
||||
const char* buffer,
|
||||
uint32_t aCount);
|
||||
|
||||
bool mCheckHeaderDone;
|
||||
bool mStreamEnded;
|
||||
Atomic<bool> mStreamEnded;
|
||||
bool mStreamInitialized;
|
||||
bool mDummyStreamInitialised;
|
||||
bool mFailUncleanStops;
|
||||
|
|
@ -126,7 +132,9 @@ private:
|
|||
|
||||
uint32_t check_header(nsIInputStream* iStr, uint32_t streamLen, nsresult* rv);
|
||||
|
||||
uint32_t mDecodedDataLength;
|
||||
Atomic<uint32_t, Relaxed> mDecodedDataLength;
|
||||
|
||||
mutable mozilla::Mutex mMutex;
|
||||
};
|
||||
|
||||
} // namespace net
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue