From 6abf5e7f7312e001dddd3933959186a99783accc Mon Sep 17 00:00:00 2001 From: "brendan%mozilla.org" Date: Tue, 21 Aug 2001 20:51:34 +0000 Subject: [PATCH] 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. git-svn-id: svn://10.0.0.236/trunk@101544 18797224-902f-48f8-a5cc-f745e15eee43 --- .../chrome/src/nsChromeProtocolHandler.cpp | 172 ++-- mozilla/chrome/src/nsChromeRegistry.cpp | 396 ++++---- .../content/xul/content/src/nsXULElement.cpp | 14 +- .../document/public/nsIXULPrototypeCache.h | 5 + .../xul/document/src/nsXULContentSink.cpp | 4 +- .../xul/document/src/nsXULDocument.cpp | 163 ++-- .../xul/document/src/nsXULPrototypeCache.cpp | 10 + mozilla/layout/generic/nsImageFrame.cpp | 1 - mozilla/layout/html/base/src/nsImageFrame.cpp | 1 - mozilla/modules/libjar/nsJAR.cpp | 8 +- mozilla/modules/libjar/nsJARChannel.cpp | 52 +- mozilla/modules/libjar/nsJARChannel.h | 10 +- mozilla/modules/libjar/nsJARInputStream.cpp | 2 +- .../modules/libjar/nsJARProtocolHandler.cpp | 18 +- mozilla/modules/libjar/nsJARURI.cpp | 4 +- mozilla/modules/libjar/nsJARURI.h | 2 +- mozilla/netwerk/base/public/nsIURL.idl | 6 +- mozilla/netwerk/base/src/Makefile.in | 46 +- .../netwerk/base/src/nsBufferedStreams.cpp | 192 ++-- mozilla/netwerk/base/src/nsBufferedStreams.h | 23 +- mozilla/netwerk/base/src/nsFileStreams.cpp | 24 +- mozilla/netwerk/base/src/nsFileStreams.h | 4 +- mozilla/netwerk/base/src/nsStdURL.cpp | 55 +- mozilla/netwerk/base/src/nsStdURL.h | 1 - .../netwerk/protocol/jar/src/nsJARChannel.cpp | 52 +- .../netwerk/protocol/jar/src/nsJARChannel.h | 10 +- .../protocol/jar/src/nsJARProtocolHandler.cpp | 18 +- mozilla/netwerk/protocol/jar/src/nsJARURI.cpp | 4 +- mozilla/netwerk/protocol/jar/src/nsJARURI.h | 2 +- .../netwerk/protocol/res/src/nsResChannel.cpp | 35 +- .../netwerk/protocol/res/src/nsResChannel.h | 4 +- .../protocol/res/src/nsResProtocolHandler.cpp | 29 +- .../chrome/src/nsChromeProtocolHandler.cpp | 172 ++-- mozilla/rdf/chrome/src/nsChromeRegistry.cpp | 396 ++++---- mozilla/xpcom/build/nsXPComInit.cpp | 2 +- mozilla/xpcom/io/nsFastLoadFile.cpp | 842 +++++++++++------- mozilla/xpcom/io/nsFastLoadFile.h | 133 ++- mozilla/xpcom/io/nsFastLoadService.cpp | 258 ++++-- mozilla/xpcom/io/nsFastLoadService.h | 2 + mozilla/xpcom/io/nsIFastLoadFileControl.idl | 60 +- mozilla/xpcom/io/nsIFastLoadService.idl | 70 +- mozilla/xpcom/io/nsISeekableStream.idl | 6 - mozilla/xpcom/io/nsIStreamBufferAccess.idl | 5 + 43 files changed, 1914 insertions(+), 1399 deletions(-) diff --git a/mozilla/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/chrome/src/nsChromeProtocolHandler.cpp index fd60d6342f3..48a6a8dbec7 100644 --- a/mozilla/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/chrome/src/nsChromeProtocolHandler.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -17,7 +17,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ /* @@ -25,29 +25,32 @@ A protocol handler for ``chrome:'' */ - -#include "nsCOMPtr.h" -#include "nsCRT.h" + #include "nsChromeProtocolHandler.h" +#include "nsCOMPtr.h" +#include "nsContentCID.h" +#include "nsCRT.h" #include "nsIChannel.h" -#include "nsIFileChannel.h" #include "nsIChromeRegistry.h" #include "nsIComponentManager.h" #include "nsIEventQueue.h" #include "nsIEventQueueService.h" +#include "nsIFastLoadService.h" +#include "nsIFile.h" +#include "nsIFileChannel.h" #include "nsIIOService.h" -#include "nsILoadGroup.h" -#include "nsIResChannel.h" #include "nsIJARChannel.h" +#include "nsIJARURI.h" +#include "nsILoadGroup.h" +#include "nsIObjectOutputStream.h" +#include "nsIResChannel.h" #include "nsIScriptSecurityManager.h" -#include "nsIStreamListener.h" #include "nsIServiceManager.h" -#include "nsIXULDocument.h" +#include "nsIStreamListener.h" #include "nsIXULPrototypeCache.h" #include "nsIXULPrototypeDocument.h" -#include "nsContentCID.h" -#include "nsXPIDLString.h" #include "nsNetCID.h" +#include "nsXPIDLString.h" #include "prlog.h" //---------------------------------------------------------------------- @@ -127,8 +130,8 @@ public: NS_IMETHOD SetLoadGroup(nsILoadGroup *); NS_IMETHOD GetLoadFlags(nsLoadFlags *); NS_IMETHOD SetLoadFlags(nsLoadFlags); - -// nsIChannel + +// nsIChannel NS_DECL_NSICHANNEL }; @@ -137,8 +140,8 @@ public: PRLogModuleInfo* nsCachedChromeChannel::gLog; #endif -NS_IMPL_ISUPPORTS2(nsCachedChromeChannel, - nsIChannel, +NS_IMPL_ISUPPORTS2(nsCachedChromeChannel, + nsIChannel, nsIRequest); nsresult @@ -267,7 +270,7 @@ nsCachedChromeChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) NS_IMETHODIMP nsCachedChromeChannel::GetLoadFlags(nsLoadFlags *aLoadFlags) { - *aLoadFlags = mLoadFlags; + *aLoadFlags = mLoadFlags; return NS_OK; } @@ -321,7 +324,7 @@ nsCachedChromeChannel::SetNotificationCallbacks(nsIInterfaceRequestor * aNotific return NS_OK; // ignored } -NS_IMETHODIMP +NS_IMETHODIMP nsCachedChromeChannel::GetContentType(char * *aContentType) { *aContentType = nsCRT::strdup("mozilla.application/cached-xul"); @@ -407,7 +410,7 @@ nsCachedChromeChannel::HandleStartLoadEvent(PLEvent* aEvent) // send On[Start|Stop]Request(). if (NS_FAILED(channel->mStatus)) return nsnull; - + PR_LOG(gLog, PR_LOG_DEBUG, ("nsCachedChromeChannel[%p]: firing OnStartRequest for %p", channel, channel->mListener.get())); @@ -432,7 +435,7 @@ nsCachedChromeChannel::HandleStopLoadEvent(PLEvent* aEvent) ("nsCachedChromeChannel[%p]: firing OnStopRequest for %p", channel, channel->mListener.get())); - (void) channel->mListener->OnStopRequest(request, channel->mContext, + (void) channel->mListener->OnStopRequest(request, channel->mContext, channel->mStatus); if (channel->mLoadGroup) { @@ -513,10 +516,10 @@ nsChromeProtocolHandler::GetDefaultPort(PRInt32 *result) return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsChromeProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval) { - // don't override anything. + // don't override anything. *_retval = PR_FALSE; return NS_OK; } @@ -534,31 +537,28 @@ nsChromeProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, { nsresult rv; - // Chrome: URLs (currently) have no additional structure beyond that provided by standard - // URLs, so there is no "outer" given to CreateInstance + // Chrome: URLs (currently) have no additional structure beyond that provided + // by standard URLs, so there is no "outer" given to CreateInstance - nsIURI* url; - rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull, - NS_GET_IID(nsIURI), - (void**)&url); - if (NS_FAILED(rv)) return rv; + nsCOMPtr url(do_CreateInstance(kStandardURLCID, &rv)); + if (NS_FAILED(rv)) + return rv; if (aBaseURI) { nsXPIDLCString aResolvedURI; rv = aBaseURI->Resolve(aSpec, getter_Copies(aResolvedURI)); - if (NS_FAILED(rv)) return rv; - rv = url->SetSpec(aResolvedURI); + if (NS_SUCCEEDED(rv)) + rv = url->SetSpec(aResolvedURI); } else { rv = url->SetSpec((char*)aSpec); } - if (NS_FAILED(rv)) { - NS_RELEASE(url); + if (NS_FAILED(rv)) return rv; - } *result = url; + NS_ADDREF(*result); return rv; } @@ -580,7 +580,7 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, // Check the prototype cache to see if we've already got the // document in the cache. - nsCOMPtr cache = + nsCOMPtr cache = do_GetService(kXULPrototypeCacheCID, &rv); if (NS_FAILED(rv)) return rv; @@ -598,7 +598,7 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, // Miss. Resolve the chrome URL using the registry and do a // normal necko load. nsCOMPtr chromeURI; - rv = aURI->Clone(getter_AddRefs(chromeURI)); // don't mangle the original + rv = aURI->Clone(getter_AddRefs(chromeURI)); // don't mangle the original if (NS_FAILED(rv)) return rv; //nsXPIDLCString oldSpec; @@ -609,31 +609,31 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, rv = reg->ConvertChromeURL(chromeURI, getter_Copies(spec)); if (NS_FAILED(rv)) return rv; - nsCOMPtr serv(do_GetService(kIOServiceCID, &rv)); + nsCOMPtr ioServ(do_GetService(kIOServiceCID, &rv)); if (NS_FAILED(rv)) return rv; - - rv = serv->NewURI(spec, nsnull, getter_AddRefs(chromeURI)); + + rv = ioServ->NewURI(spec, nsnull, getter_AddRefs(chromeURI)); if (NS_FAILED(rv)) return rv; - - rv = serv->NewChannelFromURI(chromeURI, getter_AddRefs(result)); + + rv = ioServ->NewChannelFromURI(chromeURI, getter_AddRefs(result)); if (NS_FAILED(rv)) return rv; // XXX Will be removed someday when we handle remote chrome. - nsCOMPtr jar; - nsCOMPtr res; - nsCOMPtr file; - res = do_QueryInterface(result); - if (!res) { - file = do_QueryInterface(result); - if (!file) - jar = do_QueryInterface(result); + nsCOMPtr fileChan; + nsCOMPtr resChan; + nsCOMPtr jarChan; + fileChan = do_QueryInterface(result); + if (!fileChan) { + resChan = do_QueryInterface(result); + if (!resChan) + jarChan = do_QueryInterface(result); } - if (!res && !file && !jar) { - NS_WARNING("Remote chrome not allowed! Only file:, resource:, and jar: are valid.\n"); - result = nsnull; - return NS_ERROR_FAILURE; + if (!fileChan && !resChan && !jarChan) { + NS_WARNING("Remote chrome not allowed! Only file:, resource:, and jar: are valid.\n"); + result = nsnull; + return NS_ERROR_FAILURE; } - + // Make sure that the channel remembers where it was // originally loaded from. rv = result->SetOriginalURI(aURI); @@ -644,20 +644,76 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, nsCOMPtr url = do_QueryInterface(aURI); nsXPIDLCString fileExtension; rv = url->GetFileExtension(getter_Copies(fileExtension)); - if (PL_strcasecmp(fileExtension, "xul") == 0 || PL_strcasecmp(fileExtension, "html") == 0 || + if (PL_strcasecmp(fileExtension, "xul") == 0 || + PL_strcasecmp(fileExtension, "html") == 0 || PL_strcasecmp(fileExtension, "xml") == 0) { - nsCOMPtr securityManager = + nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; - + nsCOMPtr principal; rv = securityManager->GetSystemPrincipal(getter_AddRefs(principal)); if (NS_FAILED(rv)) return rv; - + nsCOMPtr owner = do_QueryInterface(principal); result->SetOwner(owner); } + + // Track FastLoad file dependencies. + // + // This is harder than it ought to be! While an nsResChannel "is-a" + // nsIFileChannel, an nsJARChannel is not. Once you unravel the jar: + // URI, you may have a resource: URL -- but without a channel for it, + // you can't get the URI that it yields through substitution! + // + // XXXbe fix nsResChannel.cpp to move the substitution code into a new + // nsResURL class? + nsCOMPtr fastLoadServ(do_GetFastLoadService()); + if (fastLoadServ) { + nsCOMPtr objectOutput; + fastLoadServ->GetOutputStream(getter_AddRefs(objectOutput)); + if (objectOutput) { + nsCOMPtr file; + nsCOMPtr chan = result; + while (!fileChan) { + nsCOMPtr uri; + chan->GetURI(getter_AddRefs(uri)); + + // Loop, jar: URIs can nest (e.g. jar:jar:A.jar!B.jar!C.xml). + // Often, however, we have jar:resource:/chrome/A.jar!C.xml. + nsCOMPtr jarURI; + while ((jarURI = do_QueryInterface(uri)) != nsnull) + jarURI->GetJARFile(getter_AddRefs(uri)); + + // Here we must have a URL of the form resource:/chrome/A.jar + // or file:/some/path/to/A.jar. Let's hope for the latter. + nsCOMPtr fileURL(do_QueryInterface(uri)); + if (fileURL) { + fileURL->GetFile(getter_AddRefs(file)); + if (file) + break; + } + + // Thanks to the way that the resource: URL implementation + // hides its substitution code from itself and the rest of + // the world, we must make a new channel simply to get the + // substituted URI. + ioServ->NewChannelFromURI(uri, getter_AddRefs(chan)); + if (!chan) + break; + fileChan = do_QueryInterface(chan); + } + + if (!file && fileChan) + fileChan->GetFile(getter_AddRefs(file)); + if (file) { + rv = fastLoadServ->AddDependency(file); + if (NS_FAILED(rv)) + cache->AbortFastLoads(); + } + } + } } *aResult = result; diff --git a/mozilla/chrome/src/nsChromeRegistry.cpp b/mozilla/chrome/src/nsChromeRegistry.cpp index 78f371a0f2a..c99697fb393 100644 --- a/mozilla/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/chrome/src/nsChromeRegistry.cpp @@ -19,7 +19,7 @@ * * Original Author: David W. Hyatt (hyatt@netscape.com) * - * Contributor(s): + * Contributor(s): * Gagan Saksena */ @@ -165,7 +165,7 @@ NS_IMETHODIMP nsOverlayEnumerator::HasMoreElements(PRBool *aIsTrue) return NS_OK; // No arcs period. We default to false, return mInstallArcs->HasMoreElements(aIsTrue); // no profile arcs. use install arcs, } - + nsresult rv = mProfileArcs->HasMoreElements(aIsTrue); if (*aIsTrue || !mInstallArcs) return rv; @@ -229,7 +229,7 @@ NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult) nsChromeRegistry::nsChromeRegistry() { - NS_INIT_REFCNT(); + NS_INIT_REFCNT(); mInstallInitialized = PR_FALSE; mProfileInitialized = PR_FALSE; @@ -250,13 +250,13 @@ static PRBool PR_CALLBACK DatasourceEnumerator(nsHashKey *aKey, void *aData, voi return PR_FALSE; nsIRDFCompositeDataSource* compositeDS = (nsIRDFCompositeDataSource*) closure; - + nsCOMPtr supports = (nsISupports*)aData; - + nsCOMPtr dataSource = do_QueryInterface(supports); if (!dataSource) return PR_FALSE; - + nsresult rv = compositeDS->RemoveDataSource(dataSource); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to RemoveDataSource"); return PR_TRUE; @@ -265,11 +265,11 @@ static PRBool PR_CALLBACK DatasourceEnumerator(nsHashKey *aKey, void *aData, voi nsChromeRegistry::~nsChromeRegistry() { - if (mDataSourceTable) { + if (mDataSourceTable) { mDataSourceTable->Enumerate(DatasourceEnumerator, mChromeDataSource); delete mDataSourceTable; } - + if (mRDFService) { nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); mRDFService = nsnull; @@ -337,7 +337,7 @@ nsChromeRegistry::Init() rv = mRDFService->GetResource(kURICHROME_packageVersion, getter_AddRefs(mPackageVersion)); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - nsCOMPtr observerService = + nsCOMPtr observerService = do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv); if (observerService) { observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get()); @@ -345,7 +345,7 @@ nsChromeRegistry::Init() } CheckForNewChrome(); - + return NS_OK; } @@ -354,7 +354,7 @@ static nsresult SplitURL(nsIURI* aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCString& aFile) { // Splits a "chrome:" URL into its package, provider, and file parts. - // Here are the current portions of a + // Here are the current portions of a // chrome: url that make up the chrome- // // chrome://global/skin/foo?bar @@ -362,7 +362,7 @@ SplitURL(nsIURI* aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCStrin // | | | | // | | | `-- RemainingPortion // | | | - // | | `-- Provider + // | | `-- Provider // | | // | `-- Package // | @@ -415,41 +415,41 @@ SplitURL(nsIURI* aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCStrin aFile = aPackage; if (aProvider.Equals("content")) { - aFile += ".xul"; + aFile += ".xul"; } else if (aProvider.Equals("skin")) { - aFile += ".css"; + aFile += ".css"; } else if (aProvider.Equals("locale")) { - aFile += ".dtd"; + aFile += ".dtd"; } else { - NS_ERROR("unknown provider"); - return NS_ERROR_FAILURE; + NS_ERROR("unknown provider"); + return NS_ERROR_FAILURE; } } else { - // Protect against URIs containing .. that reach up out of the - // chrome directory to grant chrome privileges to non-chrome files. - int depth = 0; - PRBool sawSlash = PR_TRUE; // .. at the beginning is suspect as well as /.. - for (const char* p=aFile; *p; p++) { - if (sawSlash) { - if (p[0] == '.' && p[1] == '.'){ - depth--; // we have /.., decrement depth. - } else { - static const char escape[] = "%2E%2E"; - if(PL_strncasecmp(p, escape, sizeof(escape)-1) == 0) - depth--; // we have /%2E%2E, the HTML escape form of /.., decrement depth. - } - }else if (p[0] != '/') { - depth++; // we have /x for some x that is not / - } - sawSlash = (p[0] == '/'); - - if (depth < 0) { - return NS_ERROR_FAILURE; + // Protect against URIs containing .. that reach up out of the + // chrome directory to grant chrome privileges to non-chrome files. + int depth = 0; + PRBool sawSlash = PR_TRUE; // .. at the beginning is suspect as well as /.. + for (const char* p=aFile; *p; p++) { + if (sawSlash) { + if (p[0] == '.' && p[1] == '.'){ + depth--; // we have /.., decrement depth. + } else { + static const char escape[] = "%2E%2E"; + if (PL_strncasecmp(p, escape, sizeof(escape)-1) == 0) + depth--; // we have the HTML-escaped form of /.., decrement depth. } + } else if (p[0] != '/') { + depth++; // we have /x for some x that is not / } + sawSlash = (p[0] == '/'); + + if (depth < 0) { + return NS_ERROR_FAILURE; + } + } } return NS_OK; } @@ -499,13 +499,13 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult) if (NS_FAILED(rv)) return rv; if (!mProfileInitialized) { - // Just setSpec + // Just setSpec rv = GetInstallRoot(mInstallRoot); if (NS_FAILED(rv)) return rv; rv = LoadProfileDataSource(); if (NS_FAILED(rv)) return rv; } - + nsCAutoString finalURL; rv = GetBaseURL(package, provider, finalURL); #ifdef DEBUG @@ -541,7 +541,7 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult) else { finalURL = "resource:/chrome/packages/core/"; } - } + } *aResult = ToNewCString(finalURL + remaining); @@ -549,7 +549,7 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult) } NS_IMETHODIMP -nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvider, +nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvider, nsCString& aBaseURL) { nsCOMPtr resource; @@ -564,7 +564,7 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid if (NS_FAILED(rv)) { NS_ERROR("Unable to obtain the package resource."); return rv; - } + } // Follow the "selectedSkin" or "selectedLocale" arc. nsCOMPtr arc; @@ -579,7 +579,7 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid resource = packageResource; if (arc) { - + nsCOMPtr selectedProvider; if (NS_FAILED(rv = mChromeDataSource->GetTarget(packageResource, arc, PR_TRUE, getter_AddRefs(selectedProvider)))) { NS_ERROR("Unable to obtain the provider."); @@ -616,7 +616,7 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid FindProvider(aPackage, aProvider, arc, getter_AddRefs(selectedProvider)); resource = do_QueryInterface(selectedProvider); } - + if (!selectedProvider) return rv; @@ -626,12 +626,12 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid // From this resource, follow the "baseURL" arc. return nsChromeRegistry::FollowArc(mChromeDataSource, - aBaseURL, + aBaseURL, resource, mBaseURL); } -// locate +// locate NS_IMETHODIMP nsChromeRegistry::FindProvider(const nsCString& aPackage, const nsCString& aProvider, @@ -761,7 +761,8 @@ nsChromeRegistry::SelectPackageInProvider(nsIRDFResource *aPackageList, // get its name nsCAutoString packageName; rv = nsChromeRegistry::FollowArc(mChromeDataSource, packageName, package, mName); - if (NS_FAILED(rv)) continue; // don't fail if package has not yet been installed + if (NS_FAILED(rv)) + continue; // don't fail if package has not yet been installed if (packageName.Equals(aPackage)) { nsAutoString providerNameUC; @@ -786,7 +787,7 @@ nsChromeRegistry::SelectPackageInProvider(nsIRDFResource *aPackageList, return NS_OK; } -NS_IMETHODIMP nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, PRBool aIsOverlay, PRBool aUseProfile, +NS_IMETHODIMP nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, PRBool aIsOverlay, PRBool aUseProfile, nsIRDFDataSource **aResult) { *aResult = nsnull; @@ -810,14 +811,14 @@ NS_IMETHODIMP nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, PRBool if (aIsOverlay) overlayFile += "content/overlays.rdf"; else overlayFile += "skin/stylesheets.rdf"; - + return LoadDataSource(overlayFile, aResult, aUseProfile, nsnull); } NS_IMETHODIMP nsChromeRegistry::GetStyleSheets(nsIURI *aChromeURL, nsISupportsArray **aResult) { *aResult = nsnull; - + nsCOMPtr sheets; nsresult rv = GetDynamicInfo(aChromeURL, PR_FALSE, getter_AddRefs(sheets)); if (NS_FAILED(rv)) return rv; @@ -886,7 +887,7 @@ NS_IMETHODIMP nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOve nsCOMPtr installArcs; nsCOMPtr profileArcs; - + if (installSource) { nsCOMPtr container; @@ -911,16 +912,16 @@ NS_IMETHODIMP nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOve if (NS_FAILED(rv)) return rv; } - + *aResult = new nsOverlayEnumerator(installArcs, profileArcs); NS_ADDREF(*aResult); - + return NS_OK; } -NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, - nsIRDFDataSource **aResult, - PRBool aUseProfileDir, +NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, + nsIRDFDataSource **aResult, + PRBool aUseProfileDir, const char *aProfilePath) { // Init the data source to null. @@ -948,7 +949,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, if (mDataSourceTable) { nsCStringKey skey(key); - nsCOMPtr supports = + nsCOMPtr supports = getter_AddRefs(NS_STATIC_CAST(nsISupports*, mDataSourceTable->Get(&skey))); if (supports) @@ -963,7 +964,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, return NS_ERROR_FAILURE; } } - + nsresult rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, nsnull, NS_GET_IID(nsIRDFDataSource), @@ -988,7 +989,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, rv = remote->Init(key); if (NS_SUCCEEDED(rv)) rv = remote->Refresh(PR_TRUE); - + nsCOMPtr supports = do_QueryInterface(remote); nsCStringKey skey(key); mDataSourceTable->Put(&skey, supports.get()); @@ -1011,9 +1012,9 @@ nsChromeRegistry::GetResource(const nsCString& aURL, return NS_OK; } -nsresult +nsresult nsChromeRegistry::FollowArc(nsIRDFDataSource *aDataSource, - nsCString& aResult, + nsCString& aResult, nsIRDFResource* aChromeResource, nsIRDFResource* aProperty) { @@ -1033,7 +1034,7 @@ nsChromeRegistry::FollowArc(nsIRDFDataSource *aDataSource, return NS_ERROR_FAILURE; nsCOMPtr resource(do_QueryInterface(chromeBase)); - + if (resource) { nsXPIDLCString uri; rv = resource->GetValue(getter_Copies(uri)); @@ -1041,7 +1042,7 @@ nsChromeRegistry::FollowArc(nsIRDFDataSource *aDataSource, aResult.Assign(uri); return NS_OK; } - + nsCOMPtr literal(do_QueryInterface(chromeBase)); if (literal) { nsXPIDLString s; @@ -1060,7 +1061,7 @@ nsChromeRegistry::FollowArc(nsIRDFDataSource *aDataSource, nsresult nsChromeRegistry::UpdateArc(nsIRDFDataSource *aDataSource, nsIRDFResource* aSource, - nsIRDFResource* aProperty, + nsIRDFResource* aProperty, nsIRDFNode *aTarget, PRBool aRemove) { nsresult rv; @@ -1091,9 +1092,9 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins() rv = FlushCaches(); if (NS_FAILED(rv)) return rv; - + // Get the window mediator - nsCOMPtr windowMediator = + nsCOMPtr windowMediator = do_GetService(kWindowMediatorCID, &rv); if (NS_SUCCEEDED(rv)) { nsCOMPtr windowEnumerator; @@ -1129,7 +1130,7 @@ nsresult nsChromeRegistry::FlushCaches() // Flush the style sheet cache completely. // XXX For now flush everything. need a better call that only flushes style sheets. - nsCOMPtr xulCache = + nsCOMPtr xulCache = do_GetService("@mozilla.org/xul/xul-prototype-cache;1", &rv); if (NS_SUCCEEDED(rv) && xulCache) { xulCache->Flush(); @@ -1247,16 +1248,16 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) PRInt32 count = 0; document->GetNumberOfStyleSheets(&count); - + // Iterate over the style sheets. for (PRInt32 i = 0; i < count; i++) { // Get the style sheet nsCOMPtr styleSheet; document->GetStyleSheetAt(i, getter_AddRefs(styleSheet)); - + // Make sure we aren't the special style sheets that never change. We // want to skip those. - + nsCOMPtr attr = do_QueryInterface(attrSheet); nsCOMPtr inl = do_QueryInterface(inlineSheet); if ((attr.get() != styleSheet.get()) && @@ -1267,13 +1268,13 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) if (NS_FAILED(rv)) return rv; rv = urls->AppendElement(uri) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; - - // Remove the sheet. + + // Remove the sheet. rv = oldSheets->AppendElement(styleSheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; } } - + // Iterate over the URL array and kick off an asynchronous load of the // sheets for our doc. PRUint32 urlCount; @@ -1310,7 +1311,7 @@ NS_IMETHODIMP nsChromeRegistry::WriteInfoToDataSource(const char *aDocURI, nsCAutoString str(aDocURI); rv = NS_NewURI(getter_AddRefs(uri), str); if (NS_FAILED(rv)) return rv; - + nsCOMPtr dataSource; rv = GetDynamicDataSource(uri, aIsOverlay, aUseProfile, getter_AddRefs(dataSource)); if (NS_FAILED(rv)) return rv; @@ -1376,7 +1377,7 @@ NS_IMETHODIMP nsChromeRegistry::UpdateDynamicDataSource(nsIRDFDataSource *aDataS NS_GET_IID(nsIRDFContainer), getter_AddRefs(container)); if (NS_FAILED(rv)) return rv; - + rv = container->Init(aDataSource, aResource); if (NS_FAILED(rv)) return rv; @@ -1446,7 +1447,7 @@ NS_IMETHODIMP nsChromeRegistry::UpdateDynamicDataSources(nsIRDFDataSource *aData PRBool moreElements; rv = arcs->HasMoreElements(&moreElements); if (NS_FAILED(rv)) return rv; - + while (moreElements) { nsCOMPtr supports; @@ -1480,7 +1481,7 @@ NS_IMETHODIMP nsChromeRegistry::SelectLocale(const PRUnichar* aLocale, return SetProvider(nsCAutoString("locale"), mSelectedLocale, aLocale, aUseProfile, nsnull, PR_TRUE); } -NS_IMETHODIMP nsChromeRegistry::SelectLocaleForProfile(const PRUnichar *aLocale, +NS_IMETHODIMP nsChromeRegistry::SelectLocaleForProfile(const PRUnichar *aLocale, const PRUnichar *aProfilePath) { // to be changed to use given path @@ -1488,7 +1489,7 @@ NS_IMETHODIMP nsChromeRegistry::SelectLocaleForProfile(const PRUnichar *aLocale, } /* wstring getSelectedLocale (); */ -NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, +NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, PRUnichar **_retval) { // check if mChromeDataSource is null; do we need to apply this to every instance? @@ -1508,7 +1509,7 @@ NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, if (NS_FAILED(rv)) { NS_ERROR("Unable to obtain the package resource."); return rv; - } + } if (mChromeDataSource == nsnull) return NS_ERROR_NULL_POINTER; @@ -1547,12 +1548,12 @@ NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, if (NS_FAILED(rv)) { NS_ERROR("Unable to obtain the provider resource."); return rv; - } + } // From this resource, follow the "name" arc. nsCAutoString lc_name; // is this i18n friendly? RDF now use UTF8 internally rv = nsChromeRegistry::FollowArc(mChromeDataSource, - lc_name, + lc_name, resource, mName); if (NS_FAILED(rv)) return rv; @@ -1666,9 +1667,9 @@ NS_IMETHODIMP nsChromeRegistry::SetProvider(const nsCString& aProvider, NS_IMETHODIMP nsChromeRegistry::SetProviderForPackage(const nsCString& aProvider, - nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderPackageResource, - nsIRDFResource* aSelectionArc, + nsIRDFResource* aPackageResource, + nsIRDFResource* aProviderPackageResource, + nsIRDFResource* aSelectionArc, PRBool aUseProfile, const char *aProfilePath, PRBool aIsAdding) { @@ -1678,7 +1679,7 @@ nsChromeRegistry::SetProviderForPackage(const nsCString& aProvider, nsCAutoString dataSourceStr( "user-" ); dataSourceStr += aProvider; dataSourceStr += "s.rdf"; - + nsCOMPtr dataSource; rv = LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), aUseProfile, aProfilePath); if (NS_FAILED(rv)) return rv; @@ -1742,9 +1743,9 @@ NS_IMETHODIMP nsChromeRegistry::IsLocaleSelectedForPackage(const PRUnichar *aLoc } NS_IMETHODIMP nsChromeRegistry::SelectProviderForPackage(const nsCString& aProviderType, - const PRUnichar *aProviderName, - const PRUnichar *aPackageName, - nsIRDFResource* aSelectionArc, + const PRUnichar *aProviderName, + const PRUnichar *aPackageName, + nsIRDFResource* aSelectionArc, PRBool aUseProfile, PRBool aIsAdding) { nsCAutoString package( "urn:mozilla:package:" ); @@ -1798,10 +1799,10 @@ NS_IMETHODIMP nsChromeRegistry::SelectProviderForPackage(const nsCString& aProvi return NS_ERROR_FAILURE; } - return SetProviderForPackage(aProviderType, packageResource, providerResource, aSelectionArc, + return SetProviderForPackage(aProviderType, packageResource, providerResource, aSelectionArc, aUseProfile, nsnull, aIsAdding);; } - + NS_IMETHODIMP nsChromeRegistry::IsSkinSelected(const PRUnichar* aSkin, PRBool aUseProfile, PRBool* aResult) { @@ -1856,7 +1857,7 @@ NS_IMETHODIMP nsChromeRegistry::IsProviderSelected(const nsCString& aProvider, nsCOMPtr arcs; container->GetElements(getter_AddRefs(arcs)); - + // For each skin/package entry, follow the arcs to the real package // resource. PRBool more; @@ -1898,9 +1899,9 @@ NS_IMETHODIMP nsChromeRegistry::IsProviderSelected(const nsCString& aProvider, NS_IMETHODIMP nsChromeRegistry::IsProviderSelectedForPackage(const nsCString& aProviderType, - const PRUnichar *aProviderName, - const PRUnichar *aPackageName, - nsIRDFResource* aSelectionArc, + const PRUnichar *aProviderName, + const PRUnichar *aPackageName, + nsIRDFResource* aSelectionArc, PRBool aUseProfile, PRBool* aResult) { *aResult = PR_FALSE; @@ -1933,15 +1934,15 @@ nsChromeRegistry::IsProviderSelectedForPackage(const nsCString& aProviderType, } NS_ASSERTION(providerResource, "failed to get providerResource"); - return IsProviderSetForPackage(aProviderType, packageResource, providerResource, aSelectionArc, + return IsProviderSetForPackage(aProviderType, packageResource, providerResource, aSelectionArc, aUseProfile, aResult);; } NS_IMETHODIMP nsChromeRegistry::IsProviderSetForPackage(const nsCString& aProvider, - nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderPackageResource, - nsIRDFResource* aSelectionArc, + nsIRDFResource* aPackageResource, + nsIRDFResource* aProviderPackageResource, + nsIRDFResource* aSelectionArc, PRBool aUseProfile, PRBool* aResult) { nsresult rv; @@ -1950,7 +1951,7 @@ nsChromeRegistry::IsProviderSetForPackage(const nsCString& aProvider, nsCAutoString dataSourceStr( "user-" ); dataSourceStr += aProvider; dataSourceStr += "s.rdf"; - + nsCOMPtr dataSource; rv = LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), aUseProfile, nsnull); if (NS_FAILED(rv)) return rv; @@ -1992,11 +1993,11 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, key += "contents.rdf"; remote->Init(key); remote->Refresh(PR_TRUE); - + PRBool skinCount = GetProviderCount(nsCAutoString("skin"), dataSource); PRBool localeCount = GetProviderCount(nsCAutoString("locale"), dataSource); PRBool packageCount = GetProviderCount(nsCAutoString("package"), dataSource); - + PRBool appendPackage = PR_FALSE; PRBool appendProvider = PR_FALSE; PRBool appendProviderName = PR_FALSE; @@ -2012,7 +2013,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, appendProvider = PR_TRUE; NS_WARNING("Trying old-style manifest.rdf. Please update to contents.rdf."); } - else { + else { if ((skinCount > 1 && aProviderType.Equals("skin")) || (localeCount > 1 && aProviderType.Equals("locale"))) appendProviderName = PR_TRUE; @@ -2090,7 +2091,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, if (NS_FAILED(rv)) return rv; nsCOMPtr resource = do_QueryInterface(supports); - + // Check against the prefix string const char* value; rv = resource->GetValueConst(&value); @@ -2098,12 +2099,12 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, nsCAutoString val(value); if (val.Find(prefix) == 0) { // It's valid. - + if (aProviderType.Equals("package") && !val.Equals("urn:mozilla:package:root")) { // Add arcs for the base url and loctype // Get the value of the base literal. nsCAutoString baseURL(aBaseURL); - + // Peel off the package. const char* val2; rv = resource->GetValueConst(&val2); @@ -2112,7 +2113,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, PRInt32 index = value2.RFind(":"); nsCAutoString packageName; value2.Right(packageName, value2.Length() - index - 1); - + if (appendPackage) { baseURL += packageName; baseURL += "/"; @@ -2120,17 +2121,17 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, if (appendProvider) { baseURL += "content/"; } - + nsAutoString unistr;unistr.AssignWithConversion(baseURL); nsCOMPtr baseLiteral; mRDFService->GetLiteral(unistr.get(), getter_AddRefs(baseLiteral)); - + rv = nsChromeRegistry::UpdateArc(installSource, resource, mBaseURL, baseLiteral, aRemove); if (NS_FAILED(rv)) return rv; rv = nsChromeRegistry::UpdateArc(installSource, resource, mLocType, locLiteral, aRemove); if (NS_FAILED(rv)) return rv; } - + nsCOMPtr container; rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", nsnull, @@ -2209,7 +2210,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, if (entry) { // Get the value of the base literal. nsCAutoString baseURL(aBaseURL); - + // Peel off the package and the provider. const char* val2; rv = entry->GetValueConst(&val2); @@ -2238,22 +2239,22 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, baseURL += aProviderType; baseURL += "/"; } - + nsAutoString unistr;unistr.AssignWithConversion(baseURL); nsCOMPtr baseLiteral; mRDFService->GetLiteral(unistr.get(), getter_AddRefs(baseLiteral)); - + rv = nsChromeRegistry::UpdateArc(installSource, entry, mBaseURL, baseLiteral, aRemove); if (NS_FAILED(rv)) return rv; if (aProviderType.Equals(nsCAutoString("skin")) && !aAllowScripts) { rv = nsChromeRegistry::UpdateArc(installSource, entry, mAllowScripts, scriptLiteral, aRemove); if (NS_FAILED(rv)) return rv; } - + // Now set up the package arc. if (index != -1) { // Peel off the package name. - + nsCAutoString resourceName("urn:mozilla:package:"); resourceName += packageName; nsCOMPtr packageResource; @@ -2276,7 +2277,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, nsCOMPtr arcs; rv = dataSource->ArcLabelsOut(resource, getter_AddRefs(arcs)); if (NS_FAILED(rv)) return rv; - + PRBool moreArcs; rv = arcs->HasMoreElements(&moreArcs); if (NS_FAILED(rv)) return rv; @@ -2288,15 +2289,15 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, if (arc == mPackages) { // We are the main entry for a skin/locale. - // Set up our loctype and our script access + // Set up our loctype and our script access rv = nsChromeRegistry::UpdateArc(installSource, resource, mLocType, locLiteral, aRemove); if (NS_FAILED(rv)) return rv; } - + nsCOMPtr newTarget; rv = dataSource->GetTarget(resource, arc, PR_TRUE, getter_AddRefs(newTarget)); if (NS_FAILED(rv)) return rv; - + if (arc == mImage) { // We are an image URL. Check to see if we're a relative URL. nsCOMPtr literal(do_QueryInterface(newTarget)); @@ -2325,7 +2326,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, rv = resources->HasMoreElements(&moreElements); if (NS_FAILED(rv)) return rv; } - + // Flush the install source nsCOMPtr remoteInstall = do_QueryInterface(installSource, &rv); if (NS_FAILED(rv)) @@ -2388,7 +2389,7 @@ nsChromeRegistry::UninstallProvider(const nsCString& aProviderType, // XXX We are going to simply do a snip of the arc from the seq ROOT to // the associated package. waterson is going to provide the ability to name // roots in a datasource, and only resources that are reachable from the - // root will be saved. + // root will be saved. nsresult rv = NS_OK; nsCAutoString prefix( "urn:mozilla:" ); prefix += aProviderType; @@ -2414,14 +2415,14 @@ nsChromeRegistry::UninstallProvider(const nsCString& aProviderType, // Now make a container out of the root seq. nsCOMPtr container(do_CreateInstance("@mozilla.org/rdf/container;1")); - + // Get the resource for the root. nsCOMPtr chromeResource; if (NS_FAILED(rv = GetResource(providerRoot, getter_AddRefs(chromeResource)))) { NS_ERROR("Unable to retrieve the resource corresponding to the skin/locale root."); return rv; } - + if (NS_FAILED(container->Init(installSource, chromeResource))) return NS_ERROR_FAILURE; @@ -2438,23 +2439,23 @@ nsChromeRegistry::UninstallProvider(const nsCString& aProviderType, // Now flush the datasource. nsCOMPtr remote = do_QueryInterface(installSource); remote->Flush(); - + return NS_OK; } NS_IMETHODIMP -nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) -{ +nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) +{ nsresult rv; - nsCOMPtr userChromeDir; - + nsCOMPtr userChromeDir; + // Build a fileSpec that points to the destination - // (profile dir + chrome) + // (profile dir + chrome) rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir)); if (NS_FAILED(rv) || !userChromeDir) return NS_ERROR_FAILURE; - - PRBool exists; + + PRBool exists; rv = userChromeDir->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) { rv = userChromeDir->Create(nsIFile::DIRECTORY_TYPE, 0755); @@ -2465,14 +2466,18 @@ nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) // first get the locations of the defaults nsCOMPtr defaultUserContentFile; nsCOMPtr defaultUserChromeFile; - rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(defaultUserContentFile)); + rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, + getter_AddRefs(defaultUserContentFile)); if (NS_FAILED(rv)) - rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, getter_AddRefs(defaultUserContentFile)); + rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, + getter_AddRefs(defaultUserContentFile)); if (NS_FAILED(rv)) return(rv); - rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(defaultUserChromeFile)); + rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, + getter_AddRefs(defaultUserChromeFile)); if (NS_FAILED(rv)) - rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, getter_AddRefs(defaultUserChromeFile)); + rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, + getter_AddRefs(defaultUserChromeFile)); if (NS_FAILED(rv)) return(rv); defaultUserContentFile->Append("chrome"); @@ -2491,35 +2496,35 @@ nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) } if (NS_FAILED(rv)) return rv; - + nsXPIDLCString urlSpec; rv = userChromeDir->GetURL(getter_Copies(urlSpec)); if (NS_FAILED(rv)) return rv; aFileURL = urlSpec; - + return NS_OK; } NS_IMETHODIMP -nsChromeRegistry::GetInstallRoot(nsCString& aFileURL) -{ +nsChromeRegistry::GetInstallRoot(nsCString& aFileURL) +{ nsresult rv; - nsCOMPtr appChromeDir; + nsCOMPtr appChromeDir; // Build a fileSpec that points to the destination - // (bin dir + chrome) + // (bin dir + chrome) rv = NS_GetSpecialDirectory(NS_APP_CHROME_DIR, getter_AddRefs(appChromeDir)); if (NS_FAILED(rv) || !appChromeDir) return NS_ERROR_FAILURE; - nsXPIDLCString urlSpec; + nsXPIDLCString urlSpec; rv = appChromeDir->GetURL(getter_Copies(urlSpec)); if (NS_FAILED(rv)) return rv; aFileURL = urlSpec; - return NS_OK; + return NS_OK; } NS_IMETHODIMP @@ -2529,21 +2534,21 @@ nsChromeRegistry::ReloadChrome() nsresult rv = NS_OK; // Flush the cache completely. - nsCOMPtr xulCache = + nsCOMPtr xulCache = do_GetService("@mozilla.org/xul/xul-prototype-cache;1", &rv); if (NS_SUCCEEDED(rv) && xulCache) { rv = xulCache->Flush(); if (NS_FAILED(rv)) return rv; } - + nsCOMPtr bundleService = do_GetService(kStringBundleServiceCID, &rv); - + if (NS_SUCCEEDED(rv)) { rv = bundleService->FlushBundles(); if (NS_FAILED(rv)) return rv; } - + // Get the window mediator nsCOMPtr windowMediator = do_GetService(kWindowMediatorCID, &rv); if (NS_SUCCEEDED(rv)) { @@ -2600,14 +2605,14 @@ nsChromeRegistry::GetArcs(nsIRDFDataSource* aDataSource, NS_ERROR("Unable to retrieve the resource corresponding to the chrome skin or content."); return rv; } - + if (NS_FAILED(container->Init(aDataSource, chromeResource))) return NS_OK; nsCOMPtr arcs; if (NS_FAILED(container->GetElements(getter_AddRefs(arcs)))) return NS_OK; - + *aResult = arcs; NS_IF_ADDREF(*aResult); return NS_OK; @@ -2629,7 +2634,7 @@ nsChromeRegistry::AddToCompositeDataSource(PRBool aUseProfile) rv = NS_NewChromeUIDataSource(mChromeDataSource, getter_AddRefs(mUIDataSource)); if (NS_FAILED(rv)) return rv; } - + if (aUseProfile) { // Profiles take precedence. Load them first. nsCOMPtr dataSource; @@ -2701,15 +2706,15 @@ NS_IMETHODIMP nsChromeRegistry::GetBackstopSheets(nsIDocShell* aDocShell, nsISupportsArray **aResult) { nsresult rv = NS_NewISupportsArray(aResult); - + // Determine the agent sheets that should be loaded. if (!mScrollbarSheet) - LoadStyleSheet(getter_AddRefs(mScrollbarSheet), nsCAutoString("chrome://global/skin/scrollbars.css")); - + LoadStyleSheet(getter_AddRefs(mScrollbarSheet), nsCAutoString("chrome://global/skin/scrollbars.css")); + if (!mFormSheet) { nsCAutoString sheetURL; GetFormSheetURL(sheetURL); - LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL); + LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL); } PRBool shouldOverride = PR_FALSE; @@ -2726,7 +2731,7 @@ nsChromeRegistry::GetBackstopSheets(nsIDocShell* aDocShell, nsISupportsArray **a char* str = sheets.ToNewCString(); char* newStr; char* token = nsCRT::strtok( str, ", ", &newStr ); - while( token != NULL ) { + while (token) { nsCOMPtr content(do_QueryInterface(elt)); nsCOMPtr doc; content->GetDocument(*getter_AddRefs(doc)); @@ -2773,10 +2778,10 @@ nsChromeRegistry::GetBackstopSheets(nsIDocShell* aDocShell, nsISupportsArray **a if (mScrollbarSheet && !shouldOverride) (*aResult)->AppendElement(mScrollbarSheet); - - if (mFormSheet) + + if (mFormSheet) (*aResult)->AppendElement(mFormSheet); - + return NS_OK; } @@ -2784,24 +2789,23 @@ NS_IMETHODIMP nsChromeRegistry::GetUserSheets(PRBool aIsChrome, nsISupportsArray **aResult) { nsresult rv; - - if((aIsChrome && mUserChromeSheet) || (!aIsChrome && mUserContentSheet)) - { + + if ((aIsChrome && mUserChromeSheet) || (!aIsChrome && mUserContentSheet)) { rv = NS_NewISupportsArray(aResult); if (NS_FAILED(rv)) return rv; - if(aIsChrome && mUserChromeSheet) { + if (aIsChrome && mUserChromeSheet) { rv = (*aResult)->AppendElement(mUserChromeSheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; - } - - if(!aIsChrome && mUserContentSheet) { + } + + if (!aIsChrome && mUserContentSheet) { rv = (*aResult)->AppendElement(mUserContentSheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; } } return NS_OK; } - + nsresult nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString& aURL) { nsCOMPtr uri; @@ -2820,7 +2824,7 @@ nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet* NS_GET_IID(nsICSSLoader), getter_AddRefs(loader)); if (NS_FAILED(rv)) return rv; - if(loader) { + if (loader) { PRBool complete; rv = loader->LoadAgentSheet(aURL, *aSheet, complete, nsnull); @@ -2861,8 +2865,8 @@ nsresult nsChromeRegistry::LoadProfileDataSource() rv = FlushCaches(); if (NS_FAILED(rv)) return rv; - // XXX this sucks ASS. This is a temporary hack until we get - // around to fixing the skin switching bugs. + // XXX this sucks ASS. This is a temporary hack until we get + // around to fixing the skin switching bugs. // Select and Remove skins based on a pref set in a previous session. nsCOMPtr pref(do_GetService("@mozilla.org/preferences;1")); if (pref) { @@ -2870,30 +2874,30 @@ nsresult nsChromeRegistry::LoadProfileDataSource() rv = pref->CopyUnicharPref("general.skins.selectedSkin", getter_Copies(skinToSelect)); if (NS_SUCCEEDED(rv)) { rv = SelectSkin(skinToSelect, PR_TRUE); - if (NS_SUCCEEDED(rv)) + if (NS_SUCCEEDED(rv)) pref->DeleteBranch("general.skins.selectedSkin"); } } - rv = LoadStyleSheet(getter_AddRefs(mScrollbarSheet), nsCAutoString("chrome://global/skin/scrollbars.css")); + rv = LoadStyleSheet(getter_AddRefs(mScrollbarSheet), nsCAutoString("chrome://global/skin/scrollbars.css")); // This must always be the last line of profile initialization! nsCAutoString sheetURL; rv = GetUserSheetURL(PR_TRUE, sheetURL); if (NS_FAILED(rv)) return rv; - if(!sheetURL.IsEmpty()) { + if (!sheetURL.IsEmpty()) { (void)LoadStyleSheet(getter_AddRefs(mUserChromeSheet), sheetURL); // it's ok to not have a user.css file } rv = GetUserSheetURL(PR_FALSE, sheetURL); if (NS_FAILED(rv)) return rv; - if(!sheetURL.IsEmpty()) { + if (!sheetURL.IsEmpty()) { (void)LoadStyleSheet(getter_AddRefs(mUserContentSheet), sheetURL); // it's ok not to have a userContent.css or userChrome.css file } - rv = GetFormSheetURL(sheetURL); + rv = GetFormSheetURL(sheetURL); if (NS_FAILED(rv)) return rv; - if(!sheetURL.IsEmpty()) + if (!sheetURL.IsEmpty()) (void)LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL); } return NS_OK; @@ -2916,7 +2920,7 @@ NS_IMETHODIMP nsChromeRegistry::AllowScriptsForSkin(nsIURI* aChromeURI, PRBool * // XXX could factor this with selectproviderforpackage // get the selected skin resource for the package nsCOMPtr selectedProvider; - + nsCAutoString resourceStr("urn:mozilla:package:"); resourceStr += package; @@ -2926,7 +2930,7 @@ NS_IMETHODIMP nsChromeRegistry::AllowScriptsForSkin(nsIURI* aChromeURI, PRBool * if (NS_FAILED(rv)) { NS_ERROR("Unable to obtain the package resource."); return rv; - } + } if (NS_FAILED(rv = mChromeDataSource->GetTarget(resource, mSelectedSkin, PR_TRUE, getter_AddRefs(selectedProvider)))) return NS_OK; @@ -2943,7 +2947,7 @@ NS_IMETHODIMP nsChromeRegistry::AllowScriptsForSkin(nsIURI* aChromeURI, PRBool * // get its script access nsCAutoString scriptAccess; rv = nsChromeRegistry::FollowArc(mChromeDataSource, - scriptAccess, + scriptAccess, resource, mAllowScripts); if (NS_FAILED(rv)) return rv; @@ -2972,13 +2976,13 @@ nsChromeRegistry::CheckForNewChrome() // open the installed-chrome file nsCOMPtr listFile; - nsCOMPtr directoryService = + nsCOMPtr directoryService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; rv = directoryService->Get(NS_APP_CHROME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(listFile)); if (NS_FAILED(rv)) - return rv; + return rv; nsCOMPtr allPkgs; rv = listFile->Clone(getter_AddRefs(allPkgs)); @@ -3019,7 +3023,7 @@ nsChromeRegistry::CheckForNewChrome() rv = listFile->OpenNSPRFileDesc(PR_RDONLY, 0, &file); if (NS_FAILED(rv)) return rv; - // file is open. + // file is open. PRFileInfo finfo; @@ -3151,7 +3155,7 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) printf("***** Chrome Registration: Selecting skin %s as default\n", (const char*)chromeLocation); #endif } - else + else rv = InstallSkin(chromeURL, isProfile, PR_FALSE); } else if (content.Equals(chromeType)) @@ -3164,7 +3168,7 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) printf("***** Chrome Registration: Selecting locale %s as default\n", (const char*)chromeLocation); #endif } - else + else rv = InstallLocale(chromeURL, isProfile); } if (NS_FAILED(rv)) return rv; @@ -3175,7 +3179,7 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) return rv; } -PRBool +PRBool nsChromeRegistry::GetProviderCount(const nsCString& aProviderType, nsIRDFDataSource* aDataSource) { nsresult rv; @@ -3210,19 +3214,19 @@ nsChromeRegistry::GetProviderCount(const nsCString& aProviderType, nsIRDFDataSou NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData) { nsresult rv = NS_OK; - + if (!nsCRT::strcmp(NS_LITERAL_STRING("profile-before-change").get(), aTopic)) { mChromeDataSource = nsnull; mProfileInitialized = PR_FALSE; - + if (!nsCRT::strcmp(NS_LITERAL_STRING("shutdown-cleanse").get(), someData)) { - nsCOMPtr userChromeDir; + nsCOMPtr userChromeDir; rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir)); if (NS_SUCCEEDED(rv) && userChromeDir) rv = userChromeDir->Remove(PR_TRUE); } - } + } else if (!nsCRT::strcmp(NS_LITERAL_STRING("profile-do-change").get(), aTopic)) { if (!mProfileInitialized) rv = LoadProfileDataSource(); @@ -3231,7 +3235,7 @@ NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const PRUnichar * return rv; } -NS_IMETHODIMP nsChromeRegistry::CheckThemeVersion(const PRUnichar *aSkin, +NS_IMETHODIMP nsChromeRegistry::CheckThemeVersion(const PRUnichar *aSkin, PRBool* aResult) { nsCAutoString provider("skin"); @@ -3239,7 +3243,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckThemeVersion(const PRUnichar *aSkin, } -NS_IMETHODIMP nsChromeRegistry::CheckLocaleVersion(const PRUnichar *aLocale, +NS_IMETHODIMP nsChromeRegistry::CheckLocaleVersion(const PRUnichar *aLocale, PRBool* aResult) { nsCAutoString provider("locale"); @@ -3247,7 +3251,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckLocaleVersion(const PRUnichar *aLocale, } -NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProviderType, +NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProviderType, const PRUnichar* aProviderName, nsIRDFResource* aSelectionArc, PRBool *aCompatible) @@ -3257,7 +3261,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider // Build the provider resource str. // e.g., urn:mozilla:skin:aqua/1.0 nsCAutoString resourceStr( "urn:mozilla:" ); - resourceStr += aProviderType; + resourceStr += aProviderType; resourceStr += ":"; resourceStr.AppendWithConversion(aProviderName); @@ -3312,10 +3316,10 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider if (NS_SUCCEEDED(rv) && packageSkinEntry) { nsCOMPtr entry = do_QueryInterface(packageSkinEntry); if (entry) { - + nsCAutoString themePackageVersion; nsChromeRegistry::FollowArc(mChromeDataSource, themePackageVersion, entry, aSelectionArc); - + // Obtain the real package resource. nsCOMPtr packageNode; rv = mChromeDataSource->GetTarget(entry, mPackage, PR_TRUE, getter_AddRefs(packageNode)); @@ -3326,7 +3330,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider nsCOMPtr packageResource(do_QueryInterface(packageNode)); if (packageResource) { - + nsCAutoString packageVersion; nsChromeRegistry::FollowArc(mChromeDataSource, packageVersion, packageResource, aSelectionArc); @@ -3346,7 +3350,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider *aCompatible = PR_FALSE; } } - + // if just one theme package is NOT compatible, the theme will be disabled if (!(*aCompatible)) return NS_OK; @@ -3355,7 +3359,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider } } rv = arcs->HasMoreElements(&more); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) return rv; } diff --git a/mozilla/content/xul/content/src/nsXULElement.cpp b/mozilla/content/xul/content/src/nsXULElement.cpp index d06b0298d7a..f22acf80e5f 100644 --- a/mozilla/content/xul/content/src/nsXULElement.cpp +++ b/mozilla/content/xul/content/src/nsXULElement.cpp @@ -5230,7 +5230,7 @@ nsXULPrototypeScript::Serialize(nsIObjectOutputStream* aStream, JSScript *script = NS_REINTERPRET_CAST(JSScript*, ::JS_GetPrivate(cx, mJSObject)); if (! ::JS_XDRScript(xdr, &script)) { - rv = NS_ERROR_OUT_OF_MEMORY; // extremely likely, barring bugs! + rv = NS_ERROR_FAILURE; // likely to be a principals serialization error } else { // Get the encoded JSXDRState data and write it. The JSXDRState owns // this buffer memory and will free it beneath ::JS_XDRDestroy. @@ -5303,7 +5303,7 @@ nsXULPrototypeScript::Deserialize(nsIObjectInputStream* aStream, JSScript *script = nsnull; if (! ::JS_XDRScript(xdr, &script)) { - rv = NS_ERROR_OUT_OF_MEMORY; // likely error + rv = NS_ERROR_FAILURE; // principals deserialization error? } else { mJSObject = ::JS_NewScriptObject(cx, script); if (! mJSObject) { @@ -5436,15 +5436,13 @@ nsXULPrototypeScript::Compile(const PRUnichar* aText, // XXXbe temporary, until we serialize/deserialize everything from the // nsXULPrototypeDocument on down... - nsCOMPtr fastLoadService(do_GetService(NS_FAST_LOAD_SERVICE_CONTRACTID)); + nsCOMPtr fastLoadService(do_GetFastLoadService()); nsCOMPtr objectOutput; - fastLoadService->GetCurrentOutputStream(getter_AddRefs(objectOutput)); + fastLoadService->GetOutputStream(getter_AddRefs(objectOutput)); if (objectOutput) { rv = Serialize(objectOutput, context); - if (NS_FAILED(rv)) { - // XXXbe remove FastLoad file - fastLoadService->SetCurrentOutputStream(nsnull); - } + if (NS_FAILED(rv)) + nsXULDocument::AbortFastLoads(); } } diff --git a/mozilla/content/xul/document/public/nsIXULPrototypeCache.h b/mozilla/content/xul/document/public/nsIXULPrototypeCache.h index 3be44731d3d..9d716209719 100644 --- a/mozilla/content/xul/document/public/nsIXULPrototypeCache.h +++ b/mozilla/content/xul/document/public/nsIXULPrototypeCache.h @@ -78,6 +78,11 @@ public: * Determine if the prototype cache is enabled */ NS_IMETHOD GetEnabled(PRBool* aIsEnabled) = 0; + + /** + * Stop the FastLoad process abruptly, removing the FastLoad file. + */ + NS_IMETHOD AbortFastLoads() = 0; }; diff --git a/mozilla/content/xul/document/src/nsXULContentSink.cpp b/mozilla/content/xul/document/src/nsXULContentSink.cpp index 7ee22e30bee..83270578dc8 100644 --- a/mozilla/content/xul/document/src/nsXULContentSink.cpp +++ b/mozilla/content/xul/document/src/nsXULContentSink.cpp @@ -1572,7 +1572,7 @@ XULContentSinkImpl::OpenScript(const nsIParserNode& aNode) nsCOMPtr objectInput; nsXULDocument::GetFastLoadService(getter_AddRefs(fastLoadService)); if (fastLoadService) - fastLoadService->GetCurrentInputStream(getter_AddRefs(objectInput)); + fastLoadService->GetInputStream(getter_AddRefs(objectInput)); if (objectInput) { PRBool useXULCache = PR_TRUE; @@ -1623,7 +1623,7 @@ XULContentSinkImpl::OpenScript(const nsIParserNode& aNode) // muxed stream to get inline objects that are contained in // the current document. PRInt32 direction; - fastLoadService->GetCurrentDirection(&direction); + fastLoadService->GetDirection(&direction); if (direction != nsIFastLoadService::NS_FASTLOAD_READ) rv2 = NS_ERROR_NOT_AVAILABLE; } diff --git a/mozilla/content/xul/document/src/nsXULDocument.cpp b/mozilla/content/xul/document/src/nsXULDocument.cpp index 4d4f506153d..87fd6fd808d 100644 --- a/mozilla/content/xul/document/src/nsXULDocument.cpp +++ b/mozilla/content/xul/document/src/nsXULDocument.cpp @@ -54,6 +54,7 @@ #include "nsDOMCID.h" #include "nsDOMError.h" #include "nsIBoxObject.h" +#include "nsIChannel.h" #include "nsIChromeRegistry.h" #include "nsIComponentManager.h" #include "nsICodebasePrincipal.h" @@ -140,6 +141,7 @@ #include "nsMimeTypes.h" #include "nsISelectionController.h" #include "nsContentUtils.h" +#include "nsIFastLoadFileControl.h" #include "nsIFastLoadService.h" #include "nsIObjectInputStream.h" #include "nsIObjectOutputStream.h" @@ -750,9 +752,9 @@ nsXULDocument::StartDocumentLoad(const char* aCommand, // Try to open a FastLoad file for reading, or create one for writing. // If one exists and looks valid, the nsIFastLoadService will purvey - // a non-null input stream via its GetCurrentInputStream method, and - // we'll deserialize saved objects from that stream. Otherwise, we'll - // serialize to the output stream returned by GetCurrentOutputStream. + // a non-null input stream via its GetInputStream method, and we will + // deserialize saved objects from that stream. Otherwise, we'll write + // to the output stream returned by GetOutputStream. if (fillXULCache && nsCRT::strcmp(aCommand, "view-source") != 0) StartFastLoad(); @@ -3311,7 +3313,7 @@ nsXULDocument::AddElementToDocumentPost(nsIContent* aElement) nsCOMPtr tag; aElement->GetTag(*getter_AddRefs(tag)); if (tag.get() == nsXULAtoms::keyset) { - // Create our XUL key listener and hook it up. + // Create our XUL key listener and hook it up. nsCOMPtr xblService(do_GetService("@mozilla.org/xbl;1", &rv)); if (xblService) { nsCOMPtr rec(do_QueryInterface(aElement)); @@ -4440,9 +4442,7 @@ NS_IMETHODIMP nsXULFastLoadFileIO::GetOutputStream(nsIOutputStream** aResult) { if (! mOutputStream) { - // Need PR_RDWR even if output-only, to support backward seeks outside - // of the output buffer. - PRInt32 ioFlags = PR_RDWR; + PRInt32 ioFlags = PR_WRONLY; if (! mInputStream) ioFlags |= PR_CREATE_FILE | PR_TRUNCATE; @@ -4464,10 +4464,12 @@ nsXULFastLoadFileIO::GetOutputStream(nsIOutputStream** aResult) static PRBool gDisableXULFastLoad = PR_TRUE; // disabled by default, for now +static PRBool gChecksumXULFastLoadFile = PR_TRUE; static const char kDisableXULFastLoadPref[] = "nglayout.debug.disable_xul_fastload"; +static const char kChecksumXULFastLoadFilePref[] = "nglayout.debug.checksum_xul_fastload_file"; PR_STATIC_CALLBACK(int) -DisableXULFastLoadChangedCallback(const char* aPref, void* aClosure) +FastLoadPrefChangedCallback(const char* aPref, void* aClosure) { nsCOMPtr prefs = do_GetService(NS_PREF_CONTRACTID); if (prefs) { @@ -4476,6 +4478,8 @@ DisableXULFastLoadChangedCallback(const char* aPref, void* aClosure) if (wasEnabled && gDisableXULFastLoad) nsXULDocument::AbortFastLoads(); + + prefs->GetBoolPref(kChecksumXULFastLoadFilePref, &gChecksumXULFastLoadFile); } return 0; } @@ -4507,7 +4511,13 @@ nsXULDocument::StartFastLoad() nsCOMPtr prefs(do_GetService(NS_PREF_CONTRACTID)); if (prefs) { prefs->GetBoolPref(kDisableXULFastLoadPref, &gDisableXULFastLoad); - prefs->RegisterCallback(kDisableXULFastLoadPref, DisableXULFastLoadChangedCallback, nsnull); + prefs->GetBoolPref(kChecksumXULFastLoadFilePref, &gChecksumXULFastLoadFile); + prefs->RegisterCallback(kDisableXULFastLoadPref, + FastLoadPrefChangedCallback, + nsnull); + prefs->RegisterCallback(kChecksumXULFastLoadFilePref, + FastLoadPrefChangedCallback, + nsnull); if (gDisableXULFastLoad) return NS_ERROR_NOT_AVAILABLE; } @@ -4515,7 +4525,7 @@ nsXULDocument::StartFastLoad() // Use a local to refer to the service till we're sure we succeeded, then // commit to gFastLoadService. Same for gFastLoadFile, which is used to // delete the FastLoad file on abort. - nsCOMPtr fastLoadService(do_GetService(NS_FAST_LOAD_SERVICE_CONTRACTID)); + nsCOMPtr fastLoadService(do_GetFastLoadService()); if (! fastLoadService) return NS_ERROR_FAILURE; @@ -4530,7 +4540,7 @@ nsXULDocument::StartFastLoad() nsCOMPtr io = new nsXULFastLoadFileIO(file); if (! io) return NS_ERROR_OUT_OF_MEMORY; - fastLoadService->SetCurrentFileIO(io); + fastLoadService->SetFileIO(io); // Try to read an existent FastLoad file. PRBool exists = PR_FALSE; @@ -4540,26 +4550,59 @@ nsXULDocument::StartFastLoad() if (NS_FAILED(rv)) return rv; nsCOMPtr objectInput; - PRUint32 checksum; - rv = fastLoadService->NewInputStream(input, &checksum, - getter_AddRefs(objectInput)); - if (NS_SUCCEEDED(rv)) { - // XXXbe verify checksum, clear exists if bad - // XXXbe check dependencies, clear exists if any are newer + rv = fastLoadService->NewInputStream(input, getter_AddRefs(objectInput)); - // XXXbe version number, then scripts only for now -- bump - // version later when rest of prototype document header is - // serialized - PRUint32 version; - rv = objectInput->Read32(&version); - if (version != XUL_FASTLOAD_FILE_VERSION) { - NS_WARNING("bad FastLoad file version"); - rv = NS_ERROR_UNEXPECTED; + if (NS_SUCCEEDED(rv)) { + nsCOMPtr + readControl(do_QueryInterface(objectInput)); + if (readControl) { + if (gChecksumXULFastLoadFile) { + // Verify checksum, using the fastLoadService's checksum + // cache to avoid computing more than once per session. + PRUint32 checksum; + rv = readControl->GetChecksum(&checksum); + if (NS_SUCCEEDED(rv)) { + PRUint32 verified; + rv = fastLoadService->ComputeChecksum(file, + readControl, + &verified); + if (NS_SUCCEEDED(rv) && verified != checksum) { + NS_WARNING("bad FastLoad file checksum"); + rv = NS_ERROR_FAILURE; + } + } + } + + if (NS_SUCCEEDED(rv)) { + // Check dependencies, fail if any is newer than file. + PRTime dtime, mtime; + rv = fastLoadService->MaxDependencyModifiedTime(readControl, + &dtime); + if (NS_SUCCEEDED(rv)) { + rv = file->GetLastModificationDate(&mtime); + if (NS_SUCCEEDED(rv) && LL_CMP(mtime, <, dtime)) { + NS_WARNING("FastLoad file out of date"); + rv = NS_ERROR_FAILURE; + } + } + } + } + + if (NS_SUCCEEDED(rv)) { + // XXXbe get version number, scripts only for now -- bump + // version later when rest of prototype document header is + // serialized + PRUint32 version; + rv = objectInput->Read32(&version); + if (version != XUL_FASTLOAD_FILE_VERSION) { + NS_WARNING("bad FastLoad file version"); + rv = NS_ERROR_UNEXPECTED; + } } } if (NS_SUCCEEDED(rv)) { - fastLoadService->SetCurrentInputStream(objectInput); + fastLoadService->SetInputStream(objectInput); } else { #ifdef DEBUG file->MoveTo(nsnull, "Invalid.mfasl"); @@ -4584,7 +4627,7 @@ nsXULDocument::StartFastLoad() rv = objectOutput->Write32(XUL_FASTLOAD_FILE_VERSION); if (NS_FAILED(rv)) return rv; - fastLoadService->SetCurrentOutputStream(objectOutput); + fastLoadService->SetOutputStream(objectOutput); } // If this fails, some weird reentrancy or multi-threading has occurred. @@ -4604,7 +4647,7 @@ nsXULDocument::StartFastLoad() nsresult nsXULDocument::EndFastLoad() { - nsresult rv = NS_OK; + nsresult rv = NS_OK, rv2 = NS_OK; // Exclude all non-chrome loads and XUL cache hits right away. if (! mIsFastLoad) @@ -4621,24 +4664,8 @@ nsXULDocument::EndFastLoad() // creating the FastLoad file during this app startup) stream. nsCOMPtr objectInput; nsCOMPtr objectOutput; - gFastLoadService->GetCurrentInputStream(getter_AddRefs(objectInput)); - gFastLoadService->GetCurrentOutputStream(getter_AddRefs(objectOutput)); - - if (objectInput) { - // If this is the last of one or more XUL master documents loaded - // together at app startup, close the FastLoad service's singleton - // input stream now. - // - // There may also be an output stream opened on the FastLoad file, - // if we are updating it to included muxed documents that weren't - // available via the input stream. In that case, when we close - // the output stream, below, we'll update the FastLoad file header - // and footer. - if (! gFastLoadList) { - gFastLoadService->SetCurrentInputStream(nsnull); - rv = objectInput->Close(); - } - } + gFastLoadService->GetInputStream(getter_AddRefs(objectInput)); + gFastLoadService->GetOutputStream(getter_AddRefs(objectOutput)); if (objectOutput) { #if 0 @@ -4649,9 +4676,30 @@ nsXULDocument::EndFastLoad() // If this is the last of one or more XUL master documents loaded // together at app startup, close the FastLoad service's singleton // output stream now. + // + // NB: we must close input after output, in case the output stream + // implementation needs to read from the input stream, to compute a + // FastLoad file checksum. In that case, the implementation used + // nsIFastLoadFileIO to get the corresponding input stream for this + // output stream. if (! gFastLoadList) { - gFastLoadService->SetCurrentOutputStream(nsnull); + gFastLoadService->SetOutputStream(nsnull); rv = objectOutput->Close(); + + if (NS_SUCCEEDED(rv) && gChecksumXULFastLoadFile) { + rv = gFastLoadService->CacheChecksum(gFastLoadFile, + objectOutput); + } + } + } + + if (objectInput) { + // If this is the last of one or more XUL master documents loaded + // together at app startup, close the FastLoad service's singleton + // input stream now. + if (! gFastLoadList) { + gFastLoadService->SetInputStream(nsnull); + rv2 = objectInput->Close(); } } @@ -4661,7 +4709,7 @@ nsXULDocument::EndFastLoad() NS_RELEASE(gFastLoadFile); } - return rv; + return NS_FAILED(rv) ? rv : rv2; } @@ -4682,6 +4730,9 @@ nsXULDocument::AbortFastLoads() while (gFastLoadList) gFastLoadList->EndFastLoad(); + + if (gXULCache) + gXULCache->Flush(); return NS_OK; } @@ -4745,8 +4796,8 @@ nsXULDocument::PrepareToLoadPrototype(nsIURI* aURI, const char* aCommand, // at the end while old (available) data continues to be read // from the pre-existing part of the file. rv = gFastLoadService->StartMuxedDocument(aURI, urlspec, - nsIFastLoadService::NS_FASTLOAD_READ | - nsIFastLoadService::NS_FASTLOAD_WRITE); + nsIFastLoadService::NS_FASTLOAD_READ | + nsIFastLoadService::NS_FASTLOAD_WRITE); NS_ASSERTION(rv != NS_ERROR_NOT_AVAILABLE, "only reading FastLoad?!"); if (NS_FAILED(rv)) AbortFastLoads(); @@ -5445,9 +5496,9 @@ nsXULDocument::ResumeWalk() // If it's a 'chrome:' prototype document, then put it into // the prototype cache; other XUL documents will be reloaded - // each time. We must do this *after* NS_OpenURI, or chrome - // code will wrongly create a cached chrome channel instead - // of a real one. + // each time. We must do this after NS_OpenURI and AsyncOpen, + // or chrome code will wrongly create a cached chrome channel + // instead of a real one. if (cache && IsChromeURI(uri)) { rv = gXULCache->PutPrototype(mCurrentPrototype); if (NS_FAILED(rv)) return rv; @@ -5575,7 +5626,7 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader, const char* string) { // print a load error on bad status - if (NS_FAILED(aStatus) && aLoader) { + if (NS_FAILED(aStatus)) { nsCOMPtr request; aLoader->GetRequest(getter_AddRefs(request)); nsCOMPtr channel; @@ -5629,7 +5680,7 @@ nsXULDocument::OnStreamComplete(nsIStreamLoader* aLoader, nsXPIDLCString urispec; uri->GetSpec(getter_Copies(urispec)); rv = gFastLoadService->StartMuxedDocument(uri, urispec, - nsIFastLoadService::NS_FASTLOAD_WRITE); + nsIFastLoadService::NS_FASTLOAD_WRITE); NS_ASSERTION(rv != NS_ERROR_NOT_AVAILABLE, "reading FastLoad?!"); if (NS_SUCCEEDED(rv)) gFastLoadService->SelectMuxedDocument(uri); @@ -6565,7 +6616,7 @@ nsXULDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult) PRInt32 namespaceID; nsCOMPtr tag; - nsCOMPtr xblService = + nsCOMPtr xblService = do_GetService("@mozilla.org/xbl;1", &rv); nsCOMPtr content(do_QueryInterface(aElement)); xblService->ResolveTag(content, &namespaceID, getter_AddRefs(tag)); diff --git a/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp b/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp index 153e9d035bd..8aea06f8a31 100644 --- a/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp +++ b/mozilla/content/xul/document/src/nsXULPrototypeCache.cpp @@ -42,6 +42,7 @@ #include "nsIXBLDocumentInfo.h" #include "nsIPref.h" #include "nsIServiceManager.h" +#include "nsXULDocument.h" class nsXULPrototypeCache : public nsIXULPrototypeCache { @@ -69,6 +70,8 @@ public: NS_IMETHOD GetEnabled(PRBool* aIsEnabled); + NS_IMETHOD AbortFastLoads(); + protected: friend NS_IMETHODIMP NS_NewXULPrototypeCache(nsISupports* aOuter, REFNSIID aIID, void** aResult); @@ -330,3 +333,10 @@ nsXULPrototypeCache::GetEnabled(PRBool* aIsEnabled) *aIsEnabled = !gDisableXULCache; return NS_OK; } + + +NS_IMETHODIMP +nsXULPrototypeCache::AbortFastLoads() +{ + return nsXULDocument::AbortFastLoads(); +} diff --git a/mozilla/layout/generic/nsImageFrame.cpp b/mozilla/layout/generic/nsImageFrame.cpp index 984fc8da1bd..8fa8db38b0c 100644 --- a/mozilla/layout/generic/nsImageFrame.cpp +++ b/mozilla/layout/generic/nsImageFrame.cpp @@ -163,7 +163,6 @@ NS_IMETHODIMP nsImageFrame::GetAccessible(nsIAccessible** aAccessible) nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { - nsIAccessible* acc = nsnull; return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); } diff --git a/mozilla/layout/html/base/src/nsImageFrame.cpp b/mozilla/layout/html/base/src/nsImageFrame.cpp index 984fc8da1bd..8fa8db38b0c 100644 --- a/mozilla/layout/html/base/src/nsImageFrame.cpp +++ b/mozilla/layout/html/base/src/nsImageFrame.cpp @@ -163,7 +163,6 @@ NS_IMETHODIMP nsImageFrame::GetAccessible(nsIAccessible** aAccessible) nsCOMPtr accService = do_GetService("@mozilla.org/accessibilityService;1"); if (accService) { - nsIAccessible* acc = nsnull; return accService->CreateHTMLImageAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible); } diff --git a/mozilla/modules/libjar/nsJAR.cpp b/mozilla/modules/libjar/nsJAR.cpp index 20da7cebcba..44994a2d851 100644 --- a/mozilla/modules/libjar/nsJAR.cpp +++ b/mozilla/modules/libjar/nsJAR.cpp @@ -543,10 +543,10 @@ nsJAR::ParseManifest(nsISignatureVerifier* verifier) rv = LoadEntry(tempFilename, getter_Copies(sigBuffer), &sigLen); } if (NS_FAILED(rv)) - { - nsCAutoString tempFilename(sigFilename); tempFilename.Append("RSA", 3); - rv = LoadEntry(tempFilename, getter_Copies(sigBuffer), &sigLen); - } + { + nsCAutoString tempFilename(sigFilename); tempFilename.Append("RSA", 3); + rv = LoadEntry(tempFilename, getter_Copies(sigBuffer), &sigLen); + } if (NS_FAILED(rv)) { mGlobalStatus = nsIJAR::NO_MANIFEST; diff --git a/mozilla/modules/libjar/nsJARChannel.cpp b/mozilla/modules/libjar/nsJARChannel.cpp index bcae7d9a1be..65ebdb7564d 100644 --- a/mozilla/modules/libjar/nsJARChannel.cpp +++ b/mozilla/modules/libjar/nsJARChannel.cpp @@ -103,7 +103,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS7(nsJARChannel, NS_METHOD nsJARChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) { - nsresult rv; + nsresult rv; if (aOuter) return NS_ERROR_NO_AGGREGATION; @@ -113,16 +113,16 @@ nsJARChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(jarChannel); - rv = jarChannel->QueryInterface(aIID, aResult); + rv = jarChannel->QueryInterface(aIID, aResult); NS_RELEASE(jarChannel); - return rv; + return rv; } nsresult nsJARChannel::Init(nsIJARProtocolHandler* aHandler, nsIURI* uri) { nsresult rv; - mURI = do_QueryInterface(uri, &rv); + mURI = do_QueryInterface(uri, &rv); if (NS_FAILED(rv)) return rv; mMonitor = PR_NewMonitor(); @@ -130,7 +130,7 @@ nsJARChannel::Init(nsIJARProtocolHandler* aHandler, nsIURI* uri) return NS_ERROR_OUT_OF_MEMORY; mJARProtocolHandler = aHandler; - return NS_OK; + return NS_OK; } //////////////////////////////////////////////////////////////////////////////// @@ -152,7 +152,7 @@ nsJARChannel::GetName(PRUnichar* *result) NS_IMETHODIMP nsJARChannel::IsPending(PRBool* result) { - NS_NOTREACHED("nsJARChannel::IsPending"); + NS_NOTREACHED("nsJARChannel::IsPending"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -176,7 +176,7 @@ nsJARChannel::Cancel(nsresult status) } mStatus = status; - return rv; + return rv; } NS_IMETHODIMP @@ -189,7 +189,7 @@ nsJARChannel::Suspend() rv = mJarExtractionTransport->Suspend(); } - return rv; + return rv; } NS_IMETHODIMP @@ -202,7 +202,7 @@ nsJARChannel::Resume() rv = mJarExtractionTransport->Resume(); } - return rv; + return rv; } //////////////////////////////////////////////////////////////////////////////// @@ -244,7 +244,7 @@ nsJARChannel::OpenJARElement() if (NS_SUCCEEDED(rv)) rv = GetInputStream(getter_AddRefs(mSynchronousInputStream)); mon.Notify(); // wake up nsIChannel::Open - return rv; + return rv; } NS_IMETHODIMP @@ -257,15 +257,13 @@ nsJARChannel::Open(nsIInputStream* *result) if (NS_FAILED(rv)) return rv; if (mSynchronousInputStream == nsnull) mon.Wait(); - if (mSynchronousInputStream) - { - *result = mSynchronousInputStream; // Result of GetInputStream called on transport thread - NS_ADDREF(*result); - mSynchronousInputStream = 0; - return NS_OK; - } - else + if (!mSynchronousInputStream) return NS_ERROR_FAILURE; + + *result = mSynchronousInputStream; // Result of GetInputStream called on transport thread + NS_ADDREF(*result); + mSynchronousInputStream = 0; + return NS_OK; } NS_IMETHODIMP @@ -288,10 +286,6 @@ nsresult nsJARChannel::EnsureJARFileAvailable() { nsresult rv; - nsCOMPtr jarBaseChannel; - nsCOMPtr jarCacheFile; - nsCOMPtr jarCacheTransport; - nsCOMPtr jarBaseIn; #ifdef PR_LOGGING nsXPIDLCString jarURLStr; @@ -307,8 +301,8 @@ nsJARChannel::EnsureJARFileAvailable() if (NS_FAILED(rv)) goto error; rv = NS_NewDownloader(getter_AddRefs(mDownloader), - mJARBaseURI, this, nsnull, mSynchronousRead, mLoadGroup, mCallbacks, - mLoadFlags); + mJARBaseURI, this, nsnull, mSynchronousRead, + mLoadGroup, mCallbacks, mLoadFlags); // if DownloadComplete() was called early, need to release the reference. if (mSynchronousRead && mSynchronousInputStream) @@ -340,7 +334,7 @@ nsJARChannel::AsyncReadJARElement() if (mCallbacks) { nsCOMPtr sink = do_GetInterface(mCallbacks); if (sink) { - // don't think that this is not needed anymore + // XXX don't think that this is needed anymore // jarTransport->SetProgressEventSink(sink); } } @@ -399,7 +393,7 @@ nsJARChannel::GetContentType(char* *aContentType) } else rv = NS_ERROR_OUT_OF_MEMORY; - + nsCRT::free(fileName); } else { @@ -655,7 +649,7 @@ nsJARChannel::Open(char* *contentType, PRInt32 *contentLength) NS_IMETHODIMP nsJARChannel::Close(nsresult status) { - return NS_OK; + return NS_OK; } NS_IMETHODIMP @@ -674,7 +668,7 @@ nsJARChannel::GetInputStream(nsIInputStream* *aInputStream) NS_IMETHODIMP nsJARChannel::GetOutputStream(nsIOutputStream* *aOutputStream) { - NS_NOTREACHED("nsJARChannel::GetOutputStream"); + NS_NOTREACHED("nsJARChannel::GetOutputStream"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -690,7 +684,7 @@ nsJARChannel::GetName(char* *aName) NS_IMETHODIMP nsJARChannel::EnumerateEntries(const char *aRoot, nsISimpleEnumerator **_retval) { - NS_NOTREACHED("nsJARChannel::EnumerateEntries"); + NS_NOTREACHED("nsJARChannel::EnumerateEntries"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/modules/libjar/nsJARChannel.h b/mozilla/modules/libjar/nsJARChannel.h index 218c32f068a..41ae97dacc3 100644 --- a/mozilla/modules/libjar/nsJARChannel.h +++ b/mozilla/modules/libjar/nsJARChannel.h @@ -42,7 +42,7 @@ class nsIFileChannel; class nsJARChannel; -#define NS_JARCHANNEL_CID \ +#define NS_JARCHANNEL_CID \ { /* 0xc7e410d5-0x85f2-11d3-9f63-006008a6efe9 */ \ 0xc7e410d5, \ 0x85f2, \ @@ -82,10 +82,10 @@ public: protected: nsCOMPtr mJARProtocolHandler; - nsCOMPtr mURI; - nsCOMPtr mLoadGroup; - nsCOMPtr mCallbacks; - nsCOMPtr mOriginalURI; + nsCOMPtr mURI; + nsCOMPtr mLoadGroup; + nsCOMPtr mCallbacks; + nsCOMPtr mOriginalURI; nsLoadFlags mLoadFlags; nsCOMPtr mOwner; diff --git a/mozilla/modules/libjar/nsJARInputStream.cpp b/mozilla/modules/libjar/nsJARInputStream.cpp index 7fc72056573..6e88853b026 100644 --- a/mozilla/modules/libjar/nsJARInputStream.cpp +++ b/mozilla/modules/libjar/nsJARInputStream.cpp @@ -37,7 +37,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS1(nsJARInputStream, nsIInputStream); NS_IMETHODIMP nsJARInputStream::Available(PRUint32 *_retval) { - if (Zip() == 0) + if (Zip() == nsnull) *_retval = 0; else *_retval = Zip()->Available(mReadInfo); diff --git a/mozilla/modules/libjar/nsJARProtocolHandler.cpp b/mozilla/modules/libjar/nsJARProtocolHandler.cpp index 6a13c0c4ff2..e701d7790f6 100644 --- a/mozilla/modules/libjar/nsJARProtocolHandler.cpp +++ b/mozilla/modules/libjar/nsJARProtocolHandler.cpp @@ -17,7 +17,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ #include "nsJARProtocolHandler.h" @@ -48,7 +48,7 @@ nsresult nsJARProtocolHandler::Init() { nsresult rv; - rv = nsComponentManager::CreateInstance(kZipReaderCacheCID, + rv = nsComponentManager::CreateInstance(kZipReaderCacheCID, nsnull, NS_GET_IID(nsIZipReaderCache), getter_AddRefs(mJARCache)); @@ -62,8 +62,8 @@ nsJARProtocolHandler::~nsJARProtocolHandler() { } -NS_IMPL_THREADSAFE_ISUPPORTS2(nsJARProtocolHandler, - nsIJARProtocolHandler, +NS_IMPL_THREADSAFE_ISUPPORTS2(nsJARProtocolHandler, + nsIJARProtocolHandler, nsIProtocolHandler) NS_METHOD @@ -154,12 +154,12 @@ NS_IMETHODIMP nsJARProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result) { nsresult rv; - - nsJARChannel* channel; + + nsJARChannel* channel; rv = nsJARChannel::Create(nsnull, NS_GET_IID(nsIJARChannel), (void**)&channel); if (NS_FAILED(rv)) return rv; - rv = channel->Init(this, uri); + rv = channel->Init(this, uri); if (NS_FAILED(rv)) { NS_RELEASE(channel); return rv; @@ -170,10 +170,10 @@ nsJARProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result) } -NS_IMETHODIMP +NS_IMETHODIMP nsJARProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval) { - // don't override anything. + // don't override anything. *_retval = PR_FALSE; return NS_OK; } diff --git a/mozilla/modules/libjar/nsJARURI.cpp b/mozilla/modules/libjar/nsJARURI.cpp index d78f1c551bd..040f4d11398 100644 --- a/mozilla/modules/libjar/nsJARURI.cpp +++ b/mozilla/modules/libjar/nsJARURI.cpp @@ -82,7 +82,7 @@ nsJARURI::FormatSpec(const char* entryPath, char* *result) rv = mJARFile->GetSpec(&jarFileSpec); if (NS_FAILED(rv)) return rv; - nsCString spec(NS_JAR_SCHEME); + nsCAutoString spec(NS_JAR_SCHEME); spec += jarFileSpec; nsCRT::free(jarFileSpec); spec += NS_JAR_DELIMITER; @@ -368,7 +368,7 @@ nsJARURI::Resolve(const char *relativePath, char **result) } //////////////////////////////////////////////////////////////////////////////// -// nsIJARUri methods: +// nsIJARURI methods: NS_IMETHODIMP nsJARURI::GetJARFile(nsIURI* *jarFile) diff --git a/mozilla/modules/libjar/nsJARURI.h b/mozilla/modules/libjar/nsJARURI.h index 1af154fac1b..9d8c9358b93 100644 --- a/mozilla/modules/libjar/nsJARURI.h +++ b/mozilla/modules/libjar/nsJARURI.h @@ -23,7 +23,7 @@ #include "nsISerializable.h" #include "nsCOMPtr.h" -#define NS_JARURI_CID \ +#define NS_JARURI_CID \ { /* 0xc7e410d7-0x85f2-11d3-9f63-006008a6efe9 */ \ 0xc7e410d7, \ 0x85f2, \ diff --git a/mozilla/netwerk/base/public/nsIURL.idl b/mozilla/netwerk/base/public/nsIURL.idl index ebf89dfeb18..d4919f3742e 100644 --- a/mozilla/netwerk/base/public/nsIURL.idl +++ b/mozilla/netwerk/base/public/nsIURL.idl @@ -126,9 +126,9 @@ interface nsIURL : nsIURI /** * Protocol writers can obtain a default nsIURL implementation by calling the * component manager with NS_STANDARDURL_CID. The implementation returned will - * only implement the set of accessors specified by nsIURL. After obtaining the - * instance from the component manager, the Init routine must be called on it - * to initialize it from the user's URL spec. + * implement only the set of accessors specified by nsIURL. After obtaining the + * instance from the component manager, the Init routine must be called on the + * new instance to initialize it from the user's URL spec. */ [scriptable, uuid(8793370a-311f-11d4-9876-00c04fa0cf4a)] diff --git a/mozilla/netwerk/base/src/Makefile.in b/mozilla/netwerk/base/src/Makefile.in index 314ae8dd92b..6f58c458249 100644 --- a/mozilla/netwerk/base/src/Makefile.in +++ b/mozilla/netwerk/base/src/Makefile.in @@ -31,36 +31,36 @@ LIBRARY_NAME = neckobase_s REQUIRES = xpcom string exthandler mimetype intl pref CPPSRCS = \ - nsURLHelper.cpp \ - nsFileStreams.cpp \ + nsAsyncStreamListener.cpp \ + nsAuthURLParser.cpp \ nsBufferedStreams.cpp \ - nsIOService.cpp \ - nsSocketTransport.cpp \ - nsSocketTransportService.cpp \ + nsDirectoryIndexStream.cpp \ + nsDownloader.cpp \ + nsFileStreams.cpp \ nsFileTransport.cpp \ nsFileTransportService.cpp \ - nsSimpleStreamListener.cpp \ - nsSimpleStreamProvider.cpp \ - nsRequestObserverProxy.cpp \ - nsStreamListenerProxy.cpp \ - nsStreamProviderProxy.cpp \ - nsStdURLParser.cpp \ - nsAuthURLParser.cpp \ - nsNoAuthURLParser.cpp \ - nsStdURL.cpp \ - nsSimpleURI.cpp \ - nsNetModuleMgr.cpp \ - nsNetModRegEntry.cpp \ - nsLoadGroup.cpp \ nsInputStreamChannel.cpp \ - nsDirectoryIndexStream.cpp \ - nsStreamLoader.cpp \ - nsDownloader.cpp \ + nsIOService.cpp \ + nsLoadGroup.cpp \ + nsNetModRegEntry.cpp \ + nsNetModuleMgr.cpp \ + nsNoAuthURLParser.cpp \ nsProtocolProxyService.cpp \ nsProxyAutoConfigUtils.cpp \ - nsAsyncStreamListener.cpp \ + nsRequestObserverProxy.cpp \ + nsSimpleStreamListener.cpp \ + nsSimpleStreamProvider.cpp \ + nsSimpleURI.cpp \ + nsSocketTransport.cpp \ + nsSocketTransportService.cpp \ + nsStdURL.cpp \ + nsStdURLParser.cpp \ nsStorageTransport.cpp \ - nsStreamListenerTee.cpp \ + nsStreamListenerProxy.cpp \ + nsStreamListenerTee.cpp \ + nsStreamLoader.cpp \ + nsStreamProviderProxy.cpp \ + nsURLHelper.cpp \ $(NULL) JSFILES = \ diff --git a/mozilla/netwerk/base/src/nsBufferedStreams.cpp b/mozilla/netwerk/base/src/nsBufferedStreams.cpp index 86225310e6c..c96061497c7 100644 --- a/mozilla/netwerk/base/src/nsBufferedStreams.cpp +++ b/mozilla/netwerk/base/src/nsBufferedStreams.cpp @@ -36,12 +36,13 @@ static struct { PRUint32 mSeeksOutsideBuffer; PRUint32 mBufferReadUponSeek; PRUint32 mBufferUnreadUponSeek; + PRUint32 mBytesReadFromBuffer; PRUint32 mBigSeekIndex; struct { PRUint32 mOldOffset; PRUint32 mNewOffset; } mBigSeek[MAX_BIG_SEEKS]; -} stats; +} bufstats; #else # define METER(x) /* nothing */ #endif @@ -54,7 +55,9 @@ nsBufferedStream::nsBufferedStream() mBufferStartOffset(0), mCursor(0), mFillPoint(0), - mStream(nsnull) + mStream(nsnull), + mBufferDisabled(PR_FALSE), + mGetBufferCount(0) { NS_INIT_REFCNT(); } @@ -126,28 +129,28 @@ nsBufferedStream::Seek(PRInt32 whence, PRInt32 offset) return NS_ERROR_UNEXPECTED; } - // Let mCursor point into the existing buffer if the new position is at - // the mFillPoint "fencepost" -- the client may never get around to Read - // or Write after this seek. Let Read and Write worry about flushing and - // filling in that event. + // Let mCursor point into the existing buffer if the new position is + // between the current cursor and the mFillPoint "fencepost" -- the + // client may never get around to a Read or Write after this Seek. + // Read and Write worry about flushing and filling in that event. PRUint32 offsetInBuffer = PRUint32(absPos - mBufferStartOffset); if (offsetInBuffer <= mFillPoint) { - METER(stats.mSeeksWithinBuffer++); + METER(bufstats.mSeeksWithinBuffer++); mCursor = offsetInBuffer; return NS_OK; } - METER(stats.mSeeksOutsideBuffer++); - METER(stats.mBufferReadUponSeek += mCursor); - METER(stats.mBufferUnreadUponSeek += mFillPoint - mCursor); + METER(bufstats.mSeeksOutsideBuffer++); + METER(bufstats.mBufferReadUponSeek += mCursor); + METER(bufstats.mBufferUnreadUponSeek += mFillPoint - mCursor); rv = Flush(); if (NS_FAILED(rv)) return rv; rv = ras->Seek(whence, offset); if (NS_FAILED(rv)) return rv; - METER(if (stats.mBigSeekIndex < MAX_BIG_SEEKS) - stats.mBigSeek[stats.mBigSeekIndex].mOldOffset = + METER(if (bufstats.mBigSeekIndex < MAX_BIG_SEEKS) + bufstats.mBigSeek[bufstats.mBigSeekIndex].mOldOffset = mBufferStartOffset + mCursor); if (absPos == -1) { // then we had the SEEK_END case, above @@ -157,12 +160,11 @@ nsBufferedStream::Seek(PRInt32 whence, PRInt32 offset) else { mBufferStartOffset = absPos; } - METER(if (stats.mBigSeekIndex < MAX_BIG_SEEKS) - stats.mBigSeek[stats.mBigSeekIndex++].mNewOffset = + METER(if (bufstats.mBigSeekIndex < MAX_BIG_SEEKS) + bufstats.mBigSeek[bufstats.mBigSeekIndex++].mNewOffset = mBufferStartOffset); - mCursor = 0; - mFillPoint = 0; + mFillPoint = mCursor = 0; return Fill(); } @@ -265,6 +267,7 @@ nsBufferedInputStream::Read(char * buf, PRUint32 count, PRUint32 *result) break; } } + METER(if (read > 0) bufstats.mBytesReadFromBuffer += read); *result = read; return (read > 0) ? NS_OK : rv; } @@ -391,6 +394,7 @@ nsBufferedInputStream::PutBuffer(char* aBuffer, PRUint32 aLength) NS_IMETHODIMP nsBufferedInputStream::DisableBuffering() { + NS_ASSERTION(!mBufferDisabled, "redundant call to DisableBuffering!"); NS_ASSERTION(mGetBufferCount == 0, "DisableBuffer call between GetBuffer and PutBuffer!"); if (mGetBufferCount != 0) @@ -406,17 +410,31 @@ nsBufferedInputStream::DisableBuffering() NS_IMETHODIMP nsBufferedInputStream::EnableBuffering() { + NS_ASSERTION(mBufferDisabled, "gratuitous call to EnableBuffering!"); mBufferDisabled = PR_FALSE; return NS_OK; } +NS_IMETHODIMP +nsBufferedInputStream::GetUnbufferedStream(nsISupports* *aStream) +{ + // Empty the buffer so subsequent i/o trumps any buffered data. + mBufferStartOffset += mCursor; + mFillPoint = mCursor = 0; + + *aStream = mStream; + NS_IF_ADDREF(*aStream); + return NS_OK; +} + //////////////////////////////////////////////////////////////////////////////// // nsBufferedOutputStream -NS_IMPL_ISUPPORTS_INHERITED2(nsBufferedOutputStream, +NS_IMPL_ISUPPORTS_INHERITED3(nsBufferedOutputStream, nsBufferedStream, nsIOutputStream, - nsIBufferedOutputStream) + nsIBufferedOutputStream, + nsIStreamBufferAccess) NS_METHOD nsBufferedOutputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -468,50 +486,21 @@ nsBufferedOutputStream::Write(const char *buf, PRUint32 count, PRUint32 *result) written += amt; count -= amt; mCursor += amt; + if (mFillPoint < mCursor) + mFillPoint = mCursor; } else { - NS_ASSERTION(mCursor, "looping in nsBufferedOutputStream::Write!"); + NS_ASSERTION(mFillPoint, "iloop in nsBufferedOutputStream::Write!"); rv = Flush(); if (NS_FAILED(rv)) break; } } - if (mFillPoint < mCursor) - mFillPoint = mCursor; *result = written; return (written > 0) ? NS_OK : rv; } NS_IMETHODIMP -nsBufferedOutputStream::Fill() -{ - nsCOMPtr sos(do_QueryInterface(mStream)); - if (!sos) { - // XXXbe not OK! Seek back and write less than a buffer case fails! - return NS_OK; - } - - nsresult rv; - PRUint32 rem = mFillPoint - mCursor; - if (rem > 0) { - // slide the remainder down to the start of the buffer - // |<------------->|<--rem-->|<--->| - // b c f s - nsCRT::memcpy(mBuffer, mBuffer + mCursor, rem); - } - mBufferStartOffset += mCursor; - mFillPoint = rem; - mCursor = 0; - - PRUint32 amt; - rv = sos->Fill(mBuffer + mFillPoint, mBufferSize - mFillPoint, &amt); - if (NS_FAILED(rv)) return rv; - - mFillPoint += amt; - return NS_OK; -} - -NS_IMETHODIMP -nsBufferedOutputStream::Flush(void) +nsBufferedOutputStream::Flush() { nsresult rv; PRUint32 amt; @@ -519,20 +508,20 @@ nsBufferedOutputStream::Flush(void) // Stream already cancelled/flushed; probably because of error. return NS_OK; } - rv = Sink()->Write(mBuffer, mCursor, &amt); + rv = Sink()->Write(mBuffer, mFillPoint, &amt); if (NS_FAILED(rv)) return rv; mBufferStartOffset += amt; - if (mCursor == amt) { - mCursor = 0; + if (amt == mFillPoint) { + mFillPoint = mCursor = 0; return NS_OK; // flushed everything } // slide the remainder down to the start of the buffer // |<-------------->|<---|----->| // b a c s - PRUint32 rem = mCursor - amt; + PRUint32 rem = mFillPoint - amt; nsCRT::memcpy(mBuffer, mBuffer + amt, rem); - mCursor = rem; + mFillPoint = mCursor = rem; return NS_ERROR_FAILURE; // didn't flush all } @@ -580,4 +569,95 @@ nsBufferedOutputStream::SetObserver(nsIOutputStreamObserver * aObserver) return NS_ERROR_NOT_IMPLEMENTED; } +NS_IMETHODIMP_(char*) +nsBufferedOutputStream::GetBuffer(PRUint32 aLength, PRUint32 aAlignMask) +{ + NS_ASSERTION(mGetBufferCount == 0, "nested GetBuffer!"); + if (mGetBufferCount != 0) + return nsnull; + + if (mBufferDisabled) + return nsnull; + + char* buf = mBuffer + mCursor; + PRUint32 rem = mBufferSize - mCursor; + if (rem == 0) { + if (NS_FAILED(Flush())) + return nsnull; + buf = mBuffer + mCursor; + rem = mBufferSize - mCursor; + } + + PRUint32 mod = (NS_PTR_TO_INT32(buf) & aAlignMask); + if (mod) { + PRUint32 pad = aAlignMask + 1 - mod; + if (pad > rem) + return nsnull; + + memset(buf, 0, pad); + mCursor += pad; + buf += pad; + rem -= pad; + } + + if (aLength > rem) + return nsnull; + mGetBufferCount++; + return buf; +} + +NS_IMETHODIMP_(void) +nsBufferedOutputStream::PutBuffer(char* aBuffer, PRUint32 aLength) +{ + NS_ASSERTION(mGetBufferCount == 1, "stray PutBuffer!"); + if (--mGetBufferCount != 0) + return; + + NS_ASSERTION(mCursor + aLength <= mBufferSize, "PutBuffer botch"); + mCursor += aLength; + if (mFillPoint < mCursor) + mFillPoint = mCursor; +} + +NS_IMETHODIMP +nsBufferedOutputStream::DisableBuffering() +{ + NS_ASSERTION(!mBufferDisabled, "redundant call to DisableBuffering!"); + NS_ASSERTION(mGetBufferCount == 0, + "DisableBuffer call between GetBuffer and PutBuffer!"); + if (mGetBufferCount != 0) + return NS_ERROR_UNEXPECTED; + + // Empty the buffer so nsBufferedStream::Tell works. + nsresult rv = Flush(); + if (NS_FAILED(rv)) + return rv; + + mBufferDisabled = PR_TRUE; + return NS_OK; +} + +NS_IMETHODIMP +nsBufferedOutputStream::EnableBuffering() +{ + NS_ASSERTION(mBufferDisabled, "gratuitous call to EnableBuffering!"); + mBufferDisabled = PR_FALSE; + return NS_OK; +} + +NS_IMETHODIMP +nsBufferedOutputStream::GetUnbufferedStream(nsISupports* *aStream) +{ + // Empty the buffer so subsequent i/o trumps any buffered data. + if (mFillPoint) { + nsresult rv = Flush(); + if (NS_FAILED(rv)) + return rv; + } + + *aStream = mStream; + NS_IF_ADDREF(*aStream); + return NS_OK; +} + //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/src/nsBufferedStreams.h b/mozilla/netwerk/base/src/nsBufferedStreams.h index db764184858..94ea96fa66d 100644 --- a/mozilla/netwerk/base/src/nsBufferedStreams.h +++ b/mozilla/netwerk/base/src/nsBufferedStreams.h @@ -47,7 +47,6 @@ protected: NS_IMETHOD Fill() = 0; NS_IMETHOD Flush() = 0; -protected: PRUint32 mBufferSize; char* mBuffer; @@ -59,12 +58,14 @@ protected: PRUint32 mCursor; // mFillPoint is the amount available in the buffer for input streams, - // or the count of bytes written or read (in case of a seek/read/write - // cycle) in the buffer for output streams, and is therefore relative - // to mBufferStartOffset. + // or the high watermark of bytes written into the buffer, and therefore + // is relative to mBufferStartOffset. PRUint32 mFillPoint; nsISupports* mStream; // cast to appropriate subclass + + PRPackedBool mBufferDisabled; + PRUint8 mGetBufferCount; }; //////////////////////////////////////////////////////////////////////////////// @@ -79,9 +80,7 @@ public: NS_DECL_NSIBUFFEREDINPUTSTREAM NS_DECL_NSISTREAMBUFFERACCESS - nsBufferedInputStream() : nsBufferedStream(), - mBufferDisabled(PR_FALSE), - mGetBufferCount(0) {} + nsBufferedInputStream() : nsBufferedStream() {} virtual ~nsBufferedInputStream() {} static NS_METHOD @@ -94,21 +93,19 @@ public: protected: NS_IMETHOD Fill(); NS_IMETHOD Flush() { return NS_OK; } // no-op for input streams - -private: - PRPackedBool mBufferDisabled; - PRUint8 mGetBufferCount; }; //////////////////////////////////////////////////////////////////////////////// class nsBufferedOutputStream : public nsBufferedStream, - public nsIBufferedOutputStream + public nsIBufferedOutputStream, + public nsIStreamBufferAccess { public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIOUTPUTSTREAM NS_DECL_NSIBUFFEREDOUTPUTSTREAM + NS_DECL_NSISTREAMBUFFERACCESS nsBufferedOutputStream() : nsBufferedStream() {} virtual ~nsBufferedOutputStream() { nsBufferedOutputStream::Close(); } @@ -121,7 +118,7 @@ public: } protected: - NS_IMETHOD Fill(); + NS_IMETHOD Fill() { return NS_OK; } // no-op for input streams }; //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/src/nsFileStreams.cpp b/mozilla/netwerk/base/src/nsFileStreams.cpp index 27efa7c13f6..d05c1e45085 100644 --- a/mozilla/netwerk/base/src/nsFileStreams.cpp +++ b/mozilla/netwerk/base/src/nsFileStreams.cpp @@ -538,11 +538,10 @@ nsFileInputStream::SetObserver(nsIInputStreamObserver * aObserver) //////////////////////////////////////////////////////////////////////////////// // nsFileOutputStream -NS_IMPL_ISUPPORTS_INHERITED3(nsFileOutputStream, +NS_IMPL_ISUPPORTS_INHERITED2(nsFileOutputStream, nsFileStream, nsIOutputStream, - nsIFileOutputStream, - nsISeekableOutputStream) + nsIFileOutputStream) NS_METHOD nsFileOutputStream::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) @@ -568,7 +567,7 @@ nsFileOutputStream::Init(nsIFile* file, PRInt32 ioFlags, PRInt32 perm) nsCOMPtr localFile = do_QueryInterface(file, &rv); if (NS_FAILED(rv)) return rv; if (ioFlags == -1) - ioFlags = PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE; + ioFlags = PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE; if (perm <= 0) perm = 0664; return localFile->OpenNSPRFileDesc(ioFlags, perm, &mFD); @@ -648,21 +647,4 @@ nsFileOutputStream::SetObserver(nsIOutputStreamObserver * aObserver) return NS_ERROR_NOT_IMPLEMENTED; } -NS_IMETHODIMP -nsFileOutputStream::Fill(char * buf, PRUint32 count, PRUint32 *result) -{ - if (mFD == nsnull) - return NS_BASE_STREAM_CLOSED; - - PRInt32 cnt = PR_Read(mFD, buf, count); - if (cnt == -1) { - return NS_ErrorAccordingToNSPR(); - } - if (PR_Seek(mFD, -cnt, PR_SEEK_CUR) == -1) { - return NS_ErrorAccordingToNSPR(); - } - *result = cnt; - return NS_OK; -} - //////////////////////////////////////////////////////////////////////////////// diff --git a/mozilla/netwerk/base/src/nsFileStreams.h b/mozilla/netwerk/base/src/nsFileStreams.h index 6af6edb80e6..3528b551ba5 100644 --- a/mozilla/netwerk/base/src/nsFileStreams.h +++ b/mozilla/netwerk/base/src/nsFileStreams.h @@ -100,14 +100,12 @@ protected: //////////////////////////////////////////////////////////////////////////////// class nsFileOutputStream : public nsFileStream, - public nsIFileOutputStream, - public nsISeekableOutputStream + public nsIFileOutputStream { public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_NSIOUTPUTSTREAM NS_DECL_NSIFILEOUTPUTSTREAM - NS_DECL_NSISEEKABLEOUTPUTSTREAM nsFileOutputStream() : nsFileStream() {} virtual ~nsFileOutputStream() { nsFileOutputStream::Close(); } diff --git a/mozilla/netwerk/base/src/nsStdURL.cpp b/mozilla/netwerk/base/src/nsStdURL.cpp index c375683a68d..0fb53c85dc8 100644 --- a/mozilla/netwerk/base/src/nsStdURL.cpp +++ b/mozilla/netwerk/base/src/nsStdURL.cpp @@ -63,15 +63,14 @@ nsIURLParser * nsStdURL::gNoAuthURLParser = NULL; #if defined (XP_MAC) static void SwapSlashColon(char * s) { - while (*s) - { - if (*s == '/') - *s++ = ':'; - else if (*s == ':') - *s++ = '/'; - else - *s++; - } + while (*s) { + if (*s == '/') + *s++ = ':'; + else if (*s == ':') + *s++ = '/'; + else + *s++; + } } #endif @@ -228,7 +227,7 @@ nsStdURL::~nsStdURL() CRTFREEIF(mRef); } -NS_IMPL_AGGREGATED(nsStdURL); +NS_IMPL_AGGREGATED(nsStdURL) NS_IMETHODIMP nsStdURL::AggregatedQueryInterface(const nsIID& aIID, void** aInstancePtr) @@ -1154,10 +1153,9 @@ nsStdURL::GetFile(nsIFile * *aFile) NS_ASSERTION(mUsername == nsnull, "file: with mUsername"); - // we do not use the path cause it can contain the # char + // we do not use the path cause it can contain the # char nsCAutoString path; - if (mDirectory) - { + if (mDirectory) { rv = AppendString(path,mDirectory,ESCAPED,nsIIOService::url_Directory); #if defined( XP_MAC ) // Now Swap the / and colons to convert back to a mac path @@ -1181,9 +1179,9 @@ nsStdURL::GetFile(nsIFile * *aFile) nsCAutoString host(mHost); PRInt32 len = host.Length(); if (len == 2 && host.CharAt(1) == '|') { - host.SetCharAt(':', 1); - path.Insert(host, 0); - } + host.SetCharAt(':', 1); + path.Insert(host, 0); + } } if ((path.CharAt(0) == '/' && path.CharAt(1) == '/')) { @@ -1212,8 +1210,8 @@ nsStdURL::GetFile(nsIFile * *aFile) rv = NS_NewLocalFile(path, PR_FALSE, getter_AddRefs(localFile)); mFile = localFile; - *aFile = mFile; - NS_IF_ADDREF(*aFile); + *aFile = mFile; + NS_IF_ADDREF(*aFile); return rv; } @@ -1239,33 +1237,32 @@ nsStdURL::SetFile(nsIFile * aFile) #if defined (XP_PC) // Replace \ with / to convert to an url char* s = ePath; - while (*s) - { + while (*s) { #ifndef XP_OS2 // We need to call IsDBCSLeadByte because // Japanese windows can have 0x5C in the sencond byte // of a Japanese character, for example 0x8F 0x5C is // one Japanese character - if(::IsDBCSLeadByte(*s) && *(s+1) != nsnull) { + if (::IsDBCSLeadByte(*s) && *(s+1) != nsnull) { s++; - } else + } else #endif - if (*s == '\\') - *s = '/'; - s++; - } + if (*s == '\\') + *s = '/'; + s++; + } #endif #if defined( XP_MAC ) - // Swap the / and colons to convert to an url + // Swap the / and colons to convert to an url SwapSlashColon(ePath); #endif // Escape the path with the directory mask rv = nsURLEscape(ePath,nsIIOService::url_Directory+ nsIIOService::url_Forced,escPath); if (NS_SUCCEEDED(rv)) { - PRBool dir; + PRBool dir = PR_FALSE; rv = aFile->IsDirectory(&dir); - if (NS_SUCCEEDED(rv) && dir && escPath[escPath.Length() - 1] != '/') { + if (dir && escPath[escPath.Length() - 1] != '/') { // make sure we have a trailing slash escPath += "/"; } diff --git a/mozilla/netwerk/base/src/nsStdURL.h b/mozilla/netwerk/base/src/nsStdURL.h index 8ab069a3f85..27a10f47657 100644 --- a/mozilla/netwerk/base/src/nsStdURL.h +++ b/mozilla/netwerk/base/src/nsStdURL.h @@ -32,7 +32,6 @@ #include "nsCOMPtr.h" #include "nsIFile.h" #include "nsIFileChannel.h" -#include "nsIFileChannel.h" #include "nsISerializable.h" #define NS_THIS_STANDARDURL_IMPLEMENTATION_CID \ diff --git a/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp b/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp index bcae7d9a1be..65ebdb7564d 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp +++ b/mozilla/netwerk/protocol/jar/src/nsJARChannel.cpp @@ -103,7 +103,7 @@ NS_IMPL_THREADSAFE_ISUPPORTS7(nsJARChannel, NS_METHOD nsJARChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) { - nsresult rv; + nsresult rv; if (aOuter) return NS_ERROR_NO_AGGREGATION; @@ -113,16 +113,16 @@ nsJARChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) return NS_ERROR_OUT_OF_MEMORY; NS_ADDREF(jarChannel); - rv = jarChannel->QueryInterface(aIID, aResult); + rv = jarChannel->QueryInterface(aIID, aResult); NS_RELEASE(jarChannel); - return rv; + return rv; } nsresult nsJARChannel::Init(nsIJARProtocolHandler* aHandler, nsIURI* uri) { nsresult rv; - mURI = do_QueryInterface(uri, &rv); + mURI = do_QueryInterface(uri, &rv); if (NS_FAILED(rv)) return rv; mMonitor = PR_NewMonitor(); @@ -130,7 +130,7 @@ nsJARChannel::Init(nsIJARProtocolHandler* aHandler, nsIURI* uri) return NS_ERROR_OUT_OF_MEMORY; mJARProtocolHandler = aHandler; - return NS_OK; + return NS_OK; } //////////////////////////////////////////////////////////////////////////////// @@ -152,7 +152,7 @@ nsJARChannel::GetName(PRUnichar* *result) NS_IMETHODIMP nsJARChannel::IsPending(PRBool* result) { - NS_NOTREACHED("nsJARChannel::IsPending"); + NS_NOTREACHED("nsJARChannel::IsPending"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -176,7 +176,7 @@ nsJARChannel::Cancel(nsresult status) } mStatus = status; - return rv; + return rv; } NS_IMETHODIMP @@ -189,7 +189,7 @@ nsJARChannel::Suspend() rv = mJarExtractionTransport->Suspend(); } - return rv; + return rv; } NS_IMETHODIMP @@ -202,7 +202,7 @@ nsJARChannel::Resume() rv = mJarExtractionTransport->Resume(); } - return rv; + return rv; } //////////////////////////////////////////////////////////////////////////////// @@ -244,7 +244,7 @@ nsJARChannel::OpenJARElement() if (NS_SUCCEEDED(rv)) rv = GetInputStream(getter_AddRefs(mSynchronousInputStream)); mon.Notify(); // wake up nsIChannel::Open - return rv; + return rv; } NS_IMETHODIMP @@ -257,15 +257,13 @@ nsJARChannel::Open(nsIInputStream* *result) if (NS_FAILED(rv)) return rv; if (mSynchronousInputStream == nsnull) mon.Wait(); - if (mSynchronousInputStream) - { - *result = mSynchronousInputStream; // Result of GetInputStream called on transport thread - NS_ADDREF(*result); - mSynchronousInputStream = 0; - return NS_OK; - } - else + if (!mSynchronousInputStream) return NS_ERROR_FAILURE; + + *result = mSynchronousInputStream; // Result of GetInputStream called on transport thread + NS_ADDREF(*result); + mSynchronousInputStream = 0; + return NS_OK; } NS_IMETHODIMP @@ -288,10 +286,6 @@ nsresult nsJARChannel::EnsureJARFileAvailable() { nsresult rv; - nsCOMPtr jarBaseChannel; - nsCOMPtr jarCacheFile; - nsCOMPtr jarCacheTransport; - nsCOMPtr jarBaseIn; #ifdef PR_LOGGING nsXPIDLCString jarURLStr; @@ -307,8 +301,8 @@ nsJARChannel::EnsureJARFileAvailable() if (NS_FAILED(rv)) goto error; rv = NS_NewDownloader(getter_AddRefs(mDownloader), - mJARBaseURI, this, nsnull, mSynchronousRead, mLoadGroup, mCallbacks, - mLoadFlags); + mJARBaseURI, this, nsnull, mSynchronousRead, + mLoadGroup, mCallbacks, mLoadFlags); // if DownloadComplete() was called early, need to release the reference. if (mSynchronousRead && mSynchronousInputStream) @@ -340,7 +334,7 @@ nsJARChannel::AsyncReadJARElement() if (mCallbacks) { nsCOMPtr sink = do_GetInterface(mCallbacks); if (sink) { - // don't think that this is not needed anymore + // XXX don't think that this is needed anymore // jarTransport->SetProgressEventSink(sink); } } @@ -399,7 +393,7 @@ nsJARChannel::GetContentType(char* *aContentType) } else rv = NS_ERROR_OUT_OF_MEMORY; - + nsCRT::free(fileName); } else { @@ -655,7 +649,7 @@ nsJARChannel::Open(char* *contentType, PRInt32 *contentLength) NS_IMETHODIMP nsJARChannel::Close(nsresult status) { - return NS_OK; + return NS_OK; } NS_IMETHODIMP @@ -674,7 +668,7 @@ nsJARChannel::GetInputStream(nsIInputStream* *aInputStream) NS_IMETHODIMP nsJARChannel::GetOutputStream(nsIOutputStream* *aOutputStream) { - NS_NOTREACHED("nsJARChannel::GetOutputStream"); + NS_NOTREACHED("nsJARChannel::GetOutputStream"); return NS_ERROR_NOT_IMPLEMENTED; } @@ -690,7 +684,7 @@ nsJARChannel::GetName(char* *aName) NS_IMETHODIMP nsJARChannel::EnumerateEntries(const char *aRoot, nsISimpleEnumerator **_retval) { - NS_NOTREACHED("nsJARChannel::EnumerateEntries"); + NS_NOTREACHED("nsJARChannel::EnumerateEntries"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/netwerk/protocol/jar/src/nsJARChannel.h b/mozilla/netwerk/protocol/jar/src/nsJARChannel.h index 218c32f068a..41ae97dacc3 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARChannel.h +++ b/mozilla/netwerk/protocol/jar/src/nsJARChannel.h @@ -42,7 +42,7 @@ class nsIFileChannel; class nsJARChannel; -#define NS_JARCHANNEL_CID \ +#define NS_JARCHANNEL_CID \ { /* 0xc7e410d5-0x85f2-11d3-9f63-006008a6efe9 */ \ 0xc7e410d5, \ 0x85f2, \ @@ -82,10 +82,10 @@ public: protected: nsCOMPtr mJARProtocolHandler; - nsCOMPtr mURI; - nsCOMPtr mLoadGroup; - nsCOMPtr mCallbacks; - nsCOMPtr mOriginalURI; + nsCOMPtr mURI; + nsCOMPtr mLoadGroup; + nsCOMPtr mCallbacks; + nsCOMPtr mOriginalURI; nsLoadFlags mLoadFlags; nsCOMPtr mOwner; diff --git a/mozilla/netwerk/protocol/jar/src/nsJARProtocolHandler.cpp b/mozilla/netwerk/protocol/jar/src/nsJARProtocolHandler.cpp index 6a13c0c4ff2..e701d7790f6 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARProtocolHandler.cpp +++ b/mozilla/netwerk/protocol/jar/src/nsJARProtocolHandler.cpp @@ -17,7 +17,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ #include "nsJARProtocolHandler.h" @@ -48,7 +48,7 @@ nsresult nsJARProtocolHandler::Init() { nsresult rv; - rv = nsComponentManager::CreateInstance(kZipReaderCacheCID, + rv = nsComponentManager::CreateInstance(kZipReaderCacheCID, nsnull, NS_GET_IID(nsIZipReaderCache), getter_AddRefs(mJARCache)); @@ -62,8 +62,8 @@ nsJARProtocolHandler::~nsJARProtocolHandler() { } -NS_IMPL_THREADSAFE_ISUPPORTS2(nsJARProtocolHandler, - nsIJARProtocolHandler, +NS_IMPL_THREADSAFE_ISUPPORTS2(nsJARProtocolHandler, + nsIJARProtocolHandler, nsIProtocolHandler) NS_METHOD @@ -154,12 +154,12 @@ NS_IMETHODIMP nsJARProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result) { nsresult rv; - - nsJARChannel* channel; + + nsJARChannel* channel; rv = nsJARChannel::Create(nsnull, NS_GET_IID(nsIJARChannel), (void**)&channel); if (NS_FAILED(rv)) return rv; - rv = channel->Init(this, uri); + rv = channel->Init(this, uri); if (NS_FAILED(rv)) { NS_RELEASE(channel); return rv; @@ -170,10 +170,10 @@ nsJARProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result) } -NS_IMETHODIMP +NS_IMETHODIMP nsJARProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval) { - // don't override anything. + // don't override anything. *_retval = PR_FALSE; return NS_OK; } diff --git a/mozilla/netwerk/protocol/jar/src/nsJARURI.cpp b/mozilla/netwerk/protocol/jar/src/nsJARURI.cpp index d78f1c551bd..040f4d11398 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARURI.cpp +++ b/mozilla/netwerk/protocol/jar/src/nsJARURI.cpp @@ -82,7 +82,7 @@ nsJARURI::FormatSpec(const char* entryPath, char* *result) rv = mJARFile->GetSpec(&jarFileSpec); if (NS_FAILED(rv)) return rv; - nsCString spec(NS_JAR_SCHEME); + nsCAutoString spec(NS_JAR_SCHEME); spec += jarFileSpec; nsCRT::free(jarFileSpec); spec += NS_JAR_DELIMITER; @@ -368,7 +368,7 @@ nsJARURI::Resolve(const char *relativePath, char **result) } //////////////////////////////////////////////////////////////////////////////// -// nsIJARUri methods: +// nsIJARURI methods: NS_IMETHODIMP nsJARURI::GetJARFile(nsIURI* *jarFile) diff --git a/mozilla/netwerk/protocol/jar/src/nsJARURI.h b/mozilla/netwerk/protocol/jar/src/nsJARURI.h index 1af154fac1b..9d8c9358b93 100644 --- a/mozilla/netwerk/protocol/jar/src/nsJARURI.h +++ b/mozilla/netwerk/protocol/jar/src/nsJARURI.h @@ -23,7 +23,7 @@ #include "nsISerializable.h" #include "nsCOMPtr.h" -#define NS_JARURI_CID \ +#define NS_JARURI_CID \ { /* 0xc7e410d7-0x85f2-11d3-9f63-006008a6efe9 */ \ 0xc7e410d7, \ 0x85f2, \ diff --git a/mozilla/netwerk/protocol/res/src/nsResChannel.cpp b/mozilla/netwerk/protocol/res/src/nsResChannel.cpp index e0ea024721b..8b5ec6b1e74 100644 --- a/mozilla/netwerk/protocol/res/src/nsResChannel.cpp +++ b/mozilla/netwerk/protocol/res/src/nsResChannel.cpp @@ -17,7 +17,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ #include "nsResChannel.h" @@ -102,12 +102,12 @@ NS_INTERFACE_MAP_END_THREADSAFE NS_METHOD nsResChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) { - nsResChannel* fc = new nsResChannel(); - if (fc == nsnull) + nsResChannel* rc = new nsResChannel(); + if (rc == nsnull) return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(fc); - nsresult rv = fc->QueryInterface(aIID, aResult); - NS_RELEASE(fc); + NS_ADDREF(rc); + nsresult rv = rc->QueryInterface(aIID, aResult); + NS_RELEASE(rc); return rv; } @@ -120,16 +120,17 @@ nsResChannel::Substitutions::Init() { nsresult rv; nsResChannel* channel = GET_SUBSTITUTIONS_CHANNEL(this); - + if (mSubstitutions) return NS_ERROR_FAILURE; char* root; rv = channel->mResourceURI->GetHost(&root); if (NS_SUCCEEDED(rv)) { - char* strRoot = root; - if (strRoot == nsnull) strRoot = ""; // don't pass null to GetSubstitutions - rv = channel->mHandler->GetSubstitutions(strRoot, getter_AddRefs(mSubstitutions)); + // XXX don't pass null to GetSubstitutions! + const char* strRoot = root ? root : ""; + rv = channel->mHandler->GetSubstitutions(strRoot, + getter_AddRefs(mSubstitutions)); nsCRT::free(root); } return rv; @@ -152,13 +153,13 @@ nsResChannel::Substitutions::Next(char* *result) rv = channel->mResourceURI->GetPath(&path); if (NS_FAILED(rv)) return rv; - // XXX this path[0] check is a hack -- it seems to me that GetPath + // XXX this path[0] check is a hack -- it seems to me that GetPath // shouldn't include the leading slash: char* aResolvedURI; rv = substURI->Resolve(path[0] == '/' ? path+1 : path, &aResolvedURI); nsCRT::free(path); if (NS_FAILED(rv)) return rv; - + *result = aResolvedURI; return NS_OK; } @@ -302,7 +303,7 @@ nsResChannel::EnsureNextResolvedChannel() rv = mResolvedChannel->SetNotificationCallbacks(mCallbacks); if (NS_FAILED(rv)) goto done; } - + done: #if defined(PR_LOGGING) nsXPIDLCString resURI; @@ -432,7 +433,7 @@ nsResChannel::GetContentType(char * *aContentType) { if (mResolvedChannel) return mResolvedChannel->GetContentType(aContentType); - + // if we have not created a mResolvedChannel, use the mime service nsCOMPtr MIMEService (do_GetService(NS_MIMESERVICE_CONTRACTID)); if (!MIMEService) return NS_ERROR_FAILURE; @@ -509,7 +510,7 @@ nsResChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallb return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsResChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) { NS_NOTREACHED("nsResChannel::GetSecurityInfo"); @@ -540,11 +541,11 @@ nsResChannel::OnStopRequest(nsIRequest* request, nsISupports* context, "wrong thread calling this routine"); #endif if (NS_FAILED(aStatus) && aStatus != NS_BINDING_ABORTED) { - nsCOMPtr dummyRequest; + nsCOMPtr dummyRequest; // if we failed to process this channel, then try the next one: switch (mState) { - case ASYNC_READ: + case ASYNC_READ: return AsyncOpen(GetUserListener(), mUserContext); default: break; diff --git a/mozilla/netwerk/protocol/res/src/nsResChannel.h b/mozilla/netwerk/protocol/res/src/nsResChannel.h index ebc953fa47f..49f24d89b29 100644 --- a/mozilla/netwerk/protocol/res/src/nsResChannel.h +++ b/mozilla/netwerk/protocol/res/src/nsResChannel.h @@ -17,7 +17,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ #ifndef nsResChannel_h__ @@ -58,7 +58,7 @@ public: // Define a Create method to be used with a factory: static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult); - + nsresult Init(nsIResProtocolHandler* handler, nsIURI* uri); protected: diff --git a/mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp b/mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp index a3913480829..407732ad8cc 100644 --- a/mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp +++ b/mozilla/netwerk/protocol/res/src/nsResProtocolHandler.cpp @@ -48,9 +48,9 @@ #include "nsIFile.h" #include "nsDirectoryServiceDefs.h" #include "nsNetCID.h" +#include "nsNetUtil.h" static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); //////////////////////////////////////////////////////////////////////////////// @@ -68,10 +68,7 @@ nsResProtocolHandler::SetSpecialDir(const char* rootName, const char* sysDir) rv = NS_GetSpecialDirectory(sysDir, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; - nsCOMPtr fileURL; - rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull, - NS_GET_IID(nsIFileURL), - getter_AddRefs(fileURL)); + nsCOMPtr fileURL(do_CreateInstance(kStandardURLCID, &rv)); if (NS_FAILED(rv)) return rv; rv = fileURL->SetFile(file); @@ -195,13 +192,7 @@ nsResProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, { nsresult rv; - // Res: URLs (currently) have no additional structure beyond that provided by standard - // URLs, so there is no "outer" given to CreateInstance - - nsIURI* url; - rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull, - NS_GET_IID(nsIURI), - (void**)&url); + nsCOMPtr url(do_CreateInstance(kStandardURLCID, &rv)); if (NS_FAILED(rv)) return rv; if (aBaseURI) { @@ -213,12 +204,11 @@ nsResProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, rv = url->SetSpec((char*)aSpec); } - if (NS_FAILED(rv)) { - NS_RELEASE(url); + if (NS_FAILED(rv)) return rv; - } *result = url; + NS_ADDREF(*result); return rv; } @@ -256,7 +246,7 @@ nsResProtocolHandler::PrependSubstitution(const char *root, const char *urlStr) nsresult rv; nsAutoLock lock(mLock); - nsCOMPtr ioServ = do_GetService(kIOServiceCID, &rv); + nsCOMPtr ioServ = do_GetIOService(&rv); if (NS_FAILED(rv)) return rv; nsCOMPtr url; rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url)); @@ -266,7 +256,8 @@ nsResProtocolHandler::PrependSubstitution(const char *root, const char *urlStr) nsCOMPtr strings; nsCOMPtr newStrings; - strings = getter_AddRefs((nsISupportsArray*)mSubstitutions.Get(&key)); + strings = dont_AddRef(NS_STATIC_CAST(nsISupportsArray*, + mSubstitutions.Get(&key))); if (strings) { // we have to snapshot the array when inserting a new element because // someone could be iterating over the existing array @@ -292,7 +283,7 @@ nsResProtocolHandler::AppendSubstitution(const char *root, const char *urlStr) nsresult rv; nsAutoLock lock(mLock); - nsCOMPtr ioServ = do_GetService(kIOServiceCID, &rv); + nsCOMPtr ioServ = do_GetIOService(&rv); if (NS_FAILED(rv)) return rv; nsCOMPtr url; rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url)); @@ -348,7 +339,7 @@ nsResProtocolHandler::RemoveSubstitution(const char *root, const char *urlStr) nsresult rv; nsAutoLock lock(mLock); - nsCOMPtr ioServ = do_GetService(kIOServiceCID, &rv); + nsCOMPtr ioServ = do_GetIOService(&rv); if (NS_FAILED(rv)) return rv; nsCOMPtr url; rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url)); diff --git a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp index fd60d6342f3..48a6a8dbec7 100644 --- a/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp +++ b/mozilla/rdf/chrome/src/nsChromeProtocolHandler.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- * * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file @@ -17,7 +17,7 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): */ /* @@ -25,29 +25,32 @@ A protocol handler for ``chrome:'' */ - -#include "nsCOMPtr.h" -#include "nsCRT.h" + #include "nsChromeProtocolHandler.h" +#include "nsCOMPtr.h" +#include "nsContentCID.h" +#include "nsCRT.h" #include "nsIChannel.h" -#include "nsIFileChannel.h" #include "nsIChromeRegistry.h" #include "nsIComponentManager.h" #include "nsIEventQueue.h" #include "nsIEventQueueService.h" +#include "nsIFastLoadService.h" +#include "nsIFile.h" +#include "nsIFileChannel.h" #include "nsIIOService.h" -#include "nsILoadGroup.h" -#include "nsIResChannel.h" #include "nsIJARChannel.h" +#include "nsIJARURI.h" +#include "nsILoadGroup.h" +#include "nsIObjectOutputStream.h" +#include "nsIResChannel.h" #include "nsIScriptSecurityManager.h" -#include "nsIStreamListener.h" #include "nsIServiceManager.h" -#include "nsIXULDocument.h" +#include "nsIStreamListener.h" #include "nsIXULPrototypeCache.h" #include "nsIXULPrototypeDocument.h" -#include "nsContentCID.h" -#include "nsXPIDLString.h" #include "nsNetCID.h" +#include "nsXPIDLString.h" #include "prlog.h" //---------------------------------------------------------------------- @@ -127,8 +130,8 @@ public: NS_IMETHOD SetLoadGroup(nsILoadGroup *); NS_IMETHOD GetLoadFlags(nsLoadFlags *); NS_IMETHOD SetLoadFlags(nsLoadFlags); - -// nsIChannel + +// nsIChannel NS_DECL_NSICHANNEL }; @@ -137,8 +140,8 @@ public: PRLogModuleInfo* nsCachedChromeChannel::gLog; #endif -NS_IMPL_ISUPPORTS2(nsCachedChromeChannel, - nsIChannel, +NS_IMPL_ISUPPORTS2(nsCachedChromeChannel, + nsIChannel, nsIRequest); nsresult @@ -267,7 +270,7 @@ nsCachedChromeChannel::GetSecurityInfo(nsISupports * *aSecurityInfo) NS_IMETHODIMP nsCachedChromeChannel::GetLoadFlags(nsLoadFlags *aLoadFlags) { - *aLoadFlags = mLoadFlags; + *aLoadFlags = mLoadFlags; return NS_OK; } @@ -321,7 +324,7 @@ nsCachedChromeChannel::SetNotificationCallbacks(nsIInterfaceRequestor * aNotific return NS_OK; // ignored } -NS_IMETHODIMP +NS_IMETHODIMP nsCachedChromeChannel::GetContentType(char * *aContentType) { *aContentType = nsCRT::strdup("mozilla.application/cached-xul"); @@ -407,7 +410,7 @@ nsCachedChromeChannel::HandleStartLoadEvent(PLEvent* aEvent) // send On[Start|Stop]Request(). if (NS_FAILED(channel->mStatus)) return nsnull; - + PR_LOG(gLog, PR_LOG_DEBUG, ("nsCachedChromeChannel[%p]: firing OnStartRequest for %p", channel, channel->mListener.get())); @@ -432,7 +435,7 @@ nsCachedChromeChannel::HandleStopLoadEvent(PLEvent* aEvent) ("nsCachedChromeChannel[%p]: firing OnStopRequest for %p", channel, channel->mListener.get())); - (void) channel->mListener->OnStopRequest(request, channel->mContext, + (void) channel->mListener->OnStopRequest(request, channel->mContext, channel->mStatus); if (channel->mLoadGroup) { @@ -513,10 +516,10 @@ nsChromeProtocolHandler::GetDefaultPort(PRInt32 *result) return NS_OK; } -NS_IMETHODIMP +NS_IMETHODIMP nsChromeProtocolHandler::AllowPort(PRInt32 port, const char *scheme, PRBool *_retval) { - // don't override anything. + // don't override anything. *_retval = PR_FALSE; return NS_OK; } @@ -534,31 +537,28 @@ nsChromeProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, { nsresult rv; - // Chrome: URLs (currently) have no additional structure beyond that provided by standard - // URLs, so there is no "outer" given to CreateInstance + // Chrome: URLs (currently) have no additional structure beyond that provided + // by standard URLs, so there is no "outer" given to CreateInstance - nsIURI* url; - rv = nsComponentManager::CreateInstance(kStandardURLCID, nsnull, - NS_GET_IID(nsIURI), - (void**)&url); - if (NS_FAILED(rv)) return rv; + nsCOMPtr url(do_CreateInstance(kStandardURLCID, &rv)); + if (NS_FAILED(rv)) + return rv; if (aBaseURI) { nsXPIDLCString aResolvedURI; rv = aBaseURI->Resolve(aSpec, getter_Copies(aResolvedURI)); - if (NS_FAILED(rv)) return rv; - rv = url->SetSpec(aResolvedURI); + if (NS_SUCCEEDED(rv)) + rv = url->SetSpec(aResolvedURI); } else { rv = url->SetSpec((char*)aSpec); } - if (NS_FAILED(rv)) { - NS_RELEASE(url); + if (NS_FAILED(rv)) return rv; - } *result = url; + NS_ADDREF(*result); return rv; } @@ -580,7 +580,7 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, // Check the prototype cache to see if we've already got the // document in the cache. - nsCOMPtr cache = + nsCOMPtr cache = do_GetService(kXULPrototypeCacheCID, &rv); if (NS_FAILED(rv)) return rv; @@ -598,7 +598,7 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, // Miss. Resolve the chrome URL using the registry and do a // normal necko load. nsCOMPtr chromeURI; - rv = aURI->Clone(getter_AddRefs(chromeURI)); // don't mangle the original + rv = aURI->Clone(getter_AddRefs(chromeURI)); // don't mangle the original if (NS_FAILED(rv)) return rv; //nsXPIDLCString oldSpec; @@ -609,31 +609,31 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, rv = reg->ConvertChromeURL(chromeURI, getter_Copies(spec)); if (NS_FAILED(rv)) return rv; - nsCOMPtr serv(do_GetService(kIOServiceCID, &rv)); + nsCOMPtr ioServ(do_GetService(kIOServiceCID, &rv)); if (NS_FAILED(rv)) return rv; - - rv = serv->NewURI(spec, nsnull, getter_AddRefs(chromeURI)); + + rv = ioServ->NewURI(spec, nsnull, getter_AddRefs(chromeURI)); if (NS_FAILED(rv)) return rv; - - rv = serv->NewChannelFromURI(chromeURI, getter_AddRefs(result)); + + rv = ioServ->NewChannelFromURI(chromeURI, getter_AddRefs(result)); if (NS_FAILED(rv)) return rv; // XXX Will be removed someday when we handle remote chrome. - nsCOMPtr jar; - nsCOMPtr res; - nsCOMPtr file; - res = do_QueryInterface(result); - if (!res) { - file = do_QueryInterface(result); - if (!file) - jar = do_QueryInterface(result); + nsCOMPtr fileChan; + nsCOMPtr resChan; + nsCOMPtr jarChan; + fileChan = do_QueryInterface(result); + if (!fileChan) { + resChan = do_QueryInterface(result); + if (!resChan) + jarChan = do_QueryInterface(result); } - if (!res && !file && !jar) { - NS_WARNING("Remote chrome not allowed! Only file:, resource:, and jar: are valid.\n"); - result = nsnull; - return NS_ERROR_FAILURE; + if (!fileChan && !resChan && !jarChan) { + NS_WARNING("Remote chrome not allowed! Only file:, resource:, and jar: are valid.\n"); + result = nsnull; + return NS_ERROR_FAILURE; } - + // Make sure that the channel remembers where it was // originally loaded from. rv = result->SetOriginalURI(aURI); @@ -644,20 +644,76 @@ nsChromeProtocolHandler::NewChannel(nsIURI* aURI, nsCOMPtr url = do_QueryInterface(aURI); nsXPIDLCString fileExtension; rv = url->GetFileExtension(getter_Copies(fileExtension)); - if (PL_strcasecmp(fileExtension, "xul") == 0 || PL_strcasecmp(fileExtension, "html") == 0 || + if (PL_strcasecmp(fileExtension, "xul") == 0 || + PL_strcasecmp(fileExtension, "html") == 0 || PL_strcasecmp(fileExtension, "xml") == 0) { - nsCOMPtr securityManager = + nsCOMPtr securityManager = do_GetService(NS_SCRIPTSECURITYMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; - + nsCOMPtr principal; rv = securityManager->GetSystemPrincipal(getter_AddRefs(principal)); if (NS_FAILED(rv)) return rv; - + nsCOMPtr owner = do_QueryInterface(principal); result->SetOwner(owner); } + + // Track FastLoad file dependencies. + // + // This is harder than it ought to be! While an nsResChannel "is-a" + // nsIFileChannel, an nsJARChannel is not. Once you unravel the jar: + // URI, you may have a resource: URL -- but without a channel for it, + // you can't get the URI that it yields through substitution! + // + // XXXbe fix nsResChannel.cpp to move the substitution code into a new + // nsResURL class? + nsCOMPtr fastLoadServ(do_GetFastLoadService()); + if (fastLoadServ) { + nsCOMPtr objectOutput; + fastLoadServ->GetOutputStream(getter_AddRefs(objectOutput)); + if (objectOutput) { + nsCOMPtr file; + nsCOMPtr chan = result; + while (!fileChan) { + nsCOMPtr uri; + chan->GetURI(getter_AddRefs(uri)); + + // Loop, jar: URIs can nest (e.g. jar:jar:A.jar!B.jar!C.xml). + // Often, however, we have jar:resource:/chrome/A.jar!C.xml. + nsCOMPtr jarURI; + while ((jarURI = do_QueryInterface(uri)) != nsnull) + jarURI->GetJARFile(getter_AddRefs(uri)); + + // Here we must have a URL of the form resource:/chrome/A.jar + // or file:/some/path/to/A.jar. Let's hope for the latter. + nsCOMPtr fileURL(do_QueryInterface(uri)); + if (fileURL) { + fileURL->GetFile(getter_AddRefs(file)); + if (file) + break; + } + + // Thanks to the way that the resource: URL implementation + // hides its substitution code from itself and the rest of + // the world, we must make a new channel simply to get the + // substituted URI. + ioServ->NewChannelFromURI(uri, getter_AddRefs(chan)); + if (!chan) + break; + fileChan = do_QueryInterface(chan); + } + + if (!file && fileChan) + fileChan->GetFile(getter_AddRefs(file)); + if (file) { + rv = fastLoadServ->AddDependency(file); + if (NS_FAILED(rv)) + cache->AbortFastLoads(); + } + } + } } *aResult = result; diff --git a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp index 78f371a0f2a..c99697fb393 100644 --- a/mozilla/rdf/chrome/src/nsChromeRegistry.cpp +++ b/mozilla/rdf/chrome/src/nsChromeRegistry.cpp @@ -19,7 +19,7 @@ * * Original Author: David W. Hyatt (hyatt@netscape.com) * - * Contributor(s): + * Contributor(s): * Gagan Saksena */ @@ -165,7 +165,7 @@ NS_IMETHODIMP nsOverlayEnumerator::HasMoreElements(PRBool *aIsTrue) return NS_OK; // No arcs period. We default to false, return mInstallArcs->HasMoreElements(aIsTrue); // no profile arcs. use install arcs, } - + nsresult rv = mProfileArcs->HasMoreElements(aIsTrue); if (*aIsTrue || !mInstallArcs) return rv; @@ -229,7 +229,7 @@ NS_IMETHODIMP nsOverlayEnumerator::GetNext(nsISupports **aResult) nsChromeRegistry::nsChromeRegistry() { - NS_INIT_REFCNT(); + NS_INIT_REFCNT(); mInstallInitialized = PR_FALSE; mProfileInitialized = PR_FALSE; @@ -250,13 +250,13 @@ static PRBool PR_CALLBACK DatasourceEnumerator(nsHashKey *aKey, void *aData, voi return PR_FALSE; nsIRDFCompositeDataSource* compositeDS = (nsIRDFCompositeDataSource*) closure; - + nsCOMPtr supports = (nsISupports*)aData; - + nsCOMPtr dataSource = do_QueryInterface(supports); if (!dataSource) return PR_FALSE; - + nsresult rv = compositeDS->RemoveDataSource(dataSource); NS_ASSERTION(NS_SUCCEEDED(rv), "failed to RemoveDataSource"); return PR_TRUE; @@ -265,11 +265,11 @@ static PRBool PR_CALLBACK DatasourceEnumerator(nsHashKey *aKey, void *aData, voi nsChromeRegistry::~nsChromeRegistry() { - if (mDataSourceTable) { + if (mDataSourceTable) { mDataSourceTable->Enumerate(DatasourceEnumerator, mChromeDataSource); delete mDataSourceTable; } - + if (mRDFService) { nsServiceManager::ReleaseService(kRDFServiceCID, mRDFService); mRDFService = nsnull; @@ -337,7 +337,7 @@ nsChromeRegistry::Init() rv = mRDFService->GetResource(kURICHROME_packageVersion, getter_AddRefs(mPackageVersion)); NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get RDF resource"); - nsCOMPtr observerService = + nsCOMPtr observerService = do_GetService(NS_OBSERVERSERVICE_CONTRACTID, &rv); if (observerService) { observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get()); @@ -345,7 +345,7 @@ nsChromeRegistry::Init() } CheckForNewChrome(); - + return NS_OK; } @@ -354,7 +354,7 @@ static nsresult SplitURL(nsIURI* aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCString& aFile) { // Splits a "chrome:" URL into its package, provider, and file parts. - // Here are the current portions of a + // Here are the current portions of a // chrome: url that make up the chrome- // // chrome://global/skin/foo?bar @@ -362,7 +362,7 @@ SplitURL(nsIURI* aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCStrin // | | | | // | | | `-- RemainingPortion // | | | - // | | `-- Provider + // | | `-- Provider // | | // | `-- Package // | @@ -415,41 +415,41 @@ SplitURL(nsIURI* aChromeURI, nsCString& aPackage, nsCString& aProvider, nsCStrin aFile = aPackage; if (aProvider.Equals("content")) { - aFile += ".xul"; + aFile += ".xul"; } else if (aProvider.Equals("skin")) { - aFile += ".css"; + aFile += ".css"; } else if (aProvider.Equals("locale")) { - aFile += ".dtd"; + aFile += ".dtd"; } else { - NS_ERROR("unknown provider"); - return NS_ERROR_FAILURE; + NS_ERROR("unknown provider"); + return NS_ERROR_FAILURE; } } else { - // Protect against URIs containing .. that reach up out of the - // chrome directory to grant chrome privileges to non-chrome files. - int depth = 0; - PRBool sawSlash = PR_TRUE; // .. at the beginning is suspect as well as /.. - for (const char* p=aFile; *p; p++) { - if (sawSlash) { - if (p[0] == '.' && p[1] == '.'){ - depth--; // we have /.., decrement depth. - } else { - static const char escape[] = "%2E%2E"; - if(PL_strncasecmp(p, escape, sizeof(escape)-1) == 0) - depth--; // we have /%2E%2E, the HTML escape form of /.., decrement depth. - } - }else if (p[0] != '/') { - depth++; // we have /x for some x that is not / - } - sawSlash = (p[0] == '/'); - - if (depth < 0) { - return NS_ERROR_FAILURE; + // Protect against URIs containing .. that reach up out of the + // chrome directory to grant chrome privileges to non-chrome files. + int depth = 0; + PRBool sawSlash = PR_TRUE; // .. at the beginning is suspect as well as /.. + for (const char* p=aFile; *p; p++) { + if (sawSlash) { + if (p[0] == '.' && p[1] == '.'){ + depth--; // we have /.., decrement depth. + } else { + static const char escape[] = "%2E%2E"; + if (PL_strncasecmp(p, escape, sizeof(escape)-1) == 0) + depth--; // we have the HTML-escaped form of /.., decrement depth. } + } else if (p[0] != '/') { + depth++; // we have /x for some x that is not / } + sawSlash = (p[0] == '/'); + + if (depth < 0) { + return NS_ERROR_FAILURE; + } + } } return NS_OK; } @@ -499,13 +499,13 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult) if (NS_FAILED(rv)) return rv; if (!mProfileInitialized) { - // Just setSpec + // Just setSpec rv = GetInstallRoot(mInstallRoot); if (NS_FAILED(rv)) return rv; rv = LoadProfileDataSource(); if (NS_FAILED(rv)) return rv; } - + nsCAutoString finalURL; rv = GetBaseURL(package, provider, finalURL); #ifdef DEBUG @@ -541,7 +541,7 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult) else { finalURL = "resource:/chrome/packages/core/"; } - } + } *aResult = ToNewCString(finalURL + remaining); @@ -549,7 +549,7 @@ nsChromeRegistry::ConvertChromeURL(nsIURI* aChromeURL, char** aResult) } NS_IMETHODIMP -nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvider, +nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvider, nsCString& aBaseURL) { nsCOMPtr resource; @@ -564,7 +564,7 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid if (NS_FAILED(rv)) { NS_ERROR("Unable to obtain the package resource."); return rv; - } + } // Follow the "selectedSkin" or "selectedLocale" arc. nsCOMPtr arc; @@ -579,7 +579,7 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid resource = packageResource; if (arc) { - + nsCOMPtr selectedProvider; if (NS_FAILED(rv = mChromeDataSource->GetTarget(packageResource, arc, PR_TRUE, getter_AddRefs(selectedProvider)))) { NS_ERROR("Unable to obtain the provider."); @@ -616,7 +616,7 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid FindProvider(aPackage, aProvider, arc, getter_AddRefs(selectedProvider)); resource = do_QueryInterface(selectedProvider); } - + if (!selectedProvider) return rv; @@ -626,12 +626,12 @@ nsChromeRegistry::GetBaseURL(const nsCString& aPackage, const nsCString& aProvid // From this resource, follow the "baseURL" arc. return nsChromeRegistry::FollowArc(mChromeDataSource, - aBaseURL, + aBaseURL, resource, mBaseURL); } -// locate +// locate NS_IMETHODIMP nsChromeRegistry::FindProvider(const nsCString& aPackage, const nsCString& aProvider, @@ -761,7 +761,8 @@ nsChromeRegistry::SelectPackageInProvider(nsIRDFResource *aPackageList, // get its name nsCAutoString packageName; rv = nsChromeRegistry::FollowArc(mChromeDataSource, packageName, package, mName); - if (NS_FAILED(rv)) continue; // don't fail if package has not yet been installed + if (NS_FAILED(rv)) + continue; // don't fail if package has not yet been installed if (packageName.Equals(aPackage)) { nsAutoString providerNameUC; @@ -786,7 +787,7 @@ nsChromeRegistry::SelectPackageInProvider(nsIRDFResource *aPackageList, return NS_OK; } -NS_IMETHODIMP nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, PRBool aIsOverlay, PRBool aUseProfile, +NS_IMETHODIMP nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, PRBool aIsOverlay, PRBool aUseProfile, nsIRDFDataSource **aResult) { *aResult = nsnull; @@ -810,14 +811,14 @@ NS_IMETHODIMP nsChromeRegistry::GetDynamicDataSource(nsIURI *aChromeURL, PRBool if (aIsOverlay) overlayFile += "content/overlays.rdf"; else overlayFile += "skin/stylesheets.rdf"; - + return LoadDataSource(overlayFile, aResult, aUseProfile, nsnull); } NS_IMETHODIMP nsChromeRegistry::GetStyleSheets(nsIURI *aChromeURL, nsISupportsArray **aResult) { *aResult = nsnull; - + nsCOMPtr sheets; nsresult rv = GetDynamicInfo(aChromeURL, PR_FALSE, getter_AddRefs(sheets)); if (NS_FAILED(rv)) return rv; @@ -886,7 +887,7 @@ NS_IMETHODIMP nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOve nsCOMPtr installArcs; nsCOMPtr profileArcs; - + if (installSource) { nsCOMPtr container; @@ -911,16 +912,16 @@ NS_IMETHODIMP nsChromeRegistry::GetDynamicInfo(nsIURI *aChromeURL, PRBool aIsOve if (NS_FAILED(rv)) return rv; } - + *aResult = new nsOverlayEnumerator(installArcs, profileArcs); NS_ADDREF(*aResult); - + return NS_OK; } -NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, - nsIRDFDataSource **aResult, - PRBool aUseProfileDir, +NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, + nsIRDFDataSource **aResult, + PRBool aUseProfileDir, const char *aProfilePath) { // Init the data source to null. @@ -948,7 +949,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, if (mDataSourceTable) { nsCStringKey skey(key); - nsCOMPtr supports = + nsCOMPtr supports = getter_AddRefs(NS_STATIC_CAST(nsISupports*, mDataSourceTable->Get(&skey))); if (supports) @@ -963,7 +964,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, return NS_ERROR_FAILURE; } } - + nsresult rv = nsComponentManager::CreateInstance(kRDFXMLDataSourceCID, nsnull, NS_GET_IID(nsIRDFDataSource), @@ -988,7 +989,7 @@ NS_IMETHODIMP nsChromeRegistry::LoadDataSource(const nsCString &aFileName, rv = remote->Init(key); if (NS_SUCCEEDED(rv)) rv = remote->Refresh(PR_TRUE); - + nsCOMPtr supports = do_QueryInterface(remote); nsCStringKey skey(key); mDataSourceTable->Put(&skey, supports.get()); @@ -1011,9 +1012,9 @@ nsChromeRegistry::GetResource(const nsCString& aURL, return NS_OK; } -nsresult +nsresult nsChromeRegistry::FollowArc(nsIRDFDataSource *aDataSource, - nsCString& aResult, + nsCString& aResult, nsIRDFResource* aChromeResource, nsIRDFResource* aProperty) { @@ -1033,7 +1034,7 @@ nsChromeRegistry::FollowArc(nsIRDFDataSource *aDataSource, return NS_ERROR_FAILURE; nsCOMPtr resource(do_QueryInterface(chromeBase)); - + if (resource) { nsXPIDLCString uri; rv = resource->GetValue(getter_Copies(uri)); @@ -1041,7 +1042,7 @@ nsChromeRegistry::FollowArc(nsIRDFDataSource *aDataSource, aResult.Assign(uri); return NS_OK; } - + nsCOMPtr literal(do_QueryInterface(chromeBase)); if (literal) { nsXPIDLString s; @@ -1060,7 +1061,7 @@ nsChromeRegistry::FollowArc(nsIRDFDataSource *aDataSource, nsresult nsChromeRegistry::UpdateArc(nsIRDFDataSource *aDataSource, nsIRDFResource* aSource, - nsIRDFResource* aProperty, + nsIRDFResource* aProperty, nsIRDFNode *aTarget, PRBool aRemove) { nsresult rv; @@ -1091,9 +1092,9 @@ NS_IMETHODIMP nsChromeRegistry::RefreshSkins() rv = FlushCaches(); if (NS_FAILED(rv)) return rv; - + // Get the window mediator - nsCOMPtr windowMediator = + nsCOMPtr windowMediator = do_GetService(kWindowMediatorCID, &rv); if (NS_SUCCEEDED(rv)) { nsCOMPtr windowEnumerator; @@ -1129,7 +1130,7 @@ nsresult nsChromeRegistry::FlushCaches() // Flush the style sheet cache completely. // XXX For now flush everything. need a better call that only flushes style sheets. - nsCOMPtr xulCache = + nsCOMPtr xulCache = do_GetService("@mozilla.org/xul/xul-prototype-cache;1", &rv); if (NS_SUCCEEDED(rv) && xulCache) { xulCache->Flush(); @@ -1247,16 +1248,16 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) PRInt32 count = 0; document->GetNumberOfStyleSheets(&count); - + // Iterate over the style sheets. for (PRInt32 i = 0; i < count; i++) { // Get the style sheet nsCOMPtr styleSheet; document->GetStyleSheetAt(i, getter_AddRefs(styleSheet)); - + // Make sure we aren't the special style sheets that never change. We // want to skip those. - + nsCOMPtr attr = do_QueryInterface(attrSheet); nsCOMPtr inl = do_QueryInterface(inlineSheet); if ((attr.get() != styleSheet.get()) && @@ -1267,13 +1268,13 @@ NS_IMETHODIMP nsChromeRegistry::RefreshWindow(nsIDOMWindowInternal* aWindow) if (NS_FAILED(rv)) return rv; rv = urls->AppendElement(uri) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; - - // Remove the sheet. + + // Remove the sheet. rv = oldSheets->AppendElement(styleSheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; } } - + // Iterate over the URL array and kick off an asynchronous load of the // sheets for our doc. PRUint32 urlCount; @@ -1310,7 +1311,7 @@ NS_IMETHODIMP nsChromeRegistry::WriteInfoToDataSource(const char *aDocURI, nsCAutoString str(aDocURI); rv = NS_NewURI(getter_AddRefs(uri), str); if (NS_FAILED(rv)) return rv; - + nsCOMPtr dataSource; rv = GetDynamicDataSource(uri, aIsOverlay, aUseProfile, getter_AddRefs(dataSource)); if (NS_FAILED(rv)) return rv; @@ -1376,7 +1377,7 @@ NS_IMETHODIMP nsChromeRegistry::UpdateDynamicDataSource(nsIRDFDataSource *aDataS NS_GET_IID(nsIRDFContainer), getter_AddRefs(container)); if (NS_FAILED(rv)) return rv; - + rv = container->Init(aDataSource, aResource); if (NS_FAILED(rv)) return rv; @@ -1446,7 +1447,7 @@ NS_IMETHODIMP nsChromeRegistry::UpdateDynamicDataSources(nsIRDFDataSource *aData PRBool moreElements; rv = arcs->HasMoreElements(&moreElements); if (NS_FAILED(rv)) return rv; - + while (moreElements) { nsCOMPtr supports; @@ -1480,7 +1481,7 @@ NS_IMETHODIMP nsChromeRegistry::SelectLocale(const PRUnichar* aLocale, return SetProvider(nsCAutoString("locale"), mSelectedLocale, aLocale, aUseProfile, nsnull, PR_TRUE); } -NS_IMETHODIMP nsChromeRegistry::SelectLocaleForProfile(const PRUnichar *aLocale, +NS_IMETHODIMP nsChromeRegistry::SelectLocaleForProfile(const PRUnichar *aLocale, const PRUnichar *aProfilePath) { // to be changed to use given path @@ -1488,7 +1489,7 @@ NS_IMETHODIMP nsChromeRegistry::SelectLocaleForProfile(const PRUnichar *aLocale, } /* wstring getSelectedLocale (); */ -NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, +NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, PRUnichar **_retval) { // check if mChromeDataSource is null; do we need to apply this to every instance? @@ -1508,7 +1509,7 @@ NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, if (NS_FAILED(rv)) { NS_ERROR("Unable to obtain the package resource."); return rv; - } + } if (mChromeDataSource == nsnull) return NS_ERROR_NULL_POINTER; @@ -1547,12 +1548,12 @@ NS_IMETHODIMP nsChromeRegistry::GetSelectedLocale(const PRUnichar *aPackageName, if (NS_FAILED(rv)) { NS_ERROR("Unable to obtain the provider resource."); return rv; - } + } // From this resource, follow the "name" arc. nsCAutoString lc_name; // is this i18n friendly? RDF now use UTF8 internally rv = nsChromeRegistry::FollowArc(mChromeDataSource, - lc_name, + lc_name, resource, mName); if (NS_FAILED(rv)) return rv; @@ -1666,9 +1667,9 @@ NS_IMETHODIMP nsChromeRegistry::SetProvider(const nsCString& aProvider, NS_IMETHODIMP nsChromeRegistry::SetProviderForPackage(const nsCString& aProvider, - nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderPackageResource, - nsIRDFResource* aSelectionArc, + nsIRDFResource* aPackageResource, + nsIRDFResource* aProviderPackageResource, + nsIRDFResource* aSelectionArc, PRBool aUseProfile, const char *aProfilePath, PRBool aIsAdding) { @@ -1678,7 +1679,7 @@ nsChromeRegistry::SetProviderForPackage(const nsCString& aProvider, nsCAutoString dataSourceStr( "user-" ); dataSourceStr += aProvider; dataSourceStr += "s.rdf"; - + nsCOMPtr dataSource; rv = LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), aUseProfile, aProfilePath); if (NS_FAILED(rv)) return rv; @@ -1742,9 +1743,9 @@ NS_IMETHODIMP nsChromeRegistry::IsLocaleSelectedForPackage(const PRUnichar *aLoc } NS_IMETHODIMP nsChromeRegistry::SelectProviderForPackage(const nsCString& aProviderType, - const PRUnichar *aProviderName, - const PRUnichar *aPackageName, - nsIRDFResource* aSelectionArc, + const PRUnichar *aProviderName, + const PRUnichar *aPackageName, + nsIRDFResource* aSelectionArc, PRBool aUseProfile, PRBool aIsAdding) { nsCAutoString package( "urn:mozilla:package:" ); @@ -1798,10 +1799,10 @@ NS_IMETHODIMP nsChromeRegistry::SelectProviderForPackage(const nsCString& aProvi return NS_ERROR_FAILURE; } - return SetProviderForPackage(aProviderType, packageResource, providerResource, aSelectionArc, + return SetProviderForPackage(aProviderType, packageResource, providerResource, aSelectionArc, aUseProfile, nsnull, aIsAdding);; } - + NS_IMETHODIMP nsChromeRegistry::IsSkinSelected(const PRUnichar* aSkin, PRBool aUseProfile, PRBool* aResult) { @@ -1856,7 +1857,7 @@ NS_IMETHODIMP nsChromeRegistry::IsProviderSelected(const nsCString& aProvider, nsCOMPtr arcs; container->GetElements(getter_AddRefs(arcs)); - + // For each skin/package entry, follow the arcs to the real package // resource. PRBool more; @@ -1898,9 +1899,9 @@ NS_IMETHODIMP nsChromeRegistry::IsProviderSelected(const nsCString& aProvider, NS_IMETHODIMP nsChromeRegistry::IsProviderSelectedForPackage(const nsCString& aProviderType, - const PRUnichar *aProviderName, - const PRUnichar *aPackageName, - nsIRDFResource* aSelectionArc, + const PRUnichar *aProviderName, + const PRUnichar *aPackageName, + nsIRDFResource* aSelectionArc, PRBool aUseProfile, PRBool* aResult) { *aResult = PR_FALSE; @@ -1933,15 +1934,15 @@ nsChromeRegistry::IsProviderSelectedForPackage(const nsCString& aProviderType, } NS_ASSERTION(providerResource, "failed to get providerResource"); - return IsProviderSetForPackage(aProviderType, packageResource, providerResource, aSelectionArc, + return IsProviderSetForPackage(aProviderType, packageResource, providerResource, aSelectionArc, aUseProfile, aResult);; } NS_IMETHODIMP nsChromeRegistry::IsProviderSetForPackage(const nsCString& aProvider, - nsIRDFResource* aPackageResource, - nsIRDFResource* aProviderPackageResource, - nsIRDFResource* aSelectionArc, + nsIRDFResource* aPackageResource, + nsIRDFResource* aProviderPackageResource, + nsIRDFResource* aSelectionArc, PRBool aUseProfile, PRBool* aResult) { nsresult rv; @@ -1950,7 +1951,7 @@ nsChromeRegistry::IsProviderSetForPackage(const nsCString& aProvider, nsCAutoString dataSourceStr( "user-" ); dataSourceStr += aProvider; dataSourceStr += "s.rdf"; - + nsCOMPtr dataSource; rv = LoadDataSource(dataSourceStr, getter_AddRefs(dataSource), aUseProfile, nsnull); if (NS_FAILED(rv)) return rv; @@ -1992,11 +1993,11 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, key += "contents.rdf"; remote->Init(key); remote->Refresh(PR_TRUE); - + PRBool skinCount = GetProviderCount(nsCAutoString("skin"), dataSource); PRBool localeCount = GetProviderCount(nsCAutoString("locale"), dataSource); PRBool packageCount = GetProviderCount(nsCAutoString("package"), dataSource); - + PRBool appendPackage = PR_FALSE; PRBool appendProvider = PR_FALSE; PRBool appendProviderName = PR_FALSE; @@ -2012,7 +2013,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, appendProvider = PR_TRUE; NS_WARNING("Trying old-style manifest.rdf. Please update to contents.rdf."); } - else { + else { if ((skinCount > 1 && aProviderType.Equals("skin")) || (localeCount > 1 && aProviderType.Equals("locale"))) appendProviderName = PR_TRUE; @@ -2090,7 +2091,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, if (NS_FAILED(rv)) return rv; nsCOMPtr resource = do_QueryInterface(supports); - + // Check against the prefix string const char* value; rv = resource->GetValueConst(&value); @@ -2098,12 +2099,12 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, nsCAutoString val(value); if (val.Find(prefix) == 0) { // It's valid. - + if (aProviderType.Equals("package") && !val.Equals("urn:mozilla:package:root")) { // Add arcs for the base url and loctype // Get the value of the base literal. nsCAutoString baseURL(aBaseURL); - + // Peel off the package. const char* val2; rv = resource->GetValueConst(&val2); @@ -2112,7 +2113,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, PRInt32 index = value2.RFind(":"); nsCAutoString packageName; value2.Right(packageName, value2.Length() - index - 1); - + if (appendPackage) { baseURL += packageName; baseURL += "/"; @@ -2120,17 +2121,17 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, if (appendProvider) { baseURL += "content/"; } - + nsAutoString unistr;unistr.AssignWithConversion(baseURL); nsCOMPtr baseLiteral; mRDFService->GetLiteral(unistr.get(), getter_AddRefs(baseLiteral)); - + rv = nsChromeRegistry::UpdateArc(installSource, resource, mBaseURL, baseLiteral, aRemove); if (NS_FAILED(rv)) return rv; rv = nsChromeRegistry::UpdateArc(installSource, resource, mLocType, locLiteral, aRemove); if (NS_FAILED(rv)) return rv; } - + nsCOMPtr container; rv = nsComponentManager::CreateInstance("@mozilla.org/rdf/container;1", nsnull, @@ -2209,7 +2210,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, if (entry) { // Get the value of the base literal. nsCAutoString baseURL(aBaseURL); - + // Peel off the package and the provider. const char* val2; rv = entry->GetValueConst(&val2); @@ -2238,22 +2239,22 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, baseURL += aProviderType; baseURL += "/"; } - + nsAutoString unistr;unistr.AssignWithConversion(baseURL); nsCOMPtr baseLiteral; mRDFService->GetLiteral(unistr.get(), getter_AddRefs(baseLiteral)); - + rv = nsChromeRegistry::UpdateArc(installSource, entry, mBaseURL, baseLiteral, aRemove); if (NS_FAILED(rv)) return rv; if (aProviderType.Equals(nsCAutoString("skin")) && !aAllowScripts) { rv = nsChromeRegistry::UpdateArc(installSource, entry, mAllowScripts, scriptLiteral, aRemove); if (NS_FAILED(rv)) return rv; } - + // Now set up the package arc. if (index != -1) { // Peel off the package name. - + nsCAutoString resourceName("urn:mozilla:package:"); resourceName += packageName; nsCOMPtr packageResource; @@ -2276,7 +2277,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, nsCOMPtr arcs; rv = dataSource->ArcLabelsOut(resource, getter_AddRefs(arcs)); if (NS_FAILED(rv)) return rv; - + PRBool moreArcs; rv = arcs->HasMoreElements(&moreArcs); if (NS_FAILED(rv)) return rv; @@ -2288,15 +2289,15 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, if (arc == mPackages) { // We are the main entry for a skin/locale. - // Set up our loctype and our script access + // Set up our loctype and our script access rv = nsChromeRegistry::UpdateArc(installSource, resource, mLocType, locLiteral, aRemove); if (NS_FAILED(rv)) return rv; } - + nsCOMPtr newTarget; rv = dataSource->GetTarget(resource, arc, PR_TRUE, getter_AddRefs(newTarget)); if (NS_FAILED(rv)) return rv; - + if (arc == mImage) { // We are an image URL. Check to see if we're a relative URL. nsCOMPtr literal(do_QueryInterface(newTarget)); @@ -2325,7 +2326,7 @@ NS_IMETHODIMP nsChromeRegistry::InstallProvider(const nsCString& aProviderType, rv = resources->HasMoreElements(&moreElements); if (NS_FAILED(rv)) return rv; } - + // Flush the install source nsCOMPtr remoteInstall = do_QueryInterface(installSource, &rv); if (NS_FAILED(rv)) @@ -2388,7 +2389,7 @@ nsChromeRegistry::UninstallProvider(const nsCString& aProviderType, // XXX We are going to simply do a snip of the arc from the seq ROOT to // the associated package. waterson is going to provide the ability to name // roots in a datasource, and only resources that are reachable from the - // root will be saved. + // root will be saved. nsresult rv = NS_OK; nsCAutoString prefix( "urn:mozilla:" ); prefix += aProviderType; @@ -2414,14 +2415,14 @@ nsChromeRegistry::UninstallProvider(const nsCString& aProviderType, // Now make a container out of the root seq. nsCOMPtr container(do_CreateInstance("@mozilla.org/rdf/container;1")); - + // Get the resource for the root. nsCOMPtr chromeResource; if (NS_FAILED(rv = GetResource(providerRoot, getter_AddRefs(chromeResource)))) { NS_ERROR("Unable to retrieve the resource corresponding to the skin/locale root."); return rv; } - + if (NS_FAILED(container->Init(installSource, chromeResource))) return NS_ERROR_FAILURE; @@ -2438,23 +2439,23 @@ nsChromeRegistry::UninstallProvider(const nsCString& aProviderType, // Now flush the datasource. nsCOMPtr remote = do_QueryInterface(installSource); remote->Flush(); - + return NS_OK; } NS_IMETHODIMP -nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) -{ +nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) +{ nsresult rv; - nsCOMPtr userChromeDir; - + nsCOMPtr userChromeDir; + // Build a fileSpec that points to the destination - // (profile dir + chrome) + // (profile dir + chrome) rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir)); if (NS_FAILED(rv) || !userChromeDir) return NS_ERROR_FAILURE; - - PRBool exists; + + PRBool exists; rv = userChromeDir->Exists(&exists); if (NS_SUCCEEDED(rv) && !exists) { rv = userChromeDir->Create(nsIFile::DIRECTORY_TYPE, 0755); @@ -2465,14 +2466,18 @@ nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) // first get the locations of the defaults nsCOMPtr defaultUserContentFile; nsCOMPtr defaultUserChromeFile; - rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(defaultUserContentFile)); + rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, + getter_AddRefs(defaultUserContentFile)); if (NS_FAILED(rv)) - rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, getter_AddRefs(defaultUserContentFile)); + rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, + getter_AddRefs(defaultUserContentFile)); if (NS_FAILED(rv)) return(rv); - rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, getter_AddRefs(defaultUserChromeFile)); + rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_50_DIR, + getter_AddRefs(defaultUserChromeFile)); if (NS_FAILED(rv)) - rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, getter_AddRefs(defaultUserChromeFile)); + rv = NS_GetSpecialDirectory(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR, + getter_AddRefs(defaultUserChromeFile)); if (NS_FAILED(rv)) return(rv); defaultUserContentFile->Append("chrome"); @@ -2491,35 +2496,35 @@ nsChromeRegistry::GetProfileRoot(nsCString& aFileURL) } if (NS_FAILED(rv)) return rv; - + nsXPIDLCString urlSpec; rv = userChromeDir->GetURL(getter_Copies(urlSpec)); if (NS_FAILED(rv)) return rv; aFileURL = urlSpec; - + return NS_OK; } NS_IMETHODIMP -nsChromeRegistry::GetInstallRoot(nsCString& aFileURL) -{ +nsChromeRegistry::GetInstallRoot(nsCString& aFileURL) +{ nsresult rv; - nsCOMPtr appChromeDir; + nsCOMPtr appChromeDir; // Build a fileSpec that points to the destination - // (bin dir + chrome) + // (bin dir + chrome) rv = NS_GetSpecialDirectory(NS_APP_CHROME_DIR, getter_AddRefs(appChromeDir)); if (NS_FAILED(rv) || !appChromeDir) return NS_ERROR_FAILURE; - nsXPIDLCString urlSpec; + nsXPIDLCString urlSpec; rv = appChromeDir->GetURL(getter_Copies(urlSpec)); if (NS_FAILED(rv)) return rv; aFileURL = urlSpec; - return NS_OK; + return NS_OK; } NS_IMETHODIMP @@ -2529,21 +2534,21 @@ nsChromeRegistry::ReloadChrome() nsresult rv = NS_OK; // Flush the cache completely. - nsCOMPtr xulCache = + nsCOMPtr xulCache = do_GetService("@mozilla.org/xul/xul-prototype-cache;1", &rv); if (NS_SUCCEEDED(rv) && xulCache) { rv = xulCache->Flush(); if (NS_FAILED(rv)) return rv; } - + nsCOMPtr bundleService = do_GetService(kStringBundleServiceCID, &rv); - + if (NS_SUCCEEDED(rv)) { rv = bundleService->FlushBundles(); if (NS_FAILED(rv)) return rv; } - + // Get the window mediator nsCOMPtr windowMediator = do_GetService(kWindowMediatorCID, &rv); if (NS_SUCCEEDED(rv)) { @@ -2600,14 +2605,14 @@ nsChromeRegistry::GetArcs(nsIRDFDataSource* aDataSource, NS_ERROR("Unable to retrieve the resource corresponding to the chrome skin or content."); return rv; } - + if (NS_FAILED(container->Init(aDataSource, chromeResource))) return NS_OK; nsCOMPtr arcs; if (NS_FAILED(container->GetElements(getter_AddRefs(arcs)))) return NS_OK; - + *aResult = arcs; NS_IF_ADDREF(*aResult); return NS_OK; @@ -2629,7 +2634,7 @@ nsChromeRegistry::AddToCompositeDataSource(PRBool aUseProfile) rv = NS_NewChromeUIDataSource(mChromeDataSource, getter_AddRefs(mUIDataSource)); if (NS_FAILED(rv)) return rv; } - + if (aUseProfile) { // Profiles take precedence. Load them first. nsCOMPtr dataSource; @@ -2701,15 +2706,15 @@ NS_IMETHODIMP nsChromeRegistry::GetBackstopSheets(nsIDocShell* aDocShell, nsISupportsArray **aResult) { nsresult rv = NS_NewISupportsArray(aResult); - + // Determine the agent sheets that should be loaded. if (!mScrollbarSheet) - LoadStyleSheet(getter_AddRefs(mScrollbarSheet), nsCAutoString("chrome://global/skin/scrollbars.css")); - + LoadStyleSheet(getter_AddRefs(mScrollbarSheet), nsCAutoString("chrome://global/skin/scrollbars.css")); + if (!mFormSheet) { nsCAutoString sheetURL; GetFormSheetURL(sheetURL); - LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL); + LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL); } PRBool shouldOverride = PR_FALSE; @@ -2726,7 +2731,7 @@ nsChromeRegistry::GetBackstopSheets(nsIDocShell* aDocShell, nsISupportsArray **a char* str = sheets.ToNewCString(); char* newStr; char* token = nsCRT::strtok( str, ", ", &newStr ); - while( token != NULL ) { + while (token) { nsCOMPtr content(do_QueryInterface(elt)); nsCOMPtr doc; content->GetDocument(*getter_AddRefs(doc)); @@ -2773,10 +2778,10 @@ nsChromeRegistry::GetBackstopSheets(nsIDocShell* aDocShell, nsISupportsArray **a if (mScrollbarSheet && !shouldOverride) (*aResult)->AppendElement(mScrollbarSheet); - - if (mFormSheet) + + if (mFormSheet) (*aResult)->AppendElement(mFormSheet); - + return NS_OK; } @@ -2784,24 +2789,23 @@ NS_IMETHODIMP nsChromeRegistry::GetUserSheets(PRBool aIsChrome, nsISupportsArray **aResult) { nsresult rv; - - if((aIsChrome && mUserChromeSheet) || (!aIsChrome && mUserContentSheet)) - { + + if ((aIsChrome && mUserChromeSheet) || (!aIsChrome && mUserContentSheet)) { rv = NS_NewISupportsArray(aResult); if (NS_FAILED(rv)) return rv; - if(aIsChrome && mUserChromeSheet) { + if (aIsChrome && mUserChromeSheet) { rv = (*aResult)->AppendElement(mUserChromeSheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; - } - - if(!aIsChrome && mUserContentSheet) { + } + + if (!aIsChrome && mUserContentSheet) { rv = (*aResult)->AppendElement(mUserContentSheet) ? NS_OK : NS_ERROR_FAILURE; if (NS_FAILED(rv)) return rv; } } return NS_OK; } - + nsresult nsChromeRegistry::LoadStyleSheet(nsICSSStyleSheet** aSheet, const nsCString& aURL) { nsCOMPtr uri; @@ -2820,7 +2824,7 @@ nsresult nsChromeRegistry::LoadStyleSheetWithURL(nsIURI* aURL, nsICSSStyleSheet* NS_GET_IID(nsICSSLoader), getter_AddRefs(loader)); if (NS_FAILED(rv)) return rv; - if(loader) { + if (loader) { PRBool complete; rv = loader->LoadAgentSheet(aURL, *aSheet, complete, nsnull); @@ -2861,8 +2865,8 @@ nsresult nsChromeRegistry::LoadProfileDataSource() rv = FlushCaches(); if (NS_FAILED(rv)) return rv; - // XXX this sucks ASS. This is a temporary hack until we get - // around to fixing the skin switching bugs. + // XXX this sucks ASS. This is a temporary hack until we get + // around to fixing the skin switching bugs. // Select and Remove skins based on a pref set in a previous session. nsCOMPtr pref(do_GetService("@mozilla.org/preferences;1")); if (pref) { @@ -2870,30 +2874,30 @@ nsresult nsChromeRegistry::LoadProfileDataSource() rv = pref->CopyUnicharPref("general.skins.selectedSkin", getter_Copies(skinToSelect)); if (NS_SUCCEEDED(rv)) { rv = SelectSkin(skinToSelect, PR_TRUE); - if (NS_SUCCEEDED(rv)) + if (NS_SUCCEEDED(rv)) pref->DeleteBranch("general.skins.selectedSkin"); } } - rv = LoadStyleSheet(getter_AddRefs(mScrollbarSheet), nsCAutoString("chrome://global/skin/scrollbars.css")); + rv = LoadStyleSheet(getter_AddRefs(mScrollbarSheet), nsCAutoString("chrome://global/skin/scrollbars.css")); // This must always be the last line of profile initialization! nsCAutoString sheetURL; rv = GetUserSheetURL(PR_TRUE, sheetURL); if (NS_FAILED(rv)) return rv; - if(!sheetURL.IsEmpty()) { + if (!sheetURL.IsEmpty()) { (void)LoadStyleSheet(getter_AddRefs(mUserChromeSheet), sheetURL); // it's ok to not have a user.css file } rv = GetUserSheetURL(PR_FALSE, sheetURL); if (NS_FAILED(rv)) return rv; - if(!sheetURL.IsEmpty()) { + if (!sheetURL.IsEmpty()) { (void)LoadStyleSheet(getter_AddRefs(mUserContentSheet), sheetURL); // it's ok not to have a userContent.css or userChrome.css file } - rv = GetFormSheetURL(sheetURL); + rv = GetFormSheetURL(sheetURL); if (NS_FAILED(rv)) return rv; - if(!sheetURL.IsEmpty()) + if (!sheetURL.IsEmpty()) (void)LoadStyleSheet(getter_AddRefs(mFormSheet), sheetURL); } return NS_OK; @@ -2916,7 +2920,7 @@ NS_IMETHODIMP nsChromeRegistry::AllowScriptsForSkin(nsIURI* aChromeURI, PRBool * // XXX could factor this with selectproviderforpackage // get the selected skin resource for the package nsCOMPtr selectedProvider; - + nsCAutoString resourceStr("urn:mozilla:package:"); resourceStr += package; @@ -2926,7 +2930,7 @@ NS_IMETHODIMP nsChromeRegistry::AllowScriptsForSkin(nsIURI* aChromeURI, PRBool * if (NS_FAILED(rv)) { NS_ERROR("Unable to obtain the package resource."); return rv; - } + } if (NS_FAILED(rv = mChromeDataSource->GetTarget(resource, mSelectedSkin, PR_TRUE, getter_AddRefs(selectedProvider)))) return NS_OK; @@ -2943,7 +2947,7 @@ NS_IMETHODIMP nsChromeRegistry::AllowScriptsForSkin(nsIURI* aChromeURI, PRBool * // get its script access nsCAutoString scriptAccess; rv = nsChromeRegistry::FollowArc(mChromeDataSource, - scriptAccess, + scriptAccess, resource, mAllowScripts); if (NS_FAILED(rv)) return rv; @@ -2972,13 +2976,13 @@ nsChromeRegistry::CheckForNewChrome() // open the installed-chrome file nsCOMPtr listFile; - nsCOMPtr directoryService = + nsCOMPtr directoryService = do_GetService(NS_DIRECTORY_SERVICE_CONTRACTID, &rv); if (NS_FAILED(rv)) return rv; rv = directoryService->Get(NS_APP_CHROME_DIR, NS_GET_IID(nsILocalFile), getter_AddRefs(listFile)); if (NS_FAILED(rv)) - return rv; + return rv; nsCOMPtr allPkgs; rv = listFile->Clone(getter_AddRefs(allPkgs)); @@ -3019,7 +3023,7 @@ nsChromeRegistry::CheckForNewChrome() rv = listFile->OpenNSPRFileDesc(PR_RDONLY, 0, &file); if (NS_FAILED(rv)) return rv; - // file is open. + // file is open. PRFileInfo finfo; @@ -3151,7 +3155,7 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) printf("***** Chrome Registration: Selecting skin %s as default\n", (const char*)chromeLocation); #endif } - else + else rv = InstallSkin(chromeURL, isProfile, PR_FALSE); } else if (content.Equals(chromeType)) @@ -3164,7 +3168,7 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) printf("***** Chrome Registration: Selecting locale %s as default\n", (const char*)chromeLocation); #endif } - else + else rv = InstallLocale(chromeURL, isProfile); } if (NS_FAILED(rv)) return rv; @@ -3175,7 +3179,7 @@ nsChromeRegistry::ProcessNewChromeBuffer(char *aBuffer, PRInt32 aLength) return rv; } -PRBool +PRBool nsChromeRegistry::GetProviderCount(const nsCString& aProviderType, nsIRDFDataSource* aDataSource) { nsresult rv; @@ -3210,19 +3214,19 @@ nsChromeRegistry::GetProviderCount(const nsCString& aProviderType, nsIRDFDataSou NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const PRUnichar *aTopic, const PRUnichar *someData) { nsresult rv = NS_OK; - + if (!nsCRT::strcmp(NS_LITERAL_STRING("profile-before-change").get(), aTopic)) { mChromeDataSource = nsnull; mProfileInitialized = PR_FALSE; - + if (!nsCRT::strcmp(NS_LITERAL_STRING("shutdown-cleanse").get(), someData)) { - nsCOMPtr userChromeDir; + nsCOMPtr userChromeDir; rv = NS_GetSpecialDirectory(NS_APP_USER_CHROME_DIR, getter_AddRefs(userChromeDir)); if (NS_SUCCEEDED(rv) && userChromeDir) rv = userChromeDir->Remove(PR_TRUE); } - } + } else if (!nsCRT::strcmp(NS_LITERAL_STRING("profile-do-change").get(), aTopic)) { if (!mProfileInitialized) rv = LoadProfileDataSource(); @@ -3231,7 +3235,7 @@ NS_IMETHODIMP nsChromeRegistry::Observe(nsISupports *aSubject, const PRUnichar * return rv; } -NS_IMETHODIMP nsChromeRegistry::CheckThemeVersion(const PRUnichar *aSkin, +NS_IMETHODIMP nsChromeRegistry::CheckThemeVersion(const PRUnichar *aSkin, PRBool* aResult) { nsCAutoString provider("skin"); @@ -3239,7 +3243,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckThemeVersion(const PRUnichar *aSkin, } -NS_IMETHODIMP nsChromeRegistry::CheckLocaleVersion(const PRUnichar *aLocale, +NS_IMETHODIMP nsChromeRegistry::CheckLocaleVersion(const PRUnichar *aLocale, PRBool* aResult) { nsCAutoString provider("locale"); @@ -3247,7 +3251,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckLocaleVersion(const PRUnichar *aLocale, } -NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProviderType, +NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProviderType, const PRUnichar* aProviderName, nsIRDFResource* aSelectionArc, PRBool *aCompatible) @@ -3257,7 +3261,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider // Build the provider resource str. // e.g., urn:mozilla:skin:aqua/1.0 nsCAutoString resourceStr( "urn:mozilla:" ); - resourceStr += aProviderType; + resourceStr += aProviderType; resourceStr += ":"; resourceStr.AppendWithConversion(aProviderName); @@ -3312,10 +3316,10 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider if (NS_SUCCEEDED(rv) && packageSkinEntry) { nsCOMPtr entry = do_QueryInterface(packageSkinEntry); if (entry) { - + nsCAutoString themePackageVersion; nsChromeRegistry::FollowArc(mChromeDataSource, themePackageVersion, entry, aSelectionArc); - + // Obtain the real package resource. nsCOMPtr packageNode; rv = mChromeDataSource->GetTarget(entry, mPackage, PR_TRUE, getter_AddRefs(packageNode)); @@ -3326,7 +3330,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider nsCOMPtr packageResource(do_QueryInterface(packageNode)); if (packageResource) { - + nsCAutoString packageVersion; nsChromeRegistry::FollowArc(mChromeDataSource, packageVersion, packageResource, aSelectionArc); @@ -3346,7 +3350,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider *aCompatible = PR_FALSE; } } - + // if just one theme package is NOT compatible, the theme will be disabled if (!(*aCompatible)) return NS_OK; @@ -3355,7 +3359,7 @@ NS_IMETHODIMP nsChromeRegistry::CheckProviderVersion (const nsCString& aProvider } } rv = arcs->HasMoreElements(&more); - if (NS_FAILED(rv)) + if (NS_FAILED(rv)) return rv; } diff --git a/mozilla/xpcom/build/nsXPComInit.cpp b/mozilla/xpcom/build/nsXPComInit.cpp index c33e64c5921..4a5a5c613e5 100644 --- a/mozilla/xpcom/build/nsXPComInit.cpp +++ b/mozilla/xpcom/build/nsXPComInit.cpp @@ -246,7 +246,7 @@ static nsModuleComponentInfo components[] = { COMPONENT(FILESPEC, nsFileSpecImpl::Create), COMPONENT(DIRECTORYITERATOR, nsDirectoryIteratorImpl::Create), - COMPONENT(FAST_LOAD_SERVICE, nsFastLoadService::Create) + COMPONENT(FASTLOADSERVICE, nsFastLoadService::Create) }; #undef COMPONENT diff --git a/mozilla/xpcom/io/nsFastLoadFile.cpp b/mozilla/xpcom/io/nsFastLoadFile.cpp index 1a973243570..cdf50d58edd 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.cpp +++ b/mozilla/xpcom/io/nsFastLoadFile.cpp @@ -24,9 +24,13 @@ #include "prtypes.h" #include "nscore.h" #include "nsDebug.h" +#include "nsEnumeratorUtils.h" #include "nsMemory.h" +#include "nsXPIDLString.h" #include "nsIComponentManager.h" +#include "nsIFile.h" +#include "nsILocalFile.h" #include "nsISeekableStream.h" #include "nsISerializable.h" #include "nsIStreamBufferAccess.h" @@ -232,13 +236,16 @@ static const char magic[] = MFL_FILE_MAGIC; // -------------------------- nsFastLoadFileReader -------------------------- nsID nsFastLoadFileReader::nsFastLoadFooter::gDummyID; -nsFastLoadFileReader::nsObjectMapEntry nsFastLoadFileReader::nsFastLoadFooter::gDummySharpObjectEntry; +nsFastLoadFileReader::nsObjectMapEntry + nsFastLoadFileReader::nsFastLoadFooter::gDummySharpObjectEntry; -NS_IMPL_ISUPPORTS_INHERITED3(nsFastLoadFileReader, +NS_IMPL_ISUPPORTS_INHERITED5(nsFastLoadFileReader, nsBinaryInputStream, nsIObjectInputStream, nsIFastLoadFileControl, - nsISeekableStream) + nsIFastLoadReadControl, + nsISeekableStream, + nsIFastLoadFileReader) MOZ_DECL_CTOR_COUNTER(nsFastLoadFileReader) @@ -249,7 +256,8 @@ nsFastLoadFileReader::ReadHeader(nsFastLoadHeader *aHeader) PRUint32 bytesRead; rv = Read(NS_REINTERPRET_CAST(char*, aHeader), sizeof *aHeader, &bytesRead); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (bytesRead != sizeof *aHeader || memcmp(aHeader->mMagic, magic, MFL_FILE_MAGIC_SIZE)) { @@ -280,71 +288,11 @@ nsFastLoadFileReader::SetChecksum(PRUint32 aChecksum) return NS_OK; } -NS_IMETHODIMP -nsFastLoadFileReader::ComputeChecksum(PRUint32 *aResult) -{ - *aResult = mHeader.mChecksum; - return NS_OK; -#if 0 - PRUint32 saveChecksum = mHeader.mChecksum; - mHeader.mChecksum = 0; - NS_AccumulateFastLoadChecksum(&mHeader.mChecksum, - NS_REINTERPRET_CAST(PRUint8*, &mHeader), - sizeof mHeader, - PR_FALSE); +struct nsStringMapEntry : public PLDHashEntryHdr { + const char* mString; // key, must come first +}; - nsCOMPtr - bufferAccess(do_QueryInterface(mInputStream)); - if (bufferAccess) - bufferAccess->DisableBuffering(); - - nsCOMPtr seekable(do_QueryInterface(mInputStream)); - nsresult rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, - sizeof mHeader); - if (NS_SUCCEEDED(rv)) { - char buf[MFL_CHECKSUM_BUFSIZE]; - PRUint32 len, rem = 0; - - for (;;) { - rv = mInputStream->Read(buf + rem, sizeof buf - rem, &len); - if (NS_FAILED(rv) || len == 0) - break; - - len += rem; - rem = NS_AccumulateFastLoadChecksum(&mHeader.mChecksum, - NS_REINTERPRET_CAST(PRUint8*, - buf), - len, - PR_FALSE); - if (rem != 0) - memcpy(buf, buf + len - rem, rem); - } - - if (rem != 0) { - NS_AccumulateFastLoadChecksum(&mHeader.mChecksum, - NS_REINTERPRET_CAST(PRUint8*, buf), - rem, - PR_TRUE); - } - } - - if (bufferAccess) - bufferAccess->EnableBuffering(); - - *aResult = mHeader.mChecksum; - mHeader.mChecksum = saveChecksum; - return rv; -#endif -} - -NS_IMETHODIMP -nsFastLoadFileReader::GetDependencies(nsICollection* *aDependencies) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - -struct nsDocumentMapEntry : public PLDHashEntryHdr { - const char* mURISpec; // key, must come first +struct nsDocumentMapEntry : public nsStringMapEntry { PRUint32 mInitialSegmentOffset; // offset of URI's first segment in file }; @@ -356,34 +304,35 @@ struct nsDocumentMapReadEntry : public nsDocumentMapEntry { }; PR_STATIC_CALLBACK(PRBool) -docmap_MatchEntry(PLDHashTable *aTable, +strmap_MatchEntry(PLDHashTable *aTable, const PLDHashEntryHdr *aHdr, const void *aKey) { - const nsDocumentMapEntry* entry = - NS_STATIC_CAST(const nsDocumentMapEntry*, aHdr); - const char* spec = NS_REINTERPRET_CAST(const char*, aKey); + const nsStringMapEntry* entry = + NS_STATIC_CAST(const nsStringMapEntry*, aHdr); + const char* string = NS_REINTERPRET_CAST(const char*, aKey); - return strcmp(entry->mURISpec, spec) == 0; + return strcmp(entry->mString, string) == 0; } PR_STATIC_CALLBACK(void) -docmap_ClearEntry(PLDHashTable *aTable, PLDHashEntryHdr *aHdr) +strmap_ClearEntry(PLDHashTable *aTable, PLDHashEntryHdr *aHdr) { - nsDocumentMapEntry* entry = NS_STATIC_CAST(nsDocumentMapEntry*, aHdr); + nsStringMapEntry* entry = NS_STATIC_CAST(nsStringMapEntry*, aHdr); - nsMemory::Free((void*) entry->mURISpec); + if (entry->mString) + nsMemory::Free((void*) entry->mString); PL_DHashClearEntryStub(aTable, aHdr); } -static PLDHashTableOps docmap_DHashTableOps = { +static PLDHashTableOps strmap_DHashTableOps = { PL_DHashAllocTable, PL_DHashFreeTable, PL_DHashGetKeyStub, PL_DHashStringKey, - docmap_MatchEntry, + strmap_MatchEntry, PL_DHashMoveEntryStub, - docmap_ClearEntry, + strmap_ClearEntry, PL_DHashFinalizeStub, NULL }; @@ -407,7 +356,7 @@ objmap_ClearEntry(PLDHashTable *aTable, PLDHashEntryHdr *aHdr) // Ignore tagged object ids stored as object pointer keys (the updater // code does this). - if ((NSFastLoadOID(NS_PTR_TO_INT32(entry->mObject)) & MFL_OBJECT_DEF_TAG) == 0) + if ((NS_PTR_TO_INT32(entry->mObject) & MFL_OBJECT_DEF_TAG) == 0) NS_IF_RELEASE(entry->mObject); PL_DHashClearEntryStub(aTable, aHdr); } @@ -431,6 +380,9 @@ nsFastLoadFileReader::StartMuxedDocument(nsISupports* aURI, const char* aURISpec NS_STATIC_CAST(nsDocumentMapReadEntry*, PL_DHashTableOperate(&mFooter.mDocumentMap, aURISpec, PL_DHASH_LOOKUP)); + + // If the spec isn't in the map, return NS_ERROR_NOT_AVAILABLE so the + // FastLoad service can try for a file update. if (PL_DHASH_ENTRY_IS_FREE(docMapEntry)) return NS_ERROR_NOT_AVAILABLE; @@ -467,7 +419,7 @@ nsFastLoadFileReader::SelectMuxedDocument(nsISupports* aURI) PL_DHASH_LOOKUP)); // If the URI isn't in the map, return NS_ERROR_NOT_AVAILABLE so the - // FastLoad service can try for a file update. + // FastLoad service can try selecting the file updater. if (PL_DHASH_ENTRY_IS_FREE(uriMapEntry)) return NS_ERROR_NOT_AVAILABLE; @@ -476,7 +428,8 @@ nsFastLoadFileReader::SelectMuxedDocument(nsISupports* aURI) nsDocumentMapReadEntry* docMapEntry = mCurrentDocumentMapEntry; if (docMapEntry && docMapEntry->mBytesLeft) { rv = Tell(&docMapEntry->mSaveOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } // It turns out we get a fair amount of redundant select calls, thanks to @@ -486,7 +439,7 @@ nsFastLoadFileReader::SelectMuxedDocument(nsISupports* aURI) docMapEntry = uriMapEntry->mDocMapEntry; if (docMapEntry == mCurrentDocumentMapEntry) { TRACE_MUX(('r', "select prev %s same as current!\n", - docMapEntry->mURISpec)); + docMapEntry->mString)); } // Invariant: docMapEntry->mBytesLeft implies docMapEntry->mSaveOffset has @@ -499,7 +452,8 @@ nsFastLoadFileReader::SelectMuxedDocument(nsISupports* aURI) nsCOMPtr seekable(do_QueryInterface(mInputStream)); rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, docMapEntry->mSaveOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } mCurrentDocumentMapEntry = docMapEntry; @@ -522,7 +476,7 @@ nsFastLoadFileReader::EndMuxedDocument(nsISupports* aURI) PL_DHASH_LOOKUP)); // If the URI isn't in the map, return NS_ERROR_NOT_AVAILABLE so the - // FastLoad service can try for a file update. + // FastLoad service can try to end a select on its file updater. if (PL_DHASH_ENTRY_IS_FREE(uriMapEntry)) return NS_ERROR_NOT_AVAILABLE; @@ -560,7 +514,8 @@ nsFastLoadFileReader::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aBytesRead) rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, entry->mNextSegmentOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Clear mCurrentDocumentMapEntry temporarily to avoid recursion. mCurrentDocumentMapEntry = nsnull; @@ -570,7 +525,8 @@ nsFastLoadFileReader::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aBytesRead) rv = Read32(&entry->mBytesLeft); mCurrentDocumentMapEntry = entry; - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; NS_ASSERTION(entry->mBytesLeft >= 8, "demux segment length botch!"); entry->mBytesLeft -= 8; @@ -592,13 +548,96 @@ nsFastLoadFileReader::Read(char* aBuffer, PRUint32 aCount, PRUint32 *aBytesRead) return rv; } +/** + * XXX tuneme + */ +#define MFL_CHECKSUM_BUFSIZE 8192 + +NS_IMETHODIMP +nsFastLoadFileReader::ComputeChecksum(PRUint32 *aResult) +{ + nsCOMPtr stream = mInputStream; + + nsCOMPtr seekable(do_QueryInterface(stream)); + PRUint32 saveOffset; + nsresult rv = seekable->Tell(&saveOffset); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr bufferAccess(do_QueryInterface(stream)); + if (bufferAccess) { + rv = bufferAccess->GetUnbufferedStream(getter_AddRefs(stream)); + if (NS_FAILED(rv)) + return rv; + + seekable = do_QueryInterface(stream); + if (!seekable) + return NS_ERROR_UNEXPECTED; + } + + rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0); + if (NS_FAILED(rv)) + return rv; + + char buf[MFL_CHECKSUM_BUFSIZE]; + PRUint32 len, rem; + + rem = offsetof(nsFastLoadHeader, mChecksum); + rv = stream->Read(buf, rem, &len); + if (NS_FAILED(rv)) + return rv; + if (len != rem) + return NS_ERROR_UNEXPECTED; + + rv = seekable->Seek(nsISeekableStream::NS_SEEK_CUR, 4); + if (NS_FAILED(rv)) + return rv; + memset(buf + rem, 0, 4); + rem += 4; + + PRUint32 checksum = 0; + while (NS_SUCCEEDED(rv = stream->Read(buf + rem, sizeof buf - rem, &len)) && + len) { + len += rem; + rem = NS_AccumulateFastLoadChecksum(&checksum, + NS_REINTERPRET_CAST(PRUint8*, buf), + len, + PR_FALSE); + if (rem) + memcpy(buf, buf + len - rem, rem); + } + if (NS_FAILED(rv)) + return rv; + + if (rem) { + NS_AccumulateFastLoadChecksum(&checksum, + NS_REINTERPRET_CAST(PRUint8*, buf), + rem, + PR_TRUE); + } + + rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, saveOffset); + if (NS_FAILED(rv)) + return rv; + + *aResult = checksum; + return NS_OK; +} + +NS_IMETHODIMP +nsFastLoadFileReader::GetDependencies(nsISimpleEnumerator* *aDependencies) +{ + return NS_NewArrayEnumerator(aDependencies, mFooter.mDependencies); +} + nsresult nsFastLoadFileReader::ReadFooter(nsFastLoadFooter *aFooter) { nsresult rv; rv = ReadFooterPrefix(aFooter); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; aFooter->mIDMap = new nsID[aFooter->mNumIDs]; if (!aFooter->mIDMap) @@ -607,7 +646,8 @@ nsFastLoadFileReader::ReadFooter(nsFastLoadFooter *aFooter) PRUint32 i, n; for (i = 0, n = aFooter->mNumIDs; i < n; i++) { rv = ReadSlowID(&aFooter->mIDMap[i]); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } aFooter->mObjectMap = new nsObjectMapEntry[aFooter->mNumSharpObjects]; @@ -618,22 +658,23 @@ nsFastLoadFileReader::ReadFooter(nsFastLoadFooter *aFooter) nsObjectMapEntry* entry = &aFooter->mObjectMap[i]; rv = ReadSharpObjectInfo(entry); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; entry->mReadObject = nsnull; entry->mSkipOffset = 0; } - if (!PL_DHashTableInit(&aFooter->mDocumentMap, &docmap_DHashTableOps, + if (!PL_DHashTableInit(&aFooter->mDocumentMap, &strmap_DHashTableOps, (void *)this, sizeof(nsDocumentMapReadEntry), - PL_DHASH_MIN_SIZE)) { + aFooter->mNumMuxedDocuments)) { aFooter->mDocumentMap.ops = nsnull; return NS_ERROR_OUT_OF_MEMORY; } if (!PL_DHashTableInit(&aFooter->mURIMap, &objmap_DHashTableOps, (void *)this, sizeof(nsURIMapReadEntry), - PL_DHASH_MIN_SIZE)) { + aFooter->mNumMuxedDocuments)) { aFooter->mURIMap.ops = nsnull; return NS_ERROR_OUT_OF_MEMORY; } @@ -642,7 +683,8 @@ nsFastLoadFileReader::ReadFooter(nsFastLoadFooter *aFooter) nsFastLoadMuxedDocumentInfo info; rv = ReadMuxedDocumentInfo(&info); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; nsDocumentMapReadEntry* entry = NS_STATIC_CAST(nsDocumentMapReadEntry*, @@ -654,24 +696,36 @@ nsFastLoadFileReader::ReadFooter(nsFastLoadFooter *aFooter) return NS_ERROR_OUT_OF_MEMORY; } - NS_ASSERTION(!entry->mURISpec, "duplicate URISpec in MuxedDocumentMap"); - entry->mURISpec = info.mURISpec; + NS_ASSERTION(!entry->mString, "duplicate URISpec in MuxedDocumentMap"); + entry->mString = info.mURISpec; entry->mInitialSegmentOffset = info.mInitialSegmentOffset; entry->mNextSegmentOffset = info.mInitialSegmentOffset; entry->mBytesLeft = 0; entry->mSaveOffset = 0; } - for (i = 0, n = aFooter->mNumDependencies; i < n; i++) { - char* s; - rv = ReadStringZ(&s); - if (NS_FAILED(rv)) return rv; + nsCOMPtr readDeps; + rv = NS_NewISupportsArray(getter_AddRefs(readDeps)); + if (NS_FAILED(rv)) + return rv; - if (!aFooter->AppendDependency(s, PR_FALSE)) { - nsMemory::Free(s); - return NS_ERROR_OUT_OF_MEMORY; - } + for (i = 0, n = aFooter->mNumDependencies; i < n; i++) { + nsXPIDLCString filename; + rv = ReadStringZ(getter_Copies(filename)); + if (NS_FAILED(rv)) + return rv; + + nsCOMPtr file; + rv = NS_NewLocalFile(filename, PR_TRUE, getter_AddRefs(file)); + if (NS_FAILED(rv)) + return rv; + + rv = readDeps->AppendElement(file); + if (NS_FAILED(rv)) + return rv; } + + aFooter->mDependencies = readDeps; return NS_OK; } @@ -681,16 +735,20 @@ nsFastLoadFileReader::ReadFooterPrefix(nsFastLoadFooterPrefix *aFooterPrefix) nsresult rv; rv = Read32(&aFooterPrefix->mNumIDs); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Read32(&aFooterPrefix->mNumSharpObjects); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Read32(&aFooterPrefix->mNumMuxedDocuments); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Read32(&aFooterPrefix->mNumDependencies); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return NS_OK; } @@ -701,17 +759,21 @@ nsFastLoadFileReader::ReadSlowID(nsID *aID) nsresult rv; rv = Read32(&aID->m0); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Read16(&aID->m1); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Read16(&aID->m2); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; PRUint32 bytesRead; rv = Read(NS_REINTERPRET_CAST(char*, aID->m3), sizeof aID->m3, &bytesRead); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (bytesRead != sizeof aID->m3) return NS_ERROR_FAILURE; @@ -733,13 +795,16 @@ nsFastLoadFileReader::ReadSharpObjectInfo(nsFastLoadSharpObjectInfo *aInfo) nsresult rv; rv = Read32(&aInfo->mCIDOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Read16(&aInfo->mStrongRefCnt); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Read16(&aInfo->mWeakRefCnt); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return NS_OK; } @@ -751,7 +816,8 @@ nsFastLoadFileReader::ReadMuxedDocumentInfo(nsFastLoadMuxedDocumentInfo *aInfo) char *spec; rv = ReadStringZ(&spec); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Read32(&aInfo->mInitialSegmentOffset); if (NS_FAILED(rv)) { @@ -782,7 +848,8 @@ nsFastLoadFileReader::Open() if (bufferAccess) bufferAccess->EnableBuffering(); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (mHeader.mVersion != MFL_FILE_VERSION) return NS_ERROR_UNEXPECTED; @@ -790,21 +857,25 @@ nsFastLoadFileReader::Open() return NS_ERROR_UNEXPECTED; rv = seekable->Seek(nsISeekableStream::NS_SEEK_END, 0); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; PRUint32 fileSize; rv = seekable->Tell(&fileSize); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (fileSize != mHeader.mFileSize) return NS_ERROR_UNEXPECTED; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, PRInt32(mHeader.mFooterOffset)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = ReadFooter(&mFooter); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return seekable->Seek(nsISeekableStream::NS_SEEK_SET, sizeof(nsFastLoadHeader)); @@ -813,35 +884,21 @@ nsFastLoadFileReader::Open() NS_IMETHODIMP nsFastLoadFileReader::Close() { -#ifdef DEBUG_brendan - PRUint32 strongTotal = 0, weakTotal = 0; -#endif - // Give up our strong "keepalive" references, in case not all objects that - // were deserialized were fully re-connected. This happens for sure when - // nsFastLoadFileUpdater has to deserialize sharp objects from its aReader - // constructor parameter in order to map object info by object address, in - // order to write a valid file footer when the update process completes. + // were deserialized were fully re-connected. // - // XXXbe get rid of strongTotal, weakTotal, and the warnings + // This happens for sure when an nsFastLoadFileUpdater is created and wraps + // an nsFastLoadFileReader whose data was already deserialized by an earlier + // FastLoad episode. The reader is useful in the second such episode during + // a session not so much for reading objects as for its footer information, + // which primes the updater's tables so that after the update completes, the + // FastLoad file has a superset footer. + for (PRUint32 i = 0, n = mFooter.mNumSharpObjects; i < n; i++) { nsObjectMapEntry* entry = &mFooter.mObjectMap[i]; - -#ifdef DEBUG_brendan - strongTotal += entry->mStrongRefCnt; - weakTotal += entry->mWeakRefCnt; -#endif - entry->mReadObject = nsnull; } -#ifdef DEBUG_brendan - if (strongTotal != 0) - NS_WARNING("failed to deserialize all strong refs from FastLoad file"); - if (weakTotal != 0) - NS_WARNING("failed to deserialize all weak refs from FastLoad file"); -#endif - return mInputStream->Close(); } @@ -852,18 +909,21 @@ nsFastLoadFileReader::DeserializeObject(nsISupports* *aObject) NSFastLoadID fastCID; rv = ReadFastID(&fastCID); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; const nsID& slowCID = mFooter.GetID(fastCID); nsCOMPtr object(do_CreateInstance(slowCID, &rv)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; nsCOMPtr serializable(do_QueryInterface(object)); if (!serializable) return NS_ERROR_FAILURE; rv = serializable->Read(this); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; *aObject = object; NS_ADDREF(*aObject); @@ -877,7 +937,8 @@ nsFastLoadFileReader::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject) NSFastLoadOID oid; rv = Read32(&oid); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; oid ^= MFL_OID_XOR_KEY; nsObjectMapEntry* entry = (oid != MFL_DULL_OBJECT_OID) @@ -890,7 +951,8 @@ nsFastLoadFileReader::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject) NS_ASSERTION(aIsStrongRef, "dull object read via weak ref!"); rv = DeserializeObject(getter_AddRefs(object)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } else { NS_ASSERTION((oid & MFL_WEAK_REF_TAG) == (aIsStrongRef ? 0 : MFL_WEAK_REF_TAG), @@ -904,7 +966,8 @@ nsFastLoadFileReader::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject) nsDocumentMapReadEntry* saveDocMapEntry = nsnull; rv = seekable->Tell(&saveOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (entry->mCIDOffset != saveOffset) { // We skipped deserialization of this object from its position @@ -921,23 +984,27 @@ nsFastLoadFileReader::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject) mCurrentDocumentMapEntry = nsnull; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, entry->mCIDOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } rv = DeserializeObject(getter_AddRefs(object)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (entry->mCIDOffset != saveOffset) { // Save the "skip offset" in case we need to skip this object // definition when reading forward, later on. rv = seekable->Tell(&entry->mSkipOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Restore stream offset and mCurrentDocumentMapEntry in case // we're still reading forward through a part of the multiplex // to get object definitions eagerly. rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, saveOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; mCurrentDocumentMapEntry = saveDocMapEntry; } @@ -950,10 +1017,12 @@ nsFastLoadFileReader::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject) // We must skip over the object definition. if (oid & MFL_OBJECT_DEF_TAG) { NS_ASSERTION(entry->mSkipOffset != 0, "impossible! see above"); - nsCOMPtr seekable(do_QueryInterface(mInputStream)); + nsCOMPtr + seekable(do_QueryInterface(mInputStream)); rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, entry->mSkipOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } } @@ -972,11 +1041,13 @@ nsFastLoadFileReader::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject) if (oid & MFL_QUERY_INTERFACE_TAG) { NSFastLoadID iid; rv = ReadFastID(&iid); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = object->QueryInterface(mFooter.GetID(iid), NS_REINTERPRET_CAST(void**, aObject)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } else { *aObject = object; NS_ADDREF(*aObject); @@ -992,7 +1063,8 @@ nsFastLoadFileReader::ReadID(nsID *aResult) NSFastLoadID fastID; rv = ReadFastID(&fastID); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; *aResult = mFooter.GetID(fastID); return NS_OK; @@ -1042,10 +1114,11 @@ NS_NewFastLoadFileReader(nsIObjectInputStream* *aResult, // -------------------------- nsFastLoadFileWriter -------------------------- -NS_IMPL_ISUPPORTS_INHERITED3(nsFastLoadFileWriter, +NS_IMPL_ISUPPORTS_INHERITED4(nsFastLoadFileWriter, nsBinaryOutputStream, nsIObjectOutputStream, nsIFastLoadFileControl, + nsIFastLoadWriteControl, nsISeekableStream) MOZ_DECL_CTOR_COUNTER(nsFastLoadFileWriter) @@ -1119,22 +1192,27 @@ nsFastLoadFileWriter::WriteHeader(nsFastLoadHeader *aHeader) PRUint32 bytesWritten; rv = Write(aHeader->mMagic, MFL_FILE_MAGIC_SIZE, &bytesWritten); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (bytesWritten != MFL_FILE_MAGIC_SIZE) return NS_ERROR_FAILURE; rv = Write32(aHeader->mChecksum); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(aHeader->mVersion); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(aHeader->mFooterOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(aHeader->mFileSize); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return NS_OK; } @@ -1157,18 +1235,6 @@ nsFastLoadFileWriter::SetChecksum(PRUint32 aChecksum) return NS_OK; } -NS_IMETHODIMP -nsFastLoadFileWriter::ComputeChecksum(PRUint32 *aResult) -{ - return GetChecksum(aResult); -} - -NS_IMETHODIMP -nsFastLoadFileWriter::GetDependencies(nsICollection* *aDependencies) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} - struct nsDocumentMapWriteEntry : public nsDocumentMapEntry { PRUint32 mCurrentSegmentOffset; // last written segment's offset }; @@ -1188,7 +1254,7 @@ nsFastLoadFileWriter::StartMuxedDocument(nsISupports* aURI, const char* saveURISpec = nsnull; if (mCurrentDocumentMapEntry) { saveGeneration = mDocumentMap.generation; - saveURISpec = mCurrentDocumentMapEntry->mURISpec; + saveURISpec = mCurrentDocumentMapEntry->mString; } nsDocumentMapWriteEntry* docMapEntry = @@ -1208,15 +1274,15 @@ nsFastLoadFileWriter::StartMuxedDocument(nsISupports* aURI, "mCurrentDocumentMapEntry lost during table growth?!"); } - NS_ASSERTION(docMapEntry->mURISpec == nsnull, + NS_ASSERTION(docMapEntry->mString == nsnull, "redundant multiplexed document?"); - if (docMapEntry->mURISpec) + if (docMapEntry->mString) return NS_ERROR_UNEXPECTED; void* spec = nsMemory::Clone(aURISpec, strlen(aURISpec) + 1); if (!spec) return NS_ERROR_OUT_OF_MEMORY; - docMapEntry->mURISpec = NS_REINTERPRET_CAST(const char*, spec); + docMapEntry->mString = NS_REINTERPRET_CAST(const char*, spec); nsCOMPtr key(do_QueryInterface(aURI)); nsURIMapWriteEntry* uriMapEntry = @@ -1247,7 +1313,8 @@ nsFastLoadFileWriter::SelectMuxedDocument(nsISupports* aURI) nsresult rv; PRUint32 currentSegmentOffset; rv = seekable->Tell(¤tSegmentOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Look for an existing entry keyed by aURI, added by StartMuxedDocument. nsCOMPtr key(do_QueryInterface(aURI)); @@ -1267,22 +1334,24 @@ nsFastLoadFileWriter::SelectMuxedDocument(nsISupports* aURI) if (prevDocMapEntry) { if (prevDocMapEntry == docMapEntry) { TRACE_MUX(('w', "select prev %s same as current!\n", - prevDocMapEntry->mURISpec)); + prevDocMapEntry->mString)); return NS_OK; } PRUint32 prevSegmentOffset = prevDocMapEntry->mCurrentSegmentOffset; TRACE_MUX(('w', "select prev %s offset %lu\n", - prevDocMapEntry->mURISpec, prevSegmentOffset)); + prevDocMapEntry->mString, prevSegmentOffset)); rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, prevSegmentOffset + 4); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // The length counts all bytes in the segment, including the header // that contains [nextSegmentOffset, length]. rv = Write32(currentSegmentOffset - prevSegmentOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Seek back to the current offset only if we are not going to seek // back to *this* entry's last "current" segment offset and write its @@ -1290,7 +1359,8 @@ nsFastLoadFileWriter::SelectMuxedDocument(nsISupports* aURI) if (!docMapEntry->mInitialSegmentOffset) { rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, currentSegmentOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } } @@ -1302,14 +1372,17 @@ nsFastLoadFileWriter::SelectMuxedDocument(nsISupports* aURI) } else { rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, docMapEntry->mCurrentSegmentOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(currentSegmentOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, currentSegmentOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } // Update this document's current segment offset so we can later fix its @@ -1318,10 +1391,12 @@ nsFastLoadFileWriter::SelectMuxedDocument(nsISupports* aURI) docMapEntry->mCurrentSegmentOffset = currentSegmentOffset; rv = Write32(0); // nextSegmentOffset placeholder - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(0); // length placeholder - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; mCurrentDocumentMapEntry = docMapEntry; TRACE_MUX(('w', "select %p (%p) offset %lu\n", @@ -1347,47 +1422,28 @@ nsFastLoadFileWriter::EndMuxedDocument(nsISupports* aURI) } NS_IMETHODIMP -nsFastLoadFileWriter::Write(const char* aBuffer, PRUint32 aCount, - PRUint32 *aBytesWritten) +nsFastLoadFileWriter::AddDependency(nsIFile* aFile) { - nsresult rv; + nsXPIDLCString path; + nsresult rv = aFile->GetPath(getter_Copies(path)); + if (NS_FAILED(rv)) + return rv; - rv = mOutputStream->Write(aBuffer, aCount, aBytesWritten); + nsStringMapEntry* entry = + NS_STATIC_CAST(nsStringMapEntry*, + PL_DHashTableOperate(&mDependencyMap, path.get(), + PL_DHASH_ADD)); + if (!entry) + return NS_ERROR_OUT_OF_MEMORY; - if (NS_SUCCEEDED(rv)) { - PRUint32 bytesToCheck = *aBytesWritten; - - while (bytesToCheck != 0) { - PRUint32 bytesThatFit = bytesToCheck; - PRUint32 nextCursor = mChecksumCursor + bytesThatFit; - PRInt32 didntFit = PRInt32(nextCursor - MFL_CHECKSUM_BUFSIZE); - if (didntFit > 0) - bytesThatFit -= didntFit; - - memcpy(mChecksumBuffer + mChecksumCursor, aBuffer, bytesThatFit); - mChecksumCursor += bytesThatFit; - if (mChecksumCursor == MFL_CHECKSUM_BUFSIZE) { - nextCursor = - NS_AccumulateFastLoadChecksum(&mHeader.mChecksum, - mChecksumBuffer, - MFL_CHECKSUM_BUFSIZE, - PR_FALSE); - mCheckedByteCount += MFL_CHECKSUM_BUFSIZE - nextCursor; - - NS_ASSERTION(nextCursor == 0, "odd mChecksumBuffer alignment?"); - if (nextCursor != 0) { - memcpy(mChecksumBuffer, - mChecksumBuffer + MFL_CHECKSUM_BUFSIZE - nextCursor, - nextCursor); - } - } - - mChecksumCursor = nextCursor; - bytesToCheck -= bytesThatFit; - } + if (!entry->mString) { + const char* str = path; + void *tmp = nsMemory::Clone(str, strlen(str) + 1); + if (!tmp) + return NS_ERROR_OUT_OF_MEMORY; + entry->mString = NS_REINTERPRET_CAST(const char*, tmp); } - - return rv; + return NS_OK; } nsresult @@ -1396,16 +1452,20 @@ nsFastLoadFileWriter::WriteFooterPrefix(const nsFastLoadFooterPrefix& aFooterPre nsresult rv; rv = Write32(aFooterPrefix.mNumIDs); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(aFooterPrefix.mNumSharpObjects); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(aFooterPrefix.mNumMuxedDocuments); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(aFooterPrefix.mNumDependencies); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return NS_OK; } @@ -1416,18 +1476,22 @@ nsFastLoadFileWriter::WriteSlowID(const nsID& aID) nsresult rv; rv = Write32(aID.m0); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write16(aID.m1); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write16(aID.m2); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; PRUint32 bytesWritten; rv = Write(NS_REINTERPRET_CAST(const char*, aID.m3), sizeof aID.m3, &bytesWritten); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (bytesWritten != sizeof aID.m3) return NS_ERROR_FAILURE; @@ -1446,13 +1510,16 @@ nsFastLoadFileWriter::WriteSharpObjectInfo(const nsFastLoadSharpObjectInfo& aInf nsresult rv; rv = Write32(aInfo.mCIDOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write16(aInfo.mStrongRefCnt); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write16(aInfo.mWeakRefCnt); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return NS_OK; } @@ -1463,10 +1530,12 @@ nsFastLoadFileWriter::WriteMuxedDocumentInfo(const nsFastLoadMuxedDocumentInfo& nsresult rv; rv = WriteStringZ(aInfo.mURISpec); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(aInfo.mInitialSegmentOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return NS_OK; } @@ -1508,7 +1577,7 @@ nsFastLoadFileWriter::ObjectMapEnumerate(PLDHashTable *aTable, #ifdef NS_DEBUG NS_ASSERTION(entry->mInfo.mStrongRefCnt, "no strong ref in serialization!"); - if ((NSFastLoadOID(NS_PTR_TO_INT32(entry->mObject)) & MFL_OBJECT_DEF_TAG) == 0) { + if ((NS_PTR_TO_INT32(entry->mObject) & MFL_OBJECT_DEF_TAG) == 0) { nsrefcnt rc = entry->mObject->AddRef(); NS_ASSERTION(entry->mInfo.mStrongRefCnt <= rc - 2, "too many strong refs in serialization"); @@ -1518,7 +1587,7 @@ nsFastLoadFileWriter::ObjectMapEnumerate(PLDHashTable *aTable, // Ignore tagged object ids stored as object pointer keys (the updater // code does this). - if ((NSFastLoadOID(NS_PTR_TO_INT32(entry->mObject)) & MFL_OBJECT_DEF_TAG) == 0) + if ((NS_PTR_TO_INT32(entry->mObject) & MFL_OBJECT_DEF_TAG) == 0) NS_RELEASE(entry->mObject); return PL_DHASH_NEXT; @@ -1537,13 +1606,29 @@ nsFastLoadFileWriter::DocumentMapEnumerate(PLDHashTable *aTable, nsresult* rvp = NS_REINTERPRET_CAST(nsresult*, aData); nsFastLoadMuxedDocumentInfo info; - info.mURISpec = entry->mURISpec; + info.mURISpec = entry->mString; info.mInitialSegmentOffset = entry->mInitialSegmentOffset; *rvp = writer->WriteMuxedDocumentInfo(info); return NS_FAILED(*rvp) ? PL_DHASH_STOP : PL_DHASH_NEXT; } +PLDHashOperator PR_CALLBACK +nsFastLoadFileWriter::DependencyMapEnumerate(PLDHashTable *aTable, + PLDHashEntryHdr *aHdr, + PRUint32 aNumber, + void *aData) +{ + nsFastLoadFileWriter* writer = + NS_REINTERPRET_CAST(nsFastLoadFileWriter*, aTable->data); + nsStringMapEntry* entry = NS_STATIC_CAST(nsStringMapEntry*, aHdr); + nsresult* rvp = NS_REINTERPRET_CAST(nsresult*, aData); + + *rvp = writer->WriteStringZ(entry->mString); + + return NS_FAILED(*rvp) ? PL_DHASH_STOP :PL_DHASH_NEXT; +} + nsresult nsFastLoadFileWriter::WriteFooter() { @@ -1554,10 +1639,11 @@ nsFastLoadFileWriter::WriteFooter() footerPrefix.mNumIDs = mIDMap.entryCount; footerPrefix.mNumSharpObjects = mObjectMap.entryCount; footerPrefix.mNumMuxedDocuments = mDocumentMap.entryCount; - footerPrefix.mNumDependencies = mDependencies.Count(); + footerPrefix.mNumDependencies = mDependencyMap.entryCount; rv = WriteFooterPrefix(footerPrefix); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Enumerate mIDMap into a vector indexed by mFastID and write it. nsID* idvec = new nsID[footerPrefix.mNumIDs]; @@ -1572,7 +1658,8 @@ nsFastLoadFileWriter::WriteFooter() } delete[] idvec; - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Enumerate mObjectMap into a vector indexed by mOID and write it. nsFastLoadSharpObjectInfo* objvec = @@ -1589,23 +1676,21 @@ nsFastLoadFileWriter::WriteFooter() } delete[] objvec; - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Enumerate mDocumentMap, writing nsFastLoadMuxedDocumentInfo records count = PL_DHashTableEnumerate(&mDocumentMap, DocumentMapEnumerate, &rv); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; NS_ASSERTION(count == footerPrefix.mNumMuxedDocuments, "bad mDocumentMap enumeration!"); // Write out make-like file dependencies. - count = footerPrefix.mNumDependencies; - for (i = 0; i < count; i++) { - const char* s = - NS_REINTERPRET_CAST(const char*, mDependencies.ElementAt(PRInt32(i))); - rv = WriteStringZ(s); - if (NS_FAILED(rv)) return rv; - } + count = PL_DHashTableEnumerate(&mDependencyMap, DependencyMapEnumerate, &rv); + if (NS_FAILED(rv)) + return rv; return NS_OK; } @@ -1625,7 +1710,7 @@ nsFastLoadFileWriter::Init() return NS_ERROR_OUT_OF_MEMORY; } - if (!PL_DHashTableInit(&mDocumentMap, &docmap_DHashTableOps, (void *)this, + if (!PL_DHashTableInit(&mDocumentMap, &strmap_DHashTableOps, (void *)this, sizeof(nsDocumentMapWriteEntry), PL_DHASH_MIN_SIZE)) { mDocumentMap.ops = nsnull; @@ -1638,6 +1723,12 @@ nsFastLoadFileWriter::Init() return NS_ERROR_OUT_OF_MEMORY; } + if (!PL_DHashTableInit(&mDependencyMap, &strmap_DHashTableOps, (void *)this, + sizeof(nsStringMapEntry), PL_DHASH_MIN_SIZE)) { + mDependencyMap.ops = nsnull; + return NS_ERROR_OUT_OF_MEMORY; + } + return NS_OK; } @@ -1652,7 +1743,8 @@ nsFastLoadFileWriter::Open() rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, sizeof(nsFastLoadHeader)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return Init(); } @@ -1669,7 +1761,8 @@ nsFastLoadFileWriter::Close() nsCOMPtr seekable(do_QueryInterface(mOutputStream)); rv = seekable->Tell(&mHeader.mFooterOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // If there is a muxed document segment open, close it now by setting its // length, stored in the second PRUint32 of the segment. @@ -1678,49 +1771,117 @@ nsFastLoadFileWriter::Close() mCurrentDocumentMapEntry->mCurrentSegmentOffset; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, currentSegmentOffset + 4); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(mHeader.mFooterOffset - currentSegmentOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Seek back to the current offset to write the footer. rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, mHeader.mFooterOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; mCurrentDocumentMapEntry = nsnull; } rv = WriteFooter(); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = seekable->Tell(&mHeader.mFileSize); - if (NS_FAILED(rv)) return rv; - - /* Sum any bytes left in the checksum buffer. */ - if (mChecksumCursor != 0) { - NS_AccumulateFastLoadChecksum(&mHeader.mChecksum, - mChecksumBuffer, - mChecksumCursor, - PR_TRUE); - mCheckedByteCount += mChecksumCursor; - } - - PRUint32 headChecksum; - NS_AccumulateFastLoadChecksum(&headChecksum, - NS_REINTERPRET_CAST(PRUint8*, &mHeader), - sizeof mHeader, - PR_FALSE); - - mHeader.mChecksum = - NS_AddFastLoadChecksums(headChecksum, mHeader.mChecksum, - mCheckedByteCount); + if (NS_FAILED(rv)) + return rv; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = WriteHeader(&mHeader); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; + + // Now compute the checksum, using mFileIO to get an input stream on the + // underlying FastLoad file. + if (mFileIO) { + // Get the unbuffered output stream, which flushes the buffered header + // so we can read and checksum it along with the rest of the file, and + // which allows us to write the checksum directly. + nsCOMPtr + bufferAccess(do_QueryInterface(mOutputStream)); + nsCOMPtr output; + rv = bufferAccess->GetUnbufferedStream(getter_AddRefs(output)); + if (NS_FAILED(rv) || !output) + return NS_ERROR_UNEXPECTED; + + nsCOMPtr input; + rv = mFileIO->GetInputStream(getter_AddRefs(input)); + if (NS_FAILED(rv)) + return rv; + + // Get the unbuffered input stream, to avoid copying overhead and to + // keep our view of the file coherent with the writer -- we don't want + // to hit a stale buffer in the reader's underlying stream. + bufferAccess = do_QueryInterface(input); + rv = bufferAccess->GetUnbufferedStream(getter_AddRefs(input)); + if (NS_FAILED(rv) || !input) + return NS_ERROR_UNEXPECTED; + + // Seek the input stream to offset 0, in case it's a reader who has + // already been used to consume some of the FastLoad file. + seekable = do_QueryInterface(input); + rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, 0); + if (NS_FAILED(rv)) + return rv; + + char buf[MFL_CHECKSUM_BUFSIZE]; + PRUint32 len, rem = 0; + PRUint32 checksum = 0; + + // Ok, we're finally ready to checksum the FastLoad file we just wrote! + while (NS_SUCCEEDED(rv = + input->Read(buf + rem, sizeof buf - rem, &len)) && + len) { + len += rem; + rem = NS_AccumulateFastLoadChecksum(&checksum, + NS_REINTERPRET_CAST(PRUint8*, + buf), + len, + PR_FALSE); + if (rem) + memcpy(buf, buf + len - rem, rem); + } + if (NS_FAILED(rv)) + return rv; + + if (rem) { + NS_AccumulateFastLoadChecksum(&checksum, + NS_REINTERPRET_CAST(PRUint8*, buf), + rem, + PR_TRUE); + } + + // Store the checksum in the FastLoad file header and remember it via + // mHeader.mChecksum, for GetChecksum. + seekable = do_QueryInterface(output); + rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, + offsetof(nsFastLoadHeader, mChecksum)); + if (NS_FAILED(rv)) + return rv; + + mHeader.mChecksum = checksum; + checksum = NS_SWAP32(checksum); + PRUint32 bytesWritten; + rv = output->Write(NS_REINTERPRET_CAST(char*, &checksum), + sizeof checksum, + &bytesWritten); + if (NS_FAILED(rv)) + return rv; + if (bytesWritten != sizeof checksum) + return NS_ERROR_FAILURE; + } return mOutputStream->Close(); } @@ -1736,7 +1897,7 @@ nsFastLoadFileWriter::WriteObjectCommon(nsISupports* aObject, nsrefcnt rc; nsresult rv; - NS_ASSERTION((NSFastLoadOID(NS_PTR_TO_INT32(aObject)) & MFL_OBJECT_DEF_TAG) == 0, + NS_ASSERTION((NS_PTR_TO_INT32(aObject) & MFL_OBJECT_DEF_TAG) == 0, "odd nsISupports*, oh no!"); // Here be manual refcounting dragons! @@ -1808,7 +1969,8 @@ nsFastLoadFileWriter::WriteObjectCommon(nsISupports* aObject, oid |= (aTags & MFL_QUERY_INTERFACE_TAG); rv = Write32(oid ^ MFL_OID_XOR_KEY); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (oid & MFL_OBJECT_DEF_TAG) { nsCOMPtr classInfo(do_QueryInterface(aObject)); @@ -1818,17 +1980,21 @@ nsFastLoadFileWriter::WriteObjectCommon(nsISupports* aObject, nsCID slowCID; rv = classInfo->GetClassIDNoAlloc(&slowCID); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; NSFastLoadID fastCID; rv = MapID(slowCID, &fastCID); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = WriteFastID(fastCID); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = serializable->Write(this); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } return NS_OK; @@ -1880,11 +2046,13 @@ nsFastLoadFileWriter::WriteCompoundObject(nsISupports* aObject, #endif rv = WriteObjectCommon(rootObject, aIsStrongRef, MFL_QUERY_INTERFACE_TAG); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; NSFastLoadID iid; rv = MapID(aIID, &iid); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return WriteFastID(iid); } @@ -1896,7 +2064,8 @@ nsFastLoadFileWriter::WriteID(const nsID& aID) NSFastLoadID fastID; rv = MapID(aID, &fastID); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return WriteFastID(fastID); } @@ -1925,9 +2094,11 @@ nsFastLoadFileWriter::SetEOF() NS_COM nsresult NS_NewFastLoadFileWriter(nsIObjectOutputStream* *aResult, - nsIOutputStream* aDestStream) + nsIOutputStream* aDestStream, + nsIFastLoadFileIO* aFileIO) { - nsFastLoadFileWriter* writer = new nsFastLoadFileWriter(aDestStream); + nsFastLoadFileWriter* writer = + new nsFastLoadFileWriter(aDestStream, aFileIO); if (!writer) return NS_ERROR_OUT_OF_MEMORY; @@ -1945,8 +2116,24 @@ NS_NewFastLoadFileWriter(nsIObjectOutputStream* *aResult, // -------------------------- nsFastLoadFileUpdater -------------------------- -NS_IMPL_ISUPPORTS_INHERITED0(nsFastLoadFileUpdater, - nsFastLoadFileWriter) +NS_IMPL_ISUPPORTS_INHERITED1(nsFastLoadFileUpdater, + nsFastLoadFileWriter, + nsIFastLoadFileIO) + +NS_IMETHODIMP +nsFastLoadFileUpdater::GetInputStream(nsIInputStream** aResult) +{ + *aResult = mInputStream; + NS_IF_ADDREF(*aResult); + return NS_OK; +} + +NS_IMETHODIMP +nsFastLoadFileUpdater::GetOutputStream(nsIOutputStream** aResult) +{ + *aResult = nsnull; + return NS_OK; +} PLDHashOperator PR_CALLBACK nsFastLoadFileUpdater::CopyReadDocumentMapEntryToUpdater(PLDHashTable *aTable, @@ -1959,8 +2146,8 @@ nsFastLoadFileUpdater::CopyReadDocumentMapEntryToUpdater(PLDHashTable *aTable, nsFastLoadFileUpdater* updater = NS_REINTERPRET_CAST(nsFastLoadFileUpdater*, aData); - void* spec = nsMemory::Clone(readEntry->mURISpec, - strlen(readEntry->mURISpec) + 1); + void* spec = nsMemory::Clone(readEntry->mString, + strlen(readEntry->mString) + 1); if (!spec) return PL_DHASH_STOP; @@ -1973,7 +2160,7 @@ nsFastLoadFileUpdater::CopyReadDocumentMapEntryToUpdater(PLDHashTable *aTable, return PL_DHASH_STOP; } - writeEntry->mURISpec = NS_REINTERPRET_CAST(const char*, spec); + writeEntry->mString = NS_REINTERPRET_CAST(const char*, spec); writeEntry->mInitialSegmentOffset = readEntry->mInitialSegmentOffset; writeEntry->mCurrentSegmentOffset = 0; return PL_DHASH_NEXT; @@ -1988,7 +2175,8 @@ nsFastLoadFileUpdater::Open(nsFastLoadFileReader* aReader) nsresult rv; rv = nsFastLoadFileWriter::Init(); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; PRUint32 i, n; @@ -1999,14 +2187,16 @@ nsFastLoadFileUpdater::Open(nsFastLoadFileReader* aReader) NSFastLoadID fastID; rv = MapID(readIDMap[i], &fastID); NS_ASSERTION(fastID == i + 1, "huh?"); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; } // Map from reader dense, zero-based MFL_OID_TO_SHARP_INDEX(oid) to sharp // object offset and refcnt information in updater. PRUint32 saveReadOffset; rv = aReader->Tell(&saveReadOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; nsFastLoadFileReader::nsObjectMapEntry* readObjectMap = aReader->mFooter.mObjectMap; @@ -2036,7 +2226,8 @@ nsFastLoadFileUpdater::Open(nsFastLoadFileReader* aReader) } rv = aReader->Seek(nsISeekableStream::NS_SEEK_SET, saveReadOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Copy URI spec string and initial segment offset in FastLoad file from // nsDocumentMapReadEntry in reader to mDocumentMapWriteEntry in updater. @@ -2048,12 +2239,20 @@ nsFastLoadFileUpdater::Open(nsFastLoadFileReader* aReader) return NS_ERROR_OUT_OF_MEMORY; // Copy source filename dependencies from reader to updater. - nsFastLoadDependencyArray& readDeps = aReader->mFooter.mDependencies; - for (i = 0, n = readDeps.Count(); i < n; i++) { - const char* s = NS_REINTERPRET_CAST(const char*, - readDeps.ElementAt(PRInt32(i))); - if (!mDependencies.AppendDependency(s)) - return NS_ERROR_OUT_OF_MEMORY; + nsISupportsArray* readDeps = aReader->mFooter.mDependencies; + rv = readDeps->Count(&n); + if (NS_FAILED(rv)) + return rv; + + for (i = 0; i < n; i++) { + nsCOMPtr file; + rv = readDeps->GetElementAt(i, getter_AddRefs(file)); + if (NS_FAILED(rv)) + return rv; + + rv = AddDependency(file); + if (NS_FAILED(rv)) + return rv; } // Seek to the reader's footer offset so we overwrite the footer. First, @@ -2062,23 +2261,33 @@ nsFastLoadFileUpdater::Open(nsFastLoadFileReader* aReader) // completing this update. rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, offsetof(nsFastLoadHeader, mFooterOffset)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = Write32(0); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, aReader->mHeader.mFooterOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; + mFileIO = this; + mInputStream = aReader->mInputStream; return NS_OK; } NS_COM nsresult NS_NewFastLoadFileUpdater(nsIObjectOutputStream* *aResult, nsIOutputStream* aOutputStream, - nsFastLoadFileReader* aReader) + nsIObjectInputStream* aReaderAsStream) { + // Make sure that aReaderAsStream is an nsFastLoadFileReader. + nsCOMPtr reader(do_QueryInterface(aReaderAsStream)); + if (!reader) + return NS_ERROR_UNEXPECTED; + nsFastLoadFileUpdater* updater = new nsFastLoadFileUpdater(aOutputStream); if (!updater) return NS_ERROR_OUT_OF_MEMORY; @@ -2086,7 +2295,8 @@ NS_NewFastLoadFileUpdater(nsIObjectOutputStream* *aResult, // Stabilize updater's refcnt. nsCOMPtr stream(updater); - nsresult rv = updater->Open(aReader); + nsresult rv = updater->Open(NS_STATIC_CAST(nsFastLoadFileReader*, + aReaderAsStream)); if (NS_FAILED(rv)) return rv; diff --git a/mozilla/xpcom/io/nsFastLoadFile.h b/mozilla/xpcom/io/nsFastLoadFile.h index a9f8a03eb23..b9023af16a5 100644 --- a/mozilla/xpcom/io/nsFastLoadFile.h +++ b/mozilla/xpcom/io/nsFastLoadFile.h @@ -38,7 +38,9 @@ #include "nsVoidArray.h" #include "nsIFastLoadFileControl.h" +#include "nsIFastLoadService.h" #include "nsISeekableStream.h" +#include "nsISupportsArray.h" /** * FastLoad file Object ID (OID) is an identifier for multiply and cyclicly @@ -114,8 +116,8 @@ typedef PRUint32 NSFastLoadOID; // nsFastLoadFooter::mObjectMap index /** * Magic "number" at start of a FastLoad file. Inspired by the PNG "magic" - * string, which inspired XPCOM's typelib (.xpt) file magic. Guaranteed to - * be corrupted by FTP-as-ASCII and other likely errors, meaningful to savvy + * string, which inspired XPCOM's typelib (.xpt) file magic. Guaranteed to be + * corrupted by FTP-as-ASCII and other likely errors, meaningful to clued-in * humans, and ending in ^Z to terminate erroneous text input on Windows. */ #define MFL_FILE_MAGIC "XPCOM\nMozFASL\r\n\032" @@ -202,35 +204,19 @@ struct nsFastLoadMuxedDocumentInfo { PRUint32 mInitialSegmentOffset; }; -// Specialize nsVoidArray to avoid gratuitous string copying, yet not leak. -class NS_COM nsFastLoadDependencyArray : public nsVoidArray { - public: - ~nsFastLoadDependencyArray() { - for (PRInt32 i = 0, n = Count(); i < n; i++) - nsMemory::Free(ElementAt(i)); - } - - /** - * Append aFileName to this dependency array. Hand off the memory at - * aFileName if aCopy is false, otherwise clone it with nsMemory. - */ - PRBool AppendDependency(const char* aFileName, PRBool aCopy = PR_TRUE) { - char* s = NS_CONST_CAST(char*, aFileName); - if (aCopy) { - s = NS_REINTERPRET_CAST(char*, nsMemory::Clone(s, strlen(s) + 1)); - if (!s) return PR_FALSE; - } - PRBool ok = AppendElement(s); - if (!ok && aCopy) - nsMemory::Free(s); - return ok; - } -}; - // forward declarations of opaque types defined in nsFastLoadFile.cpp struct nsDocumentMapReadEntry; struct nsDocumentMapWriteEntry; +// So nsFastLoadFileUpdater can verify that its nsIObjectInputStream parameter +// is an nsFastLoadFileReader. +#define NS_FASTLOADFILEREADER_IID \ + {0x7d37d1bb,0xcef3,0x4c5f,{0x97,0x68,0x0f,0x89,0x7f,0x1a,0xe1,0x40}} + +struct nsIFastLoadFileReader : public nsISupports { + NS_DEFINE_STATIC_IID_ACCESSOR(NS_FASTLOADFILEREADER_IID) +}; + /** * Inherit from the concrete class nsBinaryInputStream, which inherits from * abstract nsIObjectInputStream but does not implement its direct methods. @@ -239,10 +225,12 @@ struct nsDocumentMapWriteEntry; */ class NS_COM nsFastLoadFileReader : public nsBinaryInputStream, - public nsIFastLoadFileControl, - public nsISeekableStream + public nsIFastLoadReadControl, + public nsISeekableStream, + public nsIFastLoadFileReader { public: + nsFastLoadFileReader(nsIInputStream *aStream) : nsBinaryInputStream(aStream), mCurrentDocumentMapEntry(nsnull) { @@ -264,6 +252,9 @@ class NS_COM nsFastLoadFileReader // nsIFastLoadFileControl methods NS_DECL_NSIFASTLOADFILECONTROL + // nsIFastLoadReadControl methods + NS_DECL_NSIFASTLOADREADCONTROL + // nsISeekableStream methods NS_DECL_NSISEEKABLESTREAM @@ -323,20 +314,6 @@ class NS_COM nsFastLoadFileReader return mObjectMap[index]; } - const char* GetDependency(PRUint32 aIndex) const { - static const char dummy[] = "no such file"; - NS_ASSERTION(aIndex < mNumDependencies, "aIndex out of range"); - if (aIndex >= mNumDependencies) - return dummy; - PRInt32 index = aIndex; - return NS_REINTERPRET_CAST(const char*, - mDependencies.ElementAt(PRInt32(index))); - } - - PRBool AppendDependency(const char* aFileName, PRBool aCopy = PR_TRUE) { - return mDependencies.AppendDependency(aFileName, aCopy); - } - // Map from dense, zero-based, uint32 NSFastLoadID to 16-byte nsID. nsID* mIDMap; @@ -355,7 +332,7 @@ class NS_COM nsFastLoadFileReader // List of source filename dependencies that should trigger regeneration // of the FastLoad file. - nsFastLoadDependencyArray mDependencies; + nsCOMPtr mDependencies; }; nsresult ReadFooter(nsFastLoadFooter *aFooter); @@ -382,11 +359,6 @@ NS_COM nsresult NS_NewFastLoadFileReader(nsIObjectInputStream* *aResult, nsIInputStream* aSrcStream); -/** - * XXX tuneme - */ -#define MFL_CHECKSUM_BUFSIZE 8192 - /** * Inherit from the concrete class nsBinaryInputStream, which inherits from * abstract nsIObjectInputStream but does not implement its direct methods. @@ -395,21 +367,23 @@ NS_NewFastLoadFileReader(nsIObjectInputStream* *aResult, */ class NS_COM nsFastLoadFileWriter : public nsBinaryOutputStream, - public nsIFastLoadFileControl, + public nsIFastLoadWriteControl, public nsISeekableStream { public: - nsFastLoadFileWriter(nsIOutputStream *aStream) + nsFastLoadFileWriter(nsIOutputStream *aStream, nsIFastLoadFileIO* aFileIO) : nsBinaryOutputStream(aStream), - mChecksumCursor(0), - mCheckedByteCount(0), - mCurrentDocumentMapEntry(nsnull) { + mCurrentDocumentMapEntry(nsnull), + mFileIO(aFileIO) + { mHeader.mChecksum = 0; mIDMap.ops = mObjectMap.ops = mDocumentMap.ops = mURIMap.ops = nsnull; + mDependencyMap.ops = nsnull; MOZ_COUNT_CTOR(nsFastLoadFileWriter); } - virtual ~nsFastLoadFileWriter() { + virtual ~nsFastLoadFileWriter() + { if (mIDMap.ops) PL_DHashTableFinish(&mIDMap); if (mObjectMap.ops) @@ -418,20 +392,11 @@ class NS_COM nsFastLoadFileWriter PL_DHashTableFinish(&mDocumentMap); if (mURIMap.ops) PL_DHashTableFinish(&mURIMap); + if (mDependencyMap.ops) + PL_DHashTableFinish(&mDependencyMap); MOZ_COUNT_DTOR(nsFastLoadFileWriter); } - PRUint32 GetDependencyCount() { return PRUint32(mDependencies.Count()); } - - const char* GetDependency(PRUint32 i) { - return NS_REINTERPRET_CAST(const char*, - mDependencies.ElementAt(PRInt32(i))); - } - - PRBool AppendDependency(const char* aFileName) { - return mDependencies.AppendDependency(aFileName); - } - private: // nsISupports methods NS_DECL_ISUPPORTS_INHERITED @@ -447,13 +412,12 @@ class NS_COM nsFastLoadFileWriter // nsIFastLoadFileControl methods NS_DECL_NSIFASTLOADFILECONTROL + // nsIFastLoadWriteControl methods + NS_DECL_NSIFASTLOADWRITECONTROL + // nsISeekableStream methods NS_DECL_NSISEEKABLESTREAM - // Override Write so we can compute our checksum in one pass. - NS_IMETHOD Write(const char* aBuffer, PRUint32 aCount, - PRUint32 *aBytesWritten); - nsresult MapID(const nsID& aSlowID, NSFastLoadID *aResult); nsresult WriteHeader(nsFastLoadHeader *aHeader); @@ -490,25 +454,29 @@ class NS_COM nsFastLoadFileWriter PRUint32 aNumber, void *aData); + static PLDHashOperator PR_CALLBACK + DependencyMapEnumerate(PLDHashTable *aTable, + PLDHashEntryHdr *aHdr, + PRUint32 aNumber, + void *aData); + protected: nsFastLoadHeader mHeader; - PRUint8 mChecksumBuffer[MFL_CHECKSUM_BUFSIZE]; - PRUint32 mChecksumCursor; - PRUint32 mCheckedByteCount; PLDHashTable mIDMap; PLDHashTable mObjectMap; PLDHashTable mDocumentMap; PLDHashTable mURIMap; + PLDHashTable mDependencyMap; nsDocumentMapWriteEntry* mCurrentDocumentMapEntry; - - nsFastLoadDependencyArray mDependencies; + nsCOMPtr mFileIO; }; NS_COM nsresult NS_NewFastLoadFileWriter(nsIObjectOutputStream* *aResult, - nsIOutputStream* aDestStream); + nsIOutputStream* aDestStream, + nsIFastLoadFileIO* aFileIO); /** * Subclass of nsFastLoadFileWriter, friend of nsFastLoadFileReader which it @@ -518,11 +486,12 @@ NS_NewFastLoadFileWriter(nsIObjectOutputStream* *aResult, * that maps all data on Close. */ class NS_COM nsFastLoadFileUpdater - : public nsFastLoadFileWriter + : public nsFastLoadFileWriter, + nsIFastLoadFileIO { public: nsFastLoadFileUpdater(nsIOutputStream* aOutputStream) - : nsFastLoadFileWriter(aOutputStream) { + : nsFastLoadFileWriter(aOutputStream, nsnull) { MOZ_COUNT_CTOR(nsFastLoadFileUpdater); } @@ -534,6 +503,9 @@ class NS_COM nsFastLoadFileUpdater // nsISupports methods NS_DECL_ISUPPORTS_INHERITED + // nsIFastLoadFileIO methods + NS_DECL_NSIFASTLOADFILEIO + nsresult Open(nsFastLoadFileReader* aReader); static PLDHashOperator PR_CALLBACK @@ -543,11 +515,14 @@ class NS_COM nsFastLoadFileUpdater void *aData); friend class nsFastLoadFileReader; + + protected: + nsCOMPtr mInputStream; }; NS_COM nsresult NS_NewFastLoadFileUpdater(nsIObjectOutputStream* *aResult, nsIOutputStream* aOutputStream, - nsFastLoadFileReader* aReader); + nsIObjectInputStream* aReaderAsStream); #endif // nsFastLoadFile_h___ diff --git a/mozilla/xpcom/io/nsFastLoadService.cpp b/mozilla/xpcom/io/nsFastLoadService.cpp index d7bffb34499..bf5659dca53 100644 --- a/mozilla/xpcom/io/nsFastLoadService.cpp +++ b/mozilla/xpcom/io/nsFastLoadService.cpp @@ -34,21 +34,14 @@ #include "nsString.h" #include "nsIComponentManager.h" +#include "nsIEnumerator.h" +#include "nsIFastLoadFileControl.h" #include "nsIFile.h" #include "nsIObjectInputStream.h" #include "nsIObjectOutputStream.h" #include "nsISeekableStream.h" #include "nsISupports.h" -// XXXbe we *know* that nsIObject*Stream is implemented by nsFastLoadFile.cpp -inline nsFastLoadFileReader* GetReader(nsIObjectInputStream* aStream) { - return NS_STATIC_CAST(nsFastLoadFileReader*, aStream); -} - -inline nsFastLoadFileWriter* GetWriter(nsIObjectOutputStream* aStream) { - return NS_STATIC_CAST(nsFastLoadFileWriter*, aStream); -} - PR_IMPLEMENT_DATA(nsIFastLoadService*) gFastLoadService_ = nsnull; NS_IMPL_THREADSAFE_ISUPPORTS1(nsFastLoadService, nsIFastLoadService) @@ -132,13 +125,15 @@ nsFastLoadService::NewFastLoadFile(const char* aBaseName, nsIFile* *aResult) rv = NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; nsCAutoString name(aBaseName); MASSAGE_BASENAME(name); name += PLATFORM_FASL_SUFFIX; rv = file->Append(name); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; *aResult = file; NS_ADDREF(*aResult); @@ -147,20 +142,14 @@ nsFastLoadService::NewFastLoadFile(const char* aBaseName, nsIFile* *aResult) NS_IMETHODIMP nsFastLoadService::NewInputStream(nsIInputStream* aSrcStream, - PRUint32 *aChecksum, nsIObjectInputStream* *aResult) { - nsresult rv; nsAutoLock lock(mLock); nsCOMPtr stream; - rv = NS_NewFastLoadFileReader(getter_AddRefs(stream), aSrcStream); - if (NS_FAILED(rv)) return rv; - - nsFastLoadFileReader* reader = GetReader(stream); - - rv = reader->GetChecksum(aChecksum); - if (NS_FAILED(rv)) return rv; + nsresult rv = NS_NewFastLoadFileReader(getter_AddRefs(stream), aSrcStream); + if (NS_FAILED(rv)) + return rv; *aResult = stream; NS_ADDREF(*aResult); @@ -173,18 +162,18 @@ nsFastLoadService::NewOutputStream(nsIOutputStream* aDestStream, { nsAutoLock lock(mLock); - return NS_NewFastLoadFileWriter(aResult, aDestStream); + return NS_NewFastLoadFileWriter(aResult, aDestStream, mFileIO); } NS_IMETHODIMP -nsFastLoadService::GetCurrentInputStream(nsIObjectInputStream* *aResult) +nsFastLoadService::GetInputStream(nsIObjectInputStream* *aResult) { NS_IF_ADDREF(*aResult = mInputStream); return NS_OK; } NS_IMETHODIMP -nsFastLoadService::SetCurrentInputStream(nsIObjectInputStream* aStream) +nsFastLoadService::SetInputStream(nsIObjectInputStream* aStream) { nsAutoLock lock(mLock); mInputStream = aStream; @@ -192,14 +181,14 @@ nsFastLoadService::SetCurrentInputStream(nsIObjectInputStream* aStream) } NS_IMETHODIMP -nsFastLoadService::GetCurrentOutputStream(nsIObjectOutputStream* *aResult) +nsFastLoadService::GetOutputStream(nsIObjectOutputStream* *aResult) { NS_IF_ADDREF(*aResult = mOutputStream); return NS_OK; } NS_IMETHODIMP -nsFastLoadService::SetCurrentOutputStream(nsIObjectOutputStream* aStream) +nsFastLoadService::SetOutputStream(nsIObjectOutputStream* aStream) { nsAutoLock lock(mLock); mOutputStream = aStream; @@ -207,14 +196,14 @@ nsFastLoadService::SetCurrentOutputStream(nsIObjectOutputStream* aStream) } NS_IMETHODIMP -nsFastLoadService::GetCurrentFileIO(nsIFastLoadFileIO* *aResult) +nsFastLoadService::GetFileIO(nsIFastLoadFileIO* *aResult) { NS_IF_ADDREF(*aResult = mFileIO); return NS_OK; } NS_IMETHODIMP -nsFastLoadService::SetCurrentFileIO(nsIFastLoadFileIO* aFileIO) +nsFastLoadService::SetFileIO(nsIFastLoadFileIO* aFileIO) { nsAutoLock lock(mLock); mFileIO = aFileIO; @@ -222,7 +211,7 @@ nsFastLoadService::SetCurrentFileIO(nsIFastLoadFileIO* aFileIO) } NS_IMETHODIMP -nsFastLoadService::GetCurrentDirection(PRInt32 *aResult) +nsFastLoadService::GetDirection(PRInt32 *aResult) { *aResult = mDirection; return NS_OK; @@ -233,38 +222,49 @@ nsFastLoadService::StartMuxedDocument(nsISupports* aURI, const char* aURISpec, PRInt32 aDirectionFlags) { nsresult rv = NS_ERROR_NOT_AVAILABLE; + nsCOMPtr control; nsAutoLock lock(mLock); // Try for an input stream first, in case aURISpec's data is multiplexed // in the current FastLoad file. if ((aDirectionFlags & NS_FASTLOAD_READ) && mInputStream) { - nsFastLoadFileReader* reader = GetReader(mInputStream); - rv = reader->StartMuxedDocument(aURI, aURISpec); - if (NS_SUCCEEDED(rv) || rv != NS_ERROR_NOT_AVAILABLE) - return rv; + control = do_QueryInterface(mInputStream); + if (control) { + // If aURISpec is not in the multiplex, control->StartMuxedDocument + // will return NS_ERROR_NOT_AVAILABLE. + rv = control->StartMuxedDocument(aURI, aURISpec); + if (NS_SUCCEEDED(rv) || rv != NS_ERROR_NOT_AVAILABLE) + return rv; - // If aURISpec is not found in the reader, wrap it with an updater - // and store the updater at mOutputStream. - if (!mOutputStream && mFileIO) { - nsCOMPtr output; - rv = mFileIO->GetOutputStream(getter_AddRefs(output)); - if (NS_FAILED(rv)) return rv; + // Ok, aURISpec is not in the existing mux. If we have no output + // stream yet, wrap the reader with a FastLoad file updater. + if (!mOutputStream && mFileIO) { + nsCOMPtr output; + rv = mFileIO->GetOutputStream(getter_AddRefs(output)); + if (NS_FAILED(rv)) + return rv; - rv = NS_NewFastLoadFileUpdater(getter_AddRefs(mOutputStream), - output, - reader); - if (NS_FAILED(rv)) return rv; - } + // NB: mInputStream must be an nsFastLoadFileReader! + rv = NS_NewFastLoadFileUpdater(getter_AddRefs(mOutputStream), + output, + mInputStream); + if (NS_FAILED(rv)) + return rv; + } - if (aDirectionFlags == NS_FASTLOAD_READ) { - // Tell our caller to re-start multiplexing, rather than attempt - // to select and deserialize now. - return NS_ERROR_NOT_AVAILABLE; + if (aDirectionFlags == NS_FASTLOAD_READ) { + // Tell our caller to re-start multiplexing, rather than attempt + // to select and deserialize now. + return NS_ERROR_NOT_AVAILABLE; + } } } - if ((aDirectionFlags & NS_FASTLOAD_WRITE) && mOutputStream) - rv = GetWriter(mOutputStream)->StartMuxedDocument(aURI, aURISpec); + if ((aDirectionFlags & NS_FASTLOAD_WRITE) && mOutputStream) { + control = do_QueryInterface(mOutputStream); + if (control) + rv = control->StartMuxedDocument(aURI, aURISpec); + } return rv; } @@ -272,20 +272,27 @@ NS_IMETHODIMP nsFastLoadService::SelectMuxedDocument(nsISupports* aURI) { nsresult rv = NS_ERROR_NOT_AVAILABLE; + nsCOMPtr control; nsAutoLock lock(mLock); // Try to select the reader, if any; then only if the URI was not in the // file already, select the writer/updater. if (mInputStream) { - rv = GetReader(mInputStream)->SelectMuxedDocument(aURI); - if (NS_SUCCEEDED(rv)) - mDirection = NS_FASTLOAD_READ; + control = do_QueryInterface(mInputStream); + if (control) { + rv = control->SelectMuxedDocument(aURI); + if (NS_SUCCEEDED(rv)) + mDirection = NS_FASTLOAD_READ; + } } if (rv == NS_ERROR_NOT_AVAILABLE && mOutputStream) { - rv = GetWriter(mOutputStream)->SelectMuxedDocument(aURI); - if (NS_SUCCEEDED(rv)) - mDirection = NS_FASTLOAD_WRITE; + control = do_QueryInterface(mOutputStream); + if (control) { + rv = control->SelectMuxedDocument(aURI); + if (NS_SUCCEEDED(rv)) + mDirection = NS_FASTLOAD_WRITE; + } } return rv; @@ -295,54 +302,119 @@ NS_IMETHODIMP nsFastLoadService::EndMuxedDocument(nsISupports* aURI) { nsresult rv = NS_ERROR_NOT_AVAILABLE; + nsCOMPtr control; nsAutoLock lock(mLock); // Try to end the document identified by aURI in the reader, if any; then // only if the URI was not in the file already, end the writer/updater. - if (mInputStream) - rv = GetReader(mInputStream)->EndMuxedDocument(aURI); + if (mInputStream) { + control = do_QueryInterface(mInputStream); + if (control) + rv = control->EndMuxedDocument(aURI); + } - if (rv == NS_ERROR_NOT_AVAILABLE && mOutputStream) - rv = GetWriter(mOutputStream)->EndMuxedDocument(aURI); + if (rv == NS_ERROR_NOT_AVAILABLE && mOutputStream) { + control = do_QueryInterface(mOutputStream); + if (control) + rv = control->EndMuxedDocument(aURI); + } mDirection = 0; return rv; } NS_IMETHODIMP -nsFastLoadService::AppendDependency(const char* aFileName) +nsFastLoadService::AddDependency(nsIFile* aFile) { nsAutoLock lock(mLock); - if (!mOutputStream) - return NS_OK; - if (!GetWriter(mOutputStream)->AppendDependency(aFileName)) - return NS_ERROR_OUT_OF_MEMORY; - return NS_OK; + nsCOMPtr control(do_QueryInterface(mOutputStream)); + if (!control) + return NS_ERROR_NOT_AVAILABLE; + + return control->AddDependency(aFile); } NS_IMETHODIMP -nsFastLoadService::MaxDependencyModifiedTime(PRTime *aTime) +nsFastLoadService::MaxDependencyModifiedTime(nsIFastLoadReadControl* aControl, + PRTime *aTime) { *aTime = LL_ZERO; nsAutoLock lock(mLock); - if (!mOutputStream) - return NS_OK; - nsFastLoadFileWriter* writer = GetWriter(mOutputStream); + nsCOMPtr dependencies; + nsresult rv = aControl->GetDependencies(getter_AddRefs(dependencies)); + if (NS_FAILED(rv)) + return rv; - for (PRUint32 i = 0, n = writer->GetDependencyCount(); i < n; i++) { - PRFileInfo info; - if (PR_GetFileInfo(writer->GetDependency(i), &info) == PR_SUCCESS && - LL_CMP(*aTime, <, info.modifyTime)) { - *aTime = info.modifyTime; - } + PRBool more; + while (NS_SUCCEEDED(dependencies->HasMoreElements(&more)) && more) { + nsCOMPtr file; + dependencies->GetNext(getter_AddRefs(file)); + if (!file) + return NS_ERROR_UNEXPECTED; + + PRTime lastModifiedTime; + rv = file->GetLastModificationDate(&lastModifiedTime); + if (NS_FAILED(rv)) + return rv; + + if (LL_CMP(*aTime, <, lastModifiedTime)) + *aTime = lastModifiedTime; } return NS_OK; } +NS_IMETHODIMP +nsFastLoadService::ComputeChecksum(nsIFile* aFile, + nsIFastLoadReadControl* aControl, + PRUint32 *aChecksum) +{ + nsXPIDLCString path; + nsresult rv = aFile->GetPath(getter_Copies(path)); + if (NS_FAILED(rv)) + return rv; + + nsCStringKey key(path); + PRUint32 checksum = NS_PTR_TO_INT32(mChecksumTable.Get(&key)); + if (checksum) { + *aChecksum = checksum; + return NS_OK; + } + + rv = aControl->ComputeChecksum(&checksum); + if (NS_FAILED(rv)) + return rv; + + mChecksumTable.Put(&key, NS_INT32_TO_PTR(checksum)); + *aChecksum = checksum; + return NS_OK; +} + +NS_IMETHODIMP +nsFastLoadService::CacheChecksum(nsIFile* aFile, nsIObjectOutputStream *aStream) +{ + nsCOMPtr control(do_QueryInterface(aStream)); + if (!control) + return NS_ERROR_FAILURE; + + PRUint32 checksum; + nsresult rv = control->GetChecksum(&checksum); + if (NS_FAILED(rv)) + return rv; + + nsXPIDLCString path; + rv = aFile->GetPath(getter_Copies(path)); + if (NS_FAILED(rv)) + return rv; + + nsCStringKey key(path); + mChecksumTable.Put(&key, NS_INT32_TO_PTR(checksum)); + return NS_OK; +} + struct nsFastLoadPtrEntry : public PLDHashEntryHdr { nsISupports** mPtrAddr; // key, must come first for PL_DHashGetStubOps PRUint32 mOffset; @@ -369,10 +441,12 @@ nsFastLoadService::GetFastLoadReferent(nsISupports* *aPtrAddr) nsCOMPtr seekable(do_QueryInterface(mInputStream)); rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, entry->mOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = mInputStream->ReadObject(PR_TRUE, aPtrAddr); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; // Shrink the table if half the entries are removed sentinels. PRUint32 size = PR_BIT(mFastLoadPtrMap->sizeLog2); @@ -398,7 +472,8 @@ nsFastLoadService::ReadFastLoadPtr(nsIObjectInputStream* aInputStream, nsAutoLock lock(mLock); rv = aInputStream->Read32(&nextOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; nsCOMPtr seekable(do_QueryInterface(aInputStream)); if (!seekable) @@ -406,10 +481,12 @@ nsFastLoadService::ReadFastLoadPtr(nsIObjectInputStream* aInputStream, PRUint32 thisOffset; rv = seekable->Tell(&thisOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, nextOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; if (!mFastLoadPtrMap) { mFastLoadPtrMap = PL_NewDHashTable(PL_DHashGetStubOps(), this, @@ -447,26 +524,33 @@ nsFastLoadService::WriteFastLoadPtr(nsIObjectOutputStream* aOutputStream, PRUint32 saveOffset; rv = seekable->Tell(&saveOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = aOutputStream->Write32(0); // nextOffset placeholder - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = aOutputStream->WriteObject(aObject, PR_TRUE); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; PRUint32 nextOffset; rv = seekable->Tell(&nextOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, saveOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = aOutputStream->Write32(nextOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; rv = seekable->Seek(nsISeekableStream::NS_SEEK_SET, nextOffset); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) + return rv; return NS_OK; } diff --git a/mozilla/xpcom/io/nsFastLoadService.h b/mozilla/xpcom/io/nsFastLoadService.h index 25245ca7378..e2e6a8e7e19 100644 --- a/mozilla/xpcom/io/nsFastLoadService.h +++ b/mozilla/xpcom/io/nsFastLoadService.h @@ -22,6 +22,7 @@ #include "prtypes.h" #include "pldhash.h" #include "nsCOMPtr.h" +#include "nsHashtable.h" #include "nsIFastLoadService.h" #include "nsIObjectInputStream.h" #include "nsIObjectOutputStream.h" @@ -48,4 +49,5 @@ class NS_COM nsFastLoadService : public nsIFastLoadService nsCOMPtr mOutputStream; nsCOMPtr mFileIO; PRInt32 mDirection; + nsHashtable mChecksumTable; }; diff --git a/mozilla/xpcom/io/nsIFastLoadFileControl.idl b/mozilla/xpcom/io/nsIFastLoadFileControl.idl index 9f1d2507a88..83fb6e427b7 100644 --- a/mozilla/xpcom/io/nsIFastLoadFileControl.idl +++ b/mozilla/xpcom/io/nsIFastLoadFileControl.idl @@ -23,39 +23,28 @@ #include "nsISupports.idl" #include "nsrootidl.idl" -interface nsICollection; +interface nsIFile; +interface nsISimpleEnumerator; /** - * The nsIFastLoadFileControl interface is used as an extension to classes - * implementing nsIObjectInputStream or nsIObjectOutputStream, so that those - * stream types can be used with nsIFastLoadService to get, set, and compute + * The nsIFastLoadFileControl interface and its subinterfaces are mix-ins for + * classes implementing nsIObjectInputStream and nsIObjectOutputStream, so that + * those stream types can be used with nsIFastLoadService to access and compute * FastLoad file checksums, update and check FastLoad file dependencies, and * multiplex documents loaded via non-blocking i/o. * - * If an nsIObjectInputStream or nsIObjectOutputStream implementation doesn't - * implement nsIFastLoadFileControl, that implementation may still be useful - * for object serialization, but it cannot be used to read or write a Mozilla - * FastLoad file. + * If an nsIObjectInputStream class doesn't support nsIFastLoadReadControl, or + * an nsIObjectOutputStream class doesn't support nsIFastLoadWriteControl, that + * implementation may still be useful for object serialization, but it can't be + * used to read or write a Mozilla FastLoad file. */ [scriptable, uuid(8a1e2c63-af50-4147-af7e-26289dc180dd)] interface nsIFastLoadFileControl : nsISupports { /** - * Get, set, and compute the FastLoad file checksum. The attribute gets - * and sets the recorded checksum value from the FastLoad file header, - * while the method computes the correct checksum of the implementation's - * underlying FastLoad file, independent of the header's checksum value - * (which is treated as zero when computing the checksum). + * Get and set the recorded checksum value from the FastLoad file header. */ attribute PRUint32 checksum; - PRUint32 computeChecksum(); - - /** - * Get the collection of dependency nsIFile instances recorded during the - * FastLoad file write or read/update process, and checked during the read - * process to invalidate the FastLoad file if any dependencies are newer. - */ - readonly attribute nsICollection dependencies; /** * Multiplexed document control methods. A FastLoad file may contain @@ -75,3 +64,32 @@ interface nsIFastLoadFileControl : nsISupports void selectMuxedDocument(in nsISupports aURI); void endMuxedDocument(in nsISupports aURI); }; + +[scriptable, uuid(652ecec6-d40b-45b6-afef-641d6c63a35b)] +interface nsIFastLoadReadControl : nsIFastLoadFileControl +{ + /** + * Computes the correct checksum of the FastLoad file, independent of the + * header's checksum value. The header checksum field is treated as zero + * when computing the checksum. + */ + PRUint32 computeChecksum(); + + /** + * Get the collection of dependency nsIFile instances recorded during the + * FastLoad file write or read/update process, and checked during the read + * process to invalidate the FastLoad file if any dependencies are newer. + */ + readonly attribute nsISimpleEnumerator dependencies; +}; + +[scriptable, uuid(2ad6e9e6-1379-4e45-a899-a54b27ff915c)] +interface nsIFastLoadWriteControl : nsIFastLoadFileControl +{ + /** + * Add a file dependency of the FastLoad file (e.g., a .jar file) to the + * set of dependencies that trigger regeneration if any dependency has a + * last-modified-time greater than the FastLoad file's mtime. + */ + void addDependency(in nsIFile aFile); +}; diff --git a/mozilla/xpcom/io/nsIFastLoadService.idl b/mozilla/xpcom/io/nsIFastLoadService.idl index 8117d9e4bbf..43ddc96b568 100644 --- a/mozilla/xpcom/io/nsIFastLoadService.idl +++ b/mozilla/xpcom/io/nsIFastLoadService.idl @@ -23,6 +23,7 @@ #include "nsISupports.idl" #include "nsrootidl.idl" +interface nsIFastLoadReadControl; interface nsIFile; interface nsIInputStream; interface nsIOutputStream; @@ -41,31 +42,25 @@ interface nsIFastLoadService : nsISupports { nsIFile newFastLoadFile(in string aBaseName); - nsIObjectInputStream newInputStream(in nsIInputStream aSrcStream, - out PRUint32 aChecksum); + nsIObjectInputStream newInputStream(in nsIInputStream aSrcStream); nsIObjectOutputStream newOutputStream(in nsIOutputStream aDestStream); - // Flag values for the currentDirection attribute and the aDirectionFlags + // Flag values for the direction attribute and the aDirectionFlags // parameter to startMuxedDocument. const PRInt32 NS_FASTLOAD_READ = 1; const PRInt32 NS_FASTLOAD_WRITE = 2; - /** - * XXX The only stream legal to set as current is one returned by the - * newInputStream or newOutputStream methods, above. - */ - attribute nsIObjectInputStream currentInputStream; - attribute nsIObjectOutputStream currentOutputStream; - attribute nsIFastLoadFileIO currentFileIO; - readonly attribute PRInt32 currentDirection; + attribute nsIObjectInputStream inputStream; + attribute nsIObjectOutputStream outputStream; + attribute nsIFastLoadFileIO fileIO; + readonly attribute PRInt32 direction; /** - * Consumers of currentInputStream and currentOutputStream should - * attempt to demultiplex data from the current input stream only if - * fastLoadService->StartMuxedDocument(uri, urispec, NS_FASTLOAD_READ) - * succeeds. If StartMuxedDocument fails with NS_ERROR_NOT_AVAILABLE, - * callers should slow-load the document and multiplex its data to the - * current output stream. + * Clients of inputStream and outputStream should try to demultiplex data + * from the input stream only if fastLoadService->StartMuxedDocument(uri, + * urispec, NS_FASTLOAD_READ) succeeds. If StartMuxedDocument fails with + * NS_ERROR_NOT_AVAILABLE, callers should slow-load the documents, muxing + * their data to the current output stream. */ void startMuxedDocument(in nsISupports aURI, in string aURISpec, @@ -73,8 +68,13 @@ interface nsIFastLoadService : nsISupports void selectMuxedDocument(in nsISupports aURI); void endMuxedDocument(in nsISupports aURI); - void appendDependency(in string aFileName); - PRTime maxDependencyModifiedTime(); + void addDependency(in nsIFile aFile); + PRTime maxDependencyModifiedTime(in nsIFastLoadReadControl aControl); + + PRUint32 computeChecksum(in nsIFile aFile, + in nsIFastLoadReadControl aControl); + void cacheChecksum(in nsIFile aFile, + in nsIObjectOutputStream aStream); [noscript] void getFastLoadReferent(inout nsISupports aPtr); @@ -86,29 +86,41 @@ interface nsIFastLoadService : nsISupports }; %{C++ -#define NS_FAST_LOAD_SERVICE_CLASSNAME "Mozilla FastLoad Service" +#define NS_FASTLOADSERVICE_CLASSNAME "Mozilla FastLoad Service" -#define NS_FAST_LOAD_SERVICE_CID \ +#define NS_FASTLOADSERVICE_CID \ {0xc943093c,0xac94,0x4bee,{0x84,0x0b,0x8b,0x5a,0x6e,0x31,0x4f,0xa7}} -#define NS_FAST_LOAD_SERVICE_CONTRACTID \ +#define NS_FASTLOADSERVICE_CONTRACTID \ "@mozilla.org/fast-load-service;1" #ifndef nsCOMPtr_h___ # include "nsCOMPtr.h" #endif +#ifndef __gen_nsIFile_h__ +# include "nsIFile.h" +#endif #ifndef nsIServiceManager_h___ # include "nsIServiceManager.h" #endif -inline nsresult -NS_AppendFastLoadDependency(const char* aFileName) +inline const nsGetServiceByCID +do_GetFastLoadService(nsresult *aResultCode = 0) { - nsCOMPtr - fastLoadService(do_GetService(NS_FAST_LOAD_SERVICE_CONTRACTID)); - if (!fastLoadService) - return NS_OK; - return fastLoadService->AppendDependency(aFileName); + static NS_DEFINE_CID(kFastLoadServiceCID, NS_FASTLOADSERVICE_CID); + return nsGetServiceByCID(kFastLoadServiceCID, nsnull, aResultCode); +} + +inline nsresult +NS_AddFastLoadDependency(nsIFile* aFile) +{ + nsCOMPtr fastLoadService(do_GetFastLoadService()); + if (fastLoadService) { + nsresult rv = fastLoadService->AddDependency(aFile); + if (NS_FAILED(rv) && rv != NS_ERROR_NOT_AVAILABLE) + return rv; + } + return NS_OK; } %} diff --git a/mozilla/xpcom/io/nsISeekableStream.idl b/mozilla/xpcom/io/nsISeekableStream.idl index c0742dfa773..52b17842737 100644 --- a/mozilla/xpcom/io/nsISeekableStream.idl +++ b/mozilla/xpcom/io/nsISeekableStream.idl @@ -36,9 +36,3 @@ interface nsISeekableStream : nsISupports // truncate stream to the current offset void setEOF(); }; - -[uuid(ac3fa453-e173-4044-b827-62d6e45346c6)] -interface nsISeekableOutputStream : nsISupports -{ - unsigned long fill(in charPtr buf, in unsigned long count); -}; diff --git a/mozilla/xpcom/io/nsIStreamBufferAccess.idl b/mozilla/xpcom/io/nsIStreamBufferAccess.idl index d428511f5a5..5a75341745d 100644 --- a/mozilla/xpcom/io/nsIStreamBufferAccess.idl +++ b/mozilla/xpcom/io/nsIStreamBufferAccess.idl @@ -86,6 +86,11 @@ interface nsIStreamBufferAccess : nsISupports */ void disableBuffering(); void enableBuffering(); + + /** + * The underlying, unbuffered input or output stream. + */ + readonly attribute nsISupports unbufferedStream; }; %{C++