From 34620a6326fb70a06f6ddca4f095650994590544 Mon Sep 17 00:00:00 2001 From: "dougt%netscape.com" Date: Thu, 29 Nov 2001 22:29:00 +0000 Subject: [PATCH] fixed bug 112345. JAR Channel does not cache mime service. r=neeti@netscape.com, sr=darin@netscape.com --- modules/libjar/nsJARChannel.cpp | 6 +++--- modules/libjar/nsJARChannel.h | 5 +++-- modules/libjar/nsJARProtocolHandler.cpp | 12 ++++++++++++ modules/libjar/nsJARProtocolHandler.h | 5 +++++ netwerk/protocol/jar/src/nsJARChannel.cpp | 6 +++--- netwerk/protocol/jar/src/nsJARChannel.h | 5 +++-- netwerk/protocol/jar/src/nsJARProtocolHandler.cpp | 12 ++++++++++++ netwerk/protocol/jar/src/nsJARProtocolHandler.h | 5 +++++ 8 files changed, 46 insertions(+), 10 deletions(-) diff --git a/modules/libjar/nsJARChannel.cpp b/modules/libjar/nsJARChannel.cpp index ca7b6afc892..5b05e5560b9 100644 --- a/modules/libjar/nsJARChannel.cpp +++ b/modules/libjar/nsJARChannel.cpp @@ -121,7 +121,7 @@ nsJARChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) } nsresult -nsJARChannel::Init(nsIJARProtocolHandler* aHandler, nsIURI* uri) +nsJARChannel::Init(nsJARProtocolHandler* aHandler, nsIURI* uri) { nsresult rv; mURI = do_QueryInterface(uri, &rv); @@ -410,8 +410,8 @@ nsJARChannel::GetContentType(char* *aContentType) } if (ext) { - nsCOMPtr mimeServ (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) { + nsIMIMEService* mimeServ = mJARProtocolHandler->GetCachedMimeService(); + if (mimeServ) { rv = mimeServ->GetTypeFromExtension(ext, &mContentType); } } diff --git a/modules/libjar/nsJARChannel.h b/modules/libjar/nsJARChannel.h index 4c2977e20e7..f28fd5c9b46 100644 --- a/modules/libjar/nsJARChannel.h +++ b/modules/libjar/nsJARChannel.h @@ -54,6 +54,7 @@ #include "prmon.h" #include "nsIDownloader.h" #include "nsIInputStream.h" +#include "nsJARProtocolHandler.h" #ifdef DEBUG #include "prthread.h" @@ -92,7 +93,7 @@ public: static NS_METHOD Create(nsISupports* aOuter, REFNSIID aIID, void **aResult); - nsresult Init(nsIJARProtocolHandler* aHandler, nsIURI* uri); + nsresult Init(nsJARProtocolHandler* aHandler, nsIURI* uri); nsresult EnsureJARFileAvailable(); nsresult OpenJARElement(); nsresult AsyncReadJARElement(); @@ -101,7 +102,7 @@ public: friend class nsJARDownloadObserver; protected: - nsCOMPtr mJARProtocolHandler; + nsCOMPtr mJARProtocolHandler; nsCOMPtr mURI; nsCOMPtr mLoadGroup; nsCOMPtr mCallbacks; diff --git a/modules/libjar/nsJARProtocolHandler.cpp b/modules/libjar/nsJARProtocolHandler.cpp index fcebdf7260e..a315dd86a9f 100644 --- a/modules/libjar/nsJARProtocolHandler.cpp +++ b/modules/libjar/nsJARProtocolHandler.cpp @@ -45,6 +45,9 @@ #include "nsJARChannel.h" #include "nsXPIDLString.h" #include "nsNetCID.h" +#include "nsCExternalHandlerService.h" +#include "nsIMIMEService.h" +#include "nsMimeTypes.h" static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kJARUriCID, NS_JARURI_CID); @@ -73,6 +76,15 @@ nsJARProtocolHandler::Init() return rv; } +nsIMIMEService* +nsJARProtocolHandler::GetCachedMimeService() +{ + if (!mMimeService) { + mMimeService = do_GetService(NS_MIMESERVICE_CONTRACTID); + } + return mMimeService.get(); +} + nsJARProtocolHandler::~nsJARProtocolHandler() { } diff --git a/modules/libjar/nsJARProtocolHandler.h b/modules/libjar/nsJARProtocolHandler.h index a6ccdca56fa..155e915f3f6 100644 --- a/modules/libjar/nsJARProtocolHandler.h +++ b/modules/libjar/nsJARProtocolHandler.h @@ -42,6 +42,7 @@ #include "nsIProtocolHandler.h" #include "nsIJARURI.h" #include "nsIZipReader.h" +#include "nsIMIMEService.h" #include "nsCOMPtr.h" #define NS_JARPROTOCOLHANDLER_CID \ @@ -69,8 +70,12 @@ public: nsresult Init(); + // returns non addref'ed pointer. + nsIMIMEService* GetCachedMimeService(); + protected: nsCOMPtr mJARCache; + nsCOMPtr mMimeService; }; #endif /* nsJARProtocolHandler_h___ */ diff --git a/netwerk/protocol/jar/src/nsJARChannel.cpp b/netwerk/protocol/jar/src/nsJARChannel.cpp index ca7b6afc892..5b05e5560b9 100644 --- a/netwerk/protocol/jar/src/nsJARChannel.cpp +++ b/netwerk/protocol/jar/src/nsJARChannel.cpp @@ -121,7 +121,7 @@ nsJARChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) } nsresult -nsJARChannel::Init(nsIJARProtocolHandler* aHandler, nsIURI* uri) +nsJARChannel::Init(nsJARProtocolHandler* aHandler, nsIURI* uri) { nsresult rv; mURI = do_QueryInterface(uri, &rv); @@ -410,8 +410,8 @@ nsJARChannel::GetContentType(char* *aContentType) } if (ext) { - nsCOMPtr mimeServ (do_GetService(NS_MIMESERVICE_CONTRACTID, &rv)); - if (NS_SUCCEEDED(rv)) { + nsIMIMEService* mimeServ = mJARProtocolHandler->GetCachedMimeService(); + if (mimeServ) { rv = mimeServ->GetTypeFromExtension(ext, &mContentType); } } diff --git a/netwerk/protocol/jar/src/nsJARChannel.h b/netwerk/protocol/jar/src/nsJARChannel.h index 4c2977e20e7..f28fd5c9b46 100644 --- a/netwerk/protocol/jar/src/nsJARChannel.h +++ b/netwerk/protocol/jar/src/nsJARChannel.h @@ -54,6 +54,7 @@ #include "prmon.h" #include "nsIDownloader.h" #include "nsIInputStream.h" +#include "nsJARProtocolHandler.h" #ifdef DEBUG #include "prthread.h" @@ -92,7 +93,7 @@ public: static NS_METHOD Create(nsISupports* aOuter, REFNSIID aIID, void **aResult); - nsresult Init(nsIJARProtocolHandler* aHandler, nsIURI* uri); + nsresult Init(nsJARProtocolHandler* aHandler, nsIURI* uri); nsresult EnsureJARFileAvailable(); nsresult OpenJARElement(); nsresult AsyncReadJARElement(); @@ -101,7 +102,7 @@ public: friend class nsJARDownloadObserver; protected: - nsCOMPtr mJARProtocolHandler; + nsCOMPtr mJARProtocolHandler; nsCOMPtr mURI; nsCOMPtr mLoadGroup; nsCOMPtr mCallbacks; diff --git a/netwerk/protocol/jar/src/nsJARProtocolHandler.cpp b/netwerk/protocol/jar/src/nsJARProtocolHandler.cpp index fcebdf7260e..a315dd86a9f 100644 --- a/netwerk/protocol/jar/src/nsJARProtocolHandler.cpp +++ b/netwerk/protocol/jar/src/nsJARProtocolHandler.cpp @@ -45,6 +45,9 @@ #include "nsJARChannel.h" #include "nsXPIDLString.h" #include "nsNetCID.h" +#include "nsCExternalHandlerService.h" +#include "nsIMIMEService.h" +#include "nsMimeTypes.h" static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kJARUriCID, NS_JARURI_CID); @@ -73,6 +76,15 @@ nsJARProtocolHandler::Init() return rv; } +nsIMIMEService* +nsJARProtocolHandler::GetCachedMimeService() +{ + if (!mMimeService) { + mMimeService = do_GetService(NS_MIMESERVICE_CONTRACTID); + } + return mMimeService.get(); +} + nsJARProtocolHandler::~nsJARProtocolHandler() { } diff --git a/netwerk/protocol/jar/src/nsJARProtocolHandler.h b/netwerk/protocol/jar/src/nsJARProtocolHandler.h index a6ccdca56fa..155e915f3f6 100644 --- a/netwerk/protocol/jar/src/nsJARProtocolHandler.h +++ b/netwerk/protocol/jar/src/nsJARProtocolHandler.h @@ -42,6 +42,7 @@ #include "nsIProtocolHandler.h" #include "nsIJARURI.h" #include "nsIZipReader.h" +#include "nsIMIMEService.h" #include "nsCOMPtr.h" #define NS_JARPROTOCOLHANDLER_CID \ @@ -69,8 +70,12 @@ public: nsresult Init(); + // returns non addref'ed pointer. + nsIMIMEService* GetCachedMimeService(); + protected: nsCOMPtr mJARCache; + nsCOMPtr mMimeService; }; #endif /* nsJARProtocolHandler_h___ */