diff --git a/modules/libjar/nsJARChannel.cpp b/modules/libjar/nsJARChannel.cpp index d20a5c82808..65ebdb7564d 100644 --- a/modules/libjar/nsJARChannel.cpp +++ b/modules/libjar/nsJARChannel.cpp @@ -34,7 +34,6 @@ #include "nsIProgressEventSink.h" #include "nsXPIDLString.h" #include "nsIJAR.h" -#include "nsIResProtocolHandler.h" static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID); @@ -287,7 +286,6 @@ nsresult nsJARChannel::EnsureJARFileAvailable() { nsresult rv; - nsCOMPtr fileURL; #ifdef PR_LOGGING nsXPIDLCString jarURLStr; @@ -302,28 +300,13 @@ nsJARChannel::EnsureJARFileAvailable() rv = mURI->GetJAREntry(&mJAREntry); if (NS_FAILED(rv)) goto error; - // try to get a nsIFile directly from the url, which will often succeed. - fileURL = do_QueryInterface(mJARBaseURI); - if (fileURL) - fileURL->GetFile(getter_AddRefs(mDownloadedJARFile)); + rv = NS_NewDownloader(getter_AddRefs(mDownloader), + mJARBaseURI, this, nsnull, mSynchronousRead, + mLoadGroup, mCallbacks, mLoadFlags); - if (mDownloadedJARFile) { - // after successfully downloading the jar file to the cache, - // start the extraction process: - if (mSynchronousRead) - rv = OpenJARElement(); - else - rv = AsyncReadJARElement(); - } - else { - rv = NS_NewDownloader(getter_AddRefs(mDownloader), - mJARBaseURI, this, nsnull, mSynchronousRead, - mLoadGroup, mCallbacks, mLoadFlags); - - // if DownloadComplete() was called early, need to release the reference. - if (mSynchronousRead && mSynchronousInputStream) - mDownloader = 0; - } + // if DownloadComplete() was called early, need to release the reference. + if (mSynchronousRead && mSynchronousInputStream) + mDownloader = null_nsCOMPtr(); error: if (NS_FAILED(rv) && mLoadGroup) { diff --git a/netwerk/macbuild/netwerk.mcp b/netwerk/macbuild/netwerk.mcp index f3dcdac65d8..61642c989b9 100644 Binary files a/netwerk/macbuild/netwerk.mcp and b/netwerk/macbuild/netwerk.mcp differ diff --git a/netwerk/protocol/jar/src/nsJARChannel.cpp b/netwerk/protocol/jar/src/nsJARChannel.cpp index d20a5c82808..65ebdb7564d 100644 --- a/netwerk/protocol/jar/src/nsJARChannel.cpp +++ b/netwerk/protocol/jar/src/nsJARChannel.cpp @@ -34,7 +34,6 @@ #include "nsIProgressEventSink.h" #include "nsXPIDLString.h" #include "nsIJAR.h" -#include "nsIResProtocolHandler.h" static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID); static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID); @@ -287,7 +286,6 @@ nsresult nsJARChannel::EnsureJARFileAvailable() { nsresult rv; - nsCOMPtr fileURL; #ifdef PR_LOGGING nsXPIDLCString jarURLStr; @@ -302,28 +300,13 @@ nsJARChannel::EnsureJARFileAvailable() rv = mURI->GetJAREntry(&mJAREntry); if (NS_FAILED(rv)) goto error; - // try to get a nsIFile directly from the url, which will often succeed. - fileURL = do_QueryInterface(mJARBaseURI); - if (fileURL) - fileURL->GetFile(getter_AddRefs(mDownloadedJARFile)); + rv = NS_NewDownloader(getter_AddRefs(mDownloader), + mJARBaseURI, this, nsnull, mSynchronousRead, + mLoadGroup, mCallbacks, mLoadFlags); - if (mDownloadedJARFile) { - // after successfully downloading the jar file to the cache, - // start the extraction process: - if (mSynchronousRead) - rv = OpenJARElement(); - else - rv = AsyncReadJARElement(); - } - else { - rv = NS_NewDownloader(getter_AddRefs(mDownloader), - mJARBaseURI, this, nsnull, mSynchronousRead, - mLoadGroup, mCallbacks, mLoadFlags); - - // if DownloadComplete() was called early, need to release the reference. - if (mSynchronousRead && mSynchronousInputStream) - mDownloader = 0; - } + // if DownloadComplete() was called early, need to release the reference. + if (mSynchronousRead && mSynchronousInputStream) + mDownloader = null_nsCOMPtr(); error: if (NS_FAILED(rv) && mLoadGroup) { diff --git a/netwerk/protocol/res/public/nsIResProtocolHandler.idl b/netwerk/protocol/res/public/nsIResProtocolHandler.idl index 6470604398f..cf3a309a68c 100644 --- a/netwerk/protocol/res/public/nsIResProtocolHandler.idl +++ b/netwerk/protocol/res/public/nsIResProtocolHandler.idl @@ -75,9 +75,4 @@ interface nsIResProtocolHandler : nsIProtocolHandler * Returns true if substitutions are already defined for the specified root. */ boolean hasSubstitutions(in string root); - - /** - * Resolution utility function. - */ - string resolveURI(in nsIURI resourceURI); }; diff --git a/netwerk/protocol/res/src/Makefile.in b/netwerk/protocol/res/src/Makefile.in index 213f04dc04f..4f4bcf35da9 100644 --- a/netwerk/protocol/res/src/Makefile.in +++ b/netwerk/protocol/res/src/Makefile.in @@ -31,7 +31,7 @@ LIBRARY_NAME = nkres_s REQUIRES = xpcom string CPPSRCS = \ - nsResURL.cpp \ + nsResChannel.cpp \ nsResProtocolHandler.cpp \ $(NULL) diff --git a/netwerk/protocol/res/src/makefile.win b/netwerk/protocol/res/src/makefile.win index f25cfc23bf6..f9af931aa48 100644 --- a/netwerk/protocol/res/src/makefile.win +++ b/netwerk/protocol/res/src/makefile.win @@ -27,7 +27,7 @@ LIBRARY_NAME=nkres_s LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET CPP_OBJS= \ - .\$(OBJDIR)\nsResURL.obj \ + .\$(OBJDIR)\nsResChannel.obj \ .\$(OBJDIR)\nsResProtocolHandler.obj \ $(NULL) diff --git a/netwerk/protocol/res/src/nsResProtocolHandler.cpp b/netwerk/protocol/res/src/nsResProtocolHandler.cpp index 56ee4354a6e..e075b2757f7 100644 --- a/netwerk/protocol/res/src/nsResProtocolHandler.cpp +++ b/netwerk/protocol/res/src/nsResProtocolHandler.cpp @@ -26,6 +26,8 @@ #include "nsIURL.h" #include "nsIIOService.h" #include "nsIServiceManager.h" +#include "nsResChannel.h" +#include "nsIFileChannel.h" #include "prenv.h" #include "prmem.h" #include "prprf.h" @@ -33,30 +35,16 @@ #include "nsIFile.h" #include "nsDirectoryServiceDefs.h" #include "nsNetCID.h" -#include "nsResURL.h" +#include "nsNetUtil.h" static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); -static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); //////////////////////////////////////////////////////////////////////////////// -nsResProtocolHandler *nsResProtocolHandler::mGlobalInstance = nsnull; - nsResProtocolHandler::nsResProtocolHandler() : mLock(nsnull), mSubstitutions(32) { NS_INIT_REFCNT(); - - NS_ASSERTION(!mGlobalInstance, "res handler already created!"); - mGlobalInstance = this; -} - -nsResProtocolHandler::~nsResProtocolHandler() -{ - if (mLock) - PR_DestroyLock(mLock); - - mGlobalInstance = nsnull; } nsresult @@ -67,8 +55,14 @@ nsResProtocolHandler::SetSpecialDir(const char* rootName, const char* sysDir) rv = NS_GetSpecialDirectory(sysDir, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; + nsCOMPtr fileURL(do_CreateInstance(kStandardURLCID, &rv)); + if (NS_FAILED(rv)) return rv; + + rv = fileURL->SetFile(file); + if (NS_FAILED(rv)) return rv; + nsXPIDLCString spec; - rv = file->GetURL(getter_Copies(spec)); + rv = fileURL->GetSpec(getter_Copies(spec)); if (NS_FAILED(rv)) return rv; return AppendSubstitution(rootName, spec); @@ -79,9 +73,6 @@ nsResProtocolHandler::Init() { nsresult rv; - mIOService = do_GetService(kIOServiceCID, &rv); - if (NS_FAILED(rv)) return rv; - mLock = PR_NewLock(); if (mLock == nsnull) return NS_ERROR_OUT_OF_MEMORY; @@ -130,6 +121,12 @@ nsResProtocolHandler::Init() return rv; } +nsResProtocolHandler::~nsResProtocolHandler() +{ + if (mLock) + PR_DestroyLock(mLock); +} + NS_IMPL_THREADSAFE_ISUPPORTS3(nsResProtocolHandler, nsIResProtocolHandler, nsIProtocolHandler, nsISupportsWeakReference) NS_METHOD @@ -182,31 +179,23 @@ nsResProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI, { nsresult rv; - nsCOMPtr uri(do_CreateInstance(kStandardURLCID, &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 = uri->SetSpec(aResolvedURI); + rv = url->SetSpec(aResolvedURI); } else { - rv = uri->SetSpec((char*)aSpec); + rv = url->SetSpec((char*)aSpec); } if (NS_FAILED(rv)) return rv; - nsResURL *resURL; - NS_NEWXPCOM(resURL, nsResURL); - if (!resURL) - return NS_ERROR_OUT_OF_MEMORY; - NS_ADDREF(resURL); - - rv = resURL->Init(uri); - if (NS_SUCCEEDED(rv)) - rv = CallQueryInterface(resURL, result); - NS_RELEASE(resURL); + *result = url; + NS_ADDREF(*result); return rv; } @@ -214,15 +203,19 @@ NS_IMETHODIMP nsResProtocolHandler::NewChannel(nsIURI* uri, nsIChannel* *result) { nsresult rv; - nsXPIDLCString spec; - - rv = ResolveURI(uri, getter_Copies(spec)); + + nsResChannel* channel; + rv = nsResChannel::Create(nsnull, NS_GET_IID(nsIResChannel), (void**)&channel); if (NS_FAILED(rv)) return rv; - rv = mIOService->NewChannel(spec, nsnull, result); - if (NS_FAILED(rv)) return rv; + rv = channel->Init(this, uri); + if (NS_FAILED(rv)) { + NS_RELEASE(channel); + return rv; + } - return (*result)->SetOriginalURI(uri); + *result = (nsIChannel*)(nsIResChannel*)channel; + return NS_OK; } NS_IMETHODIMP @@ -240,8 +233,10 @@ nsResProtocolHandler::PrependSubstitution(const char *root, const char *urlStr) nsresult rv; nsAutoLock lock(mLock); + nsCOMPtr ioServ = do_GetIOService(&rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr url; - rv = mIOService->NewURI(urlStr, nsnull, getter_AddRefs(url)); + rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; nsCStringKey key(root); @@ -275,8 +270,10 @@ nsResProtocolHandler::AppendSubstitution(const char *root, const char *urlStr) nsresult rv; nsAutoLock lock(mLock); + nsCOMPtr ioServ = do_GetIOService(&rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr url; - rv = mIOService->NewURI(urlStr, nsnull, getter_AddRefs(url)); + rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; nsCStringKey key(root); @@ -329,8 +326,10 @@ nsResProtocolHandler::RemoveSubstitution(const char *root, const char *urlStr) nsresult rv; nsAutoLock lock(mLock); + nsCOMPtr ioServ = do_GetIOService(&rv); + if (NS_FAILED(rv)) return rv; nsCOMPtr url; - rv = mIOService->NewURI(urlStr, nsnull, getter_AddRefs(url)); + rv = ioServ->NewURI(urlStr, nsnull, getter_AddRefs(url)); if (NS_FAILED(rv)) return rv; nsCStringKey key(root); @@ -383,29 +382,4 @@ nsResProtocolHandler::HasSubstitutions(const char *root, PRBool *result) return NS_OK; } -NS_IMETHODIMP -nsResProtocolHandler::ResolveURI(nsIURI *uri, char **result) -{ - nsresult rv; - nsXPIDLCString host, path; - - rv = uri->GetHost(getter_Copies(host)); - if (NS_FAILED(rv)) return rv; - - rv = uri->GetPath(getter_Copies(path)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr substitutions; - rv = GetSubstitutions(host.get() ? - host.get() : "", getter_AddRefs(substitutions)); - if (NS_FAILED(rv)) return rv; - - // always use the first substitution - nsCOMPtr substURI; - rv = substitutions->GetElementAt(0, getter_AddRefs(substURI)); - if (NS_FAILED(rv)) return rv; - - return substURI->Resolve(path[0] == '/' ? path.get()+1 : path.get(), result); -} - //////////////////////////////////////////////////////////////////////////////// diff --git a/netwerk/protocol/res/src/nsResProtocolHandler.h b/netwerk/protocol/res/src/nsResProtocolHandler.h index a6ce0d4a4ee..a0bb61404a3 100644 --- a/netwerk/protocol/res/src/nsResProtocolHandler.h +++ b/netwerk/protocol/res/src/nsResProtocolHandler.h @@ -26,7 +26,6 @@ #include "nsIResProtocolHandler.h" #include "nsHashtable.h" #include "nsISupportsArray.h" -#include "nsIIOService.h" #include "nsWeakReference.h" class nsResProtocolHandler : public nsIResProtocolHandler, public nsSupportsWeakReference @@ -46,14 +45,9 @@ public: nsresult Init(); nsresult SetSpecialDir(const char* rootName, const char* specialDir); - static nsResProtocolHandler *get() { return mGlobalInstance; } - -private: - static nsResProtocolHandler *mGlobalInstance; - - PRLock* mLock; - nsSupportsHashtable mSubstitutions; - nsCOMPtr mIOService; +protected: + PRLock* mLock; + nsSupportsHashtable mSubstitutions; }; #endif /* nsResProtocolHandler_h___ */ diff --git a/netwerk/protocol/res/src/nsResURL.cpp b/netwerk/protocol/res/src/nsResURL.cpp index 330f7c0c7b0..e69de29bb2d 100644 --- a/netwerk/protocol/res/src/nsResURL.cpp +++ b/netwerk/protocol/res/src/nsResURL.cpp @@ -1,84 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla. - * - * The Initial Developer of the Original Code is Netscape - * Communications. Portions created by Netscape Communications are - * Copyright (C) 2001 by Netscape Communications. All - * Rights Reserved. - * - * Contributor(s): - * Darin Fisher (original author) - */ - -#include "nsResURL.h" -#include "nsResProtocolHandler.h" -#include "nsNetCID.h" -#include "nsILocalFile.h" -#include "nsXPIDLString.h" - -static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID); - -//----------------------------------------------------------------------------- -// nsResURL -//----------------------------------------------------------------------------- - -nsresult -nsResURL::Init(nsIURI *uri) -{ - nsresult rv; - mStdURL = do_QueryInterface(uri, &rv); - return rv; -} - -//----------------------------------------------------------------------------- -// nsResURL::nsISupports -//----------------------------------------------------------------------------- - -NS_IMPL_ISUPPORTS3(nsResURL, - nsIURI, - nsIURL, - nsIFileURL) - -//----------------------------------------------------------------------------- -// nsResURL::nsIFileURL -//----------------------------------------------------------------------------- - -NS_IMETHODIMP -nsResURL::GetFile(nsIFile **result) -{ - nsresult rv; - - NS_ENSURE_TRUE(nsResProtocolHandler::get(), NS_ERROR_NOT_AVAILABLE); - NS_ENSURE_TRUE(mStdURL, NS_ERROR_NOT_INITIALIZED); - - nsXPIDLCString spec; - rv = nsResProtocolHandler::get()->ResolveURI(mStdURL, getter_Copies(spec)); - if (NS_FAILED(rv)) return rv; - - nsCOMPtr localFile = - do_CreateInstance(NS_LOCAL_FILE_CONTRACTID, &rv); - if (NS_FAILED(rv)) return rv; - - rv = localFile->SetURL(spec); - if (NS_FAILED(rv)) return rv; - - return CallQueryInterface(localFile, result); -} - -NS_IMETHODIMP -nsResURL::SetFile(nsIFile *file) -{ - NS_NOTREACHED("nsResURL::SetFile not implemented\n"); - return NS_ERROR_NOT_IMPLEMENTED; -} diff --git a/netwerk/protocol/res/src/nsResURL.h b/netwerk/protocol/res/src/nsResURL.h index 3404f971c3e..e69de29bb2d 100644 --- a/netwerk/protocol/res/src/nsResURL.h +++ b/netwerk/protocol/res/src/nsResURL.h @@ -1,51 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * The contents of this file are subject to the Mozilla Public - * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or - * implied. See the License for the specific language governing - * rights and limitations under the License. - * - * The Original Code is Mozilla. - * - * The Initial Developer of the Original Code is Netscape - * Communications. Portions created by Netscape Communications are - * Copyright (C) 2001 by Netscape Communications. All - * Rights Reserved. - * - * Contributor(s): - * Darin Fisher (original author) - */ - -#ifndef nsResURL_h__ -#define nsResURL_h__ - -#include "nsIFileChannel.h" -#include "nsCOMPtr.h" - -//----------------------------------------------------------------------------- -// nsResURL : overrides nsStdURL::nsIFileURL to provide nsIFile resolution -//----------------------------------------------------------------------------- - -class nsResURL : nsIFileURL -{ -public: - NS_DECL_ISUPPORTS - NS_FORWARD_SAFE_NSIURI(mStdURL) - NS_FORWARD_SAFE_NSIURL(mStdURL) - NS_DECL_NSIFILEURL - - nsResURL() { NS_INIT_ISUPPORTS(); } - virtual ~nsResURL() {} - - nsresult Init(nsIURI *); - -private: - nsCOMPtr mStdURL; -}; - -#endif // nsResURL_h__