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"
|
2009-02-19 20:25:18 +00:00
|
|
|
#include "nsChannelProperties.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
|
|
|
|
2011-06-12 02:30:15 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2012-12-22 13:56:21 +00:00
|
|
|
#include "mozilla/net/RemoteOpenFileChild.h"
|
|
|
|
#include "nsITabChild.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
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
//
|
2003-01-18 02:15:14 +00:00
|
|
|
// set NSPR_LOG_MODULES=nsJarProtocol:5
|
2000-03-30 07:39:31 +00:00
|
|
|
//
|
2012-07-30 14:20:58 +00:00
|
|
|
static PRLogModuleInfo *gJarProtocolLog = nullptr;
|
2003-01-18 02:15:14 +00:00
|
|
|
#endif
|
2000-03-30 07:39:31 +00:00
|
|
|
|
2013-01-29 22:30:13 +00:00
|
|
|
// If you ever want to define PR_FORCE_LOGGING in this file, see bug 545995
|
2003-01-18 02:15:14 +00:00
|
|
|
#define LOG(args) PR_LOG(gJarProtocolLog, PR_LOG_DEBUG, args)
|
|
|
|
#define LOG_ENABLED() PR_LOG_TEST(gJarProtocolLog, 4)
|
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:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
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
|
|
|
|
|
|
|
virtual ~nsJARInputThunk()
|
|
|
|
{
|
2012-11-28 18:12:56 +00:00
|
|
|
Close();
|
2003-01-28 19:13:52 +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:
|
|
|
|
|
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
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS1(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)
|
|
|
|
, mAppURI(nullptr)
|
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)
|
|
|
|
, mIsUnsafe(true)
|
2012-12-22 13:56:21 +00:00
|
|
|
, mOpeningRemote(false)
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
if (!gJarProtocolLog)
|
|
|
|
gJarProtocolLog = PR_NewLogModule("nsJarProtocol");
|
|
|
|
#endif
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
// hold an owning reference to the jar handler
|
|
|
|
NS_ADDREF(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
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
// release owning reference to the jar handler
|
|
|
|
nsJARProtocolHandler *handler = gJarHandler;
|
|
|
|
NS_RELEASE(handler); // NULL parameter
|
2000-03-29 03:58:50 +00:00
|
|
|
}
|
|
|
|
|
2012-12-22 13:56:21 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED7(nsJARChannel,
|
2009-02-19 20:25:18 +00:00
|
|
|
nsHashPropertyBag,
|
|
|
|
nsIRequest,
|
|
|
|
nsIChannel,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver,
|
|
|
|
nsIDownloadObserver,
|
2012-12-22 13:56:21 +00:00
|
|
|
nsIRemoteOpenFileListener,
|
2009-02-19 20:25:18 +00:00
|
|
|
nsIJARChannel)
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsJARChannel::Init(nsIURI *uri)
|
2000-03-30 07:39:31 +00:00
|
|
|
{
|
2000-08-24 22:35:46 +00:00
|
|
|
nsresult rv;
|
2009-02-19 20:25:18 +00:00
|
|
|
rv = nsHashPropertyBag::Init();
|
|
|
|
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
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
mJarURI->GetSpec(mSpec);
|
2001-09-18 23:07:57 +00:00
|
|
|
#endif
|
2003-01-18 02:15:14 +00:00
|
|
|
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
|
|
|
{
|
2012-11-28 18:12:56 +00:00
|
|
|
MOZ_ASSERT(resultInput);
|
|
|
|
|
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;
|
|
|
|
nsresult rv = mJarFile->Clone(getter_AddRefs(clonedFile));
|
2010-09-09 03:38:34 +00:00
|
|
|
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;
|
|
|
|
if (jarCache) {
|
|
|
|
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;
|
|
|
|
|
2012-12-22 13:56:21 +00:00
|
|
|
rv = outerReader->Open(clonedFile);
|
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;
|
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
nsRefPtr<nsJARInputThunk> input = new nsJARInputThunk(reader,
|
|
|
|
mJarURI,
|
|
|
|
mJarEntry,
|
|
|
|
jarCache != nullptr
|
|
|
|
);
|
|
|
|
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
|
2012-11-28 18:12:56 +00:00
|
|
|
nsJARChannel::LookupFile()
|
1999-11-07 21:55:12 +00:00
|
|
|
{
|
2012-11-28 18:12:56 +00:00
|
|
|
LOG(("nsJARChannel::LookupFile [this=%x %s]\n", this, mSpec.get()));
|
2000-03-30 07:39:31 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
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);
|
|
|
|
|
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
|
|
|
}
|
2012-12-22 13:56:21 +00:00
|
|
|
// if we're in child process and have special "remoteopenfile:://" scheme,
|
|
|
|
// create special nsIFile that gets file handle from parent when opened.
|
2013-02-15 22:27:21 +00:00
|
|
|
if (!mJarFile && !gJarHandler->IsMainProcess()) {
|
2012-12-22 13:56:21 +00:00
|
|
|
nsAutoCString scheme;
|
2013-02-15 22:27:21 +00:00
|
|
|
rv = mJarBaseURI->GetScheme(scheme);
|
2012-12-22 13:56:21 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && scheme.EqualsLiteral("remoteopenfile")) {
|
|
|
|
nsRefPtr<RemoteOpenFileChild> remoteFile = new RemoteOpenFileChild();
|
|
|
|
rv = remoteFile->Init(mJarBaseURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
mJarFile = remoteFile;
|
|
|
|
|
|
|
|
nsIZipReaderCache *jarCache = gJarHandler->JarCache();
|
|
|
|
if (jarCache) {
|
|
|
|
bool cached = false;
|
|
|
|
rv = jarCache->IsCached(mJarFile, &cached);
|
|
|
|
if (NS_SUCCEEDED(rv) && cached) {
|
|
|
|
// zipcache already has file mmapped: don't open on parent,
|
|
|
|
// just return and proceed to cache hit in CreateJarInput()
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-15 22:27:21 +00:00
|
|
|
mOpeningRemote = true;
|
|
|
|
|
|
|
|
if (gJarHandler->RemoteOpenFileInProgress(remoteFile, this)) {
|
|
|
|
// JarHandler will trigger OnRemoteFileOpen() after the first
|
|
|
|
// request for this file completes and we'll get a JAR cache
|
|
|
|
// hit.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-12-22 13:56:21 +00:00
|
|
|
// Open file on parent: OnRemoteFileOpenComplete called when done
|
|
|
|
nsCOMPtr<nsITabChild> tabChild;
|
|
|
|
NS_QueryNotificationCallbacks(mCallbacks, mLoadGroup, tabChild);
|
|
|
|
rv = remoteFile->AsyncRemoteFileOpen(PR_RDONLY, this, tabChild.get());
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2013-02-15 22:27:21 +00:00
|
|
|
nsresult
|
|
|
|
nsJARChannel::OpenLocalFile()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mIsPending);
|
|
|
|
|
|
|
|
// Local files are always considered safe.
|
|
|
|
mIsUnsafe = false;
|
|
|
|
|
|
|
|
nsRefPtr<nsJARInputThunk> input;
|
|
|
|
nsresult rv = CreateJarInput(gJarHandler->JarCache(),
|
|
|
|
getter_AddRefs(input));
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// Create input stream pump and call AsyncRead as a block.
|
|
|
|
rv = NS_NewInputStreamPump(getter_AddRefs(mPump), input);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = mPump->AsyncRead(this, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsJARChannel::NotifyError(nsresult aError)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(NS_FAILED(aError));
|
|
|
|
|
|
|
|
mStatus = aError;
|
|
|
|
|
|
|
|
OnStartRequest(nullptr, nullptr);
|
|
|
|
OnStopRequest(nullptr, nullptr, aError);
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
if (mPump)
|
|
|
|
return mPump->Cancel(status);
|
|
|
|
|
|
|
|
NS_ASSERTION(!mIsPending, "need to implement cancel when downloading");
|
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
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
if (mPump)
|
|
|
|
return mPump->Suspend();
|
1999-11-07 21:55:12 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_ASSERTION(!mIsPending, "need to implement suspend when downloading");
|
|
|
|
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
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
if (mPump)
|
|
|
|
return mPump->Resume();
|
|
|
|
|
|
|
|
NS_ASSERTION(!mIsPending, "need to implement resume when downloading");
|
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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2012-07-11 15:38:36 +00:00
|
|
|
if (mAppURI) {
|
|
|
|
NS_IF_ADDREF(*aURI = mAppURI);
|
|
|
|
} else {
|
|
|
|
NS_IF_ADDREF(*aURI = mJarURI);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-03-17 22:06:32 +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) {
|
|
|
|
result.Assign(UNKNOWN_CONTENT_TYPE);
|
|
|
|
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
|
|
|
|
NS_ParseContentType(aContentType, mContentType, mContentCharset);
|
|
|
|
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
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("nsJARChannel::Open [this=%x]\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
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
nsresult rv = LookupFile();
|
|
|
|
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
|
|
|
|
2012-12-22 13:56:21 +00:00
|
|
|
nsRefPtr<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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::AsyncOpen(nsIStreamListener *listener, nsISupports *ctx)
|
2000-08-24 07:36:53 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("nsJARChannel::AsyncOpen [this=%x]\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);
|
|
|
|
|
2012-11-28 18:12:56 +00:00
|
|
|
nsresult rv = LookupFile();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2009-03-05 12:27:48 +00:00
|
|
|
// These variables must only be set if we're going to trigger an
|
|
|
|
// OnStartRequest, either from AsyncRead or OnDownloadComplete.
|
2012-11-28 18:12:56 +00:00
|
|
|
//
|
|
|
|
// That means: Do not add early return statements beyond this point!
|
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
|
|
|
|
|
|
|
if (!mJarFile) {
|
|
|
|
// Not a local file...
|
|
|
|
// kick off an async download of the base URI...
|
|
|
|
rv = NS_NewDownloader(getter_AddRefs(mDownloader), this);
|
2009-03-05 12:27:48 +00:00
|
|
|
if (NS_SUCCEEDED(rv))
|
2012-11-28 18:12:56 +00:00
|
|
|
rv = NS_OpenURI(mDownloader, nullptr, mJarBaseURI, nullptr,
|
|
|
|
mLoadGroup, mCallbacks,
|
|
|
|
mLoadFlags & ~(LOAD_DOCUMENT_URI | LOAD_CALL_CONTENT_SNIFFERS));
|
2012-12-22 13:56:21 +00:00
|
|
|
} else if (mOpeningRemote) {
|
|
|
|
// nothing to do: already asked parent to open file.
|
|
|
|
} else {
|
2013-02-15 22:27:21 +00:00
|
|
|
rv = OpenLocalFile();
|
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;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
if (mLoadGroup)
|
2012-07-30 14:20:58 +00:00
|
|
|
mLoadGroup->AddRequest(this, nullptr);
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2012-08-27 23:34:30 +00:00
|
|
|
mOpened = true;
|
Bit checkin for bug 68045, r/sr=waterson&shaver, second attempt. It all works
for me on optimized and debug gcc2.96, rh7.1.
- Better failure codes from nsXULPrototypeScript::Deserialize.
- Call nsXULDocument::AbortFastLoads after nsXULPrototypeScript::Serialize
failure, instead of just nulling the FastLoad service's output stream.
- Expose nsXULDocument::AbortFastLoads via nsIXULPrototypeCache, for use from
nsChromeProtocolHandler.cpp. AbortFastLoads flushes the XUL cache now, for
good measure.
- The needless "Current" adjective in nsIFastLoadService attribute and method
names is no more.
- Add a do_GetFastLoadService() helper, to use CID instead of contractid, and
to let the compiler consolidate the static inline CID.
- Add "nglayout.debug.checksum_xul_fastload_file" pref so people can do without
the checksum verification step when reading a FastLoad file.
- Verify the FastLoad file checksum, by default. Also, cache it in the FastLoad
service so we don't recompute it when re-opening the FastLoad file as mailnews
and other top-levels start up. Fill the checksum cache in EndFastLoad, when
the last pseudo-concurrent top-level finishes loading.
My hope to compute the checksum while writing the FastLoad file ran afoul of
misordered writes. The old code to checksum the in-memory nsFastLoadHeader
also was broken on little endian platforms. Now all checksumming is done via
a separate read pass over the complete file, save for the header's checksum
field, which is summed as if it contained zero.
- Track and check FastLoad file dependencies. This required groveling with a
bunch of Necko interfaces in nsChromeProtocolHandler::NewChannel -- read it
and weep. Dependency checking, as well as checksum access and computation,
use better-factored nsIFastLoad{File,Read,Write}Control interfaces.
- nsBufferedStream::Seek wasn't flushing the buffer when seeking backward
within the buffer, but it must, because mCursor bounds the amount to write
if the buffer contains the end of file.
- Add an unbufferedStream readonly attribute to nsIStreamBufferAccess, so we
don't have to screw around with the bufferying layer when checksumming. Also
implement nsIStreamBufferAccess in nsBufferedOutputStream.
- nsISeekableOutputStream was bogus, based on a bad state I had put the
nsBufferedOutputStream code in on its way from being completely broken when
you seek backwards outside of the buffer. Removing this interface required
using nsIFastLoadFileIO in nsFastLoadFileWriter, and it also required careful
ordering of Close calls (the Reader must close after the Writer or Updater,
so that the Reader's underlying, unbuffered input stream can be read by
nsFastLoadFileWriter::Close to compute the checksum.
- Miscellaneous tab/indentation, comment typo, bracing, if( => if ( style,
nsnull vs. 0, useless variable elimination, tortured control flow,
AutoString instead of String, and gratuitous ; after nsISupportsUtils.h
macro call cleanups.
2001-08-21 20:51:34 +00:00
|
|
|
return NS_OK;
|
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;
|
|
|
|
}
|
|
|
|
|
2012-07-11 15:38:36 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARChannel::SetAppURI(nsIURI *aURI) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString scheme;
|
2012-07-11 15:38:36 +00:00
|
|
|
aURI->GetScheme(scheme);
|
|
|
|
if (!scheme.EqualsLiteral("app")) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
mAppURI = aURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIDownloadObserver
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
1999-11-07 21:55:12 +00:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel::OnDownloadComplete(nsIDownloader *downloader,
|
2004-04-21 14:58:45 +00:00
|
|
|
nsIRequest *request,
|
|
|
|
nsISupports *context,
|
2003-06-23 22:58:28 +00:00
|
|
|
nsresult status,
|
|
|
|
nsIFile *file)
|
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) {
|
|
|
|
mLoadFlags |= LOAD_REPLACE;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
// 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;
|
2007-11-27 05:32:23 +00:00
|
|
|
httpChannel->GetResponseHeader(NS_LITERAL_CSTRING("Content-Type"),
|
|
|
|
header);
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString contentType;
|
|
|
|
nsAutoCString charset;
|
2007-11-27 05:32:23 +00:00
|
|
|
NS_ParseContentType(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) {
|
2011-09-29 06:19:26 +00:00
|
|
|
bool unsafe;
|
2007-11-27 05:32:23 +00:00
|
|
|
innerJARChannel->GetIsUnsafe(&unsafe);
|
|
|
|
mIsUnsafe = unsafe;
|
|
|
|
}
|
|
|
|
}
|
2011-09-09 22:41:04 +00:00
|
|
|
|
|
|
|
channel->GetContentDispositionHeader(mContentDispositionHeader);
|
|
|
|
mContentDisposition = NS_GetContentDispositionFromHeader(mContentDispositionHeader, this);
|
2007-11-27 05:32:23 +00:00
|
|
|
}
|
|
|
|
|
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)) {
|
|
|
|
mJarFile = file;
|
2012-11-28 18:12:56 +00:00
|
|
|
|
2012-12-22 13:56:21 +00:00
|
|
|
nsRefPtr<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
|
2012-11-28 18:12:56 +00:00
|
|
|
rv = NS_NewInputStreamPump(getter_AddRefs(mPump), input);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-11-07 21:55:12 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2012-12-22 13:56:21 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsIRemoteOpenFileListener
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
nsresult
|
|
|
|
nsJARChannel::OnRemoteFileOpenComplete(nsresult aOpenStatus)
|
|
|
|
{
|
|
|
|
nsresult rv = aOpenStatus;
|
|
|
|
|
2013-02-15 22:27:21 +00:00
|
|
|
// NS_ERROR_ALREADY_OPENED here means we'll hit JAR cache in
|
|
|
|
// OpenLocalFile().
|
|
|
|
if (NS_SUCCEEDED(rv) || rv == NS_ERROR_ALREADY_OPENED) {
|
|
|
|
rv = OpenLocalFile();
|
2012-12-22 13:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
2013-02-15 22:27:21 +00:00
|
|
|
NotifyError(rv);
|
2012-12-22 13:56:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("nsJARChannel::OnStartRequest [this=%x %s]\n", this, mSpec.get()));
|
|
|
|
|
|
|
|
return mListener->OnStartRequest(this, mListenerContext);
|
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
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("nsJARChannel::OnStopRequest [this=%x %s status=%x]\n",
|
|
|
|
this, mSpec.get(), status));
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(mStatus))
|
|
|
|
mStatus = status;
|
|
|
|
|
|
|
|
if (mListener) {
|
|
|
|
mListener->OnStopRequest(this, mListenerContext, status);
|
|
|
|
mListener = 0;
|
|
|
|
mListenerContext = 0;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
mPump = 0;
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsPending = false;
|
2003-06-23 22:58:28 +00:00
|
|
|
mDownloader = 0; // this may delete the underlying jar file
|
2005-08-12 22:53:22 +00:00
|
|
|
|
|
|
|
// Drop notification callbacks to prevent cycles.
|
|
|
|
mCallbacks = 0;
|
|
|
|
mProgressSink = 0;
|
|
|
|
|
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
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
LOG(("nsJARChannel::OnDataAvailable [this=%x %s]\n", this, mSpec.get()));
|
|
|
|
#endif
|
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
|
2003-01-18 02:15:14 +00:00
|
|
|
if (mProgressSink && NS_SUCCEEDED(rv) && !(mLoadFlags & LOAD_BACKGROUND))
|
2012-09-06 02:41:02 +00:00
|
|
|
mProgressSink->OnProgress(this, nullptr, offset + count,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t(mContentLength));
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
return rv; // let the pump cancel on failure
|
|
|
|
}
|