2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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-09-17 20:12:41 +04:00
|
|
|
|
2005-01-24 02:03:39 +03:00
|
|
|
#include "nsAutoPtr.h"
|
1999-09-17 20:12:41 +04:00
|
|
|
#include "nsJARProtocolHandler.h"
|
|
|
|
#include "nsIIOService.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsIServiceManager.h"
|
1999-11-08 00:55:12 +03:00
|
|
|
#include "nsJARURI.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsJARChannel.h"
|
2002-03-06 10:48:55 +03:00
|
|
|
#include "nsString.h"
|
2001-04-10 10:01:08 +04:00
|
|
|
#include "nsNetCID.h"
|
2001-11-30 01:29:00 +03:00
|
|
|
#include "nsIMIMEService.h"
|
|
|
|
#include "nsMimeTypes.h"
|
2013-02-16 02:27:21 +04:00
|
|
|
#include "nsThreadUtils.h"
|
1999-09-17 20:12:41 +04:00
|
|
|
|
2000-05-25 12:32:09 +04:00
|
|
|
static NS_DEFINE_CID(kZipReaderCacheCID, NS_ZIPREADERCACHE_CID);
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
#define NS_JAR_CACHE_SIZE 32
|
1999-09-17 20:12:41 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsJARProtocolHandler *gJarHandler = nullptr;
|
1999-09-17 20:12:41 +04:00
|
|
|
|
|
|
|
nsJARProtocolHandler::nsJARProtocolHandler()
|
|
|
|
{
|
2013-02-16 02:27:21 +04:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2003-01-18 05:15:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsJARProtocolHandler::~nsJARProtocolHandler()
|
|
|
|
{
|
2013-12-18 20:20:45 +04:00
|
|
|
MOZ_ASSERT(gJarHandler == this);
|
|
|
|
gJarHandler = nullptr;
|
1999-09-17 20:12:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsJARProtocolHandler::Init()
|
|
|
|
{
|
2000-05-25 12:32:09 +04:00
|
|
|
nsresult rv;
|
2004-11-01 21:50:36 +03:00
|
|
|
|
|
|
|
mJARCache = do_CreateInstance(kZipReaderCacheCID, &rv);
|
2000-05-25 12:32:09 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mJARCache->Init(NS_JAR_CACHE_SIZE);
|
|
|
|
return rv;
|
1999-09-17 20:12:41 +04:00
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
nsIMIMEService *
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARProtocolHandler::MimeService()
|
2001-11-30 01:29:00 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (!mMimeService)
|
2003-09-16 20:12:59 +04:00
|
|
|
mMimeService = do_GetService("@mozilla.org/mime;1");
|
2001-11-30 01:29:00 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
return mMimeService.get();
|
1999-09-17 20:12:41 +04:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsJARProtocolHandler,
|
|
|
|
nsIJARProtocolHandler,
|
|
|
|
nsIProtocolHandler,
|
|
|
|
nsISupportsWeakReference)
|
1999-09-17 20:12:41 +04:00
|
|
|
|
2017-10-17 07:08:42 +03:00
|
|
|
already_AddRefed<nsJARProtocolHandler>
|
2005-09-16 11:09:35 +04:00
|
|
|
nsJARProtocolHandler::GetSingleton()
|
1999-09-17 20:12:41 +04:00
|
|
|
{
|
2005-09-16 11:09:35 +04:00
|
|
|
if (!gJarHandler) {
|
2017-10-17 07:08:42 +03:00
|
|
|
auto jar = MakeRefPtr<nsJARProtocolHandler>();
|
|
|
|
gJarHandler = jar.get();
|
|
|
|
if (NS_FAILED(jar->Init())) {
|
|
|
|
gJarHandler = nullptr;
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2005-09-16 11:09:35 +04:00
|
|
|
}
|
2017-10-26 09:05:02 +03:00
|
|
|
// We release this reference on module shutdown.
|
|
|
|
NS_ADDREF(gJarHandler);
|
2017-10-17 07:08:42 +03:00
|
|
|
return jar.forget();
|
1999-09-17 20:12:41 +04:00
|
|
|
}
|
2017-10-17 07:08:42 +03:00
|
|
|
return do_AddRef(gJarHandler);
|
1999-09-17 20:12:41 +04:00
|
|
|
}
|
|
|
|
|
2000-05-25 12:32:09 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARProtocolHandler::GetJARCache(nsIZipReaderCache* *result)
|
|
|
|
{
|
|
|
|
*result = mJARCache;
|
|
|
|
NS_ADDREF(*result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-17 20:12:41 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIProtocolHandler methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsJARProtocolHandler::GetScheme(nsACString &result)
|
1999-09-17 20:12:41 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
result.AssignLiteral("jar");
|
1999-09-17 20:12:41 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJARProtocolHandler::GetDefaultPort(int32_t *result)
|
1999-09-17 20:12:41 +04:00
|
|
|
{
|
|
|
|
*result = -1; // no port for JAR: URLs
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-08-08 00:42:57 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJARProtocolHandler::GetProtocolFlags(uint32_t *result)
|
2001-08-08 00:42:57 +04:00
|
|
|
{
|
2006-11-11 02:49:08 +03:00
|
|
|
// URI_LOADABLE_BY_ANYONE, since it's our inner URI that will matter
|
|
|
|
// anyway.
|
|
|
|
*result = URI_NORELATIVE | URI_NOAUTH | URI_LOADABLE_BY_ANYONE;
|
2001-08-08 00:42:57 +04:00
|
|
|
/* Although jar uris have their own concept of relative urls
|
|
|
|
it is very different from the standard behaviour, so we
|
|
|
|
have to say norelative here! */
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-17 20:12:41 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsJARProtocolHandler::NewURI(const nsACString &aSpec,
|
|
|
|
const char *aCharset,
|
|
|
|
nsIURI *aBaseURI,
|
1999-11-08 00:55:12 +03:00
|
|
|
nsIURI **result)
|
1999-09-17 20:12:41 +04:00
|
|
|
{
|
2000-05-06 03:39:25 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsJARURI> jarURI = new nsJARURI();
|
2002-03-06 10:48:55 +03:00
|
|
|
if (!jarURI)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
rv = jarURI->Init(aCharset);
|
2005-01-24 02:03:39 +03:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2000-05-06 03:39:25 +04:00
|
|
|
|
2005-01-24 02:03:39 +03:00
|
|
|
rv = jarURI->SetSpecWithBase(aSpec, aBaseURI);
|
|
|
|
if (NS_FAILED(rv))
|
1999-11-08 00:55:12 +03:00
|
|
|
return rv;
|
|
|
|
|
2005-01-24 02:03:39 +03:00
|
|
|
NS_ADDREF(*result = jarURI);
|
1999-11-08 00:55:12 +03:00
|
|
|
return rv;
|
1999-09-17 20:12:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-10-23 04:16:57 +04:00
|
|
|
nsJARProtocolHandler::NewChannel2(nsIURI* uri,
|
|
|
|
nsILoadInfo* aLoadInfo,
|
|
|
|
nsIChannel** result)
|
1999-09-17 20:12:41 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
nsJARChannel *chan = new nsJARChannel();
|
|
|
|
if (!chan)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(chan);
|
1999-11-08 00:55:12 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult rv = chan->Init(uri);
|
1999-11-08 00:55:12 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_RELEASE(chan);
|
1999-11-08 00:55:12 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-12-12 20:07:23 +03:00
|
|
|
// set the loadInfo on the new channel
|
|
|
|
rv = chan->SetLoadInfo(aLoadInfo);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(chan);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
*result = chan;
|
1999-11-08 00:55:12 +03:00
|
|
|
return NS_OK;
|
1999-09-17 20:12:41 +04:00
|
|
|
}
|
|
|
|
|
2014-10-23 04:16:57 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsJARProtocolHandler::NewChannel(nsIURI *uri, nsIChannel **result)
|
|
|
|
{
|
|
|
|
return NewChannel2(uri, nullptr, result);
|
|
|
|
}
|
|
|
|
|
2001-06-06 04:10:09 +04:00
|
|
|
|
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-22 00:51:34 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsJARProtocolHandler::AllowPort(int32_t port, const char *scheme, bool *_retval)
|
2001-06-06 04:10:09 +04:00
|
|
|
{
|
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-22 00:51:34 +04:00
|
|
|
// don't override anything.
|
2011-10-17 18:59:28 +04:00
|
|
|
*_retval = false;
|
2001-06-06 04:10:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-17 20:12:41 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|