2018-11-30 19:52:05 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2018-11-30 15:39:55 +00:00
|
|
|
/* vim:set ts=4 sw=2 sts=2 et cin: */
|
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/. */
|
2000-02-06 01:30:16 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
A protocol handler for ``chrome:''
|
|
|
|
|
|
|
|
*/
|
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
|
|
|
|
2004-10-13 19:05:48 +00:00
|
|
|
#include "nsChromeProtocolHandler.h"
|
2005-02-22 21:49:45 +00:00
|
|
|
#include "nsChromeRegistry.h"
|
1999-12-04 07:45:57 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2017-07-10 21:24:54 +00:00
|
|
|
#include "nsContentUtils.h"
|
2006-05-10 17:30:15 +00:00
|
|
|
#include "nsThreadUtils.h"
|
1999-08-29 21:58:42 +00:00
|
|
|
#include "nsIChannel.h"
|
2004-10-13 19:05:48 +00:00
|
|
|
#include "nsIChromeRegistry.h"
|
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
|
|
|
#include "nsIFile.h"
|
|
|
|
#include "nsIFileChannel.h"
|
2004-12-02 02:13:20 +00:00
|
|
|
#include "nsIStandardURL.h"
|
2004-09-07 18:59:07 +00:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 02:17:00 +00:00
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "nsIURL.h"
|
2002-03-06 07:48:55 +00:00
|
|
|
#include "nsString.h"
|
2015-04-02 14:12:27 +00:00
|
|
|
#include "nsStandardURL.h"
|
2000-02-06 01:30:16 +00:00
|
|
|
|
2004-10-13 19:05:48 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS(nsChromeProtocolHandler, nsIProtocolHandler,
|
|
|
|
nsISupportsWeakReference)
|
2004-10-13 19:05:48 +00:00
|
|
|
|
1999-07-02 04:15:43 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIProtocolHandler methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-10-13 19:05:48 +00:00
|
|
|
nsChromeProtocolHandler::GetScheme(nsACString& result) {
|
2004-09-07 18:59:07 +00:00
|
|
|
result.AssignLiteral("chrome");
|
1999-07-02 04:15:43 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
nsChromeProtocolHandler::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;
|
|
|
|
}
|
|
|
|
|
2019-03-19 15:11:31 +00:00
|
|
|
/* static */ nsresult nsChromeProtocolHandler::CreateNewURI(
|
|
|
|
const nsACString& aSpec, const char* aCharset, nsIURI* aBaseURI,
|
|
|
|
nsIURI** result) {
|
2004-12-02 02:13:20 +00:00
|
|
|
// Chrome: URLs (currently) have no additional structure beyond that provided
|
|
|
|
// by standard URLs, so there is no "outer" given to CreateInstance
|
2018-01-24 19:33:02 +00:00
|
|
|
nsresult rv;
|
2018-02-26 19:43:45 +00:00
|
|
|
nsCOMPtr<nsIURI> surl;
|
2021-08-12 07:40:58 +00:00
|
|
|
rv =
|
|
|
|
NS_MutateURI(new mozilla::net::nsStandardURL::Mutator())
|
|
|
|
.Apply(&nsIStandardURLMutator::Init, nsIStandardURL::URLTYPE_STANDARD,
|
2021-08-12 07:40:58 +00:00
|
|
|
-1, aSpec, aCharset, aBaseURI, nullptr)
|
2021-08-12 07:40:58 +00:00
|
|
|
|
|
|
|
.Finalize(surl);
|
2018-01-24 19:33:02 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-01-05 16:26:59 +00:00
|
|
|
return rv;
|
2018-01-24 19:33:02 +00:00
|
|
|
}
|
2003-01-05 16:26:59 +00:00
|
|
|
|
2004-12-02 02:13:20 +00:00
|
|
|
// Canonify the "chrome:" URL; e.g., so that we collapse
|
|
|
|
// "chrome://navigator/content/" and "chrome://navigator/content"
|
|
|
|
// and "chrome://navigator/content/navigator.xul".
|
|
|
|
|
2015-04-02 14:12:27 +00:00
|
|
|
rv = nsChromeRegistry::Canonify(surl);
|
2022-10-24 15:21:29 +00:00
|
|
|
mozilla::Unused << NS_WARN_IF(NS_FAILED(rv));
|
2004-12-02 02:13:20 +00:00
|
|
|
|
2015-04-02 14:12:27 +00:00
|
|
|
surl.forget(result);
|
2003-01-05 16:26:59 +00:00
|
|
|
return NS_OK;
|
1999-07-02 04:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2019-02-19 18:20:37 +00:00
|
|
|
nsChromeProtocolHandler::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo,
|
|
|
|
nsIChannel** aResult) {
|
2006-01-25 20:23:24 +00:00
|
|
|
nsresult rv;
|
|
|
|
|
2003-01-05 16:26:59 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
2017-05-30 16:07:59 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aLoadInfo);
|
|
|
|
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(aResult, "Null out param");
|
2008-12-09 21:27:42 +00:00
|
|
|
|
2018-02-26 19:43:45 +00:00
|
|
|
nsCOMPtr<nsIURI> debugURL = aURI;
|
2022-10-24 15:21:29 +00:00
|
|
|
rv = nsChromeRegistry::Canonify(debugURL);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-01-05 16:26:59 +00:00
|
|
|
|
1999-12-04 07:45:57 +00:00
|
|
|
nsCOMPtr<nsIChannel> result;
|
1999-07-02 04:15:43 +00:00
|
|
|
|
2009-01-29 23:34:24 +00:00
|
|
|
if (!nsChromeRegistry::gChromeRegistry) {
|
|
|
|
// We don't actually want this ref, we just want the service to
|
|
|
|
// initialize if it hasn't already.
|
2020-06-16 23:32:21 +00:00
|
|
|
nsCOMPtr<nsIChromeRegistry> reg = mozilla::services::GetChromeRegistry();
|
2005-02-25 21:11:46 +00:00
|
|
|
NS_ENSURE_TRUE(nsChromeRegistry::gChromeRegistry, NS_ERROR_FAILURE);
|
2009-01-29 23:34:24 +00:00
|
|
|
}
|
2004-12-02 02:13:20 +00:00
|
|
|
|
2009-01-29 23:34:24 +00:00
|
|
|
nsCOMPtr<nsIURI> resolvedURI;
|
|
|
|
rv = nsChromeRegistry::gChromeRegistry->ConvertChromeURL(
|
|
|
|
aURI, getter_AddRefs(resolvedURI));
|
|
|
|
if (NS_FAILED(rv)) {
|
2004-12-02 02:13:20 +00:00
|
|
|
#ifdef DEBUG
|
2016-08-26 06:02:31 +00:00
|
|
|
printf("Couldn't convert chrome URL: %s\n", aURI->GetSpecOrDefault().get());
|
2004-12-02 02:13:20 +00:00
|
|
|
#endif
|
2009-01-29 23:34:24 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2017-05-30 16:07:59 +00:00
|
|
|
// We don't want to allow the inner protocol handler modify the result
|
|
|
|
// principal URI since we want either |aURI| or anything pre-set by upper
|
|
|
|
// layers to prevail.
|
|
|
|
nsCOMPtr<nsIURI> savedResultPrincipalURI;
|
|
|
|
rv =
|
|
|
|
aLoadInfo->GetResultPrincipalURI(getter_AddRefs(savedResultPrincipalURI));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2015-02-19 19:47:59 +00:00
|
|
|
rv = NS_NewChannelInternal(getter_AddRefs(result), resolvedURI, aLoadInfo);
|
2009-01-29 23:34:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1999-12-04 07:45:57 +00:00
|
|
|
|
2009-01-29 23:34:24 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIFileChannel> fileChan(do_QueryInterface(result));
|
|
|
|
if (fileChan) {
|
|
|
|
nsCOMPtr<nsIFile> file;
|
|
|
|
fileChan->GetFile(getter_AddRefs(file));
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool exists = false;
|
2009-01-29 23:34:24 +00:00
|
|
|
file->Exists(&exists);
|
|
|
|
if (!exists) {
|
2017-12-17 14:56:09 +00:00
|
|
|
printf("Chrome file doesn't exist: %s\n",
|
|
|
|
file->HumanReadablePath().get());
|
2009-01-29 23:34:24 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
}
|
2009-01-29 23:34:24 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// Make sure that the channel remembers where it was
|
|
|
|
// originally loaded from.
|
2017-05-30 16:07:59 +00:00
|
|
|
rv = aLoadInfo->SetResultPrincipalURI(savedResultPrincipalURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-01-29 23:34:24 +00:00
|
|
|
rv = result->SetOriginalURI(aURI);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2023-10-12 08:59:50 +00:00
|
|
|
// Use a system principal for /content and /skin files.
|
|
|
|
// See bug 1855225 for discussion about whether to extend it more generally
|
|
|
|
// to other chrome:// URIs.
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString path;
|
2023-10-12 08:59:50 +00:00
|
|
|
aURI->GetPathQueryRef(path);
|
|
|
|
if (StringBeginsWith(path, "/content/"_ns) ||
|
|
|
|
StringBeginsWith(path, "/skin/"_ns)) {
|
2017-07-10 21:24:54 +00:00
|
|
|
result->SetOwner(nsContentUtils::GetSystemPrincipal());
|
2009-01-29 23:34:24 +00:00
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-08-12 19:42:36 +00:00
|
|
|
// XXX Removed dependency-tracking code from here, because we're not
|
|
|
|
// tracking them anyways (with fastload we checked only in DEBUG
|
|
|
|
// and with startupcache not at all), but this is where we would start
|
|
|
|
// if we need to re-add.
|
|
|
|
// See bug 531886, bug 533038.
|
2010-12-23 00:49:52 +00:00
|
|
|
result->SetContentCharset("UTF-8"_ns);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2023-10-12 08:59:50 +00:00
|
|
|
result.forget(aResult);
|
1999-12-04 07:45:57 +00:00
|
|
|
return NS_OK;
|
1999-07-02 04:15:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|