From 09be5128d61c3fbae62bb76f53d1ac2977db7dc7 Mon Sep 17 00:00:00 2001 From: "valeski%netscape.com" Date: Sun, 29 Aug 1999 14:31:08 +0000 Subject: [PATCH] added stream converter functionality to the doc loader. also initialize/register the multipartmixedreplace stream converter in the webshell git-svn-id: svn://10.0.0.236/trunk@45046 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/docshell/base/nsWebShell.cpp | 40 +++++++++++++++++++++++ mozilla/uriloader/base/nsDocLoader.cpp | 45 ++++++++++++++++++++++++++ mozilla/webshell/src/nsDocLoader.cpp | 45 ++++++++++++++++++++++++++ mozilla/webshell/src/nsWebShell.cpp | 40 +++++++++++++++++++++++ 4 files changed, 170 insertions(+) diff --git a/mozilla/docshell/base/nsWebShell.cpp b/mozilla/docshell/base/nsWebShell.cpp index 4e78498a801..7f5c19290a8 100644 --- a/mozilla/docshell/base/nsWebShell.cpp +++ b/mozilla/docshell/base/nsWebShell.cpp @@ -68,6 +68,13 @@ #include "prmem.h" #include "nsXPIDLString.h" +#ifndef XP_MAC +#include "nsMultiMixedConv.h" // for +#include "nsIRegistry.h" +static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID); +#endif // XP_MAC + + #ifdef XP_PC #include #endif @@ -1172,6 +1179,39 @@ nsWebShell::Init(nsNativeWidget aNativeParent, widgetInit.mWindowType = eWindowType_child; } + // STREAM CONVERTER REGISTRATION + // multipart mixed converter registration +#ifndef XP_MAC + nsIFactory *multiMixedFactSup; + rv = nsComponentManager::FindFactory(kMultiMixedConverterCID, &multiMixedFactSup); + if (SUCCEEDED(rv)) { + rv = nsComponentManager::RegisterFactory(kMultiMixedConverterCID, + "MultiMixedConverter", + NS_ISTREAMCONVERTER_KEY "?from=multipart/x-mixed-replace?to=text/html", + multiMixedFactSup, + PR_TRUE); + if (NS_FAILED(rv)) goto done; + + nsIRegistry *registry; + rv = nsServiceManager::GetService(kRegistryCID, NS_GET_IID(nsIRegistry), (nsISupports**) ®istry); + if (NS_FAILED(rv)) goto done; + + // open the registry + rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(rv)) goto done; + + // set the key + nsIRegistry::Key key, key1; + + rv = registry->AddSubtree(nsIRegistry::Common, NS_ISTREAMCONVERTER_KEY, &key); + if (NS_FAILED(rv)) goto done; + + rv = registry->AddSubtreeRaw(key, "?from=multipart/x-mixed-replace?to=text/html", &key1); + if (NS_FAILED(rv)) goto done; + } +#endif // XP_MAC + // END STREAM CONVERTER REGISTRATION + done: return rv; } diff --git a/mozilla/uriloader/base/nsDocLoader.cpp b/mozilla/uriloader/base/nsDocLoader.cpp index b7914b4a7c0..036be8cda78 100644 --- a/mozilla/uriloader/base/nsDocLoader.cpp +++ b/mozilla/uriloader/base/nsDocLoader.cpp @@ -57,6 +57,12 @@ #include "prlog.h" #include "prprf.h" +#ifndef XP_MAC +#include "nsIStreamConverterService.h" +#include "nsIStreamConverter.h" +static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID); +#endif // XP_MAC + #include // XXX ick ick ick @@ -2055,6 +2061,7 @@ nsDocumentBindInfo::OnStartRequest(nsIURI* aURL, const char *aContentType) * (and viewer) of the appropriate type... */ if (m_DocLoader) { + rv = m_DocLoader->CreateContentViewer(m_Command, #ifdef NECKO channel, @@ -2382,9 +2389,47 @@ nsChannelListener::OnStartRequest(nsIChannel *aChannel, nsISupports *aContext) nsCOMPtr container; nsCOMPtr viewer; + /////////////////////////////// + // STREAM CONVERTERS + /////////////////////////////// +#ifndef XP_MAC + char *contentType = nsnull; + rv = aChannel->GetContentType(&contentType); + if (NS_FAILED(rv)) return rv; + + // Let's shanghai this channelListener's mNextListener if we want to convert the stream. + if (!PL_strcmp(contentType, "multipart/x-mixed-replace")) { + // we want to pass off multipart/x-mixed-replace to the a stream converter + // that knows what to do with it. + NS_WITH_SERVICE(nsIStreamConverterService, StreamConvService, kStreamConverterServiceCID, &rv); + if (NS_FAILED(rv)) { + nsAllocator::Free(contentType); + return rv; + } + nsString2 from("multipart/x-mixed-replace"), to("text/html"); + + // The following call binds this channelListener's mNextListener (typically + // the nsDocumentBindInfo) to the underlying stream converter, and returns + // the underlying stream converter which we then set to be this channelListener's + // mNextListener. This effectively nestles the stream converter down right + // in between the raw stream and the final listener. + nsIStreamListener *converterListener = nsnull; + rv = StreamConvService->AsyncConvertData(from.GetUnicode(), + to.GetUnicode(), mNextListener, + &converterListener); + mNextListener = converterListener; + } + nsAllocator::Free(contentType); +#endif // XP_MAC + + ////////////////////////////// + // END STREAM CONVERTERS + ////////////////////////////// + // Pass the notification to the next listener... rv = mNextListener->OnStartRequest(aChannel, aContext); + // // Notify the document loader... mDocLoader->GetContainer(getter_AddRefs(container)); diff --git a/mozilla/webshell/src/nsDocLoader.cpp b/mozilla/webshell/src/nsDocLoader.cpp index b7914b4a7c0..036be8cda78 100644 --- a/mozilla/webshell/src/nsDocLoader.cpp +++ b/mozilla/webshell/src/nsDocLoader.cpp @@ -57,6 +57,12 @@ #include "prlog.h" #include "prprf.h" +#ifndef XP_MAC +#include "nsIStreamConverterService.h" +#include "nsIStreamConverter.h" +static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID); +#endif // XP_MAC + #include // XXX ick ick ick @@ -2055,6 +2061,7 @@ nsDocumentBindInfo::OnStartRequest(nsIURI* aURL, const char *aContentType) * (and viewer) of the appropriate type... */ if (m_DocLoader) { + rv = m_DocLoader->CreateContentViewer(m_Command, #ifdef NECKO channel, @@ -2382,9 +2389,47 @@ nsChannelListener::OnStartRequest(nsIChannel *aChannel, nsISupports *aContext) nsCOMPtr container; nsCOMPtr viewer; + /////////////////////////////// + // STREAM CONVERTERS + /////////////////////////////// +#ifndef XP_MAC + char *contentType = nsnull; + rv = aChannel->GetContentType(&contentType); + if (NS_FAILED(rv)) return rv; + + // Let's shanghai this channelListener's mNextListener if we want to convert the stream. + if (!PL_strcmp(contentType, "multipart/x-mixed-replace")) { + // we want to pass off multipart/x-mixed-replace to the a stream converter + // that knows what to do with it. + NS_WITH_SERVICE(nsIStreamConverterService, StreamConvService, kStreamConverterServiceCID, &rv); + if (NS_FAILED(rv)) { + nsAllocator::Free(contentType); + return rv; + } + nsString2 from("multipart/x-mixed-replace"), to("text/html"); + + // The following call binds this channelListener's mNextListener (typically + // the nsDocumentBindInfo) to the underlying stream converter, and returns + // the underlying stream converter which we then set to be this channelListener's + // mNextListener. This effectively nestles the stream converter down right + // in between the raw stream and the final listener. + nsIStreamListener *converterListener = nsnull; + rv = StreamConvService->AsyncConvertData(from.GetUnicode(), + to.GetUnicode(), mNextListener, + &converterListener); + mNextListener = converterListener; + } + nsAllocator::Free(contentType); +#endif // XP_MAC + + ////////////////////////////// + // END STREAM CONVERTERS + ////////////////////////////// + // Pass the notification to the next listener... rv = mNextListener->OnStartRequest(aChannel, aContext); + // // Notify the document loader... mDocLoader->GetContainer(getter_AddRefs(container)); diff --git a/mozilla/webshell/src/nsWebShell.cpp b/mozilla/webshell/src/nsWebShell.cpp index 4e78498a801..7f5c19290a8 100644 --- a/mozilla/webshell/src/nsWebShell.cpp +++ b/mozilla/webshell/src/nsWebShell.cpp @@ -68,6 +68,13 @@ #include "prmem.h" #include "nsXPIDLString.h" +#ifndef XP_MAC +#include "nsMultiMixedConv.h" // for +#include "nsIRegistry.h" +static NS_DEFINE_CID(kRegistryCID, NS_REGISTRY_CID); +#endif // XP_MAC + + #ifdef XP_PC #include #endif @@ -1172,6 +1179,39 @@ nsWebShell::Init(nsNativeWidget aNativeParent, widgetInit.mWindowType = eWindowType_child; } + // STREAM CONVERTER REGISTRATION + // multipart mixed converter registration +#ifndef XP_MAC + nsIFactory *multiMixedFactSup; + rv = nsComponentManager::FindFactory(kMultiMixedConverterCID, &multiMixedFactSup); + if (SUCCEEDED(rv)) { + rv = nsComponentManager::RegisterFactory(kMultiMixedConverterCID, + "MultiMixedConverter", + NS_ISTREAMCONVERTER_KEY "?from=multipart/x-mixed-replace?to=text/html", + multiMixedFactSup, + PR_TRUE); + if (NS_FAILED(rv)) goto done; + + nsIRegistry *registry; + rv = nsServiceManager::GetService(kRegistryCID, NS_GET_IID(nsIRegistry), (nsISupports**) ®istry); + if (NS_FAILED(rv)) goto done; + + // open the registry + rv = registry->OpenWellKnownRegistry(nsIRegistry::ApplicationComponentRegistry); + if (NS_FAILED(rv)) goto done; + + // set the key + nsIRegistry::Key key, key1; + + rv = registry->AddSubtree(nsIRegistry::Common, NS_ISTREAMCONVERTER_KEY, &key); + if (NS_FAILED(rv)) goto done; + + rv = registry->AddSubtreeRaw(key, "?from=multipart/x-mixed-replace?to=text/html", &key1); + if (NS_FAILED(rv)) goto done; + } +#endif // XP_MAC + // END STREAM CONVERTER REGISTRATION + done: return rv; }