зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1717163 - Remove stream converter service usage for decompressing HTTP responses. r=dragana,necko-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D118421
This commit is contained in:
Родитель
c14de7eabc
Коммит
f0372c521b
|
@ -46,6 +46,7 @@
|
|||
#include "nsEscape.h"
|
||||
#include "nsGlobalWindowOuter.h"
|
||||
#include "nsHttpChannel.h"
|
||||
#include "nsHTTPCompressConv.h"
|
||||
#include "nsHttpHandler.h"
|
||||
#include "nsICacheInfoChannel.h"
|
||||
#include "nsICachingChannel.h"
|
||||
|
@ -1242,21 +1243,11 @@ HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener,
|
|||
}
|
||||
|
||||
if (gHttpHandler->IsAcceptableEncoding(val, mURI->SchemeIs("https"))) {
|
||||
nsCOMPtr<nsIStreamConverterService> serv;
|
||||
rv = gHttpHandler->GetStreamConverterService(getter_AddRefs(serv));
|
||||
|
||||
// we won't fail to load the page just because we couldn't load the
|
||||
// stream converter service.. carry on..
|
||||
if (NS_FAILED(rv)) {
|
||||
if (val) LOG(("Unknown content encoding '%s', ignoring\n", val));
|
||||
continue;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIStreamListener> converter;
|
||||
RefPtr<nsHTTPCompressConv> converter = new nsHTTPCompressConv();
|
||||
nsAutoCString from(val);
|
||||
ToLowerCase(from);
|
||||
rv = serv->AsyncConvertData(from.get(), "uncompressed", nextListener,
|
||||
aCtxt, getter_AddRefs(converter));
|
||||
rv = converter->AsyncConvertData(from.get(), "uncompressed", nextListener,
|
||||
aCtxt);
|
||||
if (NS_FAILED(rv)) {
|
||||
LOG(("Unexpected failure of AsyncConvertData %s\n", val));
|
||||
return rv;
|
||||
|
|
|
@ -134,6 +134,7 @@
|
|||
#include "mozilla/dom/SecFetch.h"
|
||||
#include "mozilla/net/TRRService.h"
|
||||
#include "mozilla/URLQueryStringStripper.h"
|
||||
#include "nsUnknownDecoder.h"
|
||||
#ifdef XP_WIN
|
||||
# include "HttpWinUtils.h"
|
||||
#endif
|
||||
|
@ -1503,18 +1504,8 @@ nsresult nsHttpChannel::CallOnStartRequest() {
|
|||
mResponseHead->SetContentType(nsLiteralCString(TEXT_PLAIN));
|
||||
} else {
|
||||
// Uh-oh. We had better find out what type we are!
|
||||
nsCOMPtr<nsIStreamConverterService> serv;
|
||||
rv = gHttpHandler->GetStreamConverterService(getter_AddRefs(serv));
|
||||
// If we failed, we just fall through to the "normal" case
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIStreamListener> converter;
|
||||
rv = serv->AsyncConvertData(UNKNOWN_CONTENT_TYPE, "*/*", mListener,
|
||||
nullptr, getter_AddRefs(converter));
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
mListener = converter;
|
||||
unknownDecoderStarted = true;
|
||||
}
|
||||
}
|
||||
mListener = new nsUnknownDecoder(mListener);
|
||||
unknownDecoderStarted = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include "nsHttp.h"
|
||||
#include "nsHttpHandler.h"
|
||||
#include "nsHttpChannel.h"
|
||||
#include "nsHTTPCompressConv.h"
|
||||
#include "nsHttpAuthCache.h"
|
||||
#include "nsStandardURL.h"
|
||||
#include "LoadContextInfo.h"
|
||||
|
@ -617,20 +618,6 @@ bool nsHttpHandler::IsAcceptableEncoding(const char* enc, bool isSecure) {
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsHttpHandler::GetStreamConverterService(
|
||||
nsIStreamConverterService** result) {
|
||||
if (!mStreamConvSvc) {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIStreamConverterService> service =
|
||||
do_GetService(NS_STREAMCONVERTERSERVICE_CONTRACTID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mStreamConvSvc = new nsMainThreadPtrHolder<nsIStreamConverterService>(
|
||||
"nsHttpHandler::mStreamConvSvc", service);
|
||||
}
|
||||
*result = do_AddRef(mStreamConvSvc.get()).take();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsISiteSecurityService* nsHttpHandler::GetSSService() {
|
||||
if (!mSSService) {
|
||||
nsCOMPtr<nsISiteSecurityService> service =
|
||||
|
|
|
@ -351,7 +351,6 @@ class nsHttpHandler final : public nsIHttpProtocolHandler,
|
|||
// The HTTP handler caches pointers to specific XPCOM services, and
|
||||
// provides the following helper routines for accessing those services:
|
||||
//
|
||||
[[nodiscard]] nsresult GetStreamConverterService(nsIStreamConverterService**);
|
||||
[[nodiscard]] nsresult GetIOService(nsIIOService** result);
|
||||
nsICookieService* GetCookieService(); // not addrefed
|
||||
nsISiteSecurityService* GetSSService();
|
||||
|
@ -550,7 +549,6 @@ class nsHttpHandler final : public nsIHttpProtocolHandler,
|
|||
private:
|
||||
// cached services
|
||||
nsMainThreadPtrHandle<nsIIOService> mIOService;
|
||||
nsMainThreadPtrHandle<nsIStreamConverterService> mStreamConvSvc;
|
||||
nsMainThreadPtrHandle<nsICookieService> mCookieService;
|
||||
nsMainThreadPtrHandle<nsISiteSecurityService> mSSService;
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
XPIDL_SOURCES += ["nsICompressConvStats.idl"]
|
||||
|
||||
EXPORTS += [
|
||||
"nsHTTPCompressConv.h",
|
||||
"nsUnknownDecoder.h",
|
||||
]
|
||||
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
#include "mozilla/UniquePtrExtensions.h"
|
||||
|
||||
// brotli headers
|
||||
#undef assert
|
||||
#include "assert.h"
|
||||
#include "state.h"
|
||||
#include "brotli/decode.h"
|
||||
|
||||
|
@ -31,6 +33,23 @@ extern LazyLogModule gHttpLog;
|
|||
#define LOG(args) \
|
||||
MOZ_LOG(mozilla::net::gHttpLog, mozilla::LogLevel::Debug, args)
|
||||
|
||||
class BrotliWrapper {
|
||||
public:
|
||||
BrotliWrapper() {
|
||||
BrotliDecoderStateInit(&mState, nullptr, nullptr, nullptr);
|
||||
}
|
||||
~BrotliWrapper() { BrotliDecoderStateCleanup(&mState); }
|
||||
|
||||
BrotliDecoderState mState{};
|
||||
Atomic<size_t, Relaxed> mTotalOut{0};
|
||||
nsresult mStatus = NS_OK;
|
||||
Atomic<bool, Relaxed> mBrotliStateIsStreamEnd{false};
|
||||
|
||||
nsIRequest* mRequest{nullptr};
|
||||
nsISupports* mContext{nullptr};
|
||||
uint64_t mSourceOffset{0};
|
||||
};
|
||||
|
||||
// nsISupports implementation
|
||||
NS_IMPL_ISUPPORTS(nsHTTPCompressConv, nsIStreamConverter, nsIStreamListener,
|
||||
nsIRequestObserver, nsICompressConvStats,
|
||||
|
|
|
@ -16,11 +16,6 @@
|
|||
|
||||
# include "zlib.h"
|
||||
|
||||
// brotli includes
|
||||
# undef assert
|
||||
# include "assert.h"
|
||||
# include "state.h"
|
||||
|
||||
class nsIStringInputStream;
|
||||
|
||||
# define NS_HTTPCOMPRESSCONVERTER_CID \
|
||||
|
@ -43,22 +38,7 @@ class nsIStringInputStream;
|
|||
namespace mozilla {
|
||||
namespace net {
|
||||
|
||||
class BrotliWrapper {
|
||||
public:
|
||||
BrotliWrapper() {
|
||||
BrotliDecoderStateInit(&mState, nullptr, nullptr, nullptr);
|
||||
}
|
||||
~BrotliWrapper() { BrotliDecoderStateCleanup(&mState); }
|
||||
|
||||
BrotliDecoderState mState{};
|
||||
Atomic<size_t, Relaxed> mTotalOut{0};
|
||||
nsresult mStatus = NS_OK;
|
||||
Atomic<bool, Relaxed> mBrotliStateIsStreamEnd{false};
|
||||
|
||||
nsIRequest* mRequest{nullptr};
|
||||
nsISupports* mContext{nullptr};
|
||||
uint64_t mSourceOffset{0};
|
||||
};
|
||||
class BrotliWrapper;
|
||||
|
||||
class nsHTTPCompressConv : public nsIStreamConverter,
|
||||
public nsICompressConvStats,
|
||||
|
|
|
@ -75,8 +75,9 @@ nsUnknownDecoder::ConvertedStreamListener::OnStopRequest(nsIRequest* request,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsUnknownDecoder::nsUnknownDecoder()
|
||||
: mBuffer(nullptr),
|
||||
nsUnknownDecoder::nsUnknownDecoder(nsIStreamListener* aListener)
|
||||
: mNextListener(aListener),
|
||||
mBuffer(nullptr),
|
||||
mBufferLen(0),
|
||||
mRequireHTMLsuffix(false),
|
||||
mMutex("nsUnknownDecoder"),
|
||||
|
|
|
@ -44,7 +44,7 @@ class nsUnknownDecoder : public nsIStreamConverter,
|
|||
// nsIThreadRetargetableStreamListener methods
|
||||
NS_DECL_NSITHREADRETARGETABLESTREAMLISTENER
|
||||
|
||||
nsUnknownDecoder();
|
||||
explicit nsUnknownDecoder(nsIStreamListener* aListener = nullptr);
|
||||
|
||||
protected:
|
||||
virtual ~nsUnknownDecoder();
|
||||
|
|
Загрузка…
Ссылка в новой задаче