2012-12-22 13:56:21 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* vim: set sw=4 ts=8 et tw=80 : */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2012-05-21 11:12:37 +00:00
|
|
|
* 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/. */
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2006-03-29 22:10:37 +00:00
|
|
|
#include "nsJAR.h"
|
1999-11-07 21:55:12 +00:00
|
|
|
#include "nsJARChannel.h"
|
2003-01-18 02:15:14 +00:00
|
|
|
#include "nsJARProtocolHandler.h"
|
2000-02-09 05:04:52 +00:00
|
|
|
#include "nsMimeTypes.h"
|
2003-01-18 02:15:14 +00:00
|
|
|
#include "nsNetUtil.h"
|
2005-11-23 20:35:37 +00:00
|
|
|
#include "nsEscape.h"
|
2007-11-27 05:32:23 +00:00
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
2009-03-10 21:58:00 +00:00
|
|
|
#include "nsIViewSourceChannel.h"
|
2014-09-21 16:44:56 +00:00
|
|
|
#include "nsContentUtils.h"
|
2014-09-29 15:48:11 +00:00
|
|
|
#include "nsProxyRelease.h"
|
2015-05-15 20:21:20 +00:00
|
|
|
#include "nsContentSecurityManager.h"
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2003-10-21 22:11:49 +00:00
|
|
|
#include "nsIScriptSecurityManager.h"
|
|
|
|
#include "nsIPrincipal.h"
|
2003-01-18 02:15:14 +00:00
|
|
|
#include "nsIFileURL.h"
|
2000-06-02 23:39:45 +00:00
|
|
|
|
2016-12-16 03:16:31 +00:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
2011-06-12 02:30:15 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-12-22 13:56:21 +00:00
|
|
|
#include "nsITabChild.h"
|
2014-07-18 02:46:24 +00:00
|
|
|
#include "private/pprio.h"
|
2015-05-22 07:32:25 +00:00
|
|
|
#include "nsInputStreamPump.h"
|
2018-03-01 08:12:00 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2011-06-12 02:30:15 +00:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-12-22 13:56:21 +00:00
|
|
|
using namespace mozilla::net;
|
2011-06-12 02:30:15 +00:00
|
|
|
|
2003-06-23 22:58:28 +00:00
|
|
|
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2006-03-29 22:10:37 +00:00
|
|
|
// the entry for a directory will either be empty (in the case of the
|
|
|
|
// top-level directory) or will end with a slash
|
|
|
|
#define ENTRY_IS_DIRECTORY(_entry) \
|
|
|
|
((_entry).IsEmpty() || '/' == (_entry).Last())
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2000-01-31 23:43:09 +00:00
|
|
|
|
2013-01-29 22:30:13 +00:00
|
|
|
// Ignore any LOG macro that we inherit from arbitrary headers. (We define our
|
|
|
|
// own LOG macro below.)
|
|
|
|
#ifdef LOG
|
|
|
|
#undef LOG
|
|
|
|
#endif
|
|
|
|
|
2000-03-30 07:39:31 +00:00
|
|
|
//
|
2003-01-18 02:15:14 +00:00
|
|
|
// set NSPR_LOG_MODULES=nsJarProtocol:5
|
2000-03-30 07:39:31 +00:00
|
|
|
//
|
2016-01-28 18:35:00 +00:00
|
|
|
static LazyLogModule gJarProtocolLog("nsJarProtocol");
|
2000-03-30 07:39:31 +00:00
|
|
|
|
2015-06-03 22:25:57 +00:00
|
|
|
#define LOG(args) MOZ_LOG(gJarProtocolLog, mozilla::LogLevel::Debug, args)
|
|
|
|
#define LOG_ENABLED() MOZ_LOG_TEST(gJarProtocolLog, mozilla::LogLevel::Debug)
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsJARInputThunk
|
|
|
|
//
|
|
|
|
// this class allows us to do some extra work on the stream transport thread.
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-04-12 07:58:24 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
class nsJARInputThunk : public nsIInputStream
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
public:
|
2013-07-19 02:23:44 +00:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_DECL_NSIINPUTSTREAM
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2010-09-09 03:38:34 +00:00
|
|
|
nsJARInputThunk(nsIZipReader *zipReader,
|
2006-03-29 22:10:37 +00:00
|
|
|
nsIURI* fullJarURI,
|
|
|
|
const nsACString &jarEntry,
|
2012-11-28 18:12:56 +00:00
|
|
|
bool usingJarCache)
|
|
|
|
: mUsingJarCache(usingJarCache)
|
2010-09-09 03:38:34 +00:00
|
|
|
, mJarReader(zipReader)
|
2003-01-18 02:15:14 +00:00
|
|
|
, mJarEntry(jarEntry)
|
2003-01-28 19:13:52 +00:00
|
|
|
, mContentLength(-1)
|
2003-01-18 02:15:14 +00:00
|
|
|
{
|
2009-03-02 01:06:55 +00:00
|
|
|
if (fullJarURI) {
|
2010-07-11 12:49:52 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsresult rv =
|
|
|
|
#endif
|
|
|
|
fullJarURI->GetAsciiSpec(mJarDirSpec);
|
2009-03-02 01:06:55 +00:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "this shouldn't fail");
|
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
2003-06-23 22:58:28 +00:00
|
|
|
|
2012-10-22 17:51:07 +00:00
|
|
|
int64_t GetContentLength()
|
2003-01-28 19:13:52 +00:00
|
|
|
{
|
|
|
|
return mContentLength;
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
nsresult Init();
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2003-01-29 06:47:55 +00:00
|
|
|
private:
|
|
|
|
|
2014-06-25 02:09:14 +00:00
|
|
|
virtual ~nsJARInputThunk()
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
bool mUsingJarCache;
|
2003-01-18 02:15:14 +00:00
|
|
|
nsCOMPtr<nsIZipReader> mJarReader;
|
2009-03-02 01:06:55 +00:00
|
|
|
nsCString mJarDirSpec;
|
2003-01-18 02:15:14 +00:00
|
|
|
nsCOMPtr<nsIInputStream> mJarStream;
|
|
|
|
nsCString mJarEntry;
|
2012-10-22 17:51:07 +00:00
|
|
|
int64_t mContentLength;
|
2003-01-18 02:15:14 +00:00
|
|
|
};
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsJARInputThunk, nsIInputStream)
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsresult
|
2012-11-28 18:12:56 +00:00
|
|
|
nsJARInputThunk::Init()
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-28 19:13:52 +00:00
|
|
|
nsresult rv;
|
2006-03-29 22:10:37 +00:00
|
|
|
if (ENTRY_IS_DIRECTORY(mJarEntry)) {
|
2006-10-10 13:24:57 +00:00
|
|
|
// A directory stream also needs the Spec of the FullJarURI
|
|
|
|
// because is included in the stream data itself.
|
2006-03-29 22:10:37 +00:00
|
|
|
|
2009-03-02 01:06:55 +00:00
|
|
|
NS_ENSURE_STATE(!mJarDirSpec.IsEmpty());
|
2006-03-29 22:10:37 +00:00
|
|
|
|
2009-03-02 01:06:55 +00:00
|
|
|
rv = mJarReader->GetInputStreamWithSpec(mJarDirSpec,
|
2011-09-28 23:14:45 +00:00
|
|
|
mJarEntry,
|
2006-10-10 13:24:57 +00:00
|
|
|
getter_AddRefs(mJarStream));
|
2006-03-29 22:10:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-09-28 23:14:45 +00:00
|
|
|
rv = mJarReader->GetInputStream(mJarEntry,
|
2006-03-29 22:10:37 +00:00
|
|
|
getter_AddRefs(mJarStream));
|
|
|
|
}
|
2006-08-11 18:36:32 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// convert to the proper result if the entry wasn't found
|
|
|
|
// so that error pages work
|
|
|
|
if (rv == NS_ERROR_FILE_TARGET_DOES_NOT_EXIST)
|
|
|
|
rv = NS_ERROR_FILE_NOT_FOUND;
|
|
|
|
return rv;
|
|
|
|
}
|
2003-01-28 19:13:52 +00:00
|
|
|
|
2003-09-11 16:45:50 +00:00
|
|
|
// ask the JarStream for the content length
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t avail;
|
|
|
|
rv = mJarStream->Available((uint64_t *) &avail);
|
2009-10-04 17:20:45 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2003-01-28 19:13:52 +00:00
|
|
|
|
2012-10-22 17:51:07 +00:00
|
|
|
mContentLength = avail < INT64_MAX ? (int64_t) avail : -1;
|
2012-08-11 02:44:11 +00:00
|
|
|
|
2003-01-28 19:13:52 +00:00
|
|
|
return NS_OK;
|
2000-08-21 08:23:54 +00:00
|
|
|
}
|
|
|
|
|
1999-11-07 21:55:12 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARInputThunk::Close()
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2012-11-28 18:12:56 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
if (mJarStream)
|
2012-11-28 18:12:56 +00:00
|
|
|
rv = mJarStream->Close();
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
if (!mUsingJarCache && mJarReader)
|
|
|
|
mJarReader->Close();
|
|
|
|
|
|
|
|
mJarReader = nullptr;
|
|
|
|
|
|
|
|
return rv;
|
2000-03-29 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsJARInputThunk::Available(uint64_t *avail)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
return mJarStream->Available(avail);
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsJARInputThunk::Read(char *buf, uint32_t count, uint32_t *countRead)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
return mJarStream->Read(buf, count, countRead);
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARInputThunk::ReadSegments(nsWriteSegmentFun writer, void *closure,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t count, uint32_t *countRead)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
// stream transport does only calls Read()
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsJARInputThunk::IsNonBlocking(bool *nonBlocking)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
*nonBlocking = false;
|
1999-11-07 21:55:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2009-02-19 20:25:18 +00:00
|
|
|
// nsJARChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::nsJARChannel()
|
2012-08-27 23:34:30 +00:00
|
|
|
: mOpened(false)
|
2016-01-12 18:16:59 +00:00
|
|
|
, mContentDisposition(0)
|
2012-07-11 15:38:36 +00:00
|
|
|
, mContentLength(-1)
|
2003-01-18 02:15:14 +00:00
|
|
|
, mLoadFlags(LOAD_NORMAL)
|
|
|
|
, mStatus(NS_OK)
|
2011-10-17 14:59:28 +00:00
|
|
|
, mIsPending(false)
|
2018-03-01 08:12:00 +00:00
|
|
|
, mEnableOMT(true)
|
|
|
|
, mPendingEvent()
|
2011-10-17 14:59:28 +00:00
|
|
|
, mIsUnsafe(true)
|
2015-08-05 03:55:00 +00:00
|
|
|
, mBlockRemoteFiles(false)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
LOG(("nsJARChannel::nsJARChannel [this=%p]\n", this));
|
2015-08-05 03:55:00 +00:00
|
|
|
mBlockRemoteFiles = Preferences::GetBool("network.jar.block-remote-files", false);
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// hold an owning reference to the jar handler
|
2017-10-29 23:02:40 +00:00
|
|
|
mJarHandler = gJarHandler;
|
2000-03-30 07:39:31 +00:00
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::~nsJARChannel()
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
LOG(("nsJARChannel::~nsJARChannel [this=%p]\n", this));
|
2017-07-14 06:49:22 +00:00
|
|
|
NS_ReleaseOnMainThreadSystemGroup("nsJARChannel::mLoadInfo",
|
|
|
|
mLoadInfo.forget());
|
2000-03-29 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsJARChannel,
|
|
|
|
nsHashPropertyBag,
|
|
|
|
nsIRequest,
|
|
|
|
nsIChannel,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver,
|
2014-06-17 16:39:23 +00:00
|
|
|
nsIThreadRetargetableRequest,
|
|
|
|
nsIThreadRetargetableStreamListener,
|
2014-04-27 07:06:00 +00:00
|
|
|
nsIJARChannel)
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2015-05-22 07:32:25 +00:00
|
|
|
nsresult
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::Init(nsIURI *uri)
|
2000-03-30 07:39:31 +00:00
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
LOG(("nsJARChannel::Init [this=%p]\n", this));
|
2000-08-24 22:35:46 +00:00
|
|
|
nsresult rv;
|
2018-03-01 08:12:00 +00:00
|
|
|
|
|
|
|
mWorker = do_GetService(NS_STREAMTRANSPORTSERVICE_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
mJarURI = do_QueryInterface(uri, &rv);
|
2005-05-12 15:20:43 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2008-10-15 20:05:23 +00:00
|
|
|
mOriginalURI = mJarURI;
|
|
|
|
|
2005-05-12 15:20:43 +00:00
|
|
|
// Prevent loading jar:javascript URIs (see bug 290982).
|
|
|
|
nsCOMPtr<nsIURI> innerURI;
|
|
|
|
rv = mJarURI->GetJARFile(getter_AddRefs(innerURI));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isJS;
|
2005-05-12 15:20:43 +00:00
|
|
|
rv = innerURI->SchemeIs("javascript", &isJS);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
if (isJS) {
|
|
|
|
NS_WARNING("blocking jar:javascript:");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2001-09-14 21:19:41 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
mJarURI->GetSpec(mSpec);
|
|
|
|
return rv;
|
|
|
|
}
|
2001-09-18 23:07:57 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsresult
|
2012-11-28 18:12:56 +00:00
|
|
|
nsJARChannel::CreateJarInput(nsIZipReaderCache *jarCache, nsJARInputThunk **resultInput)
|
2003-01-18 02:15:14 +00:00
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
LOG(("nsJARChannel::CreateJarInput [this=%p]\n", this));
|
2012-11-28 18:12:56 +00:00
|
|
|
MOZ_ASSERT(resultInput);
|
2015-03-11 00:00:01 +00:00
|
|
|
MOZ_ASSERT(mJarFile || mTempMem);
|
2012-11-28 18:12:56 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// important to pass a clone of the file since the nsIFile impl is not
|
|
|
|
// necessarily MT-safe
|
|
|
|
nsCOMPtr<nsIFile> clonedFile;
|
2015-03-11 00:00:01 +00:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (mJarFile) {
|
|
|
|
rv = mJarFile->Clone(getter_AddRefs(clonedFile));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
2000-08-24 22:35:46 +00:00
|
|
|
|
2010-09-09 03:38:34 +00:00
|
|
|
nsCOMPtr<nsIZipReader> reader;
|
2017-07-21 22:19:09 +00:00
|
|
|
if (mPreCachedJarReader) {
|
2018-03-01 08:12:00 +00:00
|
|
|
reader = mPreCachedJarReader;
|
2017-07-21 22:19:09 +00:00
|
|
|
} else if (jarCache) {
|
2015-03-11 00:00:01 +00:00
|
|
|
MOZ_ASSERT(mJarFile);
|
2010-09-09 03:38:34 +00:00
|
|
|
if (mInnerJarEntry.IsEmpty())
|
2012-12-22 13:56:21 +00:00
|
|
|
rv = jarCache->GetZip(clonedFile, getter_AddRefs(reader));
|
2012-11-28 18:12:56 +00:00
|
|
|
else
|
2012-12-22 13:56:21 +00:00
|
|
|
rv = jarCache->GetInnerZip(clonedFile, mInnerJarEntry,
|
2010-09-09 03:38:34 +00:00
|
|
|
getter_AddRefs(reader));
|
|
|
|
} else {
|
|
|
|
// create an uncached jar reader
|
|
|
|
nsCOMPtr<nsIZipReader> outerReader = do_CreateInstance(kZipReaderCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2015-03-11 00:00:01 +00:00
|
|
|
if (mJarFile) {
|
|
|
|
rv = outerReader->Open(clonedFile);
|
|
|
|
} else {
|
|
|
|
rv = outerReader->OpenMemory(mTempMem->Elements(),
|
|
|
|
mTempMem->Length());
|
|
|
|
}
|
2010-09-09 03:38:34 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (mInnerJarEntry.IsEmpty())
|
|
|
|
reader = outerReader;
|
|
|
|
else {
|
|
|
|
reader = do_CreateInstance(kZipReaderCID, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2011-09-28 23:14:45 +00:00
|
|
|
rv = reader->OpenInner(outerReader, mInnerJarEntry);
|
2010-09-09 03:38:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsJARInputThunk> input = new nsJARInputThunk(reader,
|
2018-03-01 08:12:00 +00:00
|
|
|
mJarURI,
|
|
|
|
mJarEntry,
|
|
|
|
jarCache != nullptr);
|
2012-11-28 18:12:56 +00:00
|
|
|
rv = input->Init();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
// Make GetContentLength meaningful
|
|
|
|
mContentLength = input->GetContentLength();
|
|
|
|
|
|
|
|
input.forget(resultInput);
|
2003-01-18 02:15:14 +00:00
|
|
|
return NS_OK;
|
2000-03-30 07:39:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2018-03-01 08:12:00 +00:00
|
|
|
nsJARChannel::LookupFile()
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2016-12-16 03:16:31 +00:00
|
|
|
LOG(("nsJARChannel::LookupFile [this=%p %s]\n", this, mSpec.get()));
|
2000-03-30 07:39:31 +00:00
|
|
|
|
2014-08-04 15:54:28 +00:00
|
|
|
if (mJarFile)
|
|
|
|
return NS_OK;
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsresult rv;
|
2000-03-30 07:39:31 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
rv = mJarURI->GetJARFile(getter_AddRefs(mJarBaseURI));
|
2012-11-28 18:12:56 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
rv = mJarURI->GetJAREntry(mJarEntry);
|
2012-11-28 18:12:56 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2001-09-10 00:42:50 +00:00
|
|
|
|
2006-03-29 22:10:37 +00:00
|
|
|
// The name of the JAR entry must not contain URL-escaped characters:
|
2005-11-23 20:35:37 +00:00
|
|
|
// we're moving from URL domain to a filename domain here. nsStandardURL
|
|
|
|
// does basic escaping by default, which breaks reading zipped files which
|
|
|
|
// have e.g. spaces in their filenames.
|
|
|
|
NS_UnescapeURL(mJarEntry);
|
|
|
|
|
2017-06-24 00:10:54 +00:00
|
|
|
if (mJarFileOverride) {
|
|
|
|
mJarFile = mJarFileOverride;
|
|
|
|
LOG(("nsJARChannel::LookupFile [this=%p] Overriding mJarFile\n", this));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-09-14 21:19:41 +00:00
|
|
|
// try to get a nsIFile directly from the url, which will often succeed.
|
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
nsCOMPtr<nsIFileURL> fileURL = do_QueryInterface(mJarBaseURI);
|
2001-09-14 21:19:41 +00:00
|
|
|
if (fileURL)
|
2003-01-18 02:15:14 +00:00
|
|
|
fileURL->GetFile(getter_AddRefs(mJarFile));
|
2001-09-14 21:19:41 +00:00
|
|
|
}
|
2013-02-15 22:27:21 +00:00
|
|
|
|
2010-09-09 03:38:34 +00:00
|
|
|
// try to handle a nested jar
|
|
|
|
if (!mJarFile) {
|
|
|
|
nsCOMPtr<nsIJARURI> jarURI = do_QueryInterface(mJarBaseURI);
|
|
|
|
if (jarURI) {
|
|
|
|
nsCOMPtr<nsIFileURL> fileURL;
|
|
|
|
nsCOMPtr<nsIURI> innerJarURI;
|
|
|
|
rv = jarURI->GetJARFile(getter_AddRefs(innerJarURI));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
fileURL = do_QueryInterface(innerJarURI);
|
|
|
|
if (fileURL) {
|
|
|
|
fileURL->GetFile(getter_AddRefs(mJarFile));
|
|
|
|
jarURI->GetJAREntry(mInnerJarEntry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-09-21 08:26:07 +00:00
|
|
|
|
1999-11-07 21:55:12 +00:00
|
|
|
return rv;
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
1999-11-17 08:14:52 +00:00
|
|
|
|
2018-03-01 08:12:00 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-15 22:27:21 +00:00
|
|
|
nsresult
|
|
|
|
nsJARChannel::OpenLocalFile()
|
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
LOG(("nsJARChannel::OpenLocalFile [this=%p]\n", this));
|
|
|
|
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
MOZ_ASSERT(mWorker);
|
2013-02-15 22:27:21 +00:00
|
|
|
MOZ_ASSERT(mIsPending);
|
2018-03-01 08:12:00 +00:00
|
|
|
MOZ_ASSERT(mJarFile);
|
2013-02-15 22:27:21 +00:00
|
|
|
|
|
|
|
// Local files are always considered safe.
|
|
|
|
mIsUnsafe = false;
|
|
|
|
|
2018-03-01 08:12:00 +00:00
|
|
|
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());
|
2018-03-01 06:12:00 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2018-03-01 08:12:00 +00:00
|
|
|
rv = mPump->AsyncRead(this, nullptr);
|
2018-03-01 06:12:00 +00:00
|
|
|
}
|
|
|
|
|
2018-03-01 08:12:00 +00:00
|
|
|
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;
|
2013-02-15 22:27:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJARChannel::NotifyError(nsresult aError)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_FAILED(aError));
|
|
|
|
|
|
|
|
mStatus = aError;
|
|
|
|
|
|
|
|
OnStartRequest(nullptr, nullptr);
|
|
|
|
OnStopRequest(nullptr, nullptr, aError);
|
|
|
|
}
|
|
|
|
|
2014-06-17 16:39:23 +00:00
|
|
|
void
|
|
|
|
nsJARChannel::FireOnProgress(uint64_t aProgress)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_ASSERT(mProgressSink);
|
|
|
|
|
2015-01-08 19:48:52 +00:00
|
|
|
mProgressSink->OnProgress(this, nullptr, aProgress, mContentLength);
|
2014-06-17 16:39:23 +00:00
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIRequest
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-02-21 20:38:08 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetName(nsACString &result)
|
|
|
|
{
|
|
|
|
return mJarURI->GetSpec(result);
|
|
|
|
}
|
2000-04-12 07:58:24 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsJARChannel::IsPending(bool *result)
|
2003-01-18 02:15:14 +00:00
|
|
|
{
|
|
|
|
*result = mIsPending;
|
|
|
|
return NS_OK;
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::GetStatus(nsresult *status)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
if (mPump && NS_SUCCEEDED(mStatus))
|
|
|
|
mPump->GetStatus(status);
|
|
|
|
else
|
|
|
|
*status = mStatus;
|
1999-11-07 21:55:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::Cancel(nsresult status)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
mStatus = status;
|
2018-03-01 08:12:00 +00:00
|
|
|
if (mPump) {
|
2003-01-18 02:15:14 +00:00
|
|
|
return mPump->Cancel(status);
|
2018-03-01 08:12:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mIsPending) {
|
|
|
|
mPendingEvent.isCanceled = true;
|
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
|
1999-11-07 21:55:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::Suspend()
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
++mPendingEvent.suspendCount;
|
|
|
|
|
|
|
|
if (mPump) {
|
2003-01-18 02:15:14 +00:00
|
|
|
return mPump->Suspend();
|
2018-03-01 08:12:00 +00:00
|
|
|
}
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
return NS_OK;
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2000-01-08 06:26:04 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::Resume()
|
2000-01-08 06:26:04 +00:00
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
if (NS_WARN_IF(mPendingEvent.suspendCount == 0)) {
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
--mPendingEvent.suspendCount;
|
|
|
|
|
|
|
|
if (mPump) {
|
2003-01-18 02:15:14 +00:00
|
|
|
return mPump->Resume();
|
2018-03-01 08:12:00 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-08 06:26:04 +00:00
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::GetLoadFlags(nsLoadFlags *aLoadFlags)
|
2002-03-20 22:50:33 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
*aLoadFlags = mLoadFlags;
|
2002-03-20 22:50:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-08 06:26:04 +00:00
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::SetLoadFlags(nsLoadFlags aLoadFlags)
|
2002-03-20 22:50:33 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
mLoadFlags = aLoadFlags;
|
2000-01-08 06:26:04 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-04-20 02:15:06 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetIsDocument(bool *aIsDocument)
|
|
|
|
{
|
|
|
|
return NS_GetIsDocumentChannel(this, aIsDocument);
|
|
|
|
}
|
|
|
|
|
1999-11-07 21:55:12 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::GetLoadGroup(nsILoadGroup **aLoadGroup)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_IF_ADDREF(*aLoadGroup = mLoadGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-03-20 22:50:33 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::SetLoadGroup(nsILoadGroup *aLoadGroup)
|
|
|
|
{
|
|
|
|
mLoadGroup = aLoadGroup;
|
1999-11-07 21:55:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::GetOriginalURI(nsIURI **aURI)
|
2000-03-29 03:58:50 +00:00
|
|
|
{
|
2008-10-15 20:05:23 +00:00
|
|
|
*aURI = mOriginalURI;
|
|
|
|
NS_ADDREF(*aURI);
|
2003-01-18 02:15:14 +00:00
|
|
|
return NS_OK;
|
2000-03-29 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
1999-11-07 21:55:12 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::SetOriginalURI(nsIURI *aURI)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2008-10-15 20:05:23 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2003-01-18 02:15:14 +00:00
|
|
|
mOriginalURI = aURI;
|
1999-11-07 21:55:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-17 08:14:52 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::GetURI(nsIURI **aURI)
|
1999-11-17 08:14:52 +00:00
|
|
|
{
|
2016-10-20 22:24:04 +00:00
|
|
|
NS_IF_ADDREF(*aURI = mJarURI);
|
2012-07-11 15:38:36 +00:00
|
|
|
|
1999-11-17 08:14:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-07 21:55:12 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-30 20:58:55 +00:00
|
|
|
nsJARChannel::GetOwner(nsISupports **aOwner)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2012-08-30 20:58:55 +00:00
|
|
|
// JAR signatures are not processed to avoid main-thread network I/O (bug 726125)
|
|
|
|
*aOwner = mOwner;
|
|
|
|
NS_IF_ADDREF(*aOwner);
|
1999-11-07 21:55:12 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::SetOwner(nsISupports *aOwner)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2000-03-21 04:17:37 +00:00
|
|
|
mOwner = aOwner;
|
|
|
|
return NS_OK;
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2014-07-10 06:56:36 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetLoadInfo(nsILoadInfo **aLoadInfo)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aLoadInfo = mLoadInfo);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::SetLoadInfo(nsILoadInfo* aLoadInfo)
|
|
|
|
{
|
|
|
|
mLoadInfo = aLoadInfo;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-17 08:14:52 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks)
|
1999-11-17 08:14:52 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_IF_ADDREF(*aCallbacks = mCallbacks);
|
1999-11-17 08:14:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks)
|
1999-11-17 08:14:52 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
mCallbacks = aCallbacks;
|
1999-11-17 08:14:52 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-22 07:32:25 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::GetSecurityInfo(nsISupports **aSecurityInfo)
|
2000-03-17 22:06:32 +00:00
|
|
|
{
|
2004-04-21 14:58:45 +00:00
|
|
|
NS_PRECONDITION(aSecurityInfo, "Null out param");
|
|
|
|
NS_IF_ADDREF(*aSecurityInfo = mSecurityInfo);
|
2000-03-17 22:06:32 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-08-24 07:36:53 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetContentType(nsACString &result)
|
|
|
|
{
|
2012-08-27 23:34:30 +00:00
|
|
|
// If the Jar file has not been open yet,
|
|
|
|
// We return application/x-unknown-content-type
|
|
|
|
if (!mOpened) {
|
2017-09-04 05:12:56 +00:00
|
|
|
result.AssignLiteral(UNKNOWN_CONTENT_TYPE);
|
2012-08-27 23:34:30 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-12 20:09:05 +00:00
|
|
|
if (mContentType.IsEmpty()) {
|
2012-08-27 23:34:30 +00:00
|
|
|
|
2003-11-12 20:09:05 +00:00
|
|
|
//
|
|
|
|
// generate content type and set it
|
|
|
|
//
|
2012-07-30 14:20:58 +00:00
|
|
|
const char *ext = nullptr, *fileName = mJarEntry.get();
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t len = mJarEntry.Length();
|
2006-03-29 22:10:37 +00:00
|
|
|
|
|
|
|
// check if we're displaying a directory
|
|
|
|
// mJarEntry will be empty if we're trying to display
|
|
|
|
// the topmost directory in a zip, e.g. jar:foo.zip!/
|
|
|
|
if (ENTRY_IS_DIRECTORY(mJarEntry)) {
|
|
|
|
mContentType.AssignLiteral(APPLICATION_HTTP_INDEX_FORMAT);
|
2003-11-12 20:09:05 +00:00
|
|
|
}
|
2006-03-29 22:10:37 +00:00
|
|
|
else {
|
|
|
|
// not a directory, take a guess by its extension
|
2012-08-22 15:56:38 +00:00
|
|
|
for (int32_t i = len-1; i >= 0; i--) {
|
2006-03-29 22:10:37 +00:00
|
|
|
if (fileName[i] == '.') {
|
|
|
|
ext = &fileName[i + 1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ext) {
|
|
|
|
nsIMIMEService *mimeServ = gJarHandler->MimeService();
|
|
|
|
if (mimeServ)
|
|
|
|
mimeServ->GetTypeFromExtension(nsDependentCString(ext), mContentType);
|
|
|
|
}
|
|
|
|
if (mContentType.IsEmpty())
|
|
|
|
mContentType.AssignLiteral(UNKNOWN_CONTENT_TYPE);
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
result = mContentType;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-09-22 06:21:18 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::SetContentType(const nsACString &aContentType)
|
2000-09-22 06:21:18 +00:00
|
|
|
{
|
2003-06-23 21:00:46 +00:00
|
|
|
// If someone gives us a type hint we should just use that type instead of
|
|
|
|
// doing our guessing. So we don't care when this is being called.
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// mContentCharset is unchanged if not parsed
|
2015-10-01 16:51:50 +00:00
|
|
|
NS_ParseResponseContentType(aContentType, mContentType, mContentCharset);
|
2003-01-18 02:15:14 +00:00
|
|
|
return NS_OK;
|
2000-09-22 06:21:18 +00:00
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetContentCharset(nsACString &aContentCharset)
|
|
|
|
{
|
2003-06-23 21:00:46 +00:00
|
|
|
// If someone gives us a charset hint we should just use that charset.
|
|
|
|
// So we don't care when this is being called.
|
2003-01-18 02:15:14 +00:00
|
|
|
aContentCharset = mContentCharset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-07 21:55:12 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::SetContentCharset(const nsACString &aContentCharset)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
mContentCharset = aContentCharset;
|
|
|
|
return NS_OK;
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2011-09-09 22:41:04 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsJARChannel::GetContentDisposition(uint32_t *aContentDisposition)
|
2011-09-09 22:41:04 +00:00
|
|
|
{
|
|
|
|
if (mContentDispositionHeader.IsEmpty())
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
*aContentDisposition = mContentDisposition;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-02 16:43:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::SetContentDisposition(uint32_t aContentDisposition)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2011-09-09 22:41:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetContentDispositionFilename(nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2012-10-02 16:43:00 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::SetContentDispositionFilename(const nsAString &aContentDispositionFilename)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
|
|
|
|
2011-09-09 22:41:04 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetContentDispositionHeader(nsACString &aContentDispositionHeader)
|
|
|
|
{
|
|
|
|
if (mContentDispositionHeader.IsEmpty())
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
aContentDispositionHeader = mContentDispositionHeader;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-07 21:55:12 +00:00
|
|
|
NS_IMETHODIMP
|
2012-10-22 17:51:07 +00:00
|
|
|
nsJARChannel::GetContentLength(int64_t *result)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
*result = mContentLength;
|
|
|
|
return NS_OK;
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-10-22 17:51:07 +00:00
|
|
|
nsJARChannel::SetContentLength(int64_t aContentLength)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
// XXX does this really make any sense at all?
|
|
|
|
mContentLength = aContentLength;
|
|
|
|
return NS_OK;
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::Open(nsIInputStream **stream)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2016-12-16 03:16:31 +00:00
|
|
|
LOG(("nsJARChannel::Open [this=%p]\n", this));
|
2000-03-30 07:39:31 +00:00
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
NS_ENSURE_TRUE(!mOpened, NS_ERROR_IN_PROGRESS);
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
|
2000-08-24 07:36:53 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mJarFile = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsUnsafe = true;
|
2007-11-27 05:32:23 +00:00
|
|
|
|
2018-03-01 08:12:00 +00:00
|
|
|
nsresult rv = LookupFile();
|
2012-11-28 18:12:56 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
// If mJarInput was not set by LookupFile, the JAR is a remote jar.
|
|
|
|
if (!mJarFile) {
|
|
|
|
NS_NOTREACHED("need sync downloader");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2003-01-29 06:47:55 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsJARInputThunk> input;
|
2012-11-28 18:12:56 +00:00
|
|
|
rv = CreateJarInput(gJarHandler->JarCache(), getter_AddRefs(input));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2012-08-27 23:34:30 +00:00
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
input.forget(stream);
|
2012-08-27 23:34:30 +00:00
|
|
|
mOpened = true;
|
2012-11-28 18:12:56 +00:00
|
|
|
// local files are always considered safe
|
|
|
|
mIsUnsafe = false;
|
2000-08-24 07:36:53 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-05-15 20:21:20 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::Open2(nsIInputStream** aStream)
|
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
LOG(("nsJARChannel::Open2 [this=%p]\n", this));
|
2015-05-15 20:21:20 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> listener;
|
|
|
|
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
return Open(aStream);
|
|
|
|
}
|
|
|
|
|
2000-08-24 07:36:53 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
|
2000-08-24 07:36:53 +00:00
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
LOG(("nsJARChannel::AsyncOpen [this=%p]\n", this));
|
2015-11-18 01:35:30 +00:00
|
|
|
MOZ_ASSERT(!mLoadInfo ||
|
|
|
|
mLoadInfo->GetSecurityMode() == 0 ||
|
|
|
|
mLoadInfo->GetInitialSecurityCheckDone() ||
|
|
|
|
(mLoadInfo->GetSecurityMode() == nsILoadInfo::SEC_ALLOW_CROSS_ORIGIN_DATA_IS_NULL &&
|
|
|
|
nsContentUtils::IsSystemPrincipal(mLoadInfo->LoadingPrincipal())),
|
2015-08-13 04:36:33 +00:00
|
|
|
"security flags in loadInfo but asyncOpen2() not called");
|
|
|
|
|
2016-12-16 03:16:31 +00:00
|
|
|
LOG(("nsJARChannel::AsyncOpen [this=%p]\n", this));
|
1999-11-12 06:13:13 +00:00
|
|
|
|
2007-03-01 07:06:07 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(listener);
|
2012-11-28 18:12:56 +00:00
|
|
|
NS_ENSURE_TRUE(!mOpened, NS_ERROR_IN_PROGRESS);
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_ENSURE_TRUE(!mIsPending, NS_ERROR_IN_PROGRESS);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
mJarFile = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsUnsafe = true;
|
2007-11-27 05:32:23 +00:00
|
|
|
|
2004-11-15 20:16:52 +00:00
|
|
|
// Initialize mProgressSink
|
|
|
|
NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup, mProgressSink);
|
|
|
|
|
2009-03-05 12:27:48 +00:00
|
|
|
mListener = listener;
|
|
|
|
mListenerContext = ctx;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsPending = true;
|
2012-11-28 18:12:56 +00:00
|
|
|
|
2018-03-01 08:12:00 +00:00
|
|
|
nsresult rv = LookupFile();
|
2015-05-22 07:32:25 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mIsPending = false;
|
|
|
|
mListenerContext = nullptr;
|
|
|
|
mListener = nullptr;
|
2017-02-08 17:55:15 +00:00
|
|
|
mCallbacks = nullptr;
|
|
|
|
mProgressSink = nullptr;
|
2015-05-22 07:32:25 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2015-01-12 04:26:40 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel;
|
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
if (!mJarFile) {
|
|
|
|
// Not a local file...
|
2015-08-05 03:55:00 +00:00
|
|
|
|
|
|
|
// Check preferences to see if all remote jar support should be disabled
|
|
|
|
if (mBlockRemoteFiles) {
|
|
|
|
mIsUnsafe = true;
|
2017-02-08 17:55:15 +00:00
|
|
|
mIsPending = false;
|
|
|
|
mListenerContext = nullptr;
|
|
|
|
mListener = nullptr;
|
|
|
|
mCallbacks = nullptr;
|
|
|
|
mProgressSink = nullptr;
|
2015-08-05 03:55:00 +00:00
|
|
|
return NS_ERROR_UNSAFE_CONTENT_TYPE;
|
|
|
|
}
|
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
// kick off an async download of the base URI...
|
2015-03-11 00:00:01 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> downloader = new MemoryDownloader(this);
|
|
|
|
uint32_t loadFlags =
|
|
|
|
mLoadFlags & ~(LOAD_DOCUMENT_URI | LOAD_CALL_CONTENT_SNIFFERS);
|
|
|
|
rv = NS_NewChannelInternal(getter_AddRefs(channel),
|
|
|
|
mJarBaseURI,
|
|
|
|
mLoadInfo,
|
2018-01-24 16:17:31 +00:00
|
|
|
nullptr, // PerformanceStorage
|
2015-03-11 00:00:01 +00:00
|
|
|
mLoadGroup,
|
|
|
|
mCallbacks,
|
|
|
|
loadFlags);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mIsPending = false;
|
|
|
|
mListenerContext = nullptr;
|
|
|
|
mListener = nullptr;
|
2017-02-08 17:55:15 +00:00
|
|
|
mCallbacks = nullptr;
|
|
|
|
mProgressSink = nullptr;
|
2015-03-11 00:00:01 +00:00
|
|
|
return rv;
|
2014-09-21 16:44:56 +00:00
|
|
|
}
|
2015-05-15 20:21:20 +00:00
|
|
|
if (mLoadInfo && mLoadInfo->GetEnforceSecurity()) {
|
|
|
|
rv = channel->AsyncOpen2(downloader);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
rv = channel->AsyncOpen(downloader, nullptr);
|
|
|
|
}
|
2018-03-01 08:12:00 +00:00
|
|
|
|
2016-10-20 22:08:57 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-02-15 22:27:21 +00:00
|
|
|
rv = OpenLocalFile();
|
2018-03-01 08:12:00 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mIsPending = false;
|
|
|
|
mListenerContext = nullptr;
|
|
|
|
mListener = nullptr;
|
2017-02-08 17:55:15 +00:00
|
|
|
mCallbacks = nullptr;
|
|
|
|
mProgressSink = nullptr;
|
2012-11-28 18:12:56 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-01-25 19:03:13 +00:00
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->AddRequest(this, nullptr);
|
2012-11-28 18:12:56 +00:00
|
|
|
|
2016-01-25 19:03:13 +00:00
|
|
|
mOpened = true;
|
2018-03-01 08:12:00 +00:00
|
|
|
LOG(("nsJARChannel::AsyncOpen [this=%p] 8\n", this));
|
2015-06-03 08:41:44 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-01-25 19:03:13 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::AsyncOpen2(nsIStreamListener *aListener)
|
2015-06-03 08:41:44 +00:00
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
LOG(("nsJARChannel::AsyncOpen2 [this=%p]\n", this));
|
2016-01-25 19:03:13 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> listener = aListener;
|
|
|
|
nsresult rv = nsContentSecurityManager::doContentSecurityCheck(this, listener);
|
2017-02-08 17:55:15 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mIsPending = false;
|
|
|
|
mListenerContext = nullptr;
|
|
|
|
mListener = nullptr;
|
|
|
|
mCallbacks = nullptr;
|
|
|
|
mProgressSink = nullptr;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2016-01-25 19:03:13 +00:00
|
|
|
return AsyncOpen(listener, nullptr);
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2007-11-27 05:32:23 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIJARChannel
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 06:19:26 +00:00
|
|
|
nsJARChannel::GetIsUnsafe(bool *isUnsafe)
|
2007-11-27 05:32:23 +00:00
|
|
|
{
|
|
|
|
*isUnsafe = mIsUnsafe;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-05-16 05:34:43 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetJarFile(nsIFile **aFile)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(*aFile = mJarFile);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-06-24 00:10:54 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::SetJarFile(nsIFile *aFile)
|
|
|
|
{
|
|
|
|
if (mOpened) {
|
|
|
|
return NS_ERROR_IN_PROGRESS;
|
|
|
|
}
|
|
|
|
mJarFileOverride = aFile;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-21 22:19:09 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::EnsureCached(bool *aIsCached)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
*aIsCached = false;
|
|
|
|
|
|
|
|
if (mOpened) {
|
|
|
|
return NS_ERROR_ALREADY_OPENED;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPreCachedJarReader) {
|
|
|
|
// We've already been called and found the JAR is cached
|
|
|
|
*aIsCached = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> innerFileURI;
|
|
|
|
rv = mJarURI->GetJARFile(getter_AddRefs(innerFileURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFileURL> innerFileURL = do_QueryInterface(innerFileURI, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFile> jarFile;
|
|
|
|
rv = innerFileURL->GetFile(getter_AddRefs(jarFile));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIProtocolHandler> handler;
|
|
|
|
rv = ioService->GetProtocolHandler("jar", getter_AddRefs(handler));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIJARProtocolHandler> jarHandler = do_QueryInterface(handler);
|
|
|
|
MOZ_ASSERT(jarHandler);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIZipReaderCache> jarCache;
|
|
|
|
rv = jarHandler->GetJARCache(getter_AddRefs(jarCache));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = jarCache->GetZipIfCached(jarFile, getter_AddRefs(mPreCachedJarReader));
|
|
|
|
if (rv == NS_ERROR_CACHE_KEY_NOT_FOUND) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
*aIsCached = true;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-06-24 00:10:54 +00:00
|
|
|
|
2014-08-04 15:54:28 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetZipEntry(nsIZipEntry **aZipEntry)
|
|
|
|
{
|
2018-03-01 08:12:00 +00:00
|
|
|
nsresult rv = LookupFile();
|
2014-08-04 15:54:28 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!mJarFile)
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIZipReader> reader;
|
|
|
|
rv = gJarHandler->JarCache()->GetZip(mJarFile, getter_AddRefs(reader));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return reader->GetEntry(mJarEntry, aZipEntry);
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2015-03-11 00:00:01 +00:00
|
|
|
// mozilla::net::MemoryDownloader::IObserver
|
2003-01-18 02:15:14 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2015-03-11 00:00:01 +00:00
|
|
|
void
|
|
|
|
nsJARChannel::OnDownloadComplete(MemoryDownloader* aDownloader,
|
2004-04-21 14:58:45 +00:00
|
|
|
nsIRequest *request,
|
|
|
|
nsISupports *context,
|
2003-06-23 22:58:28 +00:00
|
|
|
nsresult status,
|
2015-03-11 00:00:01 +00:00
|
|
|
MemoryDownloader::Data aData)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2007-11-27 04:35:00 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2004-04-21 14:58:45 +00:00
|
|
|
nsCOMPtr<nsIChannel> channel(do_QueryInterface(request));
|
2007-11-27 04:35:00 +00:00
|
|
|
if (channel) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t loadFlags;
|
2007-11-27 04:35:00 +00:00
|
|
|
channel->GetLoadFlags(&loadFlags);
|
|
|
|
if (loadFlags & LOAD_REPLACE) {
|
2017-05-30 16:07:59 +00:00
|
|
|
// Update our URI to reflect any redirects that happen during
|
|
|
|
// the HTTP request.
|
2007-11-27 04:35:00 +00:00
|
|
|
if (!mOriginalURI) {
|
|
|
|
SetOriginalURI(mJarURI);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> innerURI;
|
|
|
|
rv = channel->GetURI(getter_AddRefs(innerURI));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
nsCOMPtr<nsIJARURI> newURI;
|
|
|
|
rv = mJarURI->CloneWithJARFile(innerURI,
|
|
|
|
getter_AddRefs(newURI));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mJarURI = newURI;
|
|
|
|
}
|
|
|
|
}
|
2007-12-13 22:34:13 +00:00
|
|
|
if (NS_SUCCEEDED(status)) {
|
|
|
|
status = rv;
|
|
|
|
}
|
2007-11-27 04:35:00 +00:00
|
|
|
}
|
2007-12-13 22:34:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(status) && channel) {
|
2017-05-30 16:07:59 +00:00
|
|
|
// In case the load info object has changed during a redirect,
|
|
|
|
// grab it from the target channel.
|
|
|
|
channel->GetLoadInfo(getter_AddRefs(mLoadInfo));
|
2007-12-13 22:34:13 +00:00
|
|
|
// Grab the security info from our base channel
|
|
|
|
channel->GetSecurityInfo(getter_AddRefs(mSecurityInfo));
|
2007-11-27 05:32:23 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel));
|
|
|
|
if (httpChannel) {
|
|
|
|
// We only want to run scripts if the server really intended to
|
|
|
|
// send us a JAR file. Check the server-supplied content type for
|
|
|
|
// a JAR type.
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString header;
|
2016-12-20 06:51:20 +00:00
|
|
|
Unused << httpChannel->GetResponseHeader(
|
|
|
|
NS_LITERAL_CSTRING("Content-Type"), header);
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString contentType;
|
|
|
|
nsAutoCString charset;
|
2015-10-01 16:51:50 +00:00
|
|
|
NS_ParseResponseContentType(header, contentType, charset);
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString channelContentType;
|
2009-03-10 21:58:00 +00:00
|
|
|
channel->GetContentType(channelContentType);
|
|
|
|
mIsUnsafe = !(contentType.Equals(channelContentType) &&
|
|
|
|
(contentType.EqualsLiteral("application/java-archive") ||
|
|
|
|
contentType.EqualsLiteral("application/x-jar")));
|
2007-11-27 05:32:23 +00:00
|
|
|
} else {
|
|
|
|
nsCOMPtr<nsIJARChannel> innerJARChannel(do_QueryInterface(channel));
|
|
|
|
if (innerJARChannel) {
|
2016-08-12 05:19:29 +00:00
|
|
|
mIsUnsafe = innerJARChannel->GetIsUnsafe();
|
2007-11-27 05:32:23 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-09 22:41:04 +00:00
|
|
|
|
|
|
|
channel->GetContentDispositionHeader(mContentDispositionHeader);
|
|
|
|
mContentDisposition = NS_GetContentDispositionFromHeader(mContentDispositionHeader, this);
|
2007-11-27 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
2015-08-05 03:55:00 +00:00
|
|
|
// This is a defense-in-depth check for the preferences to see if all remote jar
|
|
|
|
// support should be disabled. This check may not be needed.
|
|
|
|
MOZ_RELEASE_ASSERT(!mBlockRemoteFiles);
|
|
|
|
|
2011-06-12 02:30:15 +00:00
|
|
|
if (NS_SUCCEEDED(status) && mIsUnsafe &&
|
2011-09-29 06:19:26 +00:00
|
|
|
!Preferences::GetBool("network.jar.open-unsafe-types", false)) {
|
2011-06-12 02:30:15 +00:00
|
|
|
status = NS_ERROR_UNSAFE_CONTENT_TYPE;
|
2007-11-27 04:35:00 +00:00
|
|
|
}
|
|
|
|
|
2009-03-10 21:58:00 +00:00
|
|
|
if (NS_SUCCEEDED(status)) {
|
|
|
|
// Refuse to unpack view-source: jars even if open-unsafe-types is set.
|
|
|
|
nsCOMPtr<nsIViewSourceChannel> viewSource = do_QueryInterface(channel);
|
|
|
|
if (viewSource) {
|
|
|
|
status = NS_ERROR_UNSAFE_CONTENT_TYPE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
if (NS_SUCCEEDED(status)) {
|
2015-03-11 00:00:01 +00:00
|
|
|
mTempMem = Move(aData);
|
2012-11-28 18:12:56 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsJARInputThunk> input;
|
2012-11-28 18:12:56 +00:00
|
|
|
rv = CreateJarInput(nullptr, getter_AddRefs(input));
|
2003-01-18 02:15:14 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// create input stream pump
|
2017-11-22 10:18:57 +00:00
|
|
|
rv = NS_NewInputStreamPump(getter_AddRefs(mPump), input.forget());
|
2003-01-18 02:15:14 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-07-30 14:20:58 +00:00
|
|
|
rv = mPump->AsyncRead(this, nullptr);
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
|
|
|
status = rv;
|
2001-09-14 21:19:41 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(status)) {
|
2013-02-15 22:27:21 +00:00
|
|
|
NotifyError(status);
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIStreamListener
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1999-11-07 21:55:12 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::OnStartRequest(nsIRequest *req, nsISupports *ctx)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2016-12-16 03:16:31 +00:00
|
|
|
LOG(("nsJARChannel::OnStartRequest [this=%p %s]\n", this, mSpec.get()));
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2014-06-17 16:39:23 +00:00
|
|
|
mRequest = req;
|
|
|
|
nsresult rv = mListener->OnStartRequest(this, mListenerContext);
|
|
|
|
mRequest = nullptr;
|
|
|
|
|
|
|
|
return rv;
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
|
|
|
|
2000-04-13 09:20:50 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::OnStopRequest(nsIRequest *req, nsISupports *ctx, nsresult status)
|
2000-04-13 09:20:50 +00:00
|
|
|
{
|
2016-12-16 03:16:31 +00:00
|
|
|
LOG(("nsJARChannel::OnStopRequest [this=%p %s status=%" PRIx32 "]\n",
|
|
|
|
this, mSpec.get(), static_cast<uint32_t>(status)));
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mStatus))
|
|
|
|
mStatus = status;
|
|
|
|
|
|
|
|
if (mListener) {
|
|
|
|
mListener->OnStopRequest(this, mListenerContext, status);
|
2016-11-10 03:11:27 +00:00
|
|
|
mListener = nullptr;
|
|
|
|
mListenerContext = nullptr;
|
2003-01-18 02:15:14 +00:00
|
|
|
}
|
2000-04-13 09:20:50 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
if (mLoadGroup)
|
2012-07-30 14:20:58 +00:00
|
|
|
mLoadGroup->RemoveRequest(this, nullptr, status);
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2016-11-10 03:11:27 +00:00
|
|
|
mPump = nullptr;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsPending = false;
|
2005-08-12 22:53:22 +00:00
|
|
|
|
|
|
|
// Drop notification callbacks to prevent cycles.
|
2016-11-10 03:11:27 +00:00
|
|
|
mCallbacks = nullptr;
|
|
|
|
mProgressSink = nullptr;
|
2005-08-12 22:53:22 +00:00
|
|
|
|
2014-08-21 11:09:35 +00:00
|
|
|
#if defined(XP_WIN) || defined(MOZ_WIDGET_COCOA)
|
|
|
|
#else
|
2015-07-30 08:05:57 +00:00
|
|
|
// To deallocate file descriptor by RemoteOpenFileChild destructor.
|
|
|
|
mJarFile = nullptr;
|
2014-08-21 11:09:35 +00:00
|
|
|
#endif
|
2014-07-18 02:46:22 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-11-07 21:55:12 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::OnDataAvailable(nsIRequest *req, nsISupports *ctx,
|
|
|
|
nsIInputStream *stream,
|
2012-09-06 02:41:02 +00:00
|
|
|
uint64_t offset, uint32_t count)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2016-12-16 03:16:31 +00:00
|
|
|
LOG(("nsJARChannel::OnDataAvailable [this=%p %s]\n", this, mSpec.get()));
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = mListener->OnDataAvailable(this, mListenerContext, stream, offset, count);
|
|
|
|
|
|
|
|
// simply report progress here instead of hooking ourselves up as a
|
|
|
|
// nsITransportEventSink implementation.
|
2010-08-30 20:20:39 +00:00
|
|
|
// XXX do the 64-bit stuff for real
|
2014-06-17 16:39:23 +00:00
|
|
|
if (mProgressSink && NS_SUCCEEDED(rv)) {
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
FireOnProgress(offset + count);
|
|
|
|
} else {
|
2016-05-05 08:45:00 +00:00
|
|
|
NS_DispatchToMainThread(NewRunnableMethod
|
2017-06-12 19:34:10 +00:00
|
|
|
<uint64_t>("nsJARChannel::FireOnProgress",
|
|
|
|
this,
|
2016-05-05 08:45:00 +00:00
|
|
|
&nsJARChannel::FireOnProgress,
|
|
|
|
offset + count));
|
2014-06-17 16:39:23 +00:00
|
|
|
}
|
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
return rv; // let the pump cancel on failure
|
|
|
|
}
|
2014-06-17 16:39:23 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::RetargetDeliveryTo(nsIEventTarget* aEventTarget)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThreadRetargetableRequest> request = do_QueryInterface(mRequest);
|
|
|
|
if (!request) {
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return request->RetargetDeliveryTo(aEventTarget);
|
|
|
|
}
|
|
|
|
|
2017-10-15 01:30:38 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::GetDeliveryTarget(nsIEventTarget** aEventTarget)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThreadRetargetableRequest> request = do_QueryInterface(mRequest);
|
|
|
|
if (!request) {
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return request->GetDeliveryTarget(aEventTarget);
|
|
|
|
}
|
|
|
|
|
2014-06-17 16:39:23 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::CheckListenerChain()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
|
|
|
|
nsCOMPtr<nsIThreadRetargetableStreamListener> listener =
|
|
|
|
do_QueryInterface(mListener);
|
|
|
|
if (!listener) {
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return listener->CheckListenerChain();
|
|
|
|
}
|