2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00: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 16:12:41 +00:00
|
|
|
|
2017-10-29 23:02:40 +00:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
1999-09-17 16:12:41 +00:00
|
|
|
#include "nsJARProtocolHandler.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "nsComponentManagerUtils.h"
|
1999-09-17 16:12:41 +00:00
|
|
|
#include "nsCRT.h"
|
1999-11-07 21:55:12 +00:00
|
|
|
#include "nsJARURI.h"
|
|
|
|
#include "nsJARChannel.h"
|
2002-03-06 07:48:55 +00:00
|
|
|
#include "nsString.h"
|
2001-04-10 06:01:08 +00:00
|
|
|
#include "nsNetCID.h"
|
2001-11-29 22:29:00 +00:00
|
|
|
#include "nsIMIMEService.h"
|
|
|
|
#include "nsMimeTypes.h"
|
2013-02-15 22:27:21 +00:00
|
|
|
#include "nsThreadUtils.h"
|
1999-09-17 16:12:41 +00:00
|
|
|
|
2000-05-25 08:32:09 +00:00
|
|
|
static NS_DEFINE_CID(kZipReaderCacheCID, NS_ZIPREADERCACHE_CID);
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
#define NS_JAR_CACHE_SIZE 32
|
1999-09-17 16:12:41 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2017-10-29 23:02:40 +00:00
|
|
|
StaticRefPtr<nsJARProtocolHandler> gJarHandler;
|
1999-09-17 16:12:41 +00:00
|
|
|
|
|
|
|
nsJARProtocolHandler::nsJARProtocolHandler() { MOZ_ASSERT(NS_IsMainThread()); }
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
nsJARProtocolHandler::~nsJARProtocolHandler() {}
|
1999-09-17 16:12:41 +00:00
|
|
|
|
|
|
|
nsresult nsJARProtocolHandler::Init() {
|
2000-05-25 08:32:09 +00:00
|
|
|
nsresult rv;
|
2004-11-01 18:50:36 +00:00
|
|
|
|
|
|
|
mJARCache = do_CreateInstance(kZipReaderCacheCID, &rv);
|
2000-05-25 08:32:09 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = mJARCache->Init(NS_JAR_CACHE_SIZE);
|
|
|
|
return rv;
|
1999-09-17 16:12:41 +00:00
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsIMIMEService* nsJARProtocolHandler::MimeService() {
|
2003-09-16 16:12:59 +00:00
|
|
|
if (!mMimeService) mMimeService = do_GetService("@mozilla.org/mime;1");
|
2001-11-29 22:29:00 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
return mMimeService.get();
|
1999-09-17 16:12:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-26 15:29:37 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsJARProtocolHandler, nsIProtocolHandler,
|
|
|
|
nsISupportsWeakReference)
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-10-17 04:08:42 +00:00
|
|
|
already_AddRefed<nsJARProtocolHandler> nsJARProtocolHandler::GetSingleton() {
|
2005-09-16 07:09:35 +00:00
|
|
|
if (!gJarHandler) {
|
2017-10-29 23:02:40 +00:00
|
|
|
gJarHandler = new nsJARProtocolHandler();
|
|
|
|
if (NS_SUCCEEDED(gJarHandler->Init())) {
|
|
|
|
ClearOnShutdown(&gJarHandler);
|
|
|
|
} else {
|
2017-10-17 04:08:42 +00:00
|
|
|
gJarHandler = nullptr;
|
1999-09-17 16:12:41 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2017-10-17 04:08:42 +00:00
|
|
|
return do_AddRef(gJarHandler);
|
1999-09-17 16:12:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIProtocolHandler methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 07:48:55 +00:00
|
|
|
nsJARProtocolHandler::GetScheme(nsACString& result) {
|
2004-06-17 00:13:25 +00:00
|
|
|
result.AssignLiteral("jar");
|
1999-09-17 16:12:41 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-02-19 18:20:37 +00:00
|
|
|
nsJARProtocolHandler::NewChannel(nsIURI* uri, nsILoadInfo* aLoadInfo,
|
|
|
|
nsIChannel** result) {
|
2003-01-18 02:15:14 +00:00
|
|
|
nsJARChannel* chan = new nsJARChannel();
|
|
|
|
if (!chan) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(chan);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
nsresult rv = chan->Init(uri);
|
1999-11-07 21:55:12 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-01-18 02:15:14 +00:00
|
|
|
NS_RELEASE(chan);
|
1999-11-07 21:55:12 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2014-12-12 17:07:23 +00:00
|
|
|
// set the loadInfo on the new channel
|
|
|
|
rv = chan->SetLoadInfo(aLoadInfo);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(chan);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
*result = chan;
|
1999-11-07 21:55:12 +00:00
|
|
|
return NS_OK;
|
1999-09-17 16:12:41 +00: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-21 20:51:34 +00:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsJARProtocolHandler::AllowPort(int32_t port, const char* scheme,
|
|
|
|
bool* _retval) {
|
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
|
|
|
// don't override anything.
|
2011-10-17 14:59:28 +00:00
|
|
|
*_retval = false;
|
2001-06-06 00:10:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-17 16:12:41 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|