Backed out changeset 9e3a9fb7c903 (bug 1373708) for devtools failures at browser/base/content/test/static/browser_all_files_referenced.js and xpcshell failures at toolkit/mozapps/extensions/test/xpcshell/test_webextension_install.js on a CLOSED TREE

This commit is contained in:
Andreea Pavel 2018-03-13 15:46:12 +02:00
Родитель b9b5a1379d
Коммит 2c3aa80457
2 изменённых файлов: 26 добавлений и 282 удалений

Просмотреть файл

@ -26,7 +26,6 @@
#include "nsITabChild.h"
#include "private/pprio.h"
#include "nsInputStreamPump.h"
#include "nsThreadUtils.h"
using namespace mozilla;
using namespace mozilla::net;
@ -199,12 +198,9 @@ nsJARChannel::nsJARChannel()
, mLoadFlags(LOAD_NORMAL)
, mStatus(NS_OK)
, mIsPending(false)
, mEnableOMT(true)
, mPendingEvent()
, mIsUnsafe(true)
, mBlockRemoteFiles(false)
{
LOG(("nsJARChannel::nsJARChannel [this=%p]\n", this));
mBlockRemoteFiles = Preferences::GetBool("network.jar.block-remote-files", false);
// hold an owning reference to the jar handler
@ -213,7 +209,6 @@ nsJARChannel::nsJARChannel()
nsJARChannel::~nsJARChannel()
{
LOG(("nsJARChannel::~nsJARChannel [this=%p]\n", this));
NS_ReleaseOnMainThreadSystemGroup("nsJARChannel::mLoadInfo",
mLoadInfo.forget());
}
@ -231,14 +226,7 @@ NS_IMPL_ISUPPORTS_INHERITED(nsJARChannel,
nsresult
nsJARChannel::Init(nsIURI *uri)
{
LOG(("nsJARChannel::Init [this=%p]\n", this));
nsresult rv;
mWorker = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return rv;
}
mJarURI = do_QueryInterface(uri, &rv);
if (NS_FAILED(rv))
return rv;
@ -266,7 +254,6 @@ nsJARChannel::Init(nsIURI *uri)
nsresult
nsJARChannel::CreateJarInput(nsIZipReaderCache *jarCache, nsJARInputThunk **resultInput)
{
LOG(("nsJARChannel::CreateJarInput [this=%p]\n", this));
MOZ_ASSERT(resultInput);
MOZ_ASSERT(mJarFile || mTempMem);
@ -282,7 +269,7 @@ nsJARChannel::CreateJarInput(nsIZipReaderCache *jarCache, nsJARInputThunk **resu
nsCOMPtr<nsIZipReader> reader;
if (mPreCachedJarReader) {
reader = mPreCachedJarReader;
reader = mPreCachedJarReader;
} else if (jarCache) {
MOZ_ASSERT(mJarFile);
if (mInnerJarEntry.IsEmpty())
@ -319,9 +306,10 @@ nsJARChannel::CreateJarInput(nsIZipReaderCache *jarCache, nsJARInputThunk **resu
return rv;
RefPtr<nsJARInputThunk> input = new nsJARInputThunk(reader,
mJarURI,
mJarEntry,
jarCache != nullptr);
mJarURI,
mJarEntry,
jarCache != nullptr
);
rv = input->Init();
if (NS_FAILED(rv))
return rv;
@ -334,7 +322,7 @@ nsJARChannel::CreateJarInput(nsIZipReaderCache *jarCache, nsJARInputThunk **resu
}
nsresult
nsJARChannel::LookupFile()
nsJARChannel::LookupFile(bool aAllowAsync)
{
LOG(("nsJARChannel::LookupFile [this=%p %s]\n", this, mSpec.get()));
@ -389,236 +377,25 @@ nsJARChannel::LookupFile()
return rv;
}
nsresult
CreateLocalJarInput(nsIZipReaderCache* aJarCache,
nsIFile* aFile,
const nsACString& aInnerJarEntry,
nsIJARURI* aJarURI,
const nsACString& aJarEntry,
nsJARInputThunk** aResultInput)
{
LOG(("nsJARChannel::CreateLocalJarInput [aJarCache=%p, %s, %s]\n",
aJarCache,
PromiseFlatCString(aInnerJarEntry).get(),
PromiseFlatCString(aJarEntry).get()));
MOZ_ASSERT(!NS_IsMainThread());
MOZ_ASSERT(aJarCache);
MOZ_ASSERT(aResultInput);
nsresult rv;
nsCOMPtr<nsIZipReader> reader;
if (aInnerJarEntry.IsEmpty()) {
rv = aJarCache->GetZip(aFile, getter_AddRefs(reader));
} else {
rv = aJarCache->GetInnerZip(aFile,
aInnerJarEntry,
getter_AddRefs(reader));
}
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
RefPtr<nsJARInputThunk> input = new nsJARInputThunk(reader,
aJarURI,
aJarEntry,
aJarCache != nullptr);
rv = input->Init();
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
input.forget(aResultInput);
return NS_OK;
}
nsresult
nsJARChannel::OpenLocalFile()
{
LOG(("nsJARChannel::OpenLocalFile [this=%p]\n", this));
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mWorker);
MOZ_ASSERT(mIsPending);
MOZ_ASSERT(mJarFile);
// Local files are always considered safe.
mIsUnsafe = false;
nsresult rv;
// Set mLoadGroup and mOpened before AsyncOpen return, and set back if
// if failed when callback.
if (mLoadGroup) {
mLoadGroup->AddRequest(this, nullptr);
}
mOpened = true;
if (mPreCachedJarReader || !mEnableOMT) {
RefPtr<nsJARInputThunk> input;
rv = CreateJarInput(gJarHandler->JarCache(),
getter_AddRefs(input));
if (NS_WARN_IF(NS_FAILED(rv))) {
return OnOpenLocalFileComplete(rv, true);
}
return ContinueOpenLocalFile(input, true);
}
nsCOMPtr<nsIZipReaderCache> jarCache = gJarHandler->JarCache();
if (NS_WARN_IF(!jarCache)) {
return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIFile> clonedFile;
rv = mJarFile->Clone(getter_AddRefs(clonedFile));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
// clone mJarURI
nsCOMPtr<nsIURI> clonedURI;
rv = mJarURI->Clone(getter_AddRefs(clonedURI));
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsCOMPtr<nsIJARURI> clonedJarURI = do_QueryInterface(clonedURI, &rv);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
nsAutoCString jarEntry(mJarEntry);
nsAutoCString innerJarEntry(mInnerJarEntry);
RefPtr<nsJARChannel> self = this;
return mWorker->Dispatch(
NS_NewRunnableFunction("nsJARChannel::OpenLocalFile",
[self,
jarCache,
clonedFile,
clonedJarURI,
jarEntry,
innerJarEntry] () mutable {
RefPtr<nsJARInputThunk> input;
nsresult rv = CreateLocalJarInput(jarCache,
clonedFile,
innerJarEntry,
clonedJarURI,
jarEntry,
getter_AddRefs(input));
NS_ReleaseOnMainThreadSystemGroup("nsJARChannel::clonedJarURI",
clonedJarURI.forget());
nsCOMPtr<nsIRunnable> target;
if (NS_SUCCEEDED(rv)) {
target = NewRunnableMethod<RefPtr<nsJARInputThunk>, bool>(
"nsJARChannel::ContinueOpenLocalFile",
self,
&nsJARChannel::ContinueOpenLocalFile,
input,
false);
} else {
target = NewRunnableMethod<nsresult, bool>(
"nsJARChannel::OnOpenLocalFileComplete",
self,
&nsJARChannel::OnOpenLocalFileComplete,
rv,
false);
}
// nsJARChannel must be release on main thread, and sometimes
// this still hold nsJARChannel after dispatched.
self = nullptr;
NS_DispatchToMainThread(target.forget());
}));
}
nsresult
nsJARChannel::ContinueOpenLocalFile(nsJARInputThunk* aInput, bool aIsSyncCall)
{
LOG(("nsJARChannel::ContinueOpenLocalFile [this=%p %p]\n", this, aInput));
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mIsPending);
// Make GetContentLength meaningful
mContentLength = aInput->GetContentLength();
nsresult rv;
RefPtr<nsJARInputThunk> input = aInput;
// Create input stream pump and call AsyncRead as a block.
rv = NS_NewInputStreamPump(getter_AddRefs(mPump), input.forget());
RefPtr<nsJARInputThunk> input;
nsresult rv = CreateJarInput(gJarHandler->JarCache(),
getter_AddRefs(input));
if (NS_SUCCEEDED(rv)) {
rv = mPump->AsyncRead(this, nullptr);
// Create input stream pump and call AsyncRead as a block.
rv = NS_NewInputStreamPump(getter_AddRefs(mPump), input.forget());
if (NS_SUCCEEDED(rv))
rv = mPump->AsyncRead(this, nullptr);
}
if (NS_SUCCEEDED(rv)) {
rv = CheckPendingEvents();
}
return OnOpenLocalFileComplete(rv, aIsSyncCall);
}
nsresult
nsJARChannel::OnOpenLocalFileComplete(nsresult aResult, bool aIsSyncCall)
{
LOG(("nsJARChannel::OnOpenLocalFileComplete [this=%p %08x]\n",
this,
static_cast<uint32_t>(aResult)));
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mIsPending);
if (NS_FAILED(aResult)) {
if (!aIsSyncCall) {
NotifyError(aResult);
}
if (mLoadGroup) {
mLoadGroup->RemoveRequest(this, nullptr, aResult);
}
mOpened = false;
mIsPending = false;
mListenerContext = nullptr;
mListener = nullptr;
mCallbacks = nullptr;
mProgressSink = nullptr;
return aResult;
}
return NS_OK;
}
nsresult nsJARChannel::CheckPendingEvents()
{
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mIsPending);
MOZ_ASSERT(mPump);
nsresult rv;
auto suspendCount = mPendingEvent.suspendCount;
while (suspendCount--) {
if (NS_WARN_IF(NS_FAILED(rv = mPump->Suspend()))) {
return rv;
}
}
if (mPendingEvent.isCanceled) {
if (NS_WARN_IF(NS_FAILED(rv = mPump->Cancel(mStatus)))) {
return rv;
}
mPendingEvent.isCanceled = false;
}
return NS_OK;
return rv;
}
void
@ -672,41 +449,30 @@ NS_IMETHODIMP
nsJARChannel::Cancel(nsresult status)
{
mStatus = status;
if (mPump) {
if (mPump)
return mPump->Cancel(status);
}
if (mIsPending) {
mPendingEvent.isCanceled = true;
}
NS_ASSERTION(!mIsPending, "need to implement cancel when downloading");
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::Suspend()
{
++mPendingEvent.suspendCount;
if (mPump) {
if (mPump)
return mPump->Suspend();
}
NS_ASSERTION(!mIsPending, "need to implement suspend when downloading");
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::Resume()
{
if (NS_WARN_IF(mPendingEvent.suspendCount == 0)) {
return NS_ERROR_UNEXPECTED;
}
--mPendingEvent.suspendCount;
if (mPump) {
if (mPump)
return mPump->Resume();
}
NS_ASSERTION(!mIsPending, "need to implement resume when downloading");
return NS_OK;
}
@ -960,7 +726,7 @@ nsJARChannel::Open(nsIInputStream **stream)
mJarFile = nullptr;
mIsUnsafe = true;
nsresult rv = LookupFile();
nsresult rv = LookupFile(false);
if (NS_FAILED(rv))
return rv;
@ -985,7 +751,6 @@ nsJARChannel::Open(nsIInputStream **stream)
NS_IMETHODIMP
nsJARChannel::Open2(nsIInputStream** aStream)
{
LOG(("nsJARChannel::Open2 [this=%p]\n", this));
nsCOMPtr<nsIStreamListener> listener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
NS_ENSURE_SUCCESS(rv, rv);
@ -995,7 +760,6 @@ nsJARChannel::Open2(nsIInputStream** aStream)
NS_IMETHODIMP
nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
{
LOG(("nsJARChannel::AsyncOpen [this=%p]\n", this));
MOZ_ASSERT(!mLoadInfo ||
mLoadInfo->GetSecurityMode() == 0 ||
mLoadInfo->GetInitialSecurityCheckDone() ||
@ -1019,7 +783,7 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
mListenerContext = ctx;
mIsPending = true;
nsresult rv = LookupFile();
nsresult rv = LookupFile(true);
if (NS_FAILED(rv)) {
mIsPending = false;
mListenerContext = nullptr;
@ -1070,13 +834,9 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
else {
rv = channel->AsyncOpen(downloader, nullptr);
}
}
else {
rv = OpenLocalFile();
if (NS_SUCCEEDED(rv)) {
return NS_OK;
}
}
if (NS_FAILED(rv)) {
@ -1092,14 +852,13 @@ nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
mLoadGroup->AddRequest(this, nullptr);
mOpened = true;
LOG(("nsJARChannel::AsyncOpen [this=%p] 8\n", this));
return NS_OK;
}
NS_IMETHODIMP
nsJARChannel::AsyncOpen2(nsIStreamListener *aListener)
{
LOG(("nsJARChannel::AsyncOpen2 [this=%p]\n", this));
nsCOMPtr<nsIStreamListener> listener = aListener;
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
if (NS_FAILED(rv)) {
@ -1195,7 +954,7 @@ nsJARChannel::EnsureCached(bool *aIsCached)
NS_IMETHODIMP
nsJARChannel::GetZipEntry(nsIZipEntry **aZipEntry)
{
nsresult rv = LookupFile();
nsresult rv = LookupFile(false);
if (NS_FAILED(rv))
return rv;

Просмотреть файл

@ -9,7 +9,6 @@
#include "mozilla/net/MemoryDownloader.h"
#include "nsIJARChannel.h"
#include "nsIJARURI.h"
#include "nsIEventTarget.h"
#include "nsIInputStreamPump.h"
#include "nsIInterfaceRequestor.h"
#include "nsIProgressEventSink.h"
@ -59,11 +58,8 @@ private:
virtual ~nsJARChannel();
nsresult CreateJarInput(nsIZipReaderCache *, nsJARInputThunk **);
nsresult LookupFile();
nsresult LookupFile(bool aAllowAsync);
nsresult OpenLocalFile();
nsresult ContinueOpenLocalFile(nsJARInputThunk* aInput, bool aIsSyncCall);
nsresult OnOpenLocalFileComplete(nsresult aResult, bool aIsSyncCall);
nsresult CheckPendingEvents();
void NotifyError(nsresult aError);
void FireOnProgress(uint64_t aProgress);
virtual void OnDownloadComplete(mozilla::net::MemoryDownloader* aDownloader,
@ -97,15 +93,7 @@ private:
int64_t mContentLength;
uint32_t mLoadFlags;
nsresult mStatus;
bool mIsPending; // the AsyncOpen is in progress.
bool mEnableOMT;
// |Cancel()|, |Suspend()|, and |Resume()| might be called during AsyncOpen.
struct {
bool isCanceled;
uint32_t suspendCount;
} mPendingEvent;
bool mIsPending;
bool mIsUnsafe;
mozilla::net::MemoryDownloader::Data mTempMem;
@ -120,9 +108,6 @@ private:
nsCString mJarEntry;
nsCString mInnerJarEntry;
// use StreamTransportService as background thread
nsCOMPtr<nsIEventTarget> mWorker;
// True if this channel should not download any remote files.
bool mBlockRemoteFiles;
};